Merge branch 'js/reverse'
authorJunio C Hamano <junkio@cox.net>
Wed, 14 Feb 2007 03:20:06 +0000 (19:20 -0800)
committerJunio C Hamano <junkio@cox.net>
Wed, 14 Feb 2007 03:20:06 +0000 (19:20 -0800)
* js/reverse:
Teach revision machinery about --reverse

1  2 
Documentation/git-rev-list.txt
revision.c
index c742117595cd8ae5ab371a7ba21513a419af7996,beb090651b62f45851edd89a2217d4208397cc92..4f145eaba47175e48dd592ffe5018be5cb4cb375
@@@ -27,6 -27,7 +27,7 @@@ SYNOPSI
             [ \--pretty | \--header ]
             [ \--bisect ]
             [ \--merge ]
+            [ \--reverse ]
             [ \--walk-reflogs ]
             <commit>... [ \-- <paths>... ]
  
@@@ -191,7 -192,7 +192,7 @@@ limiting may be applied
        In addition to the '<commit>' listed on the command
        line, read them from the standard input.
  
 ---walk-reflogs::
 +-g, --walk-reflogs::
  
        Instead of walking the commit ancestry chain, walk
        reflog entries from the most recent one to older ones.
@@@ -266,6 -267,10 +267,10 @@@ By default, the commits are shown in re
        parent comes before all of its children, but otherwise things
        are still ordered in the commit timestamp order.
  
+ --reverse::
+       Output the commits in reverse order.
  Object Traversal
  ~~~~~~~~~~~~~~~~
  
diff --combined revision.c
index 15bdaf6095ccbe690c664f80a5b25e354d068d61,6726f736ed7b487e0f11dc5295ffb9a186327ce3..5b1794b0efbd628f935db006835168ea3e640de4
@@@ -532,7 -532,7 +532,7 @@@ static void handle_reflog(struct rev_in
        struct all_refs_cb cb;
        cb.all_revs = revs;
        cb.all_flags = flags;
 -      for_each_ref(handle_one_reflog, &cb);
 +      for_each_reflog(handle_one_reflog, &cb);
  }
  
  static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
@@@ -868,8 -868,7 +868,8 @@@ int setup_revisions(int argc, const cha
                                handle_reflog(revs, flags);
                                continue;
                        }
 -                      if (!strcmp(arg, "--walk-reflogs")) {
 +                      if (!strcmp(arg, "-g") ||
 +                                      !strcmp(arg, "--walk-reflogs")) {
                                init_reflog_walk(&revs->reflog_info);
                                continue;
                        }
                                        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) {
@@@ -1286,6 -1289,40 +1290,40 @@@ struct commit *get_revision(struct rev_
  {
        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)