summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3499cb1)
raw | patch | inline | side by side (parent: 3499cb1)
author | Thomas Rast <trast@student.ethz.ch> | |
Thu, 10 Jun 2010 11:47:23 +0000 (13:47 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 12 Jun 2010 16:39:06 +0000 (09:39 -0700) |
Add a --count option that, instead of actually listing the commits,
merely counts them.
This is mostly geared towards script use, and to this end it acts
specially when used with --left-right: it outputs the left and right
counts separately. Previously, scripts would have to run a shell loop
or small inline script over to achieve the same. (Without
--left-right, a simple |wc -l does the job.)
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merely counts them.
This is mostly geared towards script use, and to this end it acts
specially when used with --left-right: it outputs the left and right
counts separately. Previously, scripts would have to run a shell loop
or small inline script over to achieve the same. (Without
--left-right, a simple |wc -l does the job.)
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
index b9fb7a86bd4bf91205b77275fb51ff13a3bc5622..066ade9fce33b70898c1bf411319f1f8b632d44f 100644 (file)
This implies the '--topo-order' option by default, but the
'--date-order' option may also be specified.
+ifdef::git-rev-list[]
+--count::
+ Print a number stating how many commits would have been
+ listed, and suppress all other output. When used together
+ with '--left-right', instead print the counts for left and
+ right commits, separated by a tab.
+endif::git-rev-list[]
+
+
ifndef::git-rev-list[]
Diff Formatting
~~~~~~~~~~~~~~~
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 51ceb19d88918445c90eccc37f1fe5f90cedd385..efe9360e2fdb9aac3bae0c61c85531041f24708a 100644 (file)
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
graph_show_commit(revs->graph);
+ if (revs->count) {
+ if (commit->object.flags & SYMMETRIC_LEFT)
+ revs->count_left++;
+ else
+ revs->count_right++;
+ finish_commit(commit, data);
+ return;
+ }
+
if (info->show_timestamp)
printf("%lu ", commit->date);
if (info->header_prefix)
quiet ? finish_object : show_object,
&info);
+ if (revs.count) {
+ if (revs.left_right)
+ printf("%d\t%d\n", revs.count_left, revs.count_right);
+ else
+ printf("%d\n", revs.count_left + revs.count_right);
+ }
+
return 0;
}
diff --git a/revision.c b/revision.c
index f4b8b383153b2330be1729fa29488bab1848e019..21b133c89bd481b2ac1fa5076c637336b8f57eb1 100644 (file)
--- a/revision.c
+++ b/revision.c
@@ -1146,6 +1146,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->boundary = 1;
} else if (!strcmp(arg, "--left-right")) {
revs->left_right = 1;
+ } else if (!strcmp(arg, "--count")) {
+ revs->count = 1;
} else if (!strcmp(arg, "--cherry-pick")) {
revs->cherry_pick = 1;
revs->limited = 1;
diff --git a/revision.h b/revision.h
index 568f1c98de844dbadcebf1d583bffc24e6daa677..bafa72808342919485cc0590a66ffc5ef5c96c82 100644 (file)
--- a/revision.h
+++ b/revision.h
limited:1,
unpacked:1,
boundary:2,
+ count:1,
left_right:1,
rewrite_parents:1,
print_parents:1,
/* notes-specific options: which refs to show */
struct display_notes_opt notes_opt;
+
+ /* commit counts */
+ int count_left;
+ int count_right;
};
#define REV_TREE_SAME 0
index 4b8611ce2092f9062aeaeb62ce19a9121d5be537..b565638e92655c12c841c29a108516a8b13cf8d2 100755 (executable)
git tag B
'
+cat >expect <<EOF
+<tags/B
+>tags/C
+EOF
+
+test_expect_success '--left-right' '
+ git rev-list --left-right B...C > actual &&
+ git name-rev --stdin --name-only --refs="*tags/*" \
+ < actual > actual.named &&
+ test_cmp actual.named expect
+'
+
+test_expect_success '--count' '
+ git rev-list --count B...C > actual &&
+ test "$(cat actual)" = 2
+'
+
test_expect_success '--cherry-pick foo comes up empty' '
test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
'
HEAD...master -- foo)"
'
+cat >expect <<EOF
+1 2
+EOF
+
+# Insert an extra commit to break the symmetry
+test_expect_success '--count --left-right' '
+ git checkout branch &&
+ test_commit D &&
+ git rev-list --count --left-right B...D > actual &&
+ test_cmp expect actual
+'
+
test_done