git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 11, 2023, 06:39 UTC
Message-ID
<305ccc55-25e3-6b01-cd86-9a9035839d06@sunshineco.com>
In-Reply-To
<Y/hxW9i9GyKblNV4@coredump.intra.peff.net>
On 2/24/23 3:12 AM, Jeff King wrote:
Show 24 quoted lines
> 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)

Show 7 quoted lines
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> 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...
Show 5 quoted lines
> @@ -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?
Previous: Jeff KingNext: Jeff King
Message 7 of 19 in “Bug: fsck and repack don't agree when a worktree index extension is "broken"”
  1. Johannes SixtFeb 18, 2023
  2. 0/3 fsck index files from all worktreesJeff King, Feb 24, 2023
  3. 1/3 fsck: factor out index fsckJeff King, Feb 24, 2023
  4. 2/3 fsck: check index files in all worktreesJeff King, Feb 24, 2023
  5. Jeff KingFeb 24, 2023
  6. 3/3 fsck: mention file path for index errorsJeff King, Feb 24, 2023
  7. Eric SunshineMay 11, 2023
  8. Jeff KingMay 11, 2023
  9. Eric SunshineMay 11, 2023
  10. Jeff KingMay 11, 2023
  11. Eric SunshineJun 29, 2023
  12. Junio C HamanoJun 29, 2023
  13. Andreas SchwabJun 1, 2023
  14. Jeff KingJun 1, 2023
  15. Junio C HamanoFeb 24, 2023
  16. 4/3 fsck: check even zero-entry index filesJeff King, Feb 26, 2023
  17. Derrick StoleeFeb 27, 2023
  18. Junio C HamanoFeb 27, 2023
  19. Johannes SixtFeb 26, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.