cgit

commit 5b1f42ffeec7e315fc4fcff5145e5b0adca30715

Author: John Keeping <john@keeping.me.uk>

ui-shared: use the same snapshot logic as ui-refs

Make snapshot links in the commit UI use the same prefix algorithm as
those in the summary UI, so that refs starting with the snapshot prefix
are used as-is rather than composed with the prefix repeated.

Signed-off-by: John Keeping <john@keeping.me.uk>
Reviewed-by: Christian Hesse <mail@eworm.de>

 ui-shared.c | 8 +++++++-


diff --git a/ui-shared.c b/ui-shared.c
index 8ae81d265a7a5927a91b3796a988a70510a7d5c5..50a168d8873a0bf99c76790df5bad10759d6e147 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1115,9 +1115,15 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref)
 {
 	const struct cgit_snapshot_format* f;
 	struct strbuf filename = STRBUF_INIT;
+	const char *basename;
 	size_t prefixlen;
 
-	cgit_compose_snapshot_prefix(&filename, cgit_snapshot_prefix(repo), ref);
+	basename = cgit_snapshot_prefix(repo);
+	if (starts_with(ref, basename))
+		strbuf_addstr(&filename, ref);
+	else
+		cgit_compose_snapshot_prefix(&filename, basename, ref);
+
 	prefixlen = filename.len;
 	for (f = cgit_snapshot_formats; f->suffix; f++) {
 		if (!(repo->snapshots & f->bit))