From 836f4cd06dc9b2eaf739be21220c43728acb5f14 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 15 May 2025 14:57:45 +1000 Subject: [PATCH] Refactor short_commit_id function --- themed/base.html | 17 +++++++++++++++-- themed/commit.html | 15 ++++++++------- themed/log.html | 7 +++---- themed/summary.html | 11 +++++++---- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/themed/base.html b/themed/base.html index e3b6bcd..4b8a79d 100644 --- a/themed/base.html +++ b/themed/base.html @@ -1,4 +1,4 @@ -{! static int get_num_commits(); static int get_num_branches(); static int get_num_tags(); !} +{! static int get_num_commits(); static int get_num_branches(); static int get_num_tags(); static void short_commit_id(char *hex); !} {% block page_start %} @@ -30,7 +30,13 @@ {# Heroicons micro list-bullet #} - {{ ctx.qry.head }} + + {% if strcmp(ctx.qry.page, "tree") == 0 && ctx.qry.oid %} + {! short_commit_id(ctx.qry.oid); !} + {% else %} + {{ ctx.qry.head }} + {% endif %} + {# Heroicons micro chevron-down #} @@ -184,6 +190,13 @@ cgit_free_reflist_inner(&list); return num_tags; } + + static void short_commit_id(char *hex) { + char short_commit_id[8]; + memcpy(short_commit_id, hex, 7); + short_commit_id[7] = '\0'; + html_txt(short_commit_id); + } !} {! diff --git a/themed/commit.html b/themed/commit.html index a3da15e..9079558 100644 --- a/themed/commit.html +++ b/themed/commit.html @@ -39,19 +39,20 @@ {! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago
- {! char short_commit_id[8]; !} {% for struct commit_list *p = commit->parents; p; p = p->next %} {! struct commit *parent = lookup_commit_reference(the_repository, &p->item->object.oid); !} {% if parent %} - {! memcpy(short_commit_id, oid_to_hex(&p->item->object.oid), 7); !} - {! short_commit_id[7] = '\0'; !} - parent item->object.oid) }}" class="font-mono text-blue-500 hover:text-blue-600 hover:underline">{{ short_commit_id }} + parent + item->object.oid) }}" class="font-mono text-blue-500 hover:text-blue-600 hover:underline"> + {! short_commit_id(oid_to_hex(&p->item->object.oid)); !} + · {% endif %} {% endfor %} - {! memcpy(short_commit_id, oid_to_hex(&commit->object.oid), 7); !} - {! short_commit_id[7] = '\0'; !} - commit object.oid) }}" class="font-mono text-blue-500 hover:text-blue-600 hover:underline">{{ short_commit_id }} + commit + object.oid) }}" class="font-mono text-blue-500 hover:text-blue-600 hover:underline"> + {! short_commit_id(oid_to_hex(&commit->object.oid)); !} + diff --git a/themed/log.html b/themed/log.html index 4a26a53..deac76c 100644 --- a/themed/log.html +++ b/themed/log.html @@ -36,10 +36,9 @@
- {! char short_commit_id[8]; !} - {! memcpy(short_commit_id, oid_to_hex(&commit->object.oid), 7); !} - {! short_commit_id[7] = '\0'; !} - object.oid) }}" class="text-sm font-mono text-gray-500 hover:text-blue-600 hover:underline">{{ short_commit_id }} + object.oid) }}" class="text-sm font-mono text-gray-500 hover:text-blue-600 hover:underline"> + {! short_commit_id(oid_to_hex(&commit->object.oid)); !} +
object.oid) }}" class="text-gray-500 hover:text-blue-600"> diff --git a/themed/summary.html b/themed/summary.html index 9bd3004..b4caf1e 100644 --- a/themed/summary.html +++ b/themed/summary.html @@ -52,10 +52,13 @@ {{ info->author }} object.oid) }}" class="ml-2 text-gray-500 hover:text-blue-600 hover:underline">{{ info->subject }}
- {! char short_commit_id[8]; !} - {! memcpy(short_commit_id, oid_to_hex(&commit->object.oid), 7); !} - {! short_commit_id[7] = '\0'; !} - object.oid) }}" class="font-mono hover:text-blue-600 hover:underline">{{ short_commit_id }} · {! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago + +object.oid) }}" class="font-mono hover:text-blue-600 hover:underline"> + {! short_commit_id(oid_to_hex(&commit->object.oid)); !} + +· +{! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago +
{# Files #} {!