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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 3, 2016 at 16:36 UTC ea0fc3b4176a424a2b20eb76a6a503dc4d59cebb
3 files changed +20 -1
builtin/count-objects.c
+2
@@ -97,6 +97,8 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
97 OPT_END(),
98 };
99
100 + git_config(git_default_config, NULL);
101 +
102 argc = parse_options(argc, argv, prefix, opts, count_objects_usage, 0);
103 /* we do not take arguments other than flags for now */
104 if (argc)
sha1_file.c
+1 -1
@@ -260,7 +260,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)
260 * thing twice, or object directory itself.
261 */
262 for (alt = alt_odb_list; alt; alt = alt->next) {
263 - if (!strcmp(path->buf, alt->path))
263 + if (!fspathcmp(path->buf, alt->path))
264 return 0;
265 }
266 if (!fspathcmp(path->buf, normalized_objdir))
t/t5613-info-alternate.sh
+17
@@ -119,4 +119,21 @@ test_expect_success 'relative duplicates are eliminated' '
119 test_cmp expect actual.alternates
120 '
121
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 +
139 test_done