* [PATCH] fsck: avoid misleading variable name
@ 2023-06-29 18:13 Eric Sunshine
2023-06-29 19:04 ` Jeff King
0 siblings, 1 reply; 2+ messages in thread
From: Eric Sunshine @ 2023-06-29 18:13 UTC (permalink / raw)
To: git; +Cc: Jeff King, Eric Sunshine
From: Eric Sunshine <sunshine@sunshineco.com>
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, 592ec63b38 (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 <sunshine@sunshineco.com>
---
The associated discussion which led to this patch begins at [1].
[1]: https://lore.kernel.org/git/305ccc55-25e3-6b01-cd86-9a9035839d06@sunshineco.com/
builtin/fsck.c | 4 ++--
t/t1450-fsck.sh | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index d9aa4db828..0c00920703 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -808,7 +808,7 @@ static int fsck_resolve_undo(struct index_state *istate,
}
static void fsck_index(struct index_state *istate, const char *index_path,
- int is_main_index)
+ int is_current_worktree)
{
unsigned int i;
@@ -830,7 +830,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
obj->flags |= USED;
fsck_put_object_name(&fsck_walk_options, &obj->oid,
"%s:%s",
- is_main_index ? "" : index_path,
+ is_current_worktree ? "" : index_path,
istate->cache[i]->name);
mark_object_reachable(obj);
}
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 8c442adb1a..5805d47eb9 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -1036,9 +1036,9 @@ test_expect_success 'fsck detects problems in worktree index' '
test_cmp expect actual
'
-test_expect_success 'fsck reports problems in main index without filename' '
+test_expect_success 'fsck reports problems in current worktree index without filename' '
test_when_finished "rm -f .git/index && git read-tree HEAD" &&
- echo "this object will be removed to break the main index" >file &&
+ echo "this object will be removed to break current worktree index" >file &&
git add file &&
blob=$(git rev-parse :file) &&
remove_object $blob &&
--
2.41.0.362.gccff93557d
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fsck: avoid misleading variable name
2023-06-29 18:13 [PATCH] fsck: avoid misleading variable name Eric Sunshine
@ 2023-06-29 19:04 ` Jeff King
0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2023-06-29 19:04 UTC (permalink / raw)
To: Eric Sunshine; +Cc: git, Eric Sunshine
On Thu, Jun 29, 2023 at 02:13:33PM -0400, Eric Sunshine wrote:
> From: Eric Sunshine <sunshine@sunshineco.com>
>
> 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, 592ec63b38 (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.
This looks good to me. Thanks for following up!
-Peff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-29 19:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-29 18:13 [PATCH] fsck: avoid misleading variable name Eric Sunshine
2023-06-29 19:04 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).