Skip to content

Commit e89f893

Browse files
dschogitster
authored andcommitted
fsck --name-objects: be more careful parsing generation numbers
In 7b35efd (fsck_walk(): optionally name objects on the go, 2016-07-17), the `fsck` machinery learned to optionally name the objects, so that it is easier to see what part of the repository is in a bad shape, say, when objects are missing. To save on complexity, this machinery uses a parser to determine the name of a parent given a commit's name: any `~<n>` suffix is parsed and the parent's name is formed from the prefix together with `~<n+1>`. However, this parser has a bug: if it finds a suffix `<n>` that is _not_ `~<n>`, it will mistake the empty string for the prefix and `<n>` for the generation number. In other words, it will generate a name of the form `~<bogus-number>`. Let's fix this. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c891ee commit e89f893

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

fsck.c

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

t/t1450-fsck.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,15 @@ test_expect_success 'fsck --name-objects' '
658658
git init name-objects &&
659659
(
660660
cd name-objects &&
661+
git config core.logAllRefUpdates false &&
661662
test_commit julius caesar.t &&
662-
test_commit augustus &&
663-
test_commit caesar &&
663+
test_commit augustus44 &&
664+
test_commit caesar &&
664665
remove_object $(git rev-parse julius:caesar.t) &&
665-
test_must_fail git fsck --name-objects >out &&
666666
tree=$(git rev-parse --verify julius:) &&
667-
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
668670
)
669671
'
670672

0 commit comments

Comments
 (0)