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

Re: check-ref-format: include refs/ in the argument or to strip it?

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 25, 2014, 18:26 UTC
Message-ID
<20140825182636.GO20185@google.com>
In-Reply-To
<CAL=YDWk5FxnNWaFXJk3t+H0Q_axETmNeb=puuUqhiDBNeQVDGQ@mail.gmail.com>
Ronnie Sahlberg wrote:
> On Fri, Aug 22, 2014 at 10:46 PM, Jeff King <peff@peff.net> wrote:
Show 11 quoted lines
>> Yeah, this weird "do not allow refs/foo" behavior has continually
>> confused me. Coincidentally I just noticed a case today where
>> "pack-refs" treats "refs/foo" specially for no good reason:
>>
>>   http://thread.gmane.org/gmane.comp.version-control.git/255729
>>
>> After much head scratching over the years, I am of the opinion that
>> nobody every really _meant_ to prevent "refs/foo", and that code
>> comments like the one you quote above were an attempt to document
>> existing buggy behavior that was really trying to differentiate "HEAD"
>> from "refs/*". That's just my opinion, though. :)

It's still very puzzling to me. The comment came at the same time as the behavior, in v0.99.9~120 (git-check-ref-format: reject funny ref names, 2005-10-13). Before that, the behavior was even stranger --- it checked that there was exactly one slash in the argument.

I'm willing to believe we might not want that check any more, though.
[...]
> There are also a lot of places where we assume that a refs will start
> with "refs/heads/" and not just "refs/"
> for_each_branch_ref(), log_ref_setup() (so no reflogs) is_branch() to
> name a few.

for_each_branch_ref is for iterating over local branches, which are defined as refs that start with refs/heads/*. Likewise, the only point of is_branch is to check whether a ref is under refs/heads/*. That's not an assumption about all refs.

log_ref_setup implements the policy that there are only reflogs for:
 * refs where the reflog was explicitly created ("git branch
   --create-reflog" does this, but for some reason there's no
   corresponding "git update-ref --create-reflog" so people have
   to use mkdir directly for other refs), plus
 * if the '[core] logallrefupdates' configuration is enabled (and it
   is by default for non-bare repositories), then HEAD, refs/heads/*,
   refs/notes/*, and refs/remotes/*.
This is documented in git-config(1) --- see core.logAllRefUpdates.

That way, when tools internally use other refs (e.g., FETCH_HEAD), git doesn't have to automatically incur the cost of maintaining the reflog for those. What other refs should there be reflogs for? I haven't thought carefully about this.

It definitely isn't an assumption that *all* refs will match that pattern. But it might be worth changing for other reasons.

Jonathan
Previous: Ronnie SahlbergNext: Jeff King
Message 7 of 11 in “check-ref-format: include refs/ in the argument or to strip it?”
  1. Jonathan NiederAug 22, 2014
  2. Junio C HamanoAug 22, 2014
  3. Jonathan NiederAug 22, 2014
  4. Jeff KingAug 23, 2014
  5. Junio C HamanoAug 23, 2014
  6. Ronnie SahlbergAug 25, 2014
  7. Jonathan NiederAug 25, 2014
  8. Jeff KingAug 25, 2014
  9. Michael HaggertyAug 27, 2014
  10. Junio C HamanoAug 25, 2014
  11. Jonathan NiederAug 23, 2014

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.