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

[PATCH v4 04/16] revision.c: --indexed-objects add objects from all worktrees

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Aug 23, 2017, 12:36 UTC
Message-ID
<20170823123704.16518-5-pclouds@gmail.com>
In-Reply-To
<20170823123704.16518-1-pclouds@gmail.com>

This is the result of single_worktree flag never being set (no way to up until now). To get objects from current index only, set single_worktree.

The other add_index_objects_to_pending's caller is mark_reachable_objects() (e.g. "git prune") which also mark objects from all indexes.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 revision.c       | 21 +++++++++++++++++++++
 t/t5304-prune.sh |  9 +++++++++
 2 files changed, 30 insertions(+)
diff --git a/revision.c b/revision.c
index 6c46ad6c8a..f35cb49af5 100644
--- a/revision.c
+++ b/revision.c
@@ -19,6 +19,7 @@
 #include "dir.h"
 #include "cache-tree.h"
 #include "bisect.h"
+#include "worktree.h"
 
 volatile show_early_output_fn_t show_early_output;
 
@@ -1290,8 +1291,28 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
 
 void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
 {
+	struct worktree **worktrees, **p;
+
 	read_cache();
 	do_add_index_objects_to_pending(revs, &the_index);
+
+	if (revs->single_worktree)
+		return;
+
+	worktrees = get_worktrees(0);
+	for (p = worktrees; *p; p++) {
+		struct worktree *wt = *p;
+		struct index_state istate = { NULL };
+
+		if (wt->is_current)
+			continue; /* current index already taken care of */
+
+		if (read_index_from(&istate,
+				    worktree_git_path(wt, "index")) > 0)
+			do_add_index_objects_to_pending(revs, &istate);
+		discard_index(&istate);
+	}
+	free_worktrees(worktrees);
 }
 
 static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index 133b5842b1..cba45c7be9 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -283,4 +283,13 @@ test_expect_success 'prune: handle alternate object database' '
 	git -C B prune
 '
 
+test_expect_success 'prune: handle index in multiple worktrees' '
+	git worktree add second-worktree &&
+	echo "new blob for second-worktree" >second-worktree/blob &&
+	git -C second-worktree add blob &&
+	git prune --expire=now &&
+	git -C second-worktree show :blob >actual &&
+	test_cmp second-worktree/blob actual
+'
+
 test_done
-- 
2.11.0.157.gd943d85
Previous: Nguyễn Thái Ngọc DuyNext: Stefan Beller
Message 8 of 40 in “Fix git-gc losing objects in multi worktree”
  1. 00/16 Fix git-gc losing objects in multi worktreeNguyễn Thái Ngọc Duy, Aug 23, 2017
  2. 01/16 revision.h: new flag in struct rev_info wrt. worktree-related refsNguyễn Thái Ngọc Duy, Aug 23, 2017
  3. 02/16 refs.c: use is_dir_sep() in resolve_gitlink_ref()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  4. Stefan BellerAug 23, 2017
  5. Duy NguyenSep 6, 2017
  6. Stefan BellerSep 6, 2017
  7. 03/16 revision.c: refactor add_index_objects_to_pending()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  8. 04/16 revision.c: --indexed-objects add objects from all worktreesNguyễn Thái Ngọc Duy, Aug 23, 2017
  9. Stefan BellerAug 23, 2017
  10. 05/16 refs.c: refactor get_submodule_ref_store(), share common free blockNguyễn Thái Ngọc Duy, Aug 23, 2017
  11. Stefan BellerAug 23, 2017
  12. 06/16 refs: move submodule slash stripping code to get_submodule_ref_storeNguyễn Thái Ngọc Duy, Aug 23, 2017
  13. Michael HaggertySep 9, 2017
  14. 07/16 refs: add refs_head_ref()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  15. Junio C HamanoAug 24, 2017
  16. Duy NguyenSep 6, 2017
  17. 08/16 revision.c: use refs_for_each*() instead of for_each_*_submodule()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  18. Junio C HamanoAug 24, 2017
  19. 09/16 refs.c: move for_each_remote_ref_submodule() to submodule.cNguyễn Thái Ngọc Duy, Aug 23, 2017
  20. 10/16 refs: remove dead for_each_*_submodule()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  21. Stefan BellerAug 23, 2017
  22. Michael HaggertySep 9, 2017
  23. 11/16 revision.c: --all adds HEAD from all worktreesNguyễn Thái Ngọc Duy, Aug 23, 2017
  24. Stefan BellerAug 23, 2017
  25. Duy NguyenSep 6, 2017
  26. Stefan BellerSep 6, 2017
  27. Michael HaggertySep 9, 2017
  28. 12/16 files-backend: make reflog iterator go through per-worktree reflogNguyễn Thái Ngọc Duy, Aug 23, 2017
  29. Richard MawAug 24, 2017
  30. Michael HaggertySep 9, 2017
  31. 13/16 revision.c: --reflog add HEAD reflog from all worktreesNguyễn Thái Ngọc Duy, Aug 23, 2017
  32. 14/16 rev-list: expose and document --single-worktreeNguyễn Thái Ngọc Duy, Aug 23, 2017
  33. Stefan BellerAug 23, 2017
  34. 15/16 refs.c: remove fallback-to-main-store code get_submodule_ref_store()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  35. Michael HaggertySep 9, 2017
  36. 16/16 refs.c: reindent get_submodule_ref_store()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  37. Michael HaggertySep 9, 2017
  38. Michael J GruberAug 25, 2017
  39. Duy NguyenSep 6, 2017
  40. Michael HaggertySep 9, 2017

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.