All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: mhagger@alum.mit.edu
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	Jakub Narebski <jnareb@gmail.com>,
	Heiko Voigt <hvoigt@hvoigt.net>,
	Johan Herland <johan@herland.net>,
	Christian Couder <chriscool@tuxfamily.org>
Subject: Re: [PATCH v2 05/18] refs.c: extract function search_for_subdir()
Date: Thu, 03 May 2012 12:48:05 -0700	[thread overview]
Message-ID: <7v4nrxf3m2.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1335479227-7877-6-git-send-email-mhagger@alum.mit.edu> (mhagger@alum.mit.edu's message of "Fri, 27 Apr 2012 00:26:54 +0200")

mhagger@alum.mit.edu writes:

> From: Michael Haggerty <mhagger@alum.mit.edu>
>
>
> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> ---
>  refs.c |   34 ++++++++++++++++++++++++----------
>  1 file changed, 24 insertions(+), 10 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index 01fcdc7..5e51c10 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -277,6 +277,27 @@ static struct ref_entry *search_ref_dir(struct ref_dir *dir, const char *refname
>  }
>  
>  /*
> + * Search for a directory entry directly within dir (without
> + * recursing).  Sort dir if necessary.  subdirname must be a directory
> + * name (i.e., end in '/').  If mkdir is set, then create the
> + * directory if it is missing; otherwise, return NULL if the desired
> + * directory cannot be found.
> + */
> +static struct ref_entry *search_for_subdir(struct ref_dir *dir,
> +					   const char *subdirname, int mkdir)
> +{
> +	struct ref_entry *entry = search_ref_dir(dir, subdirname);
> +	if (!entry) {
> +		if (!mkdir)
> +			return NULL;
> +		entry = create_dir_entry(subdirname);
> +		add_entry_to_dir(dir, entry);
> +	}
> +	assert(entry->flag & REF_DIR);
> +	return entry;
> +}
> +
> +/*
>   * If refname is a reference name, find the ref_dir within the dir
>   * tree that should hold refname.  If refname is a directory name
>   * (i.e., ends in '/'), then return that ref_dir itself.  dir must
> @@ -294,17 +315,10 @@ static struct ref_dir *find_containing_dir(struct ref_dir *dir,
>  	for (slash = strchr(refname_copy, '/'); slash; slash = strchr(slash + 1, '/')) {
>  		char tmp = slash[1];
>  		slash[1] = '\0';
> -		entry = search_ref_dir(dir, refname_copy);
> -		if (!entry) {
> -			if (!mkdir) {
> -				dir = NULL;
> -				break;
> -			}
> -			entry = create_dir_entry(refname_copy);
> -			add_entry_to_dir(dir, entry);
> -		}
> +		entry = search_for_subdir(dir, refname_copy, mkdir);
>  		slash[1] = tmp;
> -		assert(entry->flag & REF_DIR);
> +		if (!entry)
> +			break;
>  		dir = &entry->u.subdir;
>  	}

Hrm.  The old code used to reset "dir" to NULL before breaking, so the
entire function used to return NULL.  Now, it calls search_for_subdir(),
which calls search_ref_dir() and gets NULL in entry, and returns NULL.

Wouldn't we end up returning the original parameter "dir" instead of NULL
in that case?  Would that make a difference?

  reply	other threads:[~2012-05-03 19:48 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-26 22:26 [PATCH v2 00/18] Read loose references lazily mhagger
2012-04-26 22:26 ` [PATCH v2 01/18] get_ref_dir(): return early if directory cannot be read mhagger
2012-04-26 22:26 ` [PATCH v2 02/18] get_ref_dir(): use a strbuf to hold refname mhagger
2012-04-26 22:26 ` [PATCH v2 03/18] get_ref_dir(): rename "base" parameter to "dirname" mhagger
2012-04-26 22:26 ` [PATCH v2 04/18] get_ref_dir(): require that the dirname argument ends in '/' mhagger
2012-04-26 22:26 ` [PATCH v2 05/18] refs.c: extract function search_for_subdir() mhagger
2012-05-03 19:48   ` Junio C Hamano [this message]
2012-05-03 20:56     ` Junio C Hamano
2012-05-04  7:24       ` Michael Haggerty
2012-04-26 22:26 ` [PATCH v2 06/18] get_ref_dir(): take the containing directory as argument mhagger
2012-04-26 22:26 ` [PATCH v2 07/18] do_for_each_reflog(): return early on error mhagger
2012-04-26 22:26 ` [PATCH v2 08/18] do_for_each_reflog(): use a strbuf to hold logfile name mhagger
2012-04-26 23:25   ` Junio C Hamano
2012-04-27  8:59     ` Michael Haggerty
2012-05-02 20:06       ` Junio C Hamano
2012-05-03  6:47         ` Michael Haggerty
2012-04-26 22:26 ` [PATCH v2 09/18] do_for_each_reflog(): reuse strbuf across recursive function calls mhagger
2012-04-26 22:26 ` [PATCH v2 10/18] bisect: copy filename string obtained from git_path() mhagger
2012-04-26 22:27 ` [PATCH v2 11/18] find_containing_dir(): use strbuf in implementation of this function mhagger
2012-04-26 22:27 ` [PATCH v2 12/18] refs: wrap top-level ref_dirs in ref_entries mhagger
2012-04-26 22:27 ` [PATCH v2 13/18] read_loose_refs(): rename function from get_ref_dir() mhagger
2012-04-26 22:27 ` [PATCH v2 14/18] get_ref_dir(): add function for getting a ref_dir from a ref_entry mhagger
2012-04-26 22:27 ` [PATCH v2 15/18] search_for_subdir(): return (ref_dir *) instead of (ref_entry *) mhagger
2012-04-26 22:27 ` [PATCH v2 16/18] struct ref_dir: store a reference to the enclosing ref_cache mhagger
2012-04-26 22:27 ` [PATCH v2 17/18] read_loose_refs(): eliminate ref_cache argument mhagger
2012-04-26 22:27 ` [PATCH v2 18/18] refs: read loose references lazily mhagger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v4nrxf3m2.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=hvoigt@hvoigt.net \
    --cc=jnareb@gmail.com \
    --cc=johan@herland.net \
    --cc=mhagger@alum.mit.edu \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.