alternates: use fspathcmp to detect duplicates
authorJeff King <peff@peff.net>
Mon, 3 Oct 2016 20:36:26 +0000 (16:36 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2016 20:52:37 +0000 (13:52 -0700)
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>
builtin/count-objects.c
sha1_file.c
t/t5613-info-alternate.sh
index a700409bf55b34948b3bfdb339cb194570727eb9..a04b4f2ef337d4d9d8cb24de7288630ee8ab823c 100644 (file)
@@ -97,6 +97,8 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
                OPT_END(),
        };
 
+       git_config(git_default_config, NULL);
+
        argc = parse_options(argc, argv, prefix, opts, count_objects_usage, 0);
        /* we do not take arguments other than flags for now */
        if (argc)
index 9cad56f7b0c2204b9421e58240e3bb6dbf4960f3..064651947dcab37b014309796aa32df0ed944750 100644 (file)
@@ -260,7 +260,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)
         * thing twice, or object directory itself.
         */
        for (alt = alt_odb_list; alt; alt = alt->next) {
-               if (!strcmp(path->buf, alt->path))
+               if (!fspathcmp(path->buf, alt->path))
                        return 0;
        }
        if (!fspathcmp(path->buf, normalized_objdir))
index 76f1a20e2c2cfb8c6f1971903800ecc959b70eb4..895f46bb9118bbf15d32f594ce79f0e638d25b6a 100755 (executable)
@@ -119,4 +119,21 @@ test_expect_success 'relative duplicates are eliminated' '
        test_cmp expect actual.alternates
 '
 
+test_expect_success CASE_INSENSITIVE_FS 'dup finding can be case-insensitive' '
+       git init --bare insensitive.git &&
+       # the previous entry for "A" will have used uppercase
+       cat >insensitive.git/objects/info/alternates <<-\EOF &&
+       ../../C/.git/objects
+       ../../a/.git/objects
+       EOF
+       cat >expect <<-EOF &&
+       alternate: $(pwd)/C/.git/objects
+       alternate: $(pwd)/B/.git/objects
+       alternate: $(pwd)/A/.git/objects
+       EOF
+       git -C insensitive.git count-objects -v >actual &&
+       grep ^alternate: actual >actual.alternates &&
+       test_cmp expect actual.alternates
+'
+
 test_done