add replay and log to the usage string of git-bisect
[gitweb.git] / reflog-walk.c
index 989a7aee95ae2cd5a71e68920df5ca2f69cfef83..653ec956f08141b3e15f52665cef7a260f8ed6a4 100644 (file)
@@ -71,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;
@@ -165,6 +165,14 @@ void add_reflog_for_walk(struct reflog_walk_info *info,
        if (item)
                reflogs = item->util;
        else {
+               if (*branch == '\0') {
+                       unsigned char sha1[20];
+                       const char *head = resolve_ref("HEAD", sha1, 0, NULL);
+                       if (!head)
+                               die ("No current branch");
+                       free(branch);
+                       branch = xstrdup(head);
+               }
                reflogs = read_complete_reflog(branch);
                if (!reflogs || reflogs->nr == 0)
                        die("No reflogs found for '%s'", branch);
@@ -219,21 +227,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("}: %s", info->message);
+               }
+               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);
+               }
        }
 }