Skip to content

Commit ea0fc3b

Browse files
peffgitster
authored andcommitted
alternates: use fspathcmp to detect duplicates
On a case-insensitive filesystem, we should realize that "a/objects" and "A/objects" are the same path. We already use fspathcmp() to check against the main object directory, but until recently we couldn't use it for comparing against other alternates (because their paths were not NUL-terminated strings). But now we can, so let's do so. Note that we also need to adjust count-objects to load the config, so that it can see the setting of core.ignorecase (this is required by the test, but is also a general bugfix for users of count-objects). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 087b6d5 commit ea0fc3b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

builtin/count-objects.c

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
9797
OPT_END(),
9898
};
9999

100+
git_config(git_default_config, NULL);
101+
100102
argc = parse_options(argc, argv, prefix, opts, count_objects_usage, 0);
101103
/* we do not take arguments other than flags for now */
102104
if (argc)

sha1_file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)
260260
* thing twice, or object directory itself.
261261
*/
262262
for (alt = alt_odb_list; alt; alt = alt->next) {
263-
if (!strcmp(path->buf, alt->path))
263+
if (!fspathcmp(path->buf, alt->path))
264264
return 0;
265265
}
266266
if (!fspathcmp(path->buf, normalized_objdir))

t/t5613-info-alternate.sh

+17
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,21 @@ test_expect_success 'relative duplicates are eliminated' '
119119
test_cmp expect actual.alternates
120120
'
121121

122+
test_expect_success CASE_INSENSITIVE_FS 'dup finding can be case-insensitive' '
123+
git init --bare insensitive.git &&
124+
# the previous entry for "A" will have used uppercase
125+
cat >insensitive.git/objects/info/alternates <<-\EOF &&
126+
../../C/.git/objects
127+
../../a/.git/objects
128+
EOF
129+
cat >expect <<-EOF &&
130+
alternate: $(pwd)/C/.git/objects
131+
alternate: $(pwd)/B/.git/objects
132+
alternate: $(pwd)/A/.git/objects
133+
EOF
134+
git -C insensitive.git count-objects -v >actual &&
135+
grep ^alternate: actual >actual.alternates &&
136+
test_cmp expect actual.alternates
137+
'
138+
122139
test_done

0 commit comments

Comments
 (0)