git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH] Re: BUG? git log -Sfoo --max-count=N

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Mar 7, 2011, 12:46 UTC
Message-ID
<vpqpqq3qern.fsf@bauges.imag.fr>
In-Reply-To
<87hbbgvske.fsf@wanadoo.es>
Óscar Fuentes <ofv@wanadoo.es> writes:
Show 6 quoted lines
> when [--max-count is] used with -S as in
>
> git log -Sfoo --max-count=N
>
> it acts as "inspect only the N first commits", i.e. if `foo' is not
> present on any of the first N commits no output is shown.
I'd call this a bug.

The following patch seems to fix it, but I'm not terribly happy with the way it works. Any better idea?

From 3b962e004790c36c426efff64ad34043045e4aca Mon Sep 17 00:00:00 2001
From: Matthieu Moy <Matthieu.Moy@imag.fr>
Date: Mon, 7 Mar 2011 13:41:05 +0100
Subject: [PATCH] log: fix --max-count when used together with -S or -G

--max-count is implemented by counting revisions in get_revision(), but the -S and -G take effect later (after running diff), hence, --max-count=10 -Sfoo meant "examine the 10 first revisions, and out of them, show only those changing the occurences of foo", not "show 10 revisions changing the occurences of foo".

In case the commit isn't actually shown, cancel the decrement of
max_count.
---
 builtin/log.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index f5ed690..b83900b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -263,7 +263,12 @@ static int cmd_log_walk(struct rev_info *rev)
         * retain that state information if replacing rev->diffopt in this loop
         */
        while ((commit = get_revision(rev)) != NULL) {
-               log_tree_commit(rev, commit);
+               if (!log_tree_commit(rev, commit))
+                       /*
+                        * We decremented max_count in get_revision,
+                        * but we didn't actually show the commit.
+                        */
+                       rev->max_count++;
                if (!rev->reflog_info) {
                        /* we allow cycles in reflog ancestry */
                        free(commit->buffer);
-- 
1.7.4.1.176.g6b069.dirty

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Óscar FuentesNext: Junio C Hamano
Message 2 of 8 in “BUG? git log -Sfoo --max-count=N”
  1. Óscar FuentesMar 6, 2011
  2. Re: BUG? git log -Sfoo --max-count=NMatthieu Moy, Mar 7, 2011
  3. Junio C HamanoMar 8, 2011
  4. log: fix --max-count when used together with -S or -GMatthieu Moy, Mar 9, 2011
  5. Jeff KingMar 9, 2011
  6. Matthieu MoyMar 9, 2011
  7. Junio C HamanoMar 9, 2011
  8. Jeff KingMar 10, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.