git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] lock_ref_sha1_basic: handle REF_NODEREF with invalid refs

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 12, 2016, 18:11 UTC
Message-ID
<xmqq4meivfak.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160112095257.GB9855@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 13 quoted lines
> On Tue, Jan 12, 2016 at 05:55:25AM +0100, Michael Haggerty wrote:
>
>> On 01/11/2016 04:52 PM, Jeff King wrote:
>> > We sometimes call lock_ref_sha1_basic both with REF_NODEREF
>> > to operate directly on a symbolic ref.
>> 
>> ^^^ This sentence seems to be missing some words.
>
> I think it has one too many. :)
>
> It was originally "both with a regular ref and with a symref", but I
> shortened it since we only care about the symref case. I think just
> getting rid of "both" is the right thing.

Thanks, I did notice this and wondered the same while reviewing, but totally forgot about it when I queued X-<.

Show 34 quoted lines
>> > diff --git a/refs/files-backend.c b/refs/files-backend.c
>> > index 180c837..ea67d82 100644
>> > --- a/refs/files-backend.c
>> > +++ b/refs/files-backend.c
>> > @@ -1901,6 +1901,10 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
>> >  
>> >  	refname = resolve_ref_unsafe(refname, resolve_flags,
>> >  				     lock->old_oid.hash, &type);
>> > +	if (!refname && (flags & REF_NODEREF))
>> > +		refname = resolve_ref_unsafe(orig_refname,
>> > +					     resolve_flags | RESOLVE_REF_NO_RECURSE,
>> > +					     lock->old_oid.hash, &type);
>> > [...]
>> 
>> The main risk for this change would be that this new recovery code
>> allows the function to continue, but one of the outputs of the second
>> function invocation is not correct for the code that follows. Let me
>> think out loud:
>> 
>> * refname -- now will be equal to orig_refname. I think the main effect
>> is that it will be passed to verify_refname_available_dir(). This seems
>> to be what we want.
>> 
>> * type -- now reflects orig_refname; i.e., usually REF_ISSYMREF. This
>> also seems correct.
>> 
>> * lock->old_oid.hash -- is now ZEROS. This might get compared to the
>> caller's old_sha1 in verify_lock(), and it will also be written to the
>> reflog as the "old" value. I think this is also what we want.
>> 
>> So this change looks good to me.
>
> Thanks. I had a nagging feeling that I hadn't considered all cases, but
> the way you've framed it makes sense to me.
Sounds good.  Thanks, both.
Previous: Jeff KingNext: Jeff King
Message 9 of 23 in “fix corner case with lock_ref_sha1_basic and REF_NODEREF”
  1. 0/2 fix corner case with lock_ref_sha1_basic and REF_NODEREFJeff King, Jan 11, 2016
  2. 1/2 checkout,clone: check return value of create_symrefJeff King, Jan 11, 2016
  3. Michael HaggertyJan 12, 2016
  4. Jeff KingJan 12, 2016
  5. 2/2 lock_ref_sha1_basic: handle REF_NODEREF with invalid refsJeff King, Jan 11, 2016
  6. Junio C HamanoJan 11, 2016
  7. Michael HaggertyJan 12, 2016
  8. Jeff KingJan 12, 2016
  9. Junio C HamanoJan 12, 2016
  10. 0/2 fix corner case with lock_ref_sha1_basic and REF_NODEREFJeff King, Jan 12, 2016
  11. 1/2 checkout,clone: check return value of create_symrefJeff King, Jan 12, 2016
  12. 2/2 lock_ref_sha1_basic: handle REF_NODEREF with invalid refsJeff King, Jan 12, 2016
  13. Jeff KingJan 12, 2016
  14. 2/2 lock_ref_sha1_basic: handle REF_NODEREF with invalid refsJeff King, Jan 12, 2016
  15. Junio C HamanoJan 12, 2016
  16. Jeff KingJan 12, 2016
  17. Jeff KingJan 12, 2016
  18. 0/3 fix corner cases with lock_ref_sha1_basicJeff King, Jan 12, 2016
  19. 1/3 checkout,clone: check return value of create_symrefJeff King, Jan 12, 2016
  20. 2/3 lock_ref_sha1_basic: always fill old_oid while holding lockJeff King, Jan 12, 2016
  21. Eric SunshineJan 13, 2016
  22. Jeff KingJan 13, 2016
  23. 3/3 lock_ref_sha1_basic: handle REF_NODEREF with invalid refsJeff King, Jan 12, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.