]> asedeno.scripts.mit.edu Git - git.git/blobdiff - reflog-walk.c
--walk-reflogs: actually find the right commit by date.
[git.git] / reflog-walk.c
index 2d974116ded2c3b5de8a4ab6cdcd9f02b0ff95c7..8e2cd2fcf603cdcf667b8d5d9c61a6ce902dd189 100644 (file)
@@ -4,6 +4,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "path-list.h"
+#include "reflog-walk.h"
 
 struct complete_reflogs {
        char *ref;
@@ -70,7 +71,7 @@ static int get_reflog_recno_by_time(struct complete_reflogs *array,
        unsigned long timestamp)
 {
        int i;
-       for (i = array->nr - 1; i >= 0; i++)
+       for (i = array->nr - 1; i >= 0; i--)
                if (timestamp >= array->items[i].timestamp)
                        return i;
        return -1;
@@ -218,21 +219,32 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
        commit->object.flags &= ~(ADDED | SEEN | SHOWN);
 }
 
-void show_reflog_message(struct reflog_walk_info* info)
+void show_reflog_message(struct reflog_walk_info* info, int oneline)
 {
        if (info && info->last_commit_reflog) {
                struct commit_reflog *commit_reflog = info->last_commit_reflog;
                struct reflog_info *info;
 
-               printf("Reflog: %s@{", commit_reflog->reflogs->ref);
-               info = &commit_reflog->reflogs->items[commit_reflog->recno + 1];
-               if (commit_reflog->flag)
-                       printf("%s", show_rfc2822_date(info->timestamp,
-                                               info->tz));
-               else
-                       printf("%d", commit_reflog->reflogs->nr
-                                       - 2 - commit_reflog->recno);
-               printf("} (%s)\nReflog message: %s",
-                       info->email, info->message);
+               info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
+               if (oneline) {
+                       printf("%s@{", commit_reflog->reflogs->ref);
+                       if (commit_reflog->flag)
+                               printf("%s", show_date(info->timestamp, 0, 1));
+                       else
+                               printf("%d", commit_reflog->reflogs->nr
+                                      - 2 - commit_reflog->recno);
+                       printf("}: ");
+               }
+               else {
+                       printf("Reflog: %s@{", commit_reflog->reflogs->ref);
+                       if (commit_reflog->flag)
+                               printf("%s", show_rfc2822_date(info->timestamp,
+                                                              info->tz));
+                       else
+                               printf("%d", commit_reflog->reflogs->nr
+                                      - 2 - commit_reflog->recno);
+                       printf("} (%s)\nReflog message: %s",
+                              info->email, info->message);
+               }
        }
 }