Skip to content

Commit be489d0

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 6c3d818 commit be489d0

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

revision.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "dir.h"
2020
#include "cache-tree.h"
2121
#include "bisect.h"
22+
#include "worktree.h"
2223

2324
volatile show_early_output_fn_t show_early_output;
2425

@@ -1290,8 +1291,28 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
12901291

12911292
void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
12921293
{
1294+
struct worktree **worktrees, **p;
1295+
12931296
read_cache();
12941297
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);
12951316
}
12961317

12971318
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,

t/t5304-prune.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,13 @@ test_expect_success 'prune: handle alternate object database' '
283283
git -C B prune
284284
'
285285

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+
286295
test_done

0 commit comments

Comments
 (0)