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
@@ -70,25 +70,26 @@ static void cgit_print_repo_page(struct cacheitem *item)
cgit_print_docstart(title, item);
cgit_print_pageheader(title, 0);
cgit_print_error(fmt("Unable to scan repository: %s",
strerror(errno)));
cgit_print_docend();
return;
}
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"))
show_search = 1;
cgit_print_docstart(title, item);
cgit_print_pageheader(title, show_search);
if (!cgit_query_page) {
cgit_print_summary();
} else if (!strcmp(cgit_query_page, "log")) {
diff --git a/cgit.h b/cgit.h
index 03c2fdb..6e95673 100644
--- a/cgit.h
+++ b/cgit.h
@@ -12,24 +12,25 @@ struct cacheitem {
char *name;
struct stat st;
int ttl;
int fd;
};
struct repoinfo {
char *url;
char *name;
char *path;
char *desc;
char *owner;
+ int snapshots;
};
struct repolist {
int length;
int count;
struct repoinfo *repos;
};
struct commitinfo {
struct commit *commit;
char *author;
char *author_email;
@@ -52,24 +53,25 @@ extern const char cgit_version[];
extern struct repolist cgit_repolist;
extern struct repoinfo *cgit_repo;
extern char *cgit_root_title;
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;
extern int cgit_max_msg_len;
extern char *cgit_repo_name;
extern char *cgit_repo_desc;
extern char *cgit_repo_owner;
diff --git a/cgitrc b/cgitrc
index d45f9c2..3bae642 100644
--- a/cgitrc
+++ b/cgitrc
@@ -1,22 +1,26 @@
##
## cgitrc: template for /etc/cgitrc
##
## 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
##
## http://localhost/cgit/cgit.cgi?r=repo&p=log&id=master
##
## For this to work with apache, rewrite rules must be added to httpd.conf,
## possibly looking something like this:
##
## RewriteRule ^/git/$ /cgit/cgit.cgi [L,QSA]
@@ -68,12 +72,13 @@
## ttl for static pages (addressed by SHA-1)
#cache-static-ttl=-1
## Example repository entry. Required values are repo.url and repo.path (each
## 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
@@ -11,24 +11,25 @@
struct repolist cgit_repolist;
struct repoinfo *cgit_repo;
char *cgit_root_title = "Git repository browser";
char *cgit_css = "/cgit.css";
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;
int cgit_max_msg_len = 60;
char *cgit_repo_name = NULL;
char *cgit_repo_desc = NULL;
char *cgit_repo_owner = NULL;
@@ -74,63 +75,68 @@ struct repoinfo *add_repo(const char *url)
cgit_repolist.length *= 2;
cgit_repolist.repos = xrealloc(cgit_repolist.repos,
cgit_repolist.length *
sizeof(struct repoinfo));
}
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"))
cgit_root_title = xstrdup(value);
else if (!strcmp(name, "css"))
cgit_css = xstrdup(value);
else if (!strcmp(name, "logo"))
cgit_logo = xstrdup(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);
else if (!strcmp(name, "cache-static-ttl"))
cgit_cache_static_ttl = atoi(value);
else if (!strcmp(name, "cache-dynamic-ttl"))
cgit_cache_dynamic_ttl = atoi(value);
else if (!strcmp(name, "max-message-length"))
cgit_max_msg_len = atoi(value);
else if (!strcmp(name, "repo.url"))
cgit_repo = add_repo(value);
else if (!strcmp(name, "repo.name"))
cgit_repo->name = xstrdup(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);
else if (!strcmp(name, "desc"))
cgit_repo_desc = xstrdup(value);
else if (!strcmp(name, "owner"))
cgit_repo_owner = xstrdup(value);
}
diff --git a/ui-commit.c b/ui-commit.c
index de3f2cf..3618800 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -160,29 +160,31 @@ void cgit_print_commit(const char *hex)
query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1));
html_attr(cgit_pageurl(cgit_query_repo, "tree", query));
htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
for (p = commit->parents; p ; p = p->next) {
html("<tr><th>parent</th>"
"<td colspan='2' class='sha1'>"
"<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'>");
html_txt(info->msg);
html("</div>");
html("<table class='diffstat'>");
html("<tr><th colspan='3'>Affected files</tr>\n");
cgit_diffstat(commit);
htmlf("<tr><td colspan='3' class='summary'>"