# [PATCH] Fix git rev-list --reverse --max-count=N

6 messages from 2010-01-27 to 2010-01-27. Participants: Michael Spang, Johannes Sixt, Sverre Rabbelier, Junio C Hamano.
Thread: https://gitlist.dev/t/22415

## Michael Spang, 2010-01-27 20:03

Subject: [PATCH] Fix git rev-list --reverse --max-count=N
Message-ID: <1264622600-20981-1-git-send-email-spang@google.com>
URL: https://gitlist.dev/e/1264622600-20981-1-git-send-email-spang%40google.com

```
Using --max-count with --reverse currently outputs the last N commits
in the final output rather than the first N commits. We want to
truncate the reversed list after the first few commits, rather than
truncating the initial list and reversing that.

Signed-off-by: Michael Spang <spang@google.com>
---
 revision.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/revision.c b/revision.c
index f54d43f..62135e0 100644
--- a/revision.c
+++ b/revision.c
@@ -1993,7 +1993,8 @@ static struct commit *get_revision_internal(struct rev_info *revs)
 		c = NULL;
 		break;
 	default:
-		revs->max_count--;
+		if (!revs->reverse)
+			revs->max_count--;
 	}
 
 	if (c)
@@ -2055,8 +2056,21 @@ struct commit *get_revision(struct rev_info *revs)
 		revs->reverse_output_stage = 1;
 	}
 
-	if (revs->reverse_output_stage)
-		return pop_commit(&revs->commits);
+	if (revs->reverse_output_stage) {
+		c = pop_commit(&revs->commits);
+
+		switch (revs->max_count) {
+		case -1:
+			break;
+		case 0:
+			c = NULL;
+			break;
+		default:
+			revs->max_count--;
+		}
+
+		return c;
+	}
 
 	c = get_revision_internal(revs);
 	if (c && revs->graph)
-- 
1.6.6

```

## Johannes Sixt, 2010-01-27 22:09

Subject: Re: [PATCH] Fix git rev-list --reverse --max-count=N
Message-ID: <201001272309.26054.j6t@kdbg.org>
URL: https://gitlist.dev/e/201001272309.26054.j6t%40kdbg.org
In-Reply-To: <1264622600-20981-1-git-send-email-spang@google.com>

```
On Mittwoch, 27. Januar 2010, Michael Spang wrote:
> Using --max-count with --reverse currently outputs the last N commits
> in the final output rather than the first N commits. We want to
> truncate the reversed list after the first few commits, rather than
> truncating the initial list and reversing that.

So when you have this history (A is oldest, D is newest):

   A--B--C--D

and you say

   git log --max-count=2 --reverse D

then you want

   A
   B

but I want

   C
   D

Why is your interpretation correct, an mine wrong?

-- Hannes

```

## Sverre Rabbelier, 2010-01-27 22:17

Subject: Re: [PATCH] Fix git rev-list --reverse --max-count=N
Message-ID: <fabb9a1e1001271417w1c26fffdy379f8b845e4098b1@mail.gmail.com>
URL: https://gitlist.dev/e/fabb9a1e1001271417w1c26fffdy379f8b845e4098b1%40mail.gmail.com
In-Reply-To: <201001272309.26054.j6t@kdbg.org>

```
Heya,

> So when you have this history (A is oldest, D is newest):
>
>   A--B--C--D
>
> and you say
>
>   git log --max-count=2 --reverse D
>
> then you want
>
>   A
>   B
>
> but I want
>
>   C
>   D
>

And the current behavior is

B
A

Isn't it? I agree btw, that C D is the 'correct' result.

-- 
Cheers,

Sverre Rabbelier

```

## Michael Spang, 2010-01-27 22:21

Subject: Re: [PATCH] Fix git rev-list --reverse --max-count=N
Message-ID: <abef960f1001271421s6c0f72f7xd2697ab34b53d1ea@mail.gmail.com>
URL: https://gitlist.dev/e/abef960f1001271421s6c0f72f7xd2697ab34b53d1ea%40mail.gmail.com
In-Reply-To: <201001272309.26054.j6t@kdbg.org>

```
On Wed, Jan 27, 2010 at 5:09 PM, Johannes Sixt <j6t@kdbg.org> wrote:
> On Mittwoch, 27. Januar 2010, Michael Spang wrote:
>
> So when you have this history (A is oldest, D is newest):
>
>   A--B--C--D
>
> and you say
>
>   git log --max-count=2 --reverse D
>
> then you want
>
>   A
>   B
>
> but I want
>
>   C
>   D
>
> Why is your interpretation correct, an mine wrong?

Perhaps not wrong, but for me it was unexpected. For whatever reason,
I expected "--reverse" to give you the illusion that you are iterating
from the beginning of the history, even if it's not actually possible
to iterate that way directly. In line with that, limiting the output
to N commits would give you the earliest N commits. If you instead
think "stop descending through the history once we have N commits" the
current behavior makes sense.

I talked to Junio and he says the current behavior is here to stay.

Michael

```

## Junio C Hamano, 2010-01-27 22:28

Subject: Re: [PATCH] Fix git rev-list --reverse --max-count=N
Message-ID: <7vsk9rnpxo.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vsk9rnpxo.fsf%40alter.siamese.dyndns.org
In-Reply-To: <201001272309.26054.j6t@kdbg.org>

```
Johannes Sixt <j6t@kdbg.org> writes:

> On Mittwoch, 27. Januar 2010, Michael Spang wrote:
>> Using --max-count with --reverse currently outputs the last N commits
>> in the final output rather than the first N commits. We want to
>> truncate the reversed list after the first few commits, rather than
>> truncating the initial list and reversing that.
>
> So when you have this history (A is oldest, D is newest):
>
>    A--B--C--D
>
> and you say
>
>    git log --max-count=2 --reverse D
>
> then you want
>
>    A
>    B
>
> but I want
>
>    C
>    D
>
> Why is your interpretation correct, an mine wrong?

The interaction between --max-count and --reverse was designed a long time
ago to support "I want to review the recent N commits in order to make
sure that they are natural and logical progression".  So an unconditional
change of semantics to break that expectation this late in the game will
never be acceptable, and giving title to such a patch with a word "Fix"
won't fly well (it simply _breaks_ behaviour users have long learned to
expect).

It is a different matter to add an explicit command line option (and no
configuration to change it to default) to apply reversal before count
limiting.

```

## Michael Spang, 2010-01-27 22:51

Subject: Re: [PATCH] Fix git rev-list --reverse --max-count=N
Message-ID: <abef960f1001271451n5ed454aaye1591ea35729b53f@mail.gmail.com>
URL: https://gitlist.dev/e/abef960f1001271451n5ed454aaye1591ea35729b53f%40mail.gmail.com
In-Reply-To: <7vsk9rnpxo.fsf@alter.siamese.dyndns.org>

```
On Wed, Jan 27, 2010 at 5:28 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Johannes Sixt <j6t@kdbg.org> writes:
>
> The interaction between --max-count and --reverse was designed a long time
> ago to support "I want to review the recent N commits in order to make
> sure that they are natural and logical progression".  So an unconditional
> change of semantics to break that expectation this late in the game will
> never be acceptable, and giving title to such a patch with a word "Fix"
> won't fly well (it simply _breaks_ behaviour users have long learned to
> expect).

You have my apology for calling it a fix. I just don't have the same
visibility into what undocumented behavior users depend on that you
do, and so I thought it actually was one.

The patch can die here. I understand the current behavior now, and I
don't have a strong need for the behavior I expected (piping to head
works fine).

Michael

```
