Teach revision machinery about --reverse

The option --reverse reverses the order of the commits.

[jc: with comments on rev_info.reverse from Simon 'corecode' Schubert.]

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Johannes Schindelin
2007-01-20 23:04:02 +01:00
committed by Junio C Hamano
parent eaf6459e4d
commit 9c5e66e97d
3 changed files with 45 additions and 1 deletions

View File

@ -1057,6 +1057,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
git_log_output_encoding = "";
continue;
}
if (!strcmp(arg, "--reverse")) {
revs->reverse ^= 1;
continue;
}
opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
if (opts > 0) {
@ -1285,6 +1289,40 @@ struct commit *get_revision(struct rev_info *revs)
{
struct commit *c = NULL;
if (revs->reverse) {
struct commit_list *list;
/*
* rev_info.reverse is used to note the fact that we
* want to output the list of revisions in reverse
* order. To accomplish this goal, reverse can have
* different values:
*
* 0 do nothing
* 1 reverse the list
* 2 internal use: we have already obtained and
* reversed the list, now we only need to yield
* its items.
*/
if (revs->reverse == 1) {
revs->reverse = 0;
list = NULL;
while ((c = get_revision(revs)))
commit_list_insert(c, &list);
revs->commits = list;
revs->reverse = 2;
}
if (!revs->commits)
return NULL;
c = revs->commits->item;
list = revs->commits->next;
free(revs->commits);
revs->commits = list;
return c;
}
if (0 < revs->skip_count) {
while ((c = get_revision_1(revs)) != NULL) {
if (revs->skip_count-- <= 0)