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

Jeff King committed Nov 2, 2018 at 01:22 UTC b4cfcde4db8f5787c6c8a3912b0f2667becd1995
2 files changed +16 -6
revision.c
+9 -6
@@ -1321,13 +1321,14 @@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
1321 }
1322
1323 static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
1324 - struct strbuf *path)
1324 + struct strbuf *path, unsigned int flags)
1325 {
1326 size_t baselen = path->len;
1327 int i;
1328
1329 if (it->entry_count >= 0) {
1330 struct tree *tree = lookup_tree(revs->repo, &it->oid);
1331 + tree->object.flags |= flags;
1332 add_pending_object_with_path(revs, &tree->object, "",
1333 040000, path->buf);
1334 }
@@ -1335,14 +1336,15 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
1336 for (i = 0; i < it->subtree_nr; i++) {
1337 struct cache_tree_sub *sub = it->down[i];
1338 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);
1340 strbuf_setlen(path, baselen);
1341 }
1342
1343 }
1344
1345 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)
1348 {
1349 int i;
1350
@@ -1356,13 +1358,14 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
1358 blob = lookup_blob(revs->repo, &ce->oid);
1359 if (!blob)
1360 die("unable to add index blob to traversal");
1361 + blob->object.flags |= flags;
1362 add_pending_object_with_path(revs, &blob->object, "",
1363 ce->ce_mode, ce->name);
1364 }
1365
1366 if (istate->cache_tree) {
1367 struct strbuf path = STRBUF_INIT;
1365 - add_cache_tree(istate->cache_tree, revs, &path);
1368 + add_cache_tree(istate->cache_tree, revs, &path, flags);
1369 strbuf_release(&path);
1370 }
1371 }
@@ -1372,7 +1375,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
1375 struct worktree **worktrees, **p;
1376
1377 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);
1379
1380 if (revs->single_worktree)
1381 return;
@@ -1388,7 +1391,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
1391 if (read_index_from(&istate,
1392 worktree_git_path(wt, "index"),
1393 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);
1395 discard_index(&istate);
1396 }
1397 free_worktrees(worktrees);
t/t6000-rev-list-misc.sh
+7
@@ -90,11 +90,18 @@ test_expect_success 'rev-list can show index objects' '
90 9200b628cf9dc883a85a7abc8d6e6730baee589c two
91 EOF
92 echo only-in-index >only-in-index &&
93 + test_when_finished "git reset --hard" &&
94 git add only-in-index &&
95 git rev-list --objects --indexed-objects >actual &&
96 test_cmp expect actual
97 '
98
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 +
105 test_expect_success '--bisect and --first-parent can not be combined' '
106 test_must_fail git rev-list --bisect --first-parent HEAD
107 '