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) (unidiff)
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)
70 cgit_print_docstart(title, item); 70 cgit_print_docstart(title, item);
71 cgit_print_pageheader(title, 0); 71 cgit_print_pageheader(title, 0);
72 cgit_print_error(fmt("Unable to scan repository: %s", 72 cgit_print_error(fmt("Unable to scan repository: %s",
73 strerror(errno))); 73 strerror(errno)));
74 cgit_print_docend(); 74 cgit_print_docend();
75 return; 75 return;
76 } 76 }
77 77
78 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); 78 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc);
79 show_search = 0; 79 show_search = 0;
80 setenv("GIT_DIR", cgit_repo->path, 1); 80 setenv("GIT_DIR", cgit_repo->path, 1);
81 81
82 if (cgit_query_page && !strcmp(cgit_query_page, "snapshot")) { 82 if (cgit_repo->snapshots && cgit_query_page &&
83 !strcmp(cgit_query_page, "snapshot")) {
83 cgit_print_snapshot(item, cgit_query_sha1, "zip", 84 cgit_print_snapshot(item, cgit_query_sha1, "zip",
84 cgit_repo->url, cgit_query_name); 85 cgit_repo->url, cgit_query_name);
85 return; 86 return;
86 } 87 }
87 88
88 if (cgit_query_page && !strcmp(cgit_query_page, "log")) 89 if (cgit_query_page && !strcmp(cgit_query_page, "log"))
89 show_search = 1; 90 show_search = 1;
90 cgit_print_docstart(title, item); 91 cgit_print_docstart(title, item);
91 cgit_print_pageheader(title, show_search); 92 cgit_print_pageheader(title, show_search);
92 if (!cgit_query_page) { 93 if (!cgit_query_page) {
93 cgit_print_summary(); 94 cgit_print_summary();
94 } else if (!strcmp(cgit_query_page, "log")) { 95 } 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 {
12 char *name; 12 char *name;
13 struct stat st; 13 struct stat st;
14 int ttl; 14 int ttl;
15 int fd; 15 int fd;
16}; 16};
17 17
18struct repoinfo { 18struct repoinfo {
19 char *url; 19 char *url;
20 char *name; 20 char *name;
21 char *path; 21 char *path;
22 char *desc; 22 char *desc;
23 char *owner; 23 char *owner;
24 int snapshots;
24}; 25};
25 26
26struct repolist { 27struct repolist {
27 int length; 28 int length;
28 int count; 29 int count;
29 struct repoinfo *repos; 30 struct repoinfo *repos;
30}; 31};
31 32
32struct commitinfo { 33struct commitinfo {
33 struct commit *commit; 34 struct commit *commit;
34 char *author; 35 char *author;
35 char *author_email; 36 char *author_email;
@@ -52,24 +53,25 @@ extern const char cgit_version[];
52 53
53extern struct repolist cgit_repolist; 54extern struct repolist cgit_repolist;
54extern struct repoinfo *cgit_repo; 55extern struct repoinfo *cgit_repo;
55 56
56extern char *cgit_root_title; 57extern char *cgit_root_title;
57extern char *cgit_css; 58extern char *cgit_css;
58extern char *cgit_logo; 59extern char *cgit_logo;
59extern char *cgit_logo_link; 60extern char *cgit_logo_link;
60extern char *cgit_virtual_root; 61extern char *cgit_virtual_root;
61extern char *cgit_cache_root; 62extern char *cgit_cache_root;
62 63
63extern int cgit_nocache; 64extern int cgit_nocache;
65extern int cgit_snapshots;
64extern int cgit_max_lock_attempts; 66extern int cgit_max_lock_attempts;
65extern int cgit_cache_root_ttl; 67extern int cgit_cache_root_ttl;
66extern int cgit_cache_repo_ttl; 68extern int cgit_cache_repo_ttl;
67extern int cgit_cache_dynamic_ttl; 69extern int cgit_cache_dynamic_ttl;
68extern int cgit_cache_static_ttl; 70extern int cgit_cache_static_ttl;
69extern int cgit_cache_max_create_time; 71extern int cgit_cache_max_create_time;
70 72
71extern int cgit_max_msg_len; 73extern int cgit_max_msg_len;
72 74
73extern char *cgit_repo_name; 75extern char *cgit_repo_name;
74extern char *cgit_repo_desc; 76extern char *cgit_repo_desc;
75extern char *cgit_repo_owner; 77extern char *cgit_repo_owner;
diff --git a/cgitrc b/cgitrc
index d45f9c2..3bae642 100644
--- a/cgitrc
+++ b/cgitrc
@@ -1,22 +1,26 @@
1## 1##
2## cgitrc: template for /etc/cgitrc 2## cgitrc: template for /etc/cgitrc
3## 3##
4 4
5 5
6## Uncomment and set to 1 to deactivate caching of generated pages. Mostly 6## Uncomment and set to 1 to deactivate caching of generated pages. Mostly
7## usefull for testing. 7## usefull for testing.
8#nocache=0 8#nocache=0
9 9
10 10
11## Enable/disable snapshots by default. This can be overridden per repo
12#snapshots=0
13
14
11## Specify a root for virtual urls. This makes cgit generate urls like 15## Specify a root for virtual urls. This makes cgit generate urls like
12## 16##
13## http://localhost/git/repo/log/?id=master 17## http://localhost/git/repo/log/?id=master
14## 18##
15## instead of 19## instead of
16## 20##
17## http://localhost/cgit/cgit.cgi?r=repo&p=log&id=master 21## http://localhost/cgit/cgit.cgi?r=repo&p=log&id=master
18## 22##
19## For this to work with apache, rewrite rules must be added to httpd.conf, 23## For this to work with apache, rewrite rules must be added to httpd.conf,
20## possibly looking something like this: 24## possibly looking something like this:
21## 25##
22## RewriteRule ^/git/$ /cgit/cgit.cgi [L,QSA] 26## RewriteRule ^/git/$ /cgit/cgit.cgi [L,QSA]
@@ -68,12 +72,13 @@
68## ttl for static pages (addressed by SHA-1) 72## ttl for static pages (addressed by SHA-1)
69#cache-static-ttl=-1 73#cache-static-ttl=-1
70 74
71 75
72 76
73## Example repository entry. Required values are repo.url and repo.path (each 77## Example repository entry. Required values are repo.url and repo.path (each
74## repository section must start with repo.url). 78## repository section must start with repo.url).
75#repo.url=cgit 79#repo.url=cgit
76#repo.name=cgit 80#repo.name=cgit
77#repo.desc=the caching cgi for git 81#repo.desc=the caching cgi for git
78#repo.path=/pub/git/cgit 82#repo.path=/pub/git/cgit
79#repo.owner=Lars Hjemli 83#repo.owner=Lars Hjemli
84#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 @@
11struct repolist cgit_repolist; 11struct repolist cgit_repolist;
12struct repoinfo *cgit_repo; 12struct repoinfo *cgit_repo;
13 13
14char *cgit_root_title = "Git repository browser"; 14char *cgit_root_title = "Git repository browser";
15char *cgit_css = "/cgit.css"; 15char *cgit_css = "/cgit.css";
16char *cgit_logo = "/git-logo.png"; 16char *cgit_logo = "/git-logo.png";
17char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 17char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
18char *cgit_virtual_root = NULL; 18char *cgit_virtual_root = NULL;
19 19
20char *cgit_cache_root = "/var/cache/cgit"; 20char *cgit_cache_root = "/var/cache/cgit";
21 21
22int cgit_nocache = 0; 22int cgit_nocache = 0;
23int cgit_snapshots = 0;
23int cgit_max_lock_attempts = 5; 24int cgit_max_lock_attempts = 5;
24int cgit_cache_root_ttl = 5; 25int cgit_cache_root_ttl = 5;
25int cgit_cache_repo_ttl = 5; 26int cgit_cache_repo_ttl = 5;
26int cgit_cache_dynamic_ttl = 5; 27int cgit_cache_dynamic_ttl = 5;
27int cgit_cache_static_ttl = -1; 28int cgit_cache_static_ttl = -1;
28int cgit_cache_max_create_time = 5; 29int cgit_cache_max_create_time = 5;
29 30
30int cgit_max_msg_len = 60; 31int cgit_max_msg_len = 60;
31 32
32char *cgit_repo_name = NULL; 33char *cgit_repo_name = NULL;
33char *cgit_repo_desc = NULL; 34char *cgit_repo_desc = NULL;
34char *cgit_repo_owner = NULL; 35char *cgit_repo_owner = NULL;
@@ -74,63 +75,68 @@ struct repoinfo *add_repo(const char *url)
74 cgit_repolist.length *= 2; 75 cgit_repolist.length *= 2;
75 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 76 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
76 cgit_repolist.length * 77 cgit_repolist.length *
77 sizeof(struct repoinfo)); 78 sizeof(struct repoinfo));
78 } 79 }
79 80
80 ret = &cgit_repolist.repos[cgit_repolist.count-1]; 81 ret = &cgit_repolist.repos[cgit_repolist.count-1];
81 ret->url = xstrdup(url); 82 ret->url = xstrdup(url);
82 ret->name = ret->url; 83 ret->name = ret->url;
83 ret->path = NULL; 84 ret->path = NULL;
84 ret->desc = NULL; 85 ret->desc = NULL;
85 ret->owner = NULL; 86 ret->owner = NULL;
87 ret->snapshots = cgit_snapshots;
86 return ret; 88 return ret;
87} 89}
88 90
89void cgit_global_config_cb(const char *name, const char *value) 91void cgit_global_config_cb(const char *name, const char *value)
90{ 92{
91 if (!strcmp(name, "root-title")) 93 if (!strcmp(name, "root-title"))
92 cgit_root_title = xstrdup(value); 94 cgit_root_title = xstrdup(value);
93 else if (!strcmp(name, "css")) 95 else if (!strcmp(name, "css"))
94 cgit_css = xstrdup(value); 96 cgit_css = xstrdup(value);
95 else if (!strcmp(name, "logo")) 97 else if (!strcmp(name, "logo"))
96 cgit_logo = xstrdup(value); 98 cgit_logo = xstrdup(value);
97 else if (!strcmp(name, "logo-link")) 99 else if (!strcmp(name, "logo-link"))
98 cgit_logo_link = xstrdup(value); 100 cgit_logo_link = xstrdup(value);
99 else if (!strcmp(name, "virtual-root")) 101 else if (!strcmp(name, "virtual-root"))
100 cgit_virtual_root = xstrdup(value); 102 cgit_virtual_root = xstrdup(value);
101 else if (!strcmp(name, "nocache")) 103 else if (!strcmp(name, "nocache"))
102 cgit_nocache = atoi(value); 104 cgit_nocache = atoi(value);
105 else if (!strcmp(name, "snapshots"))
106 cgit_snapshots = atoi(value);
103 else if (!strcmp(name, "cache-root")) 107 else if (!strcmp(name, "cache-root"))
104 cgit_cache_root = xstrdup(value); 108 cgit_cache_root = xstrdup(value);
105 else if (!strcmp(name, "cache-root-ttl")) 109 else if (!strcmp(name, "cache-root-ttl"))
106 cgit_cache_root_ttl = atoi(value); 110 cgit_cache_root_ttl = atoi(value);
107 else if (!strcmp(name, "cache-repo-ttl")) 111 else if (!strcmp(name, "cache-repo-ttl"))
108 cgit_cache_repo_ttl = atoi(value); 112 cgit_cache_repo_ttl = atoi(value);
109 else if (!strcmp(name, "cache-static-ttl")) 113 else if (!strcmp(name, "cache-static-ttl"))
110 cgit_cache_static_ttl = atoi(value); 114 cgit_cache_static_ttl = atoi(value);
111 else if (!strcmp(name, "cache-dynamic-ttl")) 115 else if (!strcmp(name, "cache-dynamic-ttl"))
112 cgit_cache_dynamic_ttl = atoi(value); 116 cgit_cache_dynamic_ttl = atoi(value);
113 else if (!strcmp(name, "max-message-length")) 117 else if (!strcmp(name, "max-message-length"))
114 cgit_max_msg_len = atoi(value); 118 cgit_max_msg_len = atoi(value);
115 else if (!strcmp(name, "repo.url")) 119 else if (!strcmp(name, "repo.url"))
116 cgit_repo = add_repo(value); 120 cgit_repo = add_repo(value);
117 else if (!strcmp(name, "repo.name")) 121 else if (!strcmp(name, "repo.name"))
118 cgit_repo->name = xstrdup(value); 122 cgit_repo->name = xstrdup(value);
119 else if (cgit_repo && !strcmp(name, "repo.path")) 123 else if (cgit_repo && !strcmp(name, "repo.path"))
120 cgit_repo->path = xstrdup(value); 124 cgit_repo->path = xstrdup(value);
121 else if (cgit_repo && !strcmp(name, "repo.desc")) 125 else if (cgit_repo && !strcmp(name, "repo.desc"))
122 cgit_repo->desc = xstrdup(value); 126 cgit_repo->desc = xstrdup(value);
123 else if (cgit_repo && !strcmp(name, "repo.owner")) 127 else if (cgit_repo && !strcmp(name, "repo.owner"))
124 cgit_repo->owner = xstrdup(value); 128 cgit_repo->owner = xstrdup(value);
129 else if (cgit_repo && !strcmp(name, "repo.snapshots"))
130 cgit_repo->snapshots = atoi(value);
125} 131}
126 132
127void cgit_repo_config_cb(const char *name, const char *value) 133void cgit_repo_config_cb(const char *name, const char *value)
128{ 134{
129 if (!strcmp(name, "name")) 135 if (!strcmp(name, "name"))
130 cgit_repo_name = xstrdup(value); 136 cgit_repo_name = xstrdup(value);
131 else if (!strcmp(name, "desc")) 137 else if (!strcmp(name, "desc"))
132 cgit_repo_desc = xstrdup(value); 138 cgit_repo_desc = xstrdup(value);
133 else if (!strcmp(name, "owner")) 139 else if (!strcmp(name, "owner"))
134 cgit_repo_owner = xstrdup(value); 140 cgit_repo_owner = xstrdup(value);
135} 141}
136 142
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)
160 query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1)); 160 query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1));
161 html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); 161 html_attr(cgit_pageurl(cgit_query_repo, "tree", query));
162 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); 162 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
163 for (p = commit->parents; p ; p = p->next) { 163 for (p = commit->parents; p ; p = p->next) {
164 html("<tr><th>parent</th>" 164 html("<tr><th>parent</th>"
165 "<td colspan='2' class='sha1'>" 165 "<td colspan='2' class='sha1'>"
166 "<a href='"); 166 "<a href='");
167 query = fmt("id=%s", sha1_to_hex(p->item->object.sha1)); 167 query = fmt("id=%s", sha1_to_hex(p->item->object.sha1));
168 html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); 168 html_attr(cgit_pageurl(cgit_query_repo, "commit", query));
169 htmlf("'>%s</a></td></tr>\n", 169 htmlf("'>%s</a></td></tr>\n",
170 sha1_to_hex(p->item->object.sha1)); 170 sha1_to_hex(p->item->object.sha1));
171 } 171 }
172 htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); 172 if (cgit_repo->snapshots) {
173 filename = fmt("%s-%s.zip", cgit_query_repo, hex); 173 htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='");
174 html_attr(cgit_pageurl(cgit_query_repo, "snapshot", 174 filename = fmt("%s-%s.zip", cgit_query_repo, hex);
175 fmt("id=%s&name=%s", hex, filename))); 175 html_attr(cgit_pageurl(cgit_query_repo, "snapshot",
176 htmlf("'>%s</a></td></tr>", filename); 176 fmt("id=%s&name=%s", hex, filename)));
177 htmlf("'>%s</a></td></tr>", filename);
178 }
177 179
178 html("</table>\n"); 180 html("</table>\n");
179 html("<div class='commit-subject'>"); 181 html("<div class='commit-subject'>");
180 html_txt(info->subject); 182 html_txt(info->subject);
181 html("</div>"); 183 html("</div>");
182 html("<div class='commit-msg'>"); 184 html("<div class='commit-msg'>");
183 html_txt(info->msg); 185 html_txt(info->msg);
184 html("</div>"); 186 html("</div>");
185 html("<table class='diffstat'>"); 187 html("<table class='diffstat'>");
186 html("<tr><th colspan='3'>Affected files</tr>\n"); 188 html("<tr><th colspan='3'>Affected files</tr>\n");
187 cgit_diffstat(commit); 189 cgit_diffstat(commit);
188 htmlf("<tr><td colspan='3' class='summary'>" 190 htmlf("<tr><td colspan='3' class='summary'>"