[PATCH 1/4] list-object: add get_commit_count function

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/4] list-object: add get_commit_count function

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 <[hidden email]>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/4] log: add --count option to git log

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

Signed-off-by: Lawrence Siebert <[hidden email]>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 3/4] log --count: added test

Lawrence Siebert
In reply to this post by Lawrence Siebert
added test comparing output between git log --count HEAD and
git rev-list --count HEAD

Signed-off-by: Lawrence Siebert <[hidden email]>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 4/4] git-log: update man documentation for --count

Lawrence Siebert
In reply to this post by 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 <[hidden email]>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 3/4] log --count: added test

Remi Galan Alfonso
In reply to this post by Lawrence Siebert
Hi Lawrence,

Lawrence Siebert <[hidden email]> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/4] list-object: add get_commit_count function

Remi Galan Alfonso
In reply to this post by Lawrence Siebert
Lawrence Siebert <[hidden email]> writes:
> +                get_commit_count(&revs);  

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

Rémi
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/4] log: add --count option to git log

Remi Galan Alfonso
In reply to this post by Lawrence Siebert
Lawrence Siebert <[hidden email]> writes:
> +                prepare_revision_walk(rev);        

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

Rémi
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/4] log: add --count option to git log

Lawrence Siebert
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
<[hidden email]> wrote:
> Lawrence Siebert <[hidden email]> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/4] list-object: add get_commit_count function

Junio C Hamano
In reply to this post by Lawrence Siebert
Lawrence Siebert <[hidden email]> 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 <[hidden email]>
> ---

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/4] list-object: add get_commit_count function

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

> Lawrence Siebert <[hidden email]> 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 <[hidden email]>
> > ---
>
> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html