The functionality to list tree objects in the order they were seen while traversing the commits will be used in the next commit, where we teach `git describe` to describe not only commits, but trees and blobs, too.
Helped-by: Johannes Schindelin <johannes.schinde...@gmx.de> Signed-off-by: Stefan Beller <sbel...@google.com> --- list-objects.c | 2 ++ revision.c | 2 ++ revision.h | 3 ++- t/t6100-rev-list-in-order.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100755 t/t6100-rev-list-in-order.sh diff --git a/list-objects.c b/list-objects.c index bf46f80dff..5e114c9a8a 100644 --- a/list-objects.c +++ b/list-objects.c @@ -237,6 +237,8 @@ void traverse_commit_list(struct rev_info *revs, if (commit->tree) add_pending_tree(revs, commit->tree); show_commit(commit, data); + if (revs->tree_blobs_in_commit_order) + traverse_trees_and_blobs(revs, &base_path, show_object, data); } traverse_trees_and_blobs(revs, &base_path, show_object, data); diff --git a/revision.c b/revision.c index d167223e69..9329d4ebbf 100644 --- a/revision.c +++ b/revision.c @@ -1845,6 +1845,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->dense = 0; } else if (!strcmp(arg, "--show-all")) { revs->show_all = 1; + } else if (!strcmp(arg, "--in-commit-order")) { + revs->tree_blobs_in_commit_order = 1; } else if (!strcmp(arg, "--remove-empty")) { revs->remove_empty_trees = 1; } else if (!strcmp(arg, "--merges")) { diff --git a/revision.h b/revision.h index 54761200ad..86985d68aa 100644 --- a/revision.h +++ b/revision.h @@ -121,7 +121,8 @@ struct rev_info { bisect:1, ancestry_path:1, first_parent_only:1, - line_level_traverse:1; + line_level_traverse:1, + tree_blobs_in_commit_order:1; /* Diff flags */ unsigned int diff:1, diff --git a/t/t6100-rev-list-in-order.sh b/t/t6100-rev-list-in-order.sh new file mode 100755 index 0000000000..67ebe815d2 --- /dev/null +++ b/t/t6100-rev-list-in-order.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +test_description='miscellaneous rev-list tests' + +. ./test-lib.sh + + +test_expect_success 'setup' ' + for x in one two three four + do + echo $x >$x && + git add $x && + git commit -m "add file $x" + done && + for x in four three + do + git rm $x + git commit -m "remove $x" + done && + git rev-list --in-commit-order --objects HEAD >actual.raw && + cut -c 1-40 > actual < actual.raw && + + >expect && + git rev-parse HEAD^{commit} >>expect && + git rev-parse HEAD^{tree} >>expect && + git rev-parse HEAD^{tree}:one >>expect && + git rev-parse HEAD^{tree}:two >>expect && + git rev-parse HEAD~1^{commit} >>expect && + git rev-parse HEAD~1^{tree} >>expect && + git rev-parse HEAD~1^{tree}:three >>expect && + git rev-parse HEAD~2^{commit} >>expect && + git rev-parse HEAD~2^{tree} >>expect && + git rev-parse HEAD~2^{tree}:four >>expect && + git rev-parse HEAD~3^{commit} >>expect && + # skip HEAD~3^{tree} + git rev-parse HEAD~4^{commit} >>expect && + # skip HEAD~4^{tree} + git rev-parse HEAD~5^{commit} >>expect && + git rev-parse HEAD~5^{tree} >>expect && + + test_cmp expect actual +' + +test_done -- 2.15.0.rc2.443.gfcc3b81c0a