Skip to content

Commit b4cfcde

Browse files
peffgitster
authored andcommitted
rev-list: handle flags for --indexed-objects
When a traversal sees the --indexed-objects option, it adds all blobs and valid cache-trees from the index to the traversal using add_index_objects_to_pending(). But that function totally ignores its flags parameter! That means that doing: git rev-list --objects --indexed-objects and git rev-list --objects --not --indexed-objects produce the same output, because we ignore the UNINTERESTING flag when walking the index in the second example. Nobody noticed because this feature was added as a way for tools like repack to increase their coverage of reachable objects, meaning it would only be used like the first example above. But since it's user facing (and because the documentation describes it "as if the objects are listed on the command line"), we should make sure the negative case behaves sensibly. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d582ea2 commit b4cfcde

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

revision.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,28 +1321,30 @@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
13211321
}
13221322

13231323
static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
1324-
struct strbuf *path)
1324+
struct strbuf *path, unsigned int flags)
13251325
{
13261326
size_t baselen = path->len;
13271327
int i;
13281328

13291329
if (it->entry_count >= 0) {
13301330
struct tree *tree = lookup_tree(revs->repo, &it->oid);
1331+
tree->object.flags |= flags;
13311332
add_pending_object_with_path(revs, &tree->object, "",
13321333
040000, path->buf);
13331334
}
13341335

13351336
for (i = 0; i < it->subtree_nr; i++) {
13361337
struct cache_tree_sub *sub = it->down[i];
13371338
strbuf_addf(path, "%s%s", baselen ? "/" : "", sub->name);
1338-
add_cache_tree(sub->cache_tree, revs, path);
1339+
add_cache_tree(sub->cache_tree, revs, path, flags);
13391340
strbuf_setlen(path, baselen);
13401341
}
13411342

13421343
}
13431344

13441345
static void do_add_index_objects_to_pending(struct rev_info *revs,
1345-
struct index_state *istate)
1346+
struct index_state *istate,
1347+
unsigned int flags)
13461348
{
13471349
int i;
13481350

@@ -1356,13 +1358,14 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
13561358
blob = lookup_blob(revs->repo, &ce->oid);
13571359
if (!blob)
13581360
die("unable to add index blob to traversal");
1361+
blob->object.flags |= flags;
13591362
add_pending_object_with_path(revs, &blob->object, "",
13601363
ce->ce_mode, ce->name);
13611364
}
13621365

13631366
if (istate->cache_tree) {
13641367
struct strbuf path = STRBUF_INIT;
1365-
add_cache_tree(istate->cache_tree, revs, &path);
1368+
add_cache_tree(istate->cache_tree, revs, &path, flags);
13661369
strbuf_release(&path);
13671370
}
13681371
}
@@ -1372,7 +1375,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
13721375
struct worktree **worktrees, **p;
13731376

13741377
read_index(revs->repo->index);
1375-
do_add_index_objects_to_pending(revs, revs->repo->index);
1378+
do_add_index_objects_to_pending(revs, revs->repo->index, flags);
13761379

13771380
if (revs->single_worktree)
13781381
return;
@@ -1388,7 +1391,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
13881391
if (read_index_from(&istate,
13891392
worktree_git_path(wt, "index"),
13901393
get_worktree_git_dir(wt)) > 0)
1391-
do_add_index_objects_to_pending(revs, &istate);
1394+
do_add_index_objects_to_pending(revs, &istate, flags);
13921395
discard_index(&istate);
13931396
}
13941397
free_worktrees(worktrees);

t/t6000-rev-list-misc.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,18 @@ test_expect_success 'rev-list can show index objects' '
9090
9200b628cf9dc883a85a7abc8d6e6730baee589c two
9191
EOF
9292
echo only-in-index >only-in-index &&
93+
test_when_finished "git reset --hard" &&
9394
git add only-in-index &&
9495
git rev-list --objects --indexed-objects >actual &&
9596
test_cmp expect actual
9697
'
9798

99+
test_expect_success 'rev-list can negate index objects' '
100+
git rev-parse HEAD >expect &&
101+
git rev-list -1 --objects HEAD --not --indexed-objects >actual &&
102+
test_cmp expect actual
103+
'
104+
98105
test_expect_success '--bisect and --first-parent can not be combined' '
99106
test_must_fail git rev-list --bisect --first-parent HEAD
100107
'

0 commit comments

Comments
 (0)