All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] list-object: add get_commit_count function
@ 2015-07-02  5:38 Lawrence Siebert
  2015-07-02  5:38 ` [PATCH 2/4] log: add --count option to git log Lawrence Siebert
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Lawrence Siebert @ 2015-07-02  5:38 UTC (permalink / raw)
  To: git; +Cc: gitster, 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 <lawrencesiebert@gmail.com>
---
 builtin/rev-list.c | 12 ++----------
 list-objects.c     | 14 ++++++++++++++
 list-objects.h     |  1 +
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ff84a82..7b091db 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -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;
 }
diff --git a/list-objects.c b/list-objects.c
index 41736d2..6f76301 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -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;
+}
diff --git a/list-objects.h b/list-objects.h
index 136a1da..d28c1f3 100644
--- a/list-objects.h
+++ b/list-objects.h
@@ -7,5 +7,6 @@ void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, voi
 
 typedef 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
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] log: add --count option to git log
  2015-07-02  5:38 [PATCH 1/4] list-object: add get_commit_count function Lawrence Siebert
@ 2015-07-02  5:38 ` Lawrence Siebert
  2015-07-02  9:14   ` Remi Galan Alfonso
  2015-07-02  5:38 ` [PATCH 3/4] log --count: added test Lawrence Siebert
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Lawrence Siebert @ 2015-07-02  5:38 UTC (permalink / raw)
  To: git; +Cc: gitster, Lawrence Siebert

adds --count from git rev-list to git log, without --use-bitmap-index
for the moment.

Signed-off-by: Lawrence Siebert <lawrencesiebert@gmail.com>
---
 builtin/log.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/builtin/log.c b/builtin/log.c
index 8781049..ce6df1e 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] log --count: added test
  2015-07-02  5:38 [PATCH 1/4] list-object: add get_commit_count function Lawrence Siebert
  2015-07-02  5:38 ` [PATCH 2/4] log: add --count option to git log Lawrence Siebert
@ 2015-07-02  5:38 ` Lawrence Siebert
  2015-07-02  9:09   ` Remi Galan Alfonso
  2015-07-02  5:38 ` [PATCH 4/4] git-log: update man documentation for --count Lawrence Siebert
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Lawrence Siebert @ 2015-07-02  5:38 UTC (permalink / raw)
  To: git; +Cc: gitster, Lawrence Siebert

added test comparing output between git log --count HEAD and
git rev-list --count HEAD

Signed-off-by: Lawrence Siebert <lawrencesiebert@gmail.com>
---
 t/t4202-log.sh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 1b2e981..077952b 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -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
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] git-log: update man documentation for --count
  2015-07-02  5:38 [PATCH 1/4] list-object: add get_commit_count function Lawrence Siebert
  2015-07-02  5:38 ` [PATCH 2/4] log: add --count option to git log Lawrence Siebert
  2015-07-02  5:38 ` [PATCH 3/4] log --count: added test Lawrence Siebert
@ 2015-07-02  5:38 ` Lawrence Siebert
  2015-07-02  9:13 ` [PATCH 1/4] list-object: add get_commit_count function Remi Galan Alfonso
  2015-07-03 17:49 ` Junio C Hamano
  4 siblings, 0 replies; 10+ messages in thread
From: Lawrence Siebert @ 2015-07-02  5:38 UTC (permalink / raw)
  To: git; +Cc: gitster, Lawrence Siebert

I'm not altogether sure the best way to update the internal usage
from git-log -h, but this at least updates the man page.

Signed-off-by: Lawrence Siebert <lawrencesiebert@gmail.com>
---
 Documentation/git-log.txt          | 2 ++
 Documentation/rev-list-options.txt | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 5692945..0e10e44 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -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[]
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 77ac439..f4e15fb 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -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
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/4] log --count: added test
  2015-07-02  5:38 ` [PATCH 3/4] log --count: added test Lawrence Siebert
@ 2015-07-02  9:09   ` Remi Galan Alfonso
  0 siblings, 0 replies; 10+ messages in thread
From: Remi Galan Alfonso @ 2015-07-02  9:09 UTC (permalink / raw)
  To: Lawrence Siebert; +Cc: git, gitster

Hi Lawrence,

Lawrence Siebert <lawrencesiebert@gmail.com> writes:
> +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'.

> +        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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] list-object: add get_commit_count function
  2015-07-02  5:38 [PATCH 1/4] list-object: add get_commit_count function Lawrence Siebert
                   ` (2 preceding siblings ...)
  2015-07-02  5:38 ` [PATCH 4/4] git-log: update man documentation for --count Lawrence Siebert
@ 2015-07-02  9:13 ` Remi Galan Alfonso
  2015-07-03 17:49 ` Junio C Hamano
  4 siblings, 0 replies; 10+ messages in thread
From: Remi Galan Alfonso @ 2015-07-02  9:13 UTC (permalink / raw)
  To: Lawrence Siebert; +Cc: git, gitster

Lawrence Siebert <lawrencesiebert@gmail.com> writes:
> +                get_commit_count(&revs);  

There's trailing whitespace here.
(See my message in 3/4)

Rémi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/4] log: add --count option to git log
  2015-07-02  5:38 ` [PATCH 2/4] log: add --count option to git log Lawrence Siebert
@ 2015-07-02  9:14   ` Remi Galan Alfonso
  2015-07-02 23:45     ` Lawrence Siebert
  0 siblings, 1 reply; 10+ messages in thread
From: Remi Galan Alfonso @ 2015-07-02  9:14 UTC (permalink / raw)
  To: Lawrence Siebert; +Cc: git, gitster

Lawrence Siebert <lawrencesiebert@gmail.com> writes:
> +                prepare_revision_walk(rev);        

There's trailing whitespace here.
(See my message in 3/4)

Rémi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/4] log: add --count option to git log
  2015-07-02  9:14   ` Remi Galan Alfonso
@ 2015-07-02 23:45     ` Lawrence Siebert
  0 siblings, 0 replies; 10+ messages in thread
From: Lawrence Siebert @ 2015-07-02 23:45 UTC (permalink / raw)
  To: Remi Galan Alfonso; +Cc: git, Junio C Hamano

Thanks.  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

On Thu, Jul 2, 2015 at 2:14 AM, Remi Galan Alfonso
<remi.galan-alfonso@ensimag.grenoble-inp.fr> wrote:
> Lawrence Siebert <lawrencesiebert@gmail.com> writes:
>> +                prepare_revision_walk(rev);
>
> There's trailing whitespace here.
> (See my message in 3/4)
>
> Rémi



-- 
About Me: http://about.me/lawrencesiebert
Constantly Coding: http://constantcoding.blogspot.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] list-object: add get_commit_count function
  2015-07-02  5:38 [PATCH 1/4] list-object: add get_commit_count function Lawrence Siebert
                   ` (3 preceding siblings ...)
  2015-07-02  9:13 ` [PATCH 1/4] list-object: add get_commit_count function Remi Galan Alfonso
@ 2015-07-03 17:49 ` Junio C Hamano
  2015-07-03 18:36   ` Jeff King
  4 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2015-07-03 17:49 UTC (permalink / raw)
  To: Lawrence Siebert; +Cc: git

Lawrence Siebert <lawrencesiebert@gmail.com> writes:

> 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 <lawrencesiebert@gmail.com>
> ---

No way.  Look at the things provided by list-objects.c API.  They
are not about formatting outputs.  printf() calls do not belong
there.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] list-object: add get_commit_count function
  2015-07-03 17:49 ` Junio C Hamano
@ 2015-07-03 18:36   ` Jeff King
  0 siblings, 0 replies; 10+ messages in thread
From: Jeff King @ 2015-07-03 18:36 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Lawrence Siebert, git

On Fri, Jul 03, 2015 at 10:49:40AM -0700, Junio C Hamano wrote:

> Lawrence Siebert <lawrencesiebert@gmail.com> writes:
> 
> > 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 <lawrencesiebert@gmail.com>
> > ---
> 
> No way.  Look at the things provided by list-objects.c API.  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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-07-03 18:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-02  5:38 [PATCH 1/4] list-object: add get_commit_count function Lawrence Siebert
2015-07-02  5:38 ` [PATCH 2/4] log: add --count option to git log Lawrence Siebert
2015-07-02  9:14   ` Remi Galan Alfonso
2015-07-02 23:45     ` Lawrence Siebert
2015-07-02  5:38 ` [PATCH 3/4] log --count: added test Lawrence Siebert
2015-07-02  9:09   ` Remi Galan Alfonso
2015-07-02  5:38 ` [PATCH 4/4] git-log: update man documentation for --count Lawrence Siebert
2015-07-02  9:13 ` [PATCH 1/4] list-object: add get_commit_count function Remi Galan Alfonso
2015-07-03 17:49 ` Junio C Hamano
2015-07-03 18:36   ` Jeff King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.