Skip to content

Commit 95ca489

Browse files
committed
Merge branch 'jc/missing-ref-store-fix'
We've left the command line parsing of "git log :/a/b/" broken for about a full year without anybody noticing, which has been corrected. * jc/missing-ref-store-fix: repository: mark the "refs" pointer as private sha1-name: do not assume that the ref store is initialized
2 parents bc20556 + 0220461 commit 95ca489

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

refs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,14 +1852,14 @@ static struct ref_store *ref_store_init(const char *gitdir,
18521852

18531853
struct ref_store *get_main_ref_store(struct repository *r)
18541854
{
1855-
if (r->refs)
1856-
return r->refs;
1855+
if (r->refs_private)
1856+
return r->refs_private;
18571857

18581858
if (!r->gitdir)
18591859
BUG("attempting to get main_ref_store outside of repository");
18601860

1861-
r->refs = ref_store_init(r->gitdir, REF_STORE_ALL_CAPS);
1862-
return r->refs;
1861+
r->refs_private = ref_store_init(r->gitdir, REF_STORE_ALL_CAPS);
1862+
return r->refs_private;
18631863
}
18641864

18651865
/*

repository.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ struct repository {
6767
*/
6868
struct parsed_object_pool *parsed_objects;
6969

70-
/* The store in which the refs are held. */
71-
struct ref_store *refs;
70+
/*
71+
* The store in which the refs are held. This should generally only be
72+
* accessed via get_main_ref_store(), as that will lazily initialize
73+
* the ref object.
74+
*/
75+
struct ref_store *refs_private;
7276

7377
/*
7478
* Contains path to often used file names.

sha1-name.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,8 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
18151815

18161816
cb.repo = repo;
18171817
cb.list = &list;
1818-
refs_for_each_ref(repo->refs, handle_one_ref, &cb);
1819-
refs_head_ref(repo->refs, handle_one_ref, &cb);
1818+
refs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb);
1819+
refs_head_ref(get_main_ref_store(repo), handle_one_ref, &cb);
18201820
commit_list_sort_by_date(&list);
18211821
return get_oid_oneline(repo, name + 2, oid, list);
18221822
}

t/t4208-log-magic-pathspec.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ test_expect_success '"git log -- :/a" should not be ambiguous' '
5555
git log -- :/a
5656
'
5757

58+
test_expect_success '"git log :/any/path/" should not segfault' '
59+
test_must_fail git log :/any/path/
60+
'
61+
5862
# This differs from the ":/a" check above in that :/in looks like a pathspec,
5963
# but doesn't match an actual file.
6064
test_expect_success '"git log :/in" should not be ambiguous' '

0 commit comments

Comments
 (0)