]> git.ipfire.org Git - thirdparty/git.git/commit
get_ref_dir(): don't call read_loose_refs() for "refs/bisect"
authorMichael Haggerty <mhagger@alum.mit.edu>
Mon, 20 Mar 2017 16:33:06 +0000 (17:33 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Apr 2017 10:54:31 +0000 (03:54 -0700)
commit68fb02e40de22d38cb8988c524e31f93dc40c224
tree23e7a216b9c2155d655c751b1c9971aab5a91830
parentadac8115a6e7f9841c48e4fe48b74e0ce652ef58
get_ref_dir(): don't call read_loose_refs() for "refs/bisect"

Since references under "refs/bisect/" are per-worktree, they have to
be sought in the worktree rather than in the main repository. But
since loose references are found by traversing directories, the
reference iterator won't even get the idea to look for a
"refs/bisect/" directory in the worktree if there is not a directory
with that name in the main repository. Thus `get_ref_dir()` manually
inserts a dir_entry for "refs/bisect/" whenever it reads the entry for
"refs/".

The current code then immediately calls `read_loose_refs()` on that
directory. But since the dir_entry is created with its `incomplete`
flag set, any traversal that gets to this point will read the
directory automatically. So there is no need to call
`read_loose_refs()` explicitly; the lazy mechanism suffices.

And in fact, the attempt to `read_loose_refs()` was broken anyway.
That function needs its `dirname` argument to have a trailing `/`
character, but the invocation here was passing it "refs/bisect"
without a trailing slash. So `read_loose_refs()` would read
`$GIT_DIR/refs/bisect" correctly, but if it found an entry "foo" in
that directory, it would try to read "$GIT_DIR/refs/bisectfoo".
Normally it wouldn't find anything at that path, but the failure was
canceled out because `get_ref_dir()` *also* forgot to reset the
`REF_INCOMPLETE` bit on the dir_entry. So the read was attempted again
when it was accessed, via the lazy mechanism, and this time the read
was done correctly.

This code has been broken since it was first introduced.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/files-backend.c