Skip to content

Commit eb40e51

Browse files
committed
Merge branch 'jc/t1512-fix'
A test that should have failed but didn't revealed a bug that needs to be corrected. * jc/t1512-fix: get_short_sha1(): correctly disambiguate type-limited abbreviation t1512: correct leftover constants from earlier edition
2 parents f3930e4 + 94d75d1 commit eb40e51

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

sha1_name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static int disambiguate_committish_only(const unsigned char *sha1, void *cb_data
241241
return 0;
242242

243243
/* We need to do this the hard way... */
244-
obj = deref_tag(lookup_object(sha1), NULL, 0);
244+
obj = deref_tag(parse_object(sha1), NULL, 0);
245245
if (obj && obj->type == OBJ_COMMIT)
246246
return 1;
247247
return 0;

t/t1512-rev-parse-disambiguation.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ test_expect_success 'disambiguate blob' '
7777

7878
test_expect_success 'disambiguate tree' '
7979
commit=$(echo "d7xm" | git commit-tree 000000000) &&
80+
# this commit is fffff2e and not ambiguous with the 00000* objects
8081
test $(git rev-parse $commit^{tree}) = $(git rev-parse 0000000000cdc)
8182
'
8283

@@ -99,10 +100,14 @@ test_expect_success 'disambiguate commit-ish' '
99100

100101
test_expect_success 'disambiguate commit' '
101102
commit=$(echo "hoaxj" | git commit-tree 0000000000cdc -p 000000000) &&
103+
# this commit is ffffffd8 and not ambiguous with the 00000* objects
102104
test $(git rev-parse $commit^) = $(git rev-parse 0000000000e4f)
103105
'
104106

105107
test_expect_success 'log name1..name2 takes only commit-ishes on both ends' '
108+
# These are underspecified from the prefix-length point of view
109+
# to disambiguate the commit with other objects, but there is only
110+
# one commit that has 00000* prefix at this point.
106111
git log 000000000..000000000 &&
107112
git log ..000000000 &&
108113
git log 000000000.. &&
@@ -112,16 +117,19 @@ test_expect_success 'log name1..name2 takes only commit-ishes on both ends' '
112117
'
113118

114119
test_expect_success 'rev-parse name1..name2 takes only commit-ishes on both ends' '
120+
# Likewise.
115121
git rev-parse 000000000..000000000 &&
116122
git rev-parse ..000000000 &&
117123
git rev-parse 000000000..
118124
'
119125

120126
test_expect_success 'git log takes only commit-ish' '
127+
# Likewise.
121128
git log 000000000
122129
'
123130

124131
test_expect_success 'git reset takes only commit-ish' '
132+
# Likewise.
125133
git reset 000000000
126134
'
127135

@@ -131,26 +139,30 @@ test_expect_success 'first tag' '
131139
'
132140

133141
test_expect_failure 'two semi-ambiguous commit-ish' '
142+
# At this point, we have a tag 0000000000f8f that points
143+
# at a commit 0000000000e4f, and a tree and a blob that
144+
# share 0000000000 prefix with these tag and commit.
145+
#
134146
# Once the parser becomes ultra-smart, it could notice that
135-
# 110282 before ^{commit} name many different objects, but
147+
# 0000000000 before ^{commit} name many different objects, but
136148
# that only two (HEAD and v1.0.0 tag) can be peeled to commit,
137149
# and that peeling them down to commit yield the same commit
138150
# without ambiguity.
139-
git rev-parse --verify 110282^{commit} &&
151+
git rev-parse --verify 0000000000^{commit} &&
140152
141153
# likewise
142-
git log 000000000..000000000 &&
143-
git log ..000000000 &&
144-
git log 000000000.. &&
145-
git log 000000000...000000000 &&
146-
git log ...000000000 &&
147-
git log 000000000...
154+
git log 0000000000..0000000000 &&
155+
git log ..0000000000 &&
156+
git log 0000000000.. &&
157+
git log 0000000000...0000000000 &&
158+
git log ...0000000000 &&
159+
git log 0000000000...
148160
'
149161

150162
test_expect_failure 'three semi-ambiguous tree-ish' '
151163
# Likewise for tree-ish. HEAD, v1.0.0 and HEAD^{tree} share
152164
# the prefix but peeling them to tree yields the same thing
153-
git rev-parse --verify 000000000^{tree}
165+
git rev-parse --verify 0000000000^{tree}
154166
'
155167

156168
test_expect_success 'parse describe name' '
@@ -241,7 +253,7 @@ test_expect_success 'ambiguous commit-ish' '
241253
# Now there are many commits that begin with the
242254
# common prefix, none of these should pick one at
243255
# random. They all should result in ambiguity errors.
244-
test_must_fail git rev-parse --verify 110282^{commit} &&
256+
test_must_fail git rev-parse --verify 00000000^{commit} &&
245257
246258
# likewise
247259
test_must_fail git log 000000000..000000000 &&

0 commit comments

Comments
 (0)