Skip to content

Commit 6e6a529

Browse files
sunshinecogitster
authored andcommitted
fsck: avoid misleading variable name
When reporting a problem, `git fsck` emits a message such as: missing blob 1234abcd (:file) However, this can be ambiguous when the problem is detected in the index of a worktree other than the one in which `git fsck` was invoked. To address this shortcoming, 592ec63 (fsck: mention file path for index errors, 2023-02-24) enhanced the output to mention the path of the index when the problem is detected in some other worktree: missing blob 1234abcd (.git/worktrees/wt/index:file) Unfortunately, the variable in fsck_index() which controls whether the index path should be shown is misleadingly named "is_main_index" which can be misunderstood as referring to the main worktree (i.e. the one housing the .git/ repository) rather than to the current worktree (i.e. the one in which `git fsck` was invoked). Avoid such potential confusion by choosing a name more reflective of its actual purpose. Signed-off-by: Eric Sunshine <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d3e7ea commit 6e6a529

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

builtin/fsck.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ static int fsck_resolve_undo(struct index_state *istate,
798798
}
799799

800800
static void fsck_index(struct index_state *istate, const char *index_path,
801-
int is_main_index)
801+
int is_current_worktree)
802802
{
803803
unsigned int i;
804804

@@ -820,7 +820,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
820820
obj->flags |= USED;
821821
fsck_put_object_name(&fsck_walk_options, &obj->oid,
822822
"%s:%s",
823-
is_main_index ? "" : index_path,
823+
is_current_worktree ? "" : index_path,
824824
istate->cache[i]->name);
825825
mark_object_reachable(obj);
826826
}

t/t1450-fsck.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,9 @@ test_expect_success 'fsck detects problems in worktree index' '
10391039
test_cmp expect actual
10401040
'
10411041

1042-
test_expect_success 'fsck reports problems in main index without filename' '
1042+
test_expect_success 'fsck reports problems in current worktree index without filename' '
10431043
test_when_finished "rm -f .git/index && git read-tree HEAD" &&
1044-
echo "this object will be removed to break the main index" >file &&
1044+
echo "this object will be removed to break current worktree index" >file &&
10451045
git add file &&
10461046
blob=$(git rev-parse :file) &&
10471047
remove_object $blob &&

0 commit comments

Comments
 (0)