Subject: Re: [PATCH v3 16/44] refs.c: move ref iterators to the common code

From: Michael Haggerty <[email-masked]>
Date: Tue, 13 Oct 2015 06:12:42 +0200

On 10/12/2015 11:51 PM, David Turner wrote:
> From: Ronnie Sahlberg <[email-masked]>
> 
> Signed-off-by: Ronnie Sahlberg <[email-masked]>
> ---
>  refs-be-files.c | 82 ---------------------------------------------------------
>  refs.c          | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 81 insertions(+), 82 deletions(-)
> 
> diff --git a/refs-be-files.c b/refs-be-files.c
> index ecf2b33..46fa43c 100644
> --- a/refs-be-files.c
> +++ b/refs-be-files.c
> [...]
> @@ -2012,40 +1964,6 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
>  	return ret;
>  }
>  
> -int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
> -	const char *prefix, void *cb_data)
> -{
> -	struct strbuf real_pattern = STRBUF_INIT;
> -	struct ref_filter filter;
> -	int ret;
> -
> -	if (!prefix && !starts_with(pattern, "refs/"))
> -		strbuf_addstr(&real_pattern, "refs/");
> -	else if (prefix)
> -		strbuf_addstr(&real_pattern, prefix);
> -	strbuf_addstr(&real_pattern, pattern);
> -
> -	if (!has_glob_specials(pattern)) {
> -		/* Append implied '/' '*' if not present. */
> -		strbuf_complete(&real_pattern, '/');
> -		/* No need to check for '*', there is none. */
> -		strbuf_addch(&real_pattern, '*');
> -	}
> -
> -	filter.pattern = real_pattern.buf;
> -	filter.fn = fn;
> -	filter.cb_data = cb_data;
> -	ret = for_each_ref(filter_refs, &filter);
> -
> -	strbuf_release(&real_pattern);
> -	return ret;
> -}
> -
> [...]
> diff --git a/refs.c b/refs.c
> index 44ee4f4..7714dad 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -781,3 +781,84 @@ const char *prettify_refname(const char *name)
>  		starts_with(name, "refs/remotes/") ? 13 :
>  		0);
>  }
> [...]
> +int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
> +	const char *prefix, void *cb_data)
> +{
> +	struct strbuf real_pattern = STRBUF_INIT;
> +	struct ref_filter filter;
> +	int ret;
> +
> +	if (!prefix && !starts_with(pattern, "refs/"))
> +		strbuf_addstr(&real_pattern, "refs/");
> +	else if (prefix)
> +		strbuf_addstr(&real_pattern, prefix);
> +	strbuf_addstr(&real_pattern, pattern);
> +
> +	if (!has_glob_specials(pattern)) {
> +		/* Append implied '/' '*' if not present. */
> +		if (real_pattern.buf[real_pattern.len - 1] != '/')
> +			strbuf_addch(&real_pattern, '/');

The original has

		strbuf_complete(&real_pattern, '/');

in place of the above two lines. I think you made a mistake when
rebasing on top of

    00b6c178c3 use strbuf_complete to conditionally append slash

> +		/* No need to check for '*', there is none. */
> +		strbuf_addch(&real_pattern, '*');
> +	}
> +
> +	filter.pattern = real_pattern.buf;
> +	filter.fn = fn;
> +	filter.cb_data = cb_data;
> +	ret = for_each_ref(filter_refs, &filter);
> +
> +	strbuf_release(&real_pattern);
> +	return ret;
> +}
> +
> [...]

Michael

-- 
Michael Haggerty
[email-masked]