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

Re: [PATCH 3/3] reject @{-1} not at beginning of object name

From
Jeff King <peff@peff.net>
Date
Jan 29, 2010, 11:22 UTC
Message-ID
<20100129112219.GC6165@coredump.intra.peff.net>
In-Reply-To
<7vsk9qknf6.fsf@alter.siamese.dyndns.org>
On Thu, Jan 28, 2010 at 12:02:53PM -0800, Junio C Hamano wrote:
> We might want to use @{-some string that has non digit} for other purposes
> and it may be a safer change to tweak the "do we only have digits" check
> in the post-context to detect and reject only @{-<all digits>}.

I considered that, but I didn't think it was really worth it. If we later want to make @{-foobar} meaningful, we can loosen the safety check then.

> But what I am puzzled by the code structure of get_sha1_basic(), which
> looks like this:
You are not the only one who is puzzled. :)
But yes, your analysis of what is there now looks right to me.
> And the place that parses @{-1} and @{u} are different, even though both
> dwim_log() called by the third one and dwim_ref() called by the fourth one
> call substitute_branch_name() and they are perfectly capable of resolving
> @{-1} and @{u} (and even nested stuff like @{-1}@{u}@{u} with your patch).
Ooh, gross. I didn't try @{u}@{u} in my tests, but it should work.
Show 7 quoted lines
>     Side note.  I am wondering if dwim_log()'s current implementation is
>     even correct in the first place.  When you have two "ambiguous" refs,
>     it appears to me that you will get a warning from dwim_ref(), but if
>     only one of them has a reflog associated with it, dwim_log() won't
>     complain.  Why isn't the function be (1) dwim_ref() to find the ref
>     from abbreviated refname given in str; and then (2) check if the log
>     exists for that ref?

I guess the original rationale was that you might have reflog'd one, so by asking for "foo@{yesterday}" you are disambiguating as "the one with a reflog". But that seems kind of useless to me since:

  1. It is somewhat error-prone, as it assumes that from the user's
     perspective, the fact that one ref has a log and the other does not
     is somehow a meaningful disambiguation. Which implies that users
     carefully figure out which refs have reflogs and which do not, and
     I don't think that is true.
  2. For quite a while, we have had logallrefupdates on by default (and
     I don't remember the exact semantics before that, but wasn't it
     enough to simply create a "logs" directory, which meant that you
     either logged everything or nothing?). So I don't even know how you
     would get into a situation where one ref has a log and the other
     does not.

In other words, I totally agree with your statement, and we could probably just drop the dwim_log code.

> It might be cleaner if the logic went like this instead:

Your logic makes sense to me. I think we could also simply do a left-to-right parse, eating refs, @{-N}, and @{u} as we go and converting them into a "real ref". If we get to something else, we stop. If we have a @{} left, it's a reflog. Otherwise, it's bogus (I think ^ suffixes and such have already been stripped off at this point).

Interpret_branch_name already does most of the "eating..." part above (and it needs to remain separate from get_sha1_basic, as things like "checkout" need to use it directly).

But I didn't really look too hard at it, as:
> But that is a kind of code churn that may not be worth doing.  I dunno.

Yeah, the code was sufficiently nasty and sufficiently core that I didn't really want to risk breaking it for the sake of cleanup (especially not during the -rc cycle).

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 28 of 30 in “default behaviour for `gitmerge` (no arguments)”
  1. Gareth AdamsJan 11, 2010
  2. Junio C HamanoJan 11, 2010
  3. Jeff KingJan 12, 2010
  4. Junio C HamanoJan 12, 2010
  5. Jeff KingJan 12, 2010
  6. Junio C HamanoJan 13, 2010
  7. Johannes SchindelinJan 13, 2010
  8. Junio C HamanoJan 13, 2010
  9. Johannes SchindelinJan 13, 2010
  10. Junio C HamanoJan 13, 2010
  11. Johannes SchindelinJan 13, 2010
  12. Junio C HamanoJan 13, 2010
  13. 0/2 @{u} updatesJunio C Hamano, Jan 20, 2010
  14. 1/2 t1506: more test for @{upstream} syntaxJunio C Hamano, Jan 20, 2010
  15. Jeff KingJan 26, 2010
  16. Junio C HamanoJan 26, 2010
  17. Jeff KingJan 27, 2010
  18. Junio C HamanoJan 27, 2010
  19. Jeff KingJan 28, 2010
  20. Junio C HamanoJan 26, 2010
  21. Jeff KingJan 27, 2010
  22. Junio C HamanoJan 27, 2010
  23. Jeff KingJan 28, 2010
  24. 1/3 test combinations of @{} syntaxJeff King, Jan 28, 2010
  25. 2/3 fix parsing of @{-1}@{u} combinationJeff King, Jan 28, 2010
  26. 3/3 reject @{-1} not at beginning of object nameJeff King, Jan 28, 2010
  27. Junio C HamanoJan 28, 2010
  28. Jeff KingJan 29, 2010
  29. 2/2 Teach @{upstream} syntax to strbuf_branchanme()Junio C Hamano, Jan 20, 2010
  30. Johannes SchindelinJan 20, 2010

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.