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

Re: [PATCH v2] Introduce <branch>@{upstream} as shortcut to the tracked branch

From
Jeff King <peff@peff.net>
Date
Sep 10, 2009, 15:55 UTC
Message-ID
<20090910155547.GA12409@coredump.intra.peff.net>
In-Reply-To
<alpine.DEB.1.00.0909101724520.8306@pacific.mpi-cbg.de>
On Thu, Sep 10, 2009 at 05:25:57PM +0200, Johannes Schindelin wrote:
> 	Changes since v1:
> 	- changed to @{upstream} (and @{u})

Hmm. After applying v2, I accidentally tried "git rev-parse @{t}" and was surprised to find that it worked! The problem, of course, is that we saw that it was not one of our keywords and therefore dumped it into approxidate, which happily converted it into the current time, and provided me with HEAD@{now}.

Which is sad, because it means "HEAD@{usptream}" will silently produce incorrect results.

I don't see a way around it, though, short of tightening approxidate's parsing. Maybe it could keep a flag for "I noticed _anything_ of value in this string", and we could barf if it isn't set. That would still allow arbitrary stuff like:

  the 6th of july
and keep Linus' favorite
  I ate 6 hot dogs in July.
but disallow the most obviously wrong dates like:
  t
  usptream
  total bogosity
Show 15 quoted lines
> +	ret = tracked_suffix(*string, *len);
> +	if (ret) {
> +		char *ref = xstrndup(*string, *len - ret);
> +		struct branch *tracking = branch_get(*ref ? ref : NULL);
> +
> +		free(ref);
> +		if (!tracking)
> +			die ("No tracking branch found for '%s'", ref);
> +		if (tracking->merge && tracking->merge[0]->dst) {
> +			*string = xstrdup(tracking->merge[0]->dst);
> +			*len = strlen(*string);
> +			return (char *)*string;
> +		}
> +	}
> +

I don't think it is a good idea to die for !tracking, but not for !tracking->merge. That leads to inconsistent user-visible results:

  $ git checkout HEAD^0
  $ git rev-parse HEAD@{u}
  fatal: No tracking branch found for 'HEAD'
  $ git rev-parse bogus@{u}
  bogus@{u}
  fatal: ambiguous argument 'bogus@{u}': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions
Shouldn't both cases say the same thing?
Also, your die message has two problems:
 1. It looks at ref immediately after it is free'd, spewing junk.
 2. Ref can be the empty string, which gives you the ugly:
       fatal: No tracking branch found for ''
    Should we munge that into HEAD (or "the current branch") for the
    user?
-Peff
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 35 of 39 in “tracking branch for a rebase”
  1. Pete WyckoffSep 4, 2009
  2. Michael J GruberSep 4, 2009
  3. Jeff KingSep 4, 2009
  4. Björn SteinbrinkSep 4, 2009
  5. Jeff KingSep 5, 2009
  6. Björn SteinbrinkSep 5, 2009
  7. Jeff KingSep 5, 2009
  8. Junio C HamanoSep 7, 2009
  9. Michael J GruberSep 7, 2009
  10. Junio C HamanoSep 7, 2009
  11. Jeff KingSep 7, 2009
  12. Michael J GruberSep 7, 2009
  13. Jeff KingSep 7, 2009
  14. Johannes SchindelinSep 7, 2009
  15. Michael J GruberSep 7, 2009
  16. Julian PhillipsSep 8, 2009
  17. Jeff KingSep 9, 2009
  18. Junio C HamanoSep 10, 2009
  19. Johannes SchindelinSep 10, 2009
  20. Introduce <branch>@{tracked} as shortcut to the tracked branchJohannes Schindelin, Sep 10, 2009
  21. Michael J GruberSep 10, 2009
  22. Johannes SchindelinSep 10, 2009
  23. Johan HerlandSep 10, 2009
  24. Michael J GruberSep 10, 2009
  25. Johan HerlandSep 10, 2009
  26. Johannes SchindelinSep 10, 2009
  27. Michael J GruberSep 10, 2009
  28. Jeff KingSep 10, 2009
  29. Junio C HamanoSep 10, 2009
  30. Björn SteinbrinkOct 2, 2009
  31. Jeff KingSep 10, 2009
  32. Jeff KingSep 10, 2009
  33. Johannes SchindelinSep 10, 2009
  34. Introduce <branch>@{upstream} as shortcut to the tracked branchJohannes Schindelin, Sep 10, 2009
  35. Jeff KingSep 10, 2009
  36. Johannes SchindelinSep 10, 2009
  37. Johannes SchindelinSep 10, 2009
  38. Junio C HamanoSep 11, 2009
  39. Junio C HamanoSep 5, 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.