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

Re: [PATCH] for-each-ref: remove multiple xstrdup() in get_short_ref()

From
Jeff King <peff@peff.net>
Date
Apr 7, 2009, 21:41 UTC
Message-ID
<20090407214144.GA17962@coredump.intra.peff.net>
In-Reply-To
<20090407074435.GB7327@coredump.intra.peff.net>
On Tue, Apr 07, 2009 at 03:44:35AM -0400, Jeff King wrote:
Show 6 quoted lines
> +		if (1 != sscanf(ref, scanf_fmts[i], short_name))
> [...]
> +		if (j == i) {
> +			ref += strlen(ref) - strlen(short_name);
> +			break;
> +		}

Actually, I am not sure this is correct, either. It is making the assumption that the short_name is always a suffix of the ref. But one of the rev_parse_rules is:

     "refs/remotes/%.*s/HEAD"

for which this is not true. _But_ as it happens, this rule doesn't actually work in reverse because of the way scanf works with %s. The code:

    sscanf("refs/remotes/origin/HEAD", "refs/remotes/%s/HEAD", buf);

will put "origin/HEAD" in buf, not "origin"; %s eats until it sees whitespace (which should not be occuring in a ref, fortunately).

So it actually _is_ correct to assume with the current code that the short_name is always a suffix, but I am not sure if that is what we actually want. We will always see "$remote/HEAD" instead of "$remote".

Part of me actually thinks the "incorrect" behavior we are doing now is actually more explicit and readable. But if that is the case, we should perhaps simply be excluding that final rule explicitly, and then our "suffix" assumption will hold.

-Peff
Previous: Bert WesargNext: Bert Wesarg
Message 23 of 24 in “making upstream branch information accessible”
  1. 0/5 making upstream branch information accessibleJeff King, Apr 7, 2009
  2. 1/5 for-each-ref: refactor get_short_ref functionJeff King, Apr 7, 2009
  3. 2/5 for-each-ref: refactor refname handlingJeff King, Apr 7, 2009
  4. Junio C HamanoApr 8, 2009
  5. Jeff KingApr 8, 2009
  6. 3/5 for-each-ref: add "upstream" format fieldJeff King, Apr 7, 2009
  7. 4/5 make get_short_ref a public functionJeff King, Apr 7, 2009
  8. Bert WesargApr 7, 2009
  9. Jeff KingApr 9, 2009
  10. Bert WesargApr 9, 2009
  11. Jeff KingApr 13, 2009
  12. Michael J GruberApr 7, 2009
  13. 5/5 branch: show upstream branch when double verboseJeff King, Apr 7, 2009
  14. Michael J GruberApr 7, 2009
  15. Jeff KingApr 9, 2009
  16. Santi BéjarApr 9, 2009
  17. Jeff KingApr 13, 2009
  18. Wincent ColaiutaApr 13, 2009
  19. Paolo CiarrocchiApr 7, 2009
  20. for-each-ref: remove multiple xstrdup() in get_short_ref()Bert Wesarg, Apr 7, 2009
  21. Jeff KingApr 7, 2009
  22. Bert WesargApr 7, 2009
  23. Jeff KingApr 7, 2009
  24. Bert WesargApr 7, 2009

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.