From c1572bb5ec4540b5008490cf471cc4a5e65ef728 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sat, 31 Mar 2018 14:20:01 +0100 Subject: Add "snapshot-prefix" repo configuration Allow using a user-specified value for the prefix in snapshot files instead of the repository basename. For example, files downloaded from the linux-stable.git repository should be named linux-$VERSION and not linux-stable-$VERSION, which can be achieved by setting: repo.snapshot-prefix=linux Signed-off-by: John Keeping Reviewed-by: Christian Hesse --- ui-refs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui-refs.c') diff --git a/ui-refs.c b/ui-refs.c index 75f2789..50d9d30 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -100,7 +100,7 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) if (!ref || strlen(ref) < 1) return; - basename = cgit_repobasename(repo->url); + basename = cgit_snapshot_prefix(repo); if (starts_with(ref, basename)) strbuf_addstr(&filename, ref); else -- cgit v1.2.3-24-g4f1b From f0047d2d943788fed2666e1d20c1e0d3c16701d5 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sat, 31 Mar 2018 14:57:22 +0100 Subject: ui-refs: remove unnecessary sanity check There is no way for refinfo::refname to be null, and Git will prevent zero-length refs so this check is unnecessary. Signed-off-by: John Keeping Reviewed-by: Christian Hesse --- ui-refs.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'ui-refs.c') diff --git a/ui-refs.c b/ui-refs.c index 50d9d30..7b95e8b 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -97,9 +97,6 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) struct strbuf filename = STRBUF_INIT; size_t prefixlen; - if (!ref || strlen(ref) < 1) - return; - basename = cgit_snapshot_prefix(repo); if (starts_with(ref, basename)) strbuf_addstr(&filename, ref); -- cgit v1.2.3-24-g4f1b From 71d14d9c98c39a6683780060f84429a3a7e5b348 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sat, 31 Mar 2018 15:11:05 +0100 Subject: ui-refs: use shared function to print tag downloads cgit_compose_snapshot_prefix() is identical to print_tag_downloads(), so remove the latter and use the function from ui-shared.c instead. Signed-off-by: John Keeping Reviewed-by: Christian Hesse --- ui-refs.c | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'ui-refs.c') diff --git a/ui-refs.c b/ui-refs.c index 7b95e8b..2ec3858 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -90,31 +90,6 @@ static void print_tag_header(void) "Age\n"); } -static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) -{ - const struct cgit_snapshot_format* f; - const char *basename; - struct strbuf filename = STRBUF_INIT; - size_t prefixlen; - - 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)) - continue; - strbuf_setlen(&filename, prefixlen); - strbuf_addstr(&filename, f->suffix); - cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL, filename.buf); - html("  "); - } - - strbuf_release(&filename); -} - static int print_tag(struct refinfo *ref) { struct tag *tag = NULL; @@ -134,7 +109,7 @@ static int print_tag(struct refinfo *ref) cgit_tag_link(name, NULL, NULL, name); html(""); if (ctx.repo->snapshots && (obj->type == OBJ_COMMIT)) - print_tag_downloads(ctx.repo, name); + cgit_print_snapshot_links(ctx.repo, name, "  "); else cgit_object_link(obj); html(""); -- cgit v1.2.3-24-g4f1b