mirror of
https://git.zx2c4.com/cgit
synced 2024-11-22 08:28:42 +00:00
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 <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
This commit is contained in:
parent
d85e8a9810
commit
c1572bb5ec
2
cgit.c
2
cgit.c
@ -79,6 +79,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
|
|||||||
item->util = xstrdup(value);
|
item->util = xstrdup(value);
|
||||||
} else if (!strcmp(name, "section"))
|
} else if (!strcmp(name, "section"))
|
||||||
repo->section = xstrdup(value);
|
repo->section = xstrdup(value);
|
||||||
|
else if (!strcmp(name, "snapshot-prefix"))
|
||||||
|
repo->snapshot_prefix = xstrdup(value);
|
||||||
else if (!strcmp(name, "readme") && value != NULL) {
|
else if (!strcmp(name, "readme") && value != NULL) {
|
||||||
if (repo->readme.items == ctx.cfg.readme.items)
|
if (repo->readme.items == ctx.cfg.readme.items)
|
||||||
memset(&repo->readme, 0, sizeof(repo->readme));
|
memset(&repo->readme, 0, sizeof(repo->readme));
|
||||||
|
1
cgit.h
1
cgit.h
@ -88,6 +88,7 @@ struct cgit_repo {
|
|||||||
char *clone_url;
|
char *clone_url;
|
||||||
char *logo;
|
char *logo;
|
||||||
char *logo_link;
|
char *logo_link;
|
||||||
|
char *snapshot_prefix;
|
||||||
int snapshots;
|
int snapshots;
|
||||||
int enable_commit_graph;
|
int enable_commit_graph;
|
||||||
int enable_log_filecount;
|
int enable_log_filecount;
|
||||||
|
@ -599,6 +599,13 @@ repo.snapshots::
|
|||||||
restricted by the global "snapshots" setting. Default value:
|
restricted by the global "snapshots" setting. Default value:
|
||||||
<snapshots>.
|
<snapshots>.
|
||||||
|
|
||||||
|
repo.snapshot-prefix::
|
||||||
|
Prefix to use for snapshot links instead of the repository basename.
|
||||||
|
For example, the "linux-stable" repository may wish to set this to
|
||||||
|
"linux" so that snapshots are in the format "linux-3.15.4" instead
|
||||||
|
of "linux-stable-3.15.4". Default value: <empty> meaning to use
|
||||||
|
the repository basename.
|
||||||
|
|
||||||
repo.section::
|
repo.section::
|
||||||
Override the current section name for this repository. Default value:
|
Override the current section name for this repository. Default value:
|
||||||
none.
|
none.
|
||||||
|
@ -100,7 +100,7 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)
|
|||||||
if (!ref || strlen(ref) < 1)
|
if (!ref || strlen(ref) < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
basename = cgit_repobasename(repo->url);
|
basename = cgit_snapshot_prefix(repo);
|
||||||
if (starts_with(ref, basename))
|
if (starts_with(ref, basename))
|
||||||
strbuf_addstr(&filename, ref);
|
strbuf_addstr(&filename, ref);
|
||||||
else
|
else
|
||||||
|
10
ui-shared.c
10
ui-shared.c
@ -152,6 +152,14 @@ const char *cgit_repobasename(const char *reponame)
|
|||||||
return rvbuf;
|
return rvbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *cgit_snapshot_prefix(const struct cgit_repo *repo)
|
||||||
|
{
|
||||||
|
if (repo->snapshot_prefix)
|
||||||
|
return repo->snapshot_prefix;
|
||||||
|
|
||||||
|
return cgit_repobasename(repo->url);
|
||||||
|
}
|
||||||
|
|
||||||
static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root)
|
static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root)
|
||||||
{
|
{
|
||||||
char *delim = "?";
|
char *delim = "?";
|
||||||
@ -1110,7 +1118,7 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *head,
|
|||||||
struct strbuf filename = STRBUF_INIT;
|
struct strbuf filename = STRBUF_INIT;
|
||||||
size_t prefixlen;
|
size_t prefixlen;
|
||||||
|
|
||||||
cgit_compose_snapshot_prefix(&filename, cgit_repobasename(repo->url), hex);
|
cgit_compose_snapshot_prefix(&filename, cgit_snapshot_prefix(repo), hex);
|
||||||
prefixlen = filename.len;
|
prefixlen = filename.len;
|
||||||
for (f = cgit_snapshot_formats; f->suffix; f++) {
|
for (f = cgit_snapshot_formats; f->suffix; f++) {
|
||||||
if (!(repo->snapshots & f->bit))
|
if (!(repo->snapshots & f->bit))
|
||||||
|
@ -78,6 +78,7 @@ extern void cgit_compose_snapshot_prefix(struct strbuf *filename,
|
|||||||
const char *base, const char *ref);
|
const char *base, const char *ref);
|
||||||
extern void cgit_print_snapshot_links(const struct cgit_repo *repo,
|
extern void cgit_print_snapshot_links(const struct cgit_repo *repo,
|
||||||
const char *head, const char *hex);
|
const char *head, const char *hex);
|
||||||
|
extern const char *cgit_snapshot_prefix(const struct cgit_repo *repo);
|
||||||
extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
|
extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
|
||||||
const char *page);
|
const char *page);
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ static const char *get_ref_from_filename(const struct cgit_repo *repo,
|
|||||||
if (get_oid(snapshot.buf, &oid) == 0)
|
if (get_oid(snapshot.buf, &oid) == 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
reponame = cgit_repobasename(repo->url);
|
reponame = cgit_snapshot_prefix(repo);
|
||||||
if (starts_with(snapshot.buf, reponame)) {
|
if (starts_with(snapshot.buf, reponame)) {
|
||||||
const char *new_start = snapshot.buf;
|
const char *new_start = snapshot.buf;
|
||||||
new_start += strlen(reponame);
|
new_start += strlen(reponame);
|
||||||
@ -214,7 +214,7 @@ void cgit_print_snapshot(const char *head, const char *hex,
|
|||||||
hex = head;
|
hex = head;
|
||||||
|
|
||||||
if (!prefix)
|
if (!prefix)
|
||||||
prefix = xstrdup(cgit_repobasename(ctx.repo->url));
|
prefix = xstrdup(cgit_snapshot_prefix(ctx.repo));
|
||||||
|
|
||||||
make_snapshot(f, hex, prefix, filename);
|
make_snapshot(f, hex, prefix, filename);
|
||||||
free(prefix);
|
free(prefix);
|
||||||
|
Loading…
Reference in New Issue
Block a user