summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-02-08 13:47:56 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-02-08 13:47:56 (UTC)
commitac70cb4795c90db02917db63d169b0fadfe9fb99 (patch) (side-by-side diff)
treebf7a5c4c8c2789cda2dd511f0a180df279a0b389
parentab2ab95f09994560f62fd631f07d3b6e3577aa6e (diff)
downloadcgit-ac70cb4795c90db02917db63d169b0fadfe9fb99.zip
cgit-ac70cb4795c90db02917db63d169b0fadfe9fb99.tar.gz
cgit-ac70cb4795c90db02917db63d169b0fadfe9fb99.tar.bz2
Make snapshot feature configurable
Snapshots can now be enabled/disabled by default for all repositories in cgitrc with param "snapshots". Additionally, any repo can override the default setting with param "repo.snapshots". By default, no snapshotting is enabled. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c3
-rw-r--r--cgit.h2
-rw-r--r--cgitrc5
-rw-r--r--shared.c6
-rw-r--r--ui-commit.c12
5 files changed, 22 insertions, 6 deletions
diff --git a/cgit.c b/cgit.c
index 2795ecc..7b7afba 100644
--- a/cgit.c
+++ b/cgit.c
@@ -76,13 +76,14 @@ static void cgit_print_repo_page(struct cacheitem *item)
}
title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc);
show_search = 0;
setenv("GIT_DIR", cgit_repo->path, 1);
- if (cgit_query_page && !strcmp(cgit_query_page, "snapshot")) {
+ if (cgit_repo->snapshots && cgit_query_page &&
+ !strcmp(cgit_query_page, "snapshot")) {
cgit_print_snapshot(item, cgit_query_sha1, "zip",
cgit_repo->url, cgit_query_name);
return;
}
if (cgit_query_page && !strcmp(cgit_query_page, "log"))
diff --git a/cgit.h b/cgit.h
index 03c2fdb..6e95673 100644
--- a/cgit.h
+++ b/cgit.h
@@ -18,12 +18,13 @@ struct cacheitem {
struct repoinfo {
char *url;
char *name;
char *path;
char *desc;
char *owner;
+ int snapshots;
};
struct repolist {
int length;
int count;
struct repoinfo *repos;
@@ -58,12 +59,13 @@ extern char *cgit_css;
extern char *cgit_logo;
extern char *cgit_logo_link;
extern char *cgit_virtual_root;
extern char *cgit_cache_root;
extern int cgit_nocache;
+extern int cgit_snapshots;
extern int cgit_max_lock_attempts;
extern int cgit_cache_root_ttl;
extern int cgit_cache_repo_ttl;
extern int cgit_cache_dynamic_ttl;
extern int cgit_cache_static_ttl;
extern int cgit_cache_max_create_time;
diff --git a/cgitrc b/cgitrc
index d45f9c2..3bae642 100644
--- a/cgitrc
+++ b/cgitrc
@@ -5,12 +5,16 @@
## Uncomment and set to 1 to deactivate caching of generated pages. Mostly
## usefull for testing.
#nocache=0
+## Enable/disable snapshots by default. This can be overridden per repo
+#snapshots=0
+
+
## Specify a root for virtual urls. This makes cgit generate urls like
##
## http://localhost/git/repo/log/?id=master
##
## instead of
##
@@ -74,6 +78,7 @@
## repository section must start with repo.url).
#repo.url=cgit
#repo.name=cgit
#repo.desc=the caching cgi for git
#repo.path=/pub/git/cgit
#repo.owner=Lars Hjemli
+#repo.snapshots=1 # override a sitewide snapshot-setting
diff --git a/shared.c b/shared.c
index 5757d0c..531d8c0 100644
--- a/shared.c
+++ b/shared.c
@@ -17,12 +17,13 @@ char *cgit_logo = "/git-logo.png";
char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
char *cgit_virtual_root = NULL;
char *cgit_cache_root = "/var/cache/cgit";
int cgit_nocache = 0;
+int cgit_snapshots = 0;
int cgit_max_lock_attempts = 5;
int cgit_cache_root_ttl = 5;
int cgit_cache_repo_ttl = 5;
int cgit_cache_dynamic_ttl = 5;
int cgit_cache_static_ttl = -1;
int cgit_cache_max_create_time = 5;
@@ -80,12 +81,13 @@ struct repoinfo *add_repo(const char *url)
ret = &cgit_repolist.repos[cgit_repolist.count-1];
ret->url = xstrdup(url);
ret->name = ret->url;
ret->path = NULL;
ret->desc = NULL;
ret->owner = NULL;
+ ret->snapshots = cgit_snapshots;
return ret;
}
void cgit_global_config_cb(const char *name, const char *value)
{
if (!strcmp(name, "root-title"))
@@ -97,12 +99,14 @@ void cgit_global_config_cb(const char *name, const char *value)
else if (!strcmp(name, "logo-link"))
cgit_logo_link = xstrdup(value);
else if (!strcmp(name, "virtual-root"))
cgit_virtual_root = xstrdup(value);
else if (!strcmp(name, "nocache"))
cgit_nocache = atoi(value);
+ else if (!strcmp(name, "snapshots"))
+ cgit_snapshots = atoi(value);
else if (!strcmp(name, "cache-root"))
cgit_cache_root = xstrdup(value);
else if (!strcmp(name, "cache-root-ttl"))
cgit_cache_root_ttl = atoi(value);
else if (!strcmp(name, "cache-repo-ttl"))
cgit_cache_repo_ttl = atoi(value);
@@ -119,12 +123,14 @@ void cgit_global_config_cb(const char *name, const char *value)
else if (cgit_repo && !strcmp(name, "repo.path"))
cgit_repo->path = xstrdup(value);
else if (cgit_repo && !strcmp(name, "repo.desc"))
cgit_repo->desc = xstrdup(value);
else if (cgit_repo && !strcmp(name, "repo.owner"))
cgit_repo->owner = xstrdup(value);
+ else if (cgit_repo && !strcmp(name, "repo.snapshots"))
+ cgit_repo->snapshots = atoi(value);
}
void cgit_repo_config_cb(const char *name, const char *value)
{
if (!strcmp(name, "name"))
cgit_repo_name = xstrdup(value);
diff --git a/ui-commit.c b/ui-commit.c
index de3f2cf..3618800 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -166,17 +166,19 @@ void cgit_print_commit(const char *hex)
"<a href='");
query = fmt("id=%s", sha1_to_hex(p->item->object.sha1));
html_attr(cgit_pageurl(cgit_query_repo, "commit", query));
htmlf("'>%s</a></td></tr>\n",
sha1_to_hex(p->item->object.sha1));
}
- htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='");
- filename = fmt("%s-%s.zip", cgit_query_repo, hex);
- html_attr(cgit_pageurl(cgit_query_repo, "snapshot",
- fmt("id=%s&name=%s", hex, filename)));
- htmlf("'>%s</a></td></tr>", filename);
+ if (cgit_repo->snapshots) {
+ htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='");
+ filename = fmt("%s-%s.zip", cgit_query_repo, hex);
+ html_attr(cgit_pageurl(cgit_query_repo, "snapshot",
+ fmt("id=%s&name=%s", hex, filename)));
+ htmlf("'>%s</a></td></tr>", filename);
+ }
html("</table>\n");
html("<div class='commit-subject'>");
html_txt(info->subject);
html("</div>");
html("<div class='commit-msg'>");