revision.c: --indexed-objects add objects from all worktrees

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 23, 2017 at 19:36 UTC be489d02d2f95b34e8f0fd15b9ec4752a11edd4c
2 files changed +30
revision.c
+21
@@ -19,6 +19,7 @@
19 #include "dir.h"
20 #include "cache-tree.h"
21 #include "bisect.h"
22 +#include "worktree.h"
23
24 volatile show_early_output_fn_t show_early_output;
25
@@ -1290,8 +1291,28 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
1291
1292 void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
1293 {
1294 + struct worktree **worktrees, **p;
1295 +
1296 read_cache();
1297 do_add_index_objects_to_pending(revs, &the_index);
1298 +
1299 + if (revs->single_worktree)
1300 + return;
1301 +
1302 + worktrees = get_worktrees(0);
1303 + for (p = worktrees; *p; p++) {
1304 + struct worktree *wt = *p;
1305 + struct index_state istate = { NULL };
1306 +
1307 + if (wt->is_current)
1308 + continue; /* current index already taken care of */
1309 +
1310 + if (read_index_from(&istate,
1311 + worktree_git_path(wt, "index")) > 0)
1312 + do_add_index_objects_to_pending(revs, &istate);
1313 + discard_index(&istate);
1314 + }
1315 + free_worktrees(worktrees);
1316 }
1317
1318 static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
t/t5304-prune.sh
+9
@@ -283,4 +283,13 @@ test_expect_success 'prune: handle alternate object database' '
283 git -C B prune
284 '
285
286 +test_expect_success 'prune: handle index in multiple worktrees' '
287 + git worktree add second-worktree &&
288 + echo "new blob for second-worktree" >second-worktree/blob &&
289 + git -C second-worktree add blob &&
290 + git prune --expire=now &&
291 + git -C second-worktree show :blob >actual &&
292 + test_cmp second-worktree/blob actual
293 +'
294 +
295 test_done