From 8c891eed3a89ff945b7957cdf62037b2e2b6eca7 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 10 Feb 2021 18:01:29 +0000 Subject: [PATCH 1/2] t1450: robustify `remove_object()` This function can be simplified by using the `test_oid_to_path()` helper, which incidentally also makes it more robust by not relying on the exact file system layout of the loose object files. While at it, do not define those functions in a test case, it buys us nothing. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t1450-fsck.sh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index b17f5c21fb..0c58cb349b 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) && From e89f89361cd7b706858eb22a6cf3d59d31a00acf Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 10 Feb 2021 18:01:30 +0000 Subject: [PATCH 2/2] fsck --name-objects: be more careful parsing generation numbers In 7b35efd734e (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 `~` suffix is parsed and the parent's name is formed from the prefix together with `~`. However, this parser has a bug: if it finds a suffix `` that is _not_ `~`, it will mistake the empty string for the prefix and `` for the generation number. In other words, it will generate a name of the form `~`. Let's fix this. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- fsck.c | 5 +++++ t/t1450-fsck.sh | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/fsck.c b/fsck.c index 5e282b3b6b..293c1a2ef5 100644 --- a/fsck.c +++ b/fsck.c @@ -461,6 +461,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 0c58cb349b..d3a3d2722b 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -658,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 ) '