]> granicus.if.org Git - cgit/commitdiff
Make snapshot feature configurable
authorLars Hjemli <hjemli@gmail.com>
Thu, 8 Feb 2007 13:47:56 +0000 (14:47 +0100)
committerLars Hjemli <hjemli@gmail.com>
Thu, 8 Feb 2007 13:47:56 +0000 (14:47 +0100)
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>
cgit.c
cgit.h
cgitrc
shared.c
ui-commit.c

diff --git a/cgit.c b/cgit.c
index 2795ecce02b8b09dd05852d75fcc59f3bb85e634..7b7afba481de797994690ee538cb5482070dcece 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -79,7 +79,8 @@ static void cgit_print_repo_page(struct cacheitem *item)
        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;
diff --git a/cgit.h b/cgit.h
index 03c2fdb7cf3f1cbb446aeb2dd7812e7face6b4f9..6e95673324c3f6d9f73bc81319c4b4a9f2cc9bbb 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -21,6 +21,7 @@ struct repoinfo {
        char *path;
        char *desc;
        char *owner;
+       int snapshots;
 };
 
 struct repolist {
@@ -61,6 +62,7 @@ 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;
diff --git a/cgitrc b/cgitrc
index d45f9c2624230309615f5ce17b41998478540529..3bae642b696aab1d06ca3e41cfee77cad557da50 100644 (file)
--- a/cgitrc
+++ b/cgitrc
@@ -8,6 +8,10 @@
 #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
@@ -77,3 +81,4 @@
 #repo.desc=the caching cgi for git
 #repo.path=/pub/git/cgit
 #repo.owner=Lars Hjemli
+#repo.snapshots=1    # override a sitewide snapshot-setting
index 5757d0c53b2cc2c6b869a4f0e593b2a76fa57a0a..531d8c0fdd9bd47a9488cee364b036447ae80d4e 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -20,6 +20,7 @@ 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;
@@ -83,6 +84,7 @@ struct repoinfo *add_repo(const char *url)
        ret->path = NULL;
        ret->desc = NULL;
        ret->owner = NULL;
+       ret->snapshots = cgit_snapshots;
        return ret;
 }
 
@@ -100,6 +102,8 @@ void cgit_global_config_cb(const char *name, const char *value)
                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"))
@@ -122,6 +126,8 @@ void cgit_global_config_cb(const char *name, const char *value)
                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)
index de3f2cf7bae7647f8c8b65f27fd1e74ad5133855..361880013e0347a1aedf2c03647d123ca0ea508e 100644 (file)
@@ -169,11 +169,13 @@ void cgit_print_commit(const char *hex)
                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'>");