Merge branch 'jn/fsck-ident'
[gitweb.git] / reflog-walk.c
index 596bafebdd839f410a96caaba30491d4d7b2be16..caba4f743f2dcc1cf7046cec294f242b2af19052 100644 (file)
@@ -8,6 +8,7 @@
 
 struct complete_reflogs {
        char *ref;
+       const char *short_ref;
        struct reflog_info {
                unsigned char osha1[20], nsha1[20];
                char *email;
@@ -243,15 +244,26 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
 
 void get_reflog_selector(struct strbuf *sb,
                         struct reflog_walk_info *reflog_info,
-                        enum date_mode dmode)
+                        enum date_mode dmode,
+                        int shorten)
 {
        struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
        struct reflog_info *info;
+       const char *printed_ref;
 
        if (!commit_reflog)
                return;
 
-       strbuf_addf(sb, "%s@{", commit_reflog->reflogs->ref);
+       if (shorten) {
+               if (!commit_reflog->reflogs->short_ref)
+                       commit_reflog->reflogs->short_ref
+                               = shorten_unambiguous_ref(commit_reflog->reflogs->ref, 0);
+               printed_ref = commit_reflog->reflogs->short_ref;
+       } else {
+               printed_ref = commit_reflog->reflogs->ref;
+       }
+
+       strbuf_addf(sb, "%s@{", printed_ref);
        if (commit_reflog->flag || dmode) {
                info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
                strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
@@ -263,6 +275,23 @@ void get_reflog_selector(struct strbuf *sb,
        strbuf_addch(sb, '}');
 }
 
+void get_reflog_message(struct strbuf *sb,
+                       struct reflog_walk_info *reflog_info)
+{
+       struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
+       struct reflog_info *info;
+       size_t len;
+
+       if (!commit_reflog)
+               return;
+
+       info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
+       len = strlen(info->message);
+       if (len > 0)
+               len--; /* strip away trailing newline */
+       strbuf_add(sb, info->message, len);
+}
+
 void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
        enum date_mode dmode)
 {
@@ -272,7 +301,7 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
                struct strbuf selector = STRBUF_INIT;
 
                info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
-               get_reflog_selector(&selector, reflog_info, dmode);
+               get_reflog_selector(&selector, reflog_info, dmode, 0);
                if (oneline) {
                        printf("%s: %s", selector.buf, info->message);
                }