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

Re: about rev-parse's quietness

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 15, 2015, 19:59 UTC
Message-ID
<xmqqk2qnhpi8.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<561F7F5A.4060708@atlas-elektronik.com>
<stefan.naewe@atlas-elektronik.com> writes:
Show 7 quoted lines
> Let's see:
> $ git rev-parse --verify --quiet master@{xyz} || echo No
> No
>
> $ git rev-parse --verify --quiet master@{u} || echo No
> fatal: no upstream configured for branch 'master'
> No

Yup, that is unfortunate. The above two pass different codepaths in sha1_name.c::get_sha1_basic().

 * The code first notices "master@{anything}" has @{anything}
   suffix, which could be @{123} (counted reflog), @{1.hour.ago}
   (timed reflog), @{-1} (prior checkout---valid only when nothing
   comes before "@{...}") or @{upstream}/@{push}.
 * The first two goes through dwim_log(), together with
   'master@{xyz}' to locate the reflog of 'master' (i.e. what comes
   before that @{anything}) and identifies that we need to look at
   the log for 'refs/heads/master', looks up an appropriate entry,
   and the processing ends there, returning success.  However, 'xyz'
   is not a valid specification for either counted or timed reflog,
   so the function returns failure for 'master@{xyz}', letting the
   remainder of the callchain to take care of it.
 
 * The third one goes to interpret_nth_prior_checkout() and the
   processing ends there, returning success.
 * The last one goes to dwim_ref(), together with just 'master'
   without any @{anything}.  It tries to turn master@{upstream} or
   master@{push} to refs/remotes/origin/master and then it is used
   to grab the object name pointed by it.

The helper function dwim_ref() calls to turn master@{upstream} to refs/remotes/origin/master, interpret_branch_name(), is designed to die() when fed a ref without upstream (or @{push} when there is no such thing).

Naively, one would imagine that the die() can be demoted to an internal error return to the caller (just like 'master@{xyz}' is rejected silently in the dwim_log() codepath) and everything else should go well. It is unfortunately not sufficient, though, as the other callers to interpret_branch_name() rely on the function to die and are not prepared to show the error messages themselves.

So I think this is fixable and the right approach to fix it is as hinted above, i.e.

 * audit callers of interpret_branch_name() and find the ones that
   depend on the function to die (i.e. it does not handle the case
   where interpret_branch_name() notices that 'master@{upstream}'
   does not exist).  Change them to die with an appropriate message
   themselves.
 * change interpret_branch_mark(), which is actually where the die()
   happens, so that it can notice a request to use 'master@{upstream}' 
   when there is no such upstream and signal an error to the caller.

I am not saying that you should be the one to fix it, though ;-) The above is to help those who may be interested to look into the codepath to do so.

Thanks.
Previous: stefan.naewe@atlas-elektronik.com
Message 2 of 2 in “about rev-parse's quietness”
  1. stefan.naewe@atlas-elektronik.comOct 15, 2015
  2. Junio C HamanoOct 15, 2015

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.