list-object: add get_commit_count function
PATCH 1/4 list-object: add get_commit_count function
Moving commit counting from rev-list into list-object which is a step toward letting git log do counting as well.
--- builtin/rev-list.c | 12 ++---------- list-objects.c | 14 ++++++++++++++ list-objects.h | 1 + 3 files changed, 17 insertions(+), 10 deletions(-)
builtin/rev-list.c +2 -10
@@ -388,16 +388,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)traverse_commit_list (&revs, show_commit, show_object, &info); -if (revs.count) { -if (revs.left_right && revs.cherry_mark) -printf ("%d\t%d\t%d\n" , revs.count_left, revs.count_right, revs.count_same); -else if (revs.left_right) -printf ("%d\t%d\n" , revs.count_left, revs.count_right); -else if (revs.cherry_mark) -printf ("%d\t%d\n" , revs.count_left + revs.count_right, revs.count_same); -else -printf ("%d\n" , revs.count_left + revs.count_right); - } +if (revs.count) +get_commit_count (&revs);return 0 ; }
list-objects.c +14 -0
@@ -234,3 +234,17 @@ void traverse_commit_list(struct rev_info *revs,object_array_clear (&revs->pending);strbuf_release (&base); } + +void get_commit_count (struct rev_info * revs) { +if (revs->count) { +if (revs->left_right && revs->cherry_mark) +printf ("%d\t%d\t%d\n" , revs->count_left, revs->count_right, revs->count_same); +else if (revs->left_right) +printf ("%d\t%d\n" , revs->count_left, revs->count_right); +else if (revs->cherry_mark) +printf ("%d\t%d\n" , revs->count_left + revs->count_right, revs->count_same); +else +printf ("%d\n" , revs->count_left + revs->count_right); + } +return ; +}
list-objects.h +1 -0
@@ -7,5 +7,6 @@ void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, voitypedef void (*show_edge_fn )(struct commit *);void mark_edges_uninteresting (struct rev_info *,show_edge_fn ); +void get_commit_count (struct rev_info * revs);#endif
Signature · 1 line
1.9.1
Quoted 1 line · Lawrence Siebert
+
get_commit_count(&revs);
There's trailing whitespace here.
(See my message in 3/4)
Rémi
PATCH 2/4 log: add --count option to git log
In reply to Lawrence Siebertadds --count from git rev-list to git log, without --use-bitmap-index for the moment.
--- builtin/log.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
builtin/log.c +29 -0
@@ -25,6 +25,7 @@#include "version.h" #include "mailmap.h" #include "gpg-interface.h" +#include "list-objects.h" /* Set a default date-time format for git log ("log.date" config variable) */ static const char *default_date_mode =NULL ;
@@ -317,12 +318,40 @@ static void finish_early_output(struct rev_info *rev)show_early_header (rev,"done" , n); } +static void show_object (struct object *obj, +const struct name_path *path,const char *component, +void *cb_data) +{ +return ; +} + +static void show_commit (struct commit *commit,void *data) +{ +struct rev_info *revs = (struct rev_info *)data; +if (commit->object.flags &PATCHSAME ) + revs->count_same++; +else if (commit->object.flags &SYMMETRIC_LEFT ) + revs->count_left++; +else + revs->count_right++; +if (commit->parents) { +free_commit_list (commit->parents); + commit->parents =NULL ; + } +free_commit_buffer (commit); +} +static int cmd_log_walk (struct rev_info *rev) {struct commit *commit;int saved_nrl =0 ;int saved_dcctc =0 ; +if (rev->count) { +prepare_revision_walk (rev); +traverse_commit_list (rev, show_commit, show_object, rev); +get_commit_count (rev); + }if (rev->early_output)setup_early_output (rev);
Signature · 1 line
1.9.1
Re: [PATCH 2/4] log: add --count option to git log
Quoted 1 line · Lawrence Siebert
+
prepare_revision_walk(rev);
There's trailing whitespace here.
(See my message in 3/4)
Rémi
PATCH 3/4 log --count: added test
In reply to Lawrence Siebertadded test comparing output between git log --count HEAD and git rev-list --count HEAD
--- t/t4202-log.sh | 7 +++++++ 1 file changed, 7 insertions(+)
t/t4202-log.sh +7 -0
@@ -871,4 +871,11 @@ test_expect_success 'log --graph --no-walk is forbidden' ' test_must_fail git log --graph --no-walk ' +test_expect_success 'log --count' ' + git log --count HEAD > actual && + git rev-list --count HEAD > expect && + test_cmp expect actual +' + + test_done
Signature · 1 line
1.9.1
Re: [PATCH 3/4] log --count: added test
Hi Lawrence,
t/t4202-log.sh test_expect_success 'log --graph --no-walk is forbidden' ' · line 876
Quoted 3 lines · Lawrence Siebert
t/t4202-log.sh +3
-0+test_expect_success 'log --count' ' + git log --count HEAD > actual && + git rev-list --count HEAD > expect &&
Why the huge space here between 'git' and 'rev-list'?
Also no space after the redirection ('>'), it should be '>actual' and '>expect'.
t/t4202-log.sh test_expect_success 'log --graph --no-walk is forbidden' ' · line 879
Quoted 3 lines
t/t4202-log.sh +3
-0+ test_cmp expect actual +' +
In the mail I see some trailing whitespace after the last two lines. I can't apply it myself before some time, so I can't see if 'git am' warns me about trailing whitespace.
You can use 'git log --check' to see the trailing whitespace in your commits.
I'll look if I see some trailing whitespace in your other parts of the patch but I might miss some.
Rémi
PATCH 4/4 git-log: update man documentation for --count
In reply to Lawrence SiebertI'm not altogether sure the best way to update the internal usage from git-log -h, but this at least updates the man page.
--- Documentation/git-log.txt | 2 ++ Documentation/rev-list-options.txt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
Documentation/git-log.txt +2 -0
@@ -90,6 +90,8 @@ include::line-range-format.txt[] Paths may need to be prefixed with ``\-- '' to separate them from options or the revision range, when confusion arises. + +:git-log: 1 include::rev-list-options.txt[] include::pretty-formats.txt[]
Documentation/rev-list-options.txt +1 -1
@@ -797,7 +797,7 @@ This implies the `--topo-order` option by default, but the in between them in that case. If `<barrier>` is specified, it is the string that will be shown instead of the default one. -ifdef::git-rev-list[] +ifdef::git-log,git-rev-list[] --count:: Print a number stating how many commits would have been listed, and suppress all other output. When used together
Signature · 1 line
1.9.1
Re: [PATCH 2/4] log: add --count option to git log
In reply to Remi Galan AlfonsoThanks. I've modified my vim config to avoid this happening again, and i'll submit a fixed version of these patches.
I'd love if there was a precommit hook to test for this.
Lawrence
Quoted 7 lines · Remi Galan Alfonso
Quoted 1 line · Lawrence Siebert
+
prepare_revision_walk(rev);There's trailing whitespace here.
(See my message in 3/4)Rémi
Signature · 2 lines
About Me: http://about.me/lawrencesiebert Constantly Coding: http://constantcoding.blogspot.com
Quoted 5 lines · Lawrence Siebert
Moving commit counting from rev-list into list-object which is a step toward letting git log do counting as well.
Signed-off-by Lawrence Siebert <[email protected]>---
No way. Look at the things provided by list-objects.c API. They are not about formatting outputs. printf() calls do not belong there.
Quoted 11 lines · Junio C Hamano
Quoted 5 lines · Lawrence Siebert
Moving commit counting from rev-list into list-object which is a step toward letting git log do counting as well.
Signed-off-by Lawrence Siebert <[email protected]>---
No way. Look at the things provided by
list-objects.cAPI. They are not about formatting outputs.printf()calls do not belong there.
Moreover, if we are going to provide an abstracted function to show the commit count, we would also need to provide one to _create_ the count. IOW, this get_commit_count, wherever it goes, should be accompanied by the matching code that is put into "show_commit" in patch 2.
-Peff