aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-02-17 17:21:42 -0800
committerJunio C Hamano <gitster@pobox.com>2021-02-17 17:21:42 -0800
commit9e634a91c8b6f57508aa91bd7306194d6ef6c14a (patch)
treec9e4a0ba9b454bc634d23116b7ac54ba41925b7a
parent9bdccbcda77df036edef5badda76418d0ae80997 (diff)
parente89f89361cd7b706858eb22a6cf3d59d31a00acf (diff)
downloadgit-9e634a91c8b6f57508aa91bd7306194d6ef6c14a.tar.xz
Merge branch 'js/fsck-name-objects-fix'
Fix "git fsck --name-objects" which apparently has not been used by anybody who is motivated enough to report breakage. * js/fsck-name-objects-fix: fsck --name-objects: be more careful parsing generation numbers t1450: robustify `remove_object()`
-rw-r--r--fsck.c5
-rwxr-xr-xt/t1450-fsck.sh26
2 files changed, 17 insertions, 14 deletions
diff --git a/fsck.c b/fsck.c
index 4b7f0b73d7..71134fdefa 100644
--- a/fsck.c
+++ b/fsck.c
@@ -463,6 +463,11 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio
generation += power * (name[--len] - '0');
if (power > 1 && len && name[len - 1] == '~')
name_prefix_len = len - 1;
+ else {
+ /* Maybe a non-first parent, e.g. HEAD^2 */
+ generation = 0;
+ name_prefix_len = len;
+ }
}
}
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index a30fc5f74a..231243152b 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -40,17 +40,13 @@ test_expect_success 'HEAD is part of refs, valid objects appear valid' '
# specific corruption you test afterwards, lest a later test trip over
# it.
-test_expect_success 'setup: helpers for corruption tests' '
- sha1_file() {
- remainder=${1#??} &&
- firsttwo=${1%$remainder} &&
- echo ".git/objects/$firsttwo/$remainder"
- } &&
+sha1_file () {
+ git rev-parse --git-path objects/$(test_oid_to_path "$1")
+}
- remove_object() {
- rm "$(sha1_file "$1")"
- }
-'
+remove_object () {
+ rm "$(sha1_file "$1")"
+}
test_expect_success 'object with bad sha1' '
sha=$(echo blob | git hash-object -w --stdin) &&
@@ -662,13 +658,15 @@ test_expect_success 'fsck --name-objects' '
git init name-objects &&
(
cd name-objects &&
+ git config core.logAllRefUpdates false &&
test_commit julius caesar.t &&
- test_commit augustus &&
- test_commit caesar &&
+ test_commit augustus44 &&
+ test_commit caesar &&
remove_object $(git rev-parse julius:caesar.t) &&
- test_must_fail git fsck --name-objects >out &&
tree=$(git rev-parse --verify julius:) &&
- test_i18ngrep "$tree (refs/tags/julius:" out
+ git tag -d julius &&
+ test_must_fail git fsck --name-objects >out &&
+ test_i18ngrep "$tree (refs/tags/augustus44\\^:" out
)
'