Re: [PATCH 3/3] fsck: mention file path for index errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/24/23 3:12 AM, Jeff King wrote:
If we encounter an error in an index file, we may say something like:

   error: 1234abcd: invalid sha1 pointer in resolve-undo

But if you have multiple worktrees, each with its own index, it can be
very helpful to know which file had the problem. So let's pass that path
down through the various index-fsck functions and use it where
appropriate. After this patch you should get something like:

   error: 1234abcd: invalid sha1 pointer in resolve-undo of .git/worktrees/wt/index

That's a bit verbose, but since the point is that you shouldn't see this
normally, we're better to err on the side of more details.

I've also added the index filename to the name used by "fsck
--name-objects", which will show up if we find the object to be missing,
etc. This is bending the rules a little there, as the option claims to
write names that can be fed to rev-parse. But there is no revision
syntax to access the index of another worktree, so the best we can do is
make up something that a human will probably understand.

I did take care to retain the existing ":file" syntax for the current
worktree. So the uglier output should kick in only when it's actually
necessary. See the included tests for examples of both forms.

This made me think of the work Duy did[1,2] to make it possible to reference per-worktree refs from other worktrees which allows one to say, for instance:

    git rev-parse main-worktree/HEAD:somefile
    git rev-parse worktrees/foo/HEAD:somefile

but, of course, that special syntax doesn't extend to "index", so your made-up syntax is probably good enough.

[1]: 3a3b9d8cde (refs: new ref types to make per-worktree refs visible to all worktrees, 2018-10-21)

[2]: ab3e1f78ae (revision.c: better error reporting on ref from different worktrees, 2018-10-21)

Signed-off-by: Jeff King <peff@xxxxxxxx>
---
diff --git a/builtin/fsck.c b/builtin/fsck.c
@@ -795,7 +797,8 @@ static int fsck_resolve_undo(struct index_state *istate)
-static void fsck_index(struct index_state *istate)
+static void fsck_index(struct index_state *istate, const char *index_path,
+		       int is_main_index)

This adds an `is_main_index` flag, but...

@@ -993,12 +998,19 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
+			if (read_index_from(&istate, path,
  					    get_worktree_git_dir(wt)) > 0)
-				fsck_index(&istate);
+				fsck_index(&istate, path, wt->is_current);

...this accesses `is_current`, the value of which is "true" only for the worktree in which the Git command was run, which is not necessarily the main worktree. The main worktree, on the other hand, is guaranteed to be the first entry returned by get_worktrees(), so shouldn't this instead be:

    worktrees = get_worktrees();
    for (p = worktrees; *p; p++) {
        ...
        fsck_index(&istate, path, p == worktrees);
        ...
    }
    free_worktrees(worktrees);

Or am I fundamentally misunderstanding something?




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux