From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, jonathantanmy@google.com,
Stefan Beller <sbeller@google.com>
Subject: [PATCHv5 3/7] revision.h: introduce blob/tree walking in order of the commits
Date: Wed, 15 Nov 2017 18:00:35 -0800 [thread overview]
Message-ID: <20171116020039.17810-4-sbeller@google.com> (raw)
In-Reply-To: <20171116020039.17810-1-sbeller@google.com>
The functionality to list tree objects in the order they were seen
while traversing the commits will be used in one of the next commits,
where we teach `git describe` to describe not only commits, but blobs, too.
The change in list-objects.c is rather minimal as we'll be re-using
the infrastructure put in place of the revision walking machinery. For
example one could expect that add_pending_tree is not called, but rather
commit->tree is directly passed to the tree traversal function. This
however requires a lot more code than just emptying the queue containing
trees after each commit.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
Documentation/rev-list-options.txt | 5 +++
list-objects.c | 8 ++++
revision.c | 2 +
revision.h | 3 +-
t/t6100-rev-list-in-order.sh | 77 ++++++++++++++++++++++++++++++++++++++
5 files changed, 94 insertions(+), 1 deletion(-)
create mode 100755 t/t6100-rev-list-in-order.sh
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 13501e1556..9066e0c777 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -686,6 +686,11 @@ ifdef::git-rev-list[]
all object IDs which I need to download if I have the commit
object _bar_ but not _foo_''.
+--in-commit-order::
+ Print tree and blob ids in order of the commits. The tree
+ and blob ids are printed after they are first referenced
+ by a commit.
+
--objects-edge::
Similar to `--objects`, but also print the IDs of excluded
commits prefixed with a ``-'' character. This is used by
diff --git a/list-objects.c b/list-objects.c
index 7c2ce9c4bd..4caa6fcb77 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -239,6 +239,14 @@ 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)
+ /*
+ * NEEDSWORK: Adding the tree and then flushing it here
+ * needs a reallocation for each commit. Can we pass the
+ * tree directory without allocation churn?
+ */
+ traverse_trees_and_blobs(revs, &csp, show_object, data);
}
traverse_trees_and_blobs(revs, &csp, 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..b2bb0a7f61
--- /dev/null
+++ b/t/t6100-rev-list-in-order.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+test_description='rev-list testing in-commit-order'
+
+. ./test-lib.sh
+
+test_expect_success 'setup a commit history with trees, blobs' '
+ for x in one two three four
+ do
+ echo $x >$x &&
+ git add $x &&
+ git commit -m "add file $x" ||
+ return 1
+ done &&
+ for x in four three
+ do
+ git rm $x &&
+ git commit -m "remove $x" ||
+ return 1
+ done
+'
+
+test_expect_success 'rev-list --in-commit-order' '
+ git rev-list --in-commit-order --objects HEAD >actual.raw &&
+ cut -c 1-40 >actual <actual.raw &&
+
+ git cat-file --batch-check="%(objectname)" >expect.raw <<-\EOF &&
+ HEAD^{commit}
+ HEAD^{tree}
+ HEAD^{tree}:one
+ HEAD^{tree}:two
+ HEAD~1^{commit}
+ HEAD~1^{tree}
+ HEAD~1^{tree}:three
+ HEAD~2^{commit}
+ HEAD~2^{tree}
+ HEAD~2^{tree}:four
+ HEAD~3^{commit}
+ # HEAD~3^{tree} skipped, same as HEAD~1^{tree}
+ HEAD~4^{commit}
+ # HEAD~4^{tree} skipped, same as HEAD^{tree}
+ HEAD~5^{commit}
+ HEAD~5^{tree}
+ EOF
+ grep -v "#" >expect <expect.raw &&
+
+ test_cmp expect actual
+'
+
+test_expect_success 'rev-list lists blobs and trees after commits' '
+ git rev-list --objects HEAD >actual.raw &&
+ cut -c 1-40 >actual <actual.raw &&
+
+ git cat-file --batch-check="%(objectname)" >expect.raw <<-\EOF &&
+ HEAD^{commit}
+ HEAD~1^{commit}
+ HEAD~2^{commit}
+ HEAD~3^{commit}
+ HEAD~4^{commit}
+ HEAD~5^{commit}
+ HEAD^{tree}
+ HEAD^{tree}:one
+ HEAD^{tree}:two
+ HEAD~1^{tree}
+ HEAD~1^{tree}:three
+ HEAD~2^{tree}
+ HEAD~2^{tree}:four
+ # HEAD~3^{tree} skipped, same as HEAD~1^{tree}
+ # HEAD~4^{tree} skipped, same as HEAD^{tree}
+ HEAD~5^{tree}
+ EOF
+ grep -v "#" >expect <expect.raw &&
+
+ test_cmp expect actual
+'
+
+test_done
--
2.15.0.128.gcadd42da22
next prev parent reply other threads:[~2017-11-16 2:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-16 2:00 [PATCHv5 0/7] describe blob Stefan Beller
2017-11-16 2:00 ` [PATCHv5 1/7] t6120: fix typo in test name Stefan Beller
2017-11-16 2:00 ` [PATCHv5 2/7] list-objects.c: factor out traverse_trees_and_blobs Stefan Beller
2017-11-16 2:00 ` Stefan Beller [this message]
2017-11-16 2:00 ` [PATCHv5 4/7] builtin/describe.c: rename `oid` to avoid variable shadowing Stefan Beller
2017-11-16 2:00 ` [PATCHv5 5/7] builtin/describe.c: print debug statements earlier Stefan Beller
2017-11-16 2:00 ` [PATCHv5 6/7] builtin/describe.c: factor out describe_commit Stefan Beller
2017-11-16 2:00 ` [PATCHv5 7/7] builtin/describe.c: describe a blob Stefan Beller
2017-11-16 3:24 ` Junio C Hamano
2017-11-16 19:34 ` Stefan Beller
2017-11-22 7:55 ` Junio C Hamano
2017-11-22 17:00 ` Stefan Beller
2017-11-24 7:18 ` Junio C Hamano
2017-11-27 19:38 ` Stefan Beller
2017-11-27 23:37 ` Junio C Hamano
2017-11-20 15:10 ` Philip Oakley
2017-12-19 19:22 ` Junio C Hamano
2017-12-19 19:39 ` Stefan Beller
2017-12-22 23:10 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171116020039.17810-4-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jonathantanmy@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).