log: fix --max-count when used together with -S or -G
The --max-count limit is implemented by counting revisions in get_revision(), but the -S and -G take effect later when 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. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Mar 9, 2011 at 21:52 UTC
251df09be3af658404f5f5f670a013d5806645d4
5 files changed
+26
-1
builtin/log.c
+7
-1
@@ -263,7 +263,13 @@ static int cmd_log_walk(struct rev_info *rev)
263
* retain that state information if replacing rev->diffopt in this loop
264
*/
265
while ((commit = get_revision(rev)) != NULL) {
266
- log_tree_commit(rev, commit);
266
+ if (!log_tree_commit(rev, commit) &&
267
+ rev->max_count >= 0)
268
+ /*
269
+ * We decremented max_count in get_revision,
270
+ * but we didn't actually show the commit.
271
+ */
272
+ rev->max_count++;
273
if (!rev->reflog_info) {
274
/* we allow cycles in reflog ancestry */
275
free(commit->buffer);
t/t4013-diff-various.sh
+3
@@ -210,6 +210,9 @@ log -m -p master
210
log -SF master
211
log -S F master
212
log -SF -p master
213
+log -SF master --max-count=0
214
+log -SF master --max-count=1
215
+log -SF master --max-count=2
216
log -GF master
217
log -GF -p master
218
log -GF -p --pickaxe-all master
t/t4013/diff.log_-SF_master_--max-count=0
new
+2
@@ -0,0 +1,2 @@
1
+$ git log -SF master --max-count=0
2
+$
t/t4013/diff.log_-SF_master_--max-count=1
new
+7
@@ -0,0 +1,7 @@
1
+$ git log -SF master --max-count=1
2
+commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
3
+Author: A U Thor <author@example.com>
4
+Date: Mon Jun 26 00:02:00 2006 +0000
5
+
6
+ Third
7
+$
t/t4013/diff.log_-SF_master_--max-count=2
new
+7
@@ -0,0 +1,7 @@
1
+$ git log -SF master --max-count=2
2
+commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
3
+Author: A U Thor <author@example.com>
4
+Date: Mon Jun 26 00:02:00 2006 +0000
5
+
6
+ Third
7
+$