Re: [PATCH v3 06/12] refs: add refs_head_ref()
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Apr 22, 2017, 06:37 UTC
- Message-ID
- <4519cd91-80e1-a416-658e-e10e542b41ff@alum.mit.edu>
- In-Reply-To
- <20170419110145.5086-7-pclouds@gmail.com>
On 04/19/2017 01:01 PM, Nguyễn Thái Ngọc Duy wrote:
Show 61 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> refs.c | 19 +++++++++----------
> refs.h | 2 ++
> 2 files changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index 26474cb62a..a252ae43ee 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1208,27 +1208,26 @@ int refs_rename_ref_available(struct ref_store *refs,
> return ok;
> }
>
> -int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
> +int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
> {
> struct object_id oid;
> int flag;
>
> - if (submodule) {
> - if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0)
> - return fn("HEAD", &oid, 0, cb_data);
> -
> - return 0;
> - }
> -
> - if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag))
> + if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING,
> + oid.hash, &flag))
> return fn("HEAD", &oid, flag, cb_data);
>
> return 0;
> }
>
> +int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
> +{
> + return refs_head_ref(get_submodule_ref_store(submodule), fn, cb_data);
> +}
> +
> int head_ref(each_ref_fn fn, void *cb_data)
> {
> - return head_ref_submodule(NULL, fn, cb_data);
> + return refs_head_ref(get_main_ref_store(), fn, cb_data);
> }
>
> /*
> diff --git a/refs.h b/refs.h
> index 447381d378..0572473ef7 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -233,6 +233,8 @@ typedef int each_ref_fn(const char *refname,
> * modifies the reference also returns a nonzero value to immediately
> * stop the iteration. Returned references are sorted.
> */
> +int refs_head_ref(struct ref_store *refs,
> + each_ref_fn fn, void *cb_data);
> int refs_for_each_ref(struct ref_store *refs,
> each_ref_fn fn, void *cb_data);
> int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
> I'm seeing segfaults in t3600 after this patch, apparently because `refs==NULL` gets passed from `head_ref_submodule()` to `refs_head_ref()`.
Michael