Skip to content

Commit 9e634a9

Browse files
committed
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()`
2 parents 9bdccbc + e89f893 commit 9e634a9

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

fsck.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio
463463
generation += power * (name[--len] - '0');
464464
if (power > 1 && len && name[len - 1] == '~')
465465
name_prefix_len = len - 1;
466+
else {
467+
/* Maybe a non-first parent, e.g. HEAD^2 */
468+
generation = 0;
469+
name_prefix_len = len;
470+
}
466471
}
467472
}
468473

t/t1450-fsck.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,13 @@ test_expect_success 'HEAD is part of refs, valid objects appear valid' '
4040
# specific corruption you test afterwards, lest a later test trip over
4141
# it.
4242

43-
test_expect_success 'setup: helpers for corruption tests' '
44-
sha1_file() {
45-
remainder=${1#??} &&
46-
firsttwo=${1%$remainder} &&
47-
echo ".git/objects/$firsttwo/$remainder"
48-
} &&
43+
sha1_file () {
44+
git rev-parse --git-path objects/$(test_oid_to_path "$1")
45+
}
4946

50-
remove_object() {
51-
rm "$(sha1_file "$1")"
52-
}
53-
'
47+
remove_object () {
48+
rm "$(sha1_file "$1")"
49+
}
5450

5551
test_expect_success 'object with bad sha1' '
5652
sha=$(echo blob | git hash-object -w --stdin) &&
@@ -662,13 +658,15 @@ test_expect_success 'fsck --name-objects' '
662658
git init name-objects &&
663659
(
664660
cd name-objects &&
661+
git config core.logAllRefUpdates false &&
665662
test_commit julius caesar.t &&
666-
test_commit augustus &&
667-
test_commit caesar &&
663+
test_commit augustus44 &&
664+
test_commit caesar &&
668665
remove_object $(git rev-parse julius:caesar.t) &&
669-
test_must_fail git fsck --name-objects >out &&
670666
tree=$(git rev-parse --verify julius:) &&
671-
test_i18ngrep "$tree (refs/tags/julius:" out
667+
git tag -d julius &&
668+
test_must_fail git fsck --name-objects >out &&
669+
test_i18ngrep "$tree (refs/tags/augustus44\\^:" out
672670
)
673671
'
674672

0 commit comments

Comments
 (0)