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

Re: [PATCH 2/3] fsck: check index files in all worktrees

From
Jeff King <peff@peff.net>
Date
Feb 24, 2023, 08:45 UTC
Message-ID
<Y/h5G+D3jRLXeD16@coredump.intra.peff.net>
In-Reply-To
<Y/hw1YVgCYWX2yNK@coredump.intra.peff.net>
On Fri, Feb 24, 2023 at 03:09:58AM -0500, Jeff King wrote:
Show 11 quoted lines
> +		for (p = get_worktrees(); *p; p++) {
> +			struct worktree *wt = *p;
> +			struct index_state istate =
> +				INDEX_STATE_INIT(the_repository);
> +
> +			if (read_index_from(&istate,
> +					    worktree_git_path(wt, "index"),
> +					    get_worktree_git_dir(wt)) > 0)
> +				fsck_index(&istate);
> +			discard_index(&istate);
> +		}

I didn't realize that get_worktrees() returns an allocated array, so this is a small leak. I'll squash this in locally:

diff --git a/builtin/fsck.c b/builtin/fsck.c
index ddd13cb2b3..c11cb2a95f 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -984,12 +984,13 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 	}
 
 	if (keep_cache_objects) {
-		struct worktree **p;
+		struct worktree **worktrees, **p;
 
 		verify_index_checksum = 1;
 		verify_ce_order = 1;
 
-		for (p = get_worktrees(); *p; p++) {
+		worktrees = get_worktrees();
+		for (p = worktrees; *p; p++) {
 			struct worktree *wt = *p;
 			struct index_state istate =
 				INDEX_STATE_INIT(the_repository);
@@ -1000,7 +1001,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 				fsck_index(&istate);
 			discard_index(&istate);
 		}
-
+		free_worktrees(worktrees);
 	}
 
 	check_connectivity();

but I'll hold off for other comments before sending a re-roll.

-Peff
Previous: Jeff KingNext: Jeff King
Message 5 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.