Re: [PATCH v3 06/12] refs: add refs_head_ref()
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Apr 22, 2017, 08:15 UTC
- Message-ID
- <CACsJy8ADCVBiLoPg_Tz0L6CMdh_eFmK4RYzfQ-PmUgBK7w9e=A@mail.gmail.com>
- In-Reply-To
- <4519cd91-80e1-a416-658e-e10e542b41ff@alum.mit.edu>
On Sat, Apr 22, 2017 at 1:37 PM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
Show 65 quoted lines
> On 04/19/2017 01:01 PM, Nguyễn Thái Ngọc Duy wrote:
>> 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()`.Eventually it's the caller's responsibility not to pass NULL ref store to refs_* functions. That happens in "revision.c: use refs_for_each*() instead of for_each_*_submodule()" patch, which is too late and would break bisect. Will fix.
-- Duy