From 86715592fd319a6e04cbb9c84415c0a052ca4344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 21 May 2020 11:52:04 +0200 Subject: [PATCH 1/4] fsck: fix a typo in a comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported-by: Junio C Hamano Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- fsck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsck.c b/fsck.c index b9b3350f76..bc71b0f35b 100644 --- a/fsck.c +++ b/fsck.c @@ -598,7 +598,7 @@ static int verify_ordered(unsigned mode1, const char *name1, /* * There can be non-consecutive duplicates due to the implicitly - * add slash, e.g.: + * added slash, e.g.: * * foo * foo.bar From fc12aa7bfd50fd175a0760b446de1e4514a69d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 21 May 2020 11:52:28 +0200 Subject: [PATCH 2/4] t1450: increase test coverage of in-tree d/f detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exercise the case of putting a conflict candidate file name back on the stack because a matching directory might yet come up later. Do that by factoring out the test code into a function to allow for more concise notation in the form of parameters indicating names of trees (with trailing slash) and blobs (without trailing slash) in no particular order (they are sorted by git mktree). Then add the new test case as a second function call. Fix a typo in the test title while at it ("dublicate"). Reported-by: Derrick Stolee Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- t/t1450-fsck.sh | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index c43bc6870a..a006ef1ee1 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -234,21 +234,33 @@ test_expect_success 'tree object with duplicate entries' ' test_i18ngrep "error in tree .*contains duplicate file entries" out ' -test_expect_success 'tree object with dublicate names' ' - test_when_finished "remove_object \$blob" && - test_when_finished "remove_object \$tree" && - test_when_finished "remove_object \$badtree" && - blob=$(echo blob | git hash-object -w --stdin) && - printf "100644 blob %s\t%s\n" $blob x.2 >tree && - tree=$(git mktree badtree && - printf "100644 blob %s\t%s\n" $blob x >>badtree && - printf "040000 tree %s\t%s\n" $tree x >>badtree && - badtree=$(git mktree out && - test_i18ngrep "$badtree" out && - test_i18ngrep "error in tree .*contains duplicate file entries" out -' +check_duplicate_names () { + expect=$1 && + shift && + names=$@ && + test_expect_$expect "tree object with duplicate names: $names" ' + test_when_finished "remove_object \$blob" && + test_when_finished "remove_object \$tree" && + test_when_finished "remove_object \$badtree" && + blob=$(echo blob | git hash-object -w --stdin) && + printf "100644 blob %s\t%s\n" $blob x.2 >tree && + tree=$(git mktree badtree && + badtree=$(git mktree out && + test_i18ngrep "$badtree" out && + test_i18ngrep "error in tree .*contains duplicate file entries" out + ' +} + +check_duplicate_names success x x.1 x/ +check_duplicate_names success x x.1.2 x.1/ x/ test_expect_success 'unparseable tree object' ' test_oid_cache <<-\EOF && From 3d71b1cf6031e5dc4381a067fba16167d14f567a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 21 May 2020 11:52:43 +0200 Subject: [PATCH 3/4] t1450: demonstrate undetected in-tree d/f conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- t/t1450-fsck.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index a006ef1ee1..7e70a253f8 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -261,6 +261,7 @@ check_duplicate_names () { check_duplicate_names success x x.1 x/ check_duplicate_names success x x.1.2 x.1/ x/ +check_duplicate_names failure x x.1 x.1.2 x/ test_expect_success 'unparseable tree object' ' test_oid_cache <<-\EOF && From fe747043dc96fd5c151496f0e45dbf80de07793d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 21 May 2020 11:52:54 +0200 Subject: [PATCH 4/4] fsck: detect more in-tree d/f conflicts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the conflict candidate file name from the top of the stack is not a prefix of the current candiate directory then we can discard it as no matching directory can come up later. But we are not done checking the candidate directory -- the stack might still hold a matching file name, so stay in the loop and check the next candidate file name. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- fsck.c | 2 +- t/t1450-fsck.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsck.c b/fsck.c index bc71b0f35b..2095491735 100644 --- a/fsck.c +++ b/fsck.c @@ -620,7 +620,7 @@ static int verify_ordered(unsigned mode1, const char *name1, if (!f_name) break; if (!skip_prefix(name2, f_name, &p)) - break; + continue; if (!*p) return TREE_HAS_DUPS; if (is_less_than_slash(*p)) { diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 7e70a253f8..6555a62099 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -261,7 +261,7 @@ check_duplicate_names () { check_duplicate_names success x x.1 x/ check_duplicate_names success x x.1.2 x.1/ x/ -check_duplicate_names failure x x.1 x.1.2 x/ +check_duplicate_names success x x.1 x.1.2 x/ test_expect_success 'unparseable tree object' ' test_oid_cache <<-\EOF &&