]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-log.c
ui-shared: Simplify cgit_print_error_page() logic
[ps-cgit] / ui-log.c
index 45732550bd7dc68e768862a5cb6c4f2bd03ba660..d6d94f658391e57cdc11da36c7a0f7902d8716e1 100644 (file)
--- a/ui-log.c
+++ b/ui-log.c
@@ -61,38 +61,38 @@ void show_commit_decorations(struct commit *commit)
 
        buf[sizeof(buf) - 1] = 0;
        deco = get_name_decoration(&commit->object);
+       if (!deco)
+               return;
        html("<span class='decoration'>");
        while (deco) {
-               if (starts_with(deco->name, "refs/heads/")) {
-                       strncpy(buf, deco->name + 11, sizeof(buf) - 1);
+               strncpy(buf, prettify_refname(deco->name), sizeof(buf) - 1);
+               switch(deco->type) {
+               case DECORATION_NONE:
+                       /* If the git-core doesn't recognize it,
+                        * don't display anything. */
+                       break;
+               case DECORATION_REF_LOCAL:
                        cgit_log_link(buf, NULL, "branch-deco", buf, NULL,
-                                     ctx.qry.vpath, 0, NULL, NULL,
-                                     ctx.qry.showmsg, 0);
-               }
-               else if (starts_with(deco->name, "tag: refs/tags/")) {
-                       strncpy(buf, deco->name + 15, sizeof(buf) - 1);
-                       cgit_tag_link(buf, NULL, "tag-deco", buf);
-               }
-               else if (starts_with(deco->name, "refs/tags/")) {
-                       strncpy(buf, deco->name + 10, sizeof(buf) - 1);
+                               ctx.qry.vpath, 0, NULL, NULL,
+                               ctx.qry.showmsg, 0);
+                       break;
+               case DECORATION_REF_TAG:
                        cgit_tag_link(buf, NULL, "tag-deco", buf);
-               }
-               else if (starts_with(deco->name, "refs/remotes/")) {
+                       break;
+               case DECORATION_REF_REMOTE:
                        if (!ctx.repo->enable_remote_branches)
-                               goto next;
-                       strncpy(buf, deco->name + 13, sizeof(buf) - 1);
+                               break;
                        cgit_log_link(buf, NULL, "remote-deco", NULL,
-                                     oid_to_hex(&commit->object.oid),
-                                     ctx.qry.vpath, 0, NULL, NULL,
-                                     ctx.qry.showmsg, 0);
-               }
-               else {
-                       strncpy(buf, deco->name, sizeof(buf) - 1);
+                               oid_to_hex(&commit->object.oid),
+                               ctx.qry.vpath, 0, NULL, NULL,
+                               ctx.qry.showmsg, 0);
+                       break;
+               default:
                        cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
-                                        oid_to_hex(&commit->object.oid),
-                                        ctx.qry.vpath);
+                                       oid_to_hex(&commit->object.oid),
+                                       ctx.qry.vpath);
+                       break;
                }
-next:
                deco = deco->next;
        }
        html("</span>");
@@ -141,7 +141,9 @@ static int show_commit(struct commit *commit, struct rev_info *revs)
 
        /* When we get here we have precisely one parent. */
        parent = parents->item;
-       parse_commit(parent);
+       /* If we can't parse the commit, let print_commit() report an error. */
+       if (parse_commit(parent))
+               return 1;
 
        files = 0;
        add_lines = 0;
@@ -202,7 +204,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
        }
        else {
                html("<td>");
-               cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
+               cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2);
                html("</td>");
        }
 
@@ -242,7 +244,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
 
        if (revs->graph) {
                html("</td><td>");
-               cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
+               cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2);
        }
 
        if (!lines_counted && (ctx.repo->enable_log_filecount ||