author | Lars Hjemli <hjemli@gmail.com> | 2007-02-08 13:47:56 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-02-08 13:47:56 (UTC) |
commit | ac70cb4795c90db02917db63d169b0fadfe9fb99 (patch) (unidiff) | |
tree | bf7a5c4c8c2789cda2dd511f0a180df279a0b389 | |
parent | ab2ab95f09994560f62fd631f07d3b6e3577aa6e (diff) | |
download | cgit-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>
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | cgitrc | 5 | ||||
-rw-r--r-- | shared.c | 6 | ||||
-rw-r--r-- | ui-commit.c | 12 |
5 files changed, 22 insertions, 6 deletions
@@ -34,97 +34,98 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
34 | } | 34 | } |
35 | cgit_repo = cgit_get_repoinfo(cgit_query_repo); | 35 | cgit_repo = cgit_get_repoinfo(cgit_query_repo); |
36 | if (!cgit_repo) { | 36 | if (!cgit_repo) { |
37 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 37 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
38 | cgit_print_docstart(title, item); | 38 | cgit_print_docstart(title, item); |
39 | cgit_print_pageheader(title, 0); | 39 | cgit_print_pageheader(title, 0); |
40 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | 40 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); |
41 | cgit_print_docend(); | 41 | cgit_print_docend(); |
42 | return 0; | 42 | return 0; |
43 | } | 43 | } |
44 | 44 | ||
45 | if (!cgit_query_page) { | 45 | if (!cgit_query_page) { |
46 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, | 46 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, |
47 | cgit_repo->url)); | 47 | cgit_repo->url)); |
48 | item->ttl = cgit_cache_repo_ttl; | 48 | item->ttl = cgit_cache_repo_ttl; |
49 | } else { | 49 | } else { |
50 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 50 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
51 | cgit_repo->url, cgit_query_page, | 51 | cgit_repo->url, cgit_query_page, |
52 | cache_safe_filename(cgit_querystring))); | 52 | cache_safe_filename(cgit_querystring))); |
53 | if (cgit_query_has_symref) | 53 | if (cgit_query_has_symref) |
54 | item->ttl = cgit_cache_dynamic_ttl; | 54 | item->ttl = cgit_cache_dynamic_ttl; |
55 | else if (cgit_query_has_sha1) | 55 | else if (cgit_query_has_sha1) |
56 | item->ttl = cgit_cache_static_ttl; | 56 | item->ttl = cgit_cache_static_ttl; |
57 | else | 57 | else |
58 | item->ttl = cgit_cache_repo_ttl; | 58 | item->ttl = cgit_cache_repo_ttl; |
59 | } | 59 | } |
60 | return 1; | 60 | return 1; |
61 | } | 61 | } |
62 | 62 | ||
63 | static void cgit_print_repo_page(struct cacheitem *item) | 63 | static void cgit_print_repo_page(struct cacheitem *item) |
64 | { | 64 | { |
65 | char *title; | 65 | char *title; |
66 | int show_search; | 66 | int show_search; |
67 | 67 | ||
68 | if (chdir(cgit_repo->path)) { | 68 | if (chdir(cgit_repo->path)) { |
69 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 69 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
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")) { |
95 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100, | 96 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100, |
96 | cgit_query_search); | 97 | cgit_query_search); |
97 | } else if (!strcmp(cgit_query_page, "tree")) { | 98 | } else if (!strcmp(cgit_query_page, "tree")) { |
98 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 99 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
99 | } else if (!strcmp(cgit_query_page, "commit")) { | 100 | } else if (!strcmp(cgit_query_page, "commit")) { |
100 | cgit_print_commit(cgit_query_sha1); | 101 | cgit_print_commit(cgit_query_sha1); |
101 | } else if (!strcmp(cgit_query_page, "view")) { | 102 | } else if (!strcmp(cgit_query_page, "view")) { |
102 | cgit_print_view(cgit_query_sha1); | 103 | cgit_print_view(cgit_query_sha1); |
103 | } else if (!strcmp(cgit_query_page, "diff")) { | 104 | } else if (!strcmp(cgit_query_page, "diff")) { |
104 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); | 105 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); |
105 | } else { | 106 | } else { |
106 | cgit_print_error("Invalid request"); | 107 | cgit_print_error("Invalid request"); |
107 | } | 108 | } |
108 | cgit_print_docend(); | 109 | cgit_print_docend(); |
109 | } | 110 | } |
110 | 111 | ||
111 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 112 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
112 | { | 113 | { |
113 | static char buf[PATH_MAX]; | 114 | static char buf[PATH_MAX]; |
114 | int stdout2; | 115 | int stdout2; |
115 | 116 | ||
116 | getcwd(buf, sizeof(buf)); | 117 | getcwd(buf, sizeof(buf)); |
117 | item->st.st_mtime = time(NULL); | 118 | item->st.st_mtime = time(NULL); |
118 | 119 | ||
119 | if (use_cache) { | 120 | if (use_cache) { |
120 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 121 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
121 | "Preserving STDOUT"); | 122 | "Preserving STDOUT"); |
122 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 123 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
123 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 124 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
124 | } | 125 | } |
125 | 126 | ||
126 | if (cgit_query_repo) | 127 | if (cgit_query_repo) |
127 | cgit_print_repo_page(item); | 128 | cgit_print_repo_page(item); |
128 | else | 129 | else |
129 | cgit_print_repolist(item); | 130 | cgit_print_repolist(item); |
130 | 131 | ||
@@ -1,111 +1,113 @@ | |||
1 | #ifndef CGIT_H | 1 | #ifndef CGIT_H |
2 | #define CGIT_H | 2 | #define CGIT_H |
3 | 3 | ||
4 | #include "git.h" | 4 | #include "git.h" |
5 | #include <openssl/sha.h> | 5 | #include <openssl/sha.h> |
6 | #include <ctype.h> | 6 | #include <ctype.h> |
7 | #include <sched.h> | 7 | #include <sched.h> |
8 | 8 | ||
9 | typedef void (*configfn)(const char *name, const char *value); | 9 | typedef void (*configfn)(const char *name, const char *value); |
10 | 10 | ||
11 | struct cacheitem { | 11 | 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 | ||
18 | struct repoinfo { | 18 | struct 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 | ||
26 | struct repolist { | 27 | struct 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 | ||
32 | struct commitinfo { | 33 | struct commitinfo { |
33 | struct commit *commit; | 34 | struct commit *commit; |
34 | char *author; | 35 | char *author; |
35 | char *author_email; | 36 | char *author_email; |
36 | unsigned long author_date; | 37 | unsigned long author_date; |
37 | char *committer; | 38 | char *committer; |
38 | char *committer_email; | 39 | char *committer_email; |
39 | unsigned long committer_date; | 40 | unsigned long committer_date; |
40 | char *subject; | 41 | char *subject; |
41 | char *msg; | 42 | char *msg; |
42 | }; | 43 | }; |
43 | 44 | ||
44 | struct taginfo { | 45 | struct taginfo { |
45 | char *tagger; | 46 | char *tagger; |
46 | char *tagger_email; | 47 | char *tagger_email; |
47 | int tagger_date; | 48 | int tagger_date; |
48 | char *msg; | 49 | char *msg; |
49 | }; | 50 | }; |
50 | 51 | ||
51 | extern const char cgit_version[]; | 52 | extern const char cgit_version[]; |
52 | 53 | ||
53 | extern struct repolist cgit_repolist; | 54 | extern struct repolist cgit_repolist; |
54 | extern struct repoinfo *cgit_repo; | 55 | extern struct repoinfo *cgit_repo; |
55 | 56 | ||
56 | extern char *cgit_root_title; | 57 | extern char *cgit_root_title; |
57 | extern char *cgit_css; | 58 | extern char *cgit_css; |
58 | extern char *cgit_logo; | 59 | extern char *cgit_logo; |
59 | extern char *cgit_logo_link; | 60 | extern char *cgit_logo_link; |
60 | extern char *cgit_virtual_root; | 61 | extern char *cgit_virtual_root; |
61 | extern char *cgit_cache_root; | 62 | extern char *cgit_cache_root; |
62 | 63 | ||
63 | extern int cgit_nocache; | 64 | extern int cgit_nocache; |
65 | extern int cgit_snapshots; | ||
64 | extern int cgit_max_lock_attempts; | 66 | extern int cgit_max_lock_attempts; |
65 | extern int cgit_cache_root_ttl; | 67 | extern int cgit_cache_root_ttl; |
66 | extern int cgit_cache_repo_ttl; | 68 | extern int cgit_cache_repo_ttl; |
67 | extern int cgit_cache_dynamic_ttl; | 69 | extern int cgit_cache_dynamic_ttl; |
68 | extern int cgit_cache_static_ttl; | 70 | extern int cgit_cache_static_ttl; |
69 | extern int cgit_cache_max_create_time; | 71 | extern int cgit_cache_max_create_time; |
70 | 72 | ||
71 | extern int cgit_max_msg_len; | 73 | extern int cgit_max_msg_len; |
72 | 74 | ||
73 | extern char *cgit_repo_name; | 75 | extern char *cgit_repo_name; |
74 | extern char *cgit_repo_desc; | 76 | extern char *cgit_repo_desc; |
75 | extern char *cgit_repo_owner; | 77 | extern char *cgit_repo_owner; |
76 | 78 | ||
77 | extern int cgit_query_has_symref; | 79 | extern int cgit_query_has_symref; |
78 | extern int cgit_query_has_sha1; | 80 | extern int cgit_query_has_sha1; |
79 | 81 | ||
80 | extern char *cgit_querystring; | 82 | extern char *cgit_querystring; |
81 | extern char *cgit_query_repo; | 83 | extern char *cgit_query_repo; |
82 | extern char *cgit_query_page; | 84 | extern char *cgit_query_page; |
83 | extern char *cgit_query_search; | 85 | extern char *cgit_query_search; |
84 | extern char *cgit_query_head; | 86 | extern char *cgit_query_head; |
85 | extern char *cgit_query_sha1; | 87 | extern char *cgit_query_sha1; |
86 | extern char *cgit_query_sha2; | 88 | extern char *cgit_query_sha2; |
87 | extern char *cgit_query_path; | 89 | extern char *cgit_query_path; |
88 | extern char *cgit_query_name; | 90 | extern char *cgit_query_name; |
89 | extern int cgit_query_ofs; | 91 | extern int cgit_query_ofs; |
90 | 92 | ||
91 | extern int htmlfd; | 93 | extern int htmlfd; |
92 | 94 | ||
93 | extern void cgit_global_config_cb(const char *name, const char *value); | 95 | extern void cgit_global_config_cb(const char *name, const char *value); |
94 | extern void cgit_repo_config_cb(const char *name, const char *value); | 96 | extern void cgit_repo_config_cb(const char *name, const char *value); |
95 | extern void cgit_querystring_cb(const char *name, const char *value); | 97 | extern void cgit_querystring_cb(const char *name, const char *value); |
96 | 98 | ||
97 | extern int chk_zero(int result, char *msg); | 99 | extern int chk_zero(int result, char *msg); |
98 | extern int chk_positive(int result, char *msg); | 100 | extern int chk_positive(int result, char *msg); |
99 | 101 | ||
100 | extern int hextoint(char c); | 102 | extern int hextoint(char c); |
101 | 103 | ||
102 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 104 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
103 | 105 | ||
104 | extern char *fmt(const char *format,...); | 106 | extern char *fmt(const char *format,...); |
105 | 107 | ||
106 | extern void html(const char *txt); | 108 | extern void html(const char *txt); |
107 | extern void htmlf(const char *format,...); | 109 | extern void htmlf(const char *format,...); |
108 | extern void html_txt(char *txt); | 110 | extern void html_txt(char *txt); |
109 | extern void html_ntxt(int len, char *txt); | 111 | extern void html_ntxt(int len, char *txt); |
110 | extern void html_attr(char *txt); | 112 | extern void html_attr(char *txt); |
111 | extern void html_hidden(char *name, char *value); | 113 | extern void html_hidden(char *name, char *value); |
@@ -1,79 +1,84 @@ | |||
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] |
23 | ## RewriteRule ^/git/([^/]+)/$ /cgit/cgit.cgi?r=$1 [L,QSA] | 27 | ## RewriteRule ^/git/([^/]+)/$ /cgit/cgit.cgi?r=$1 [L,QSA] |
24 | ## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit/cgit.cgi?r=$1&p=$2 [L,QSA] | 28 | ## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit/cgit.cgi?r=$1&p=$2 [L,QSA] |
25 | ## | 29 | ## |
26 | ## This setting is disabled by default. | 30 | ## This setting is disabled by default. |
27 | #virtual-root=/git | 31 | #virtual-root=/git |
28 | 32 | ||
29 | 33 | ||
30 | ## Set the title printed on the root page | 34 | ## Set the title printed on the root page |
31 | #root-title=Git repository browser | 35 | #root-title=Git repository browser |
32 | 36 | ||
33 | 37 | ||
34 | ## Link to css file | 38 | ## Link to css file |
35 | #css=/cgit/cgit.css | 39 | #css=/cgit/cgit.css |
36 | 40 | ||
37 | 41 | ||
38 | ## Link to logo file | 42 | ## Link to logo file |
39 | #logo=/cgit/git-logo.png | 43 | #logo=/cgit/git-logo.png |
40 | 44 | ||
41 | 45 | ||
42 | ## Url loaded when clicking the logo | 46 | ## Url loaded when clicking the logo |
43 | #logo-link=http://www.kernel.org/pub/software/scm/git/docs/ | 47 | #logo-link=http://www.kernel.org/pub/software/scm/git/docs/ |
44 | 48 | ||
45 | 49 | ||
46 | ## Number of chars shown of commit subject message (in log view) | 50 | ## Number of chars shown of commit subject message (in log view) |
47 | #max-message-length=60 | 51 | #max-message-length=60 |
48 | 52 | ||
49 | 53 | ||
50 | ## Root of cached output | 54 | ## Root of cached output |
51 | #cache-root=/var/cache/cgit | 55 | #cache-root=/var/cache/cgit |
52 | 56 | ||
53 | 57 | ||
54 | ## | 58 | ## |
55 | ## Time-To-Live settings: specifies how long (in minutes) different pages | 59 | ## Time-To-Live settings: specifies how long (in minutes) different pages |
56 | ## should be cached (0 for instant expiration, -1 for immortal pages) | 60 | ## should be cached (0 for instant expiration, -1 for immortal pages) |
57 | ## | 61 | ## |
58 | 62 | ||
59 | ## ttl for root page | 63 | ## ttl for root page |
60 | #cache-root-ttl=5 | 64 | #cache-root-ttl=5 |
61 | 65 | ||
62 | ## ttl for repo summary page | 66 | ## ttl for repo summary page |
63 | #cache-repo-ttl=5 | 67 | #cache-repo-ttl=5 |
64 | 68 | ||
65 | ## ttl for other dynamic pages | 69 | ## ttl for other dynamic pages |
66 | #cache-dynamic-ttl=5 | 70 | #cache-dynamic-ttl=5 |
67 | 71 | ||
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 | ||
@@ -1,172 +1,178 @@ | |||
1 | /* shared.c: global vars + some callback functions | 1 | /* shared.c: global vars + some callback functions |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | struct repolist cgit_repolist; | 11 | struct repolist cgit_repolist; |
12 | struct repoinfo *cgit_repo; | 12 | struct repoinfo *cgit_repo; |
13 | 13 | ||
14 | char *cgit_root_title = "Git repository browser"; | 14 | char *cgit_root_title = "Git repository browser"; |
15 | char *cgit_css = "/cgit.css"; | 15 | char *cgit_css = "/cgit.css"; |
16 | char *cgit_logo = "/git-logo.png"; | 16 | char *cgit_logo = "/git-logo.png"; |
17 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 17 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
18 | char *cgit_virtual_root = NULL; | 18 | char *cgit_virtual_root = NULL; |
19 | 19 | ||
20 | char *cgit_cache_root = "/var/cache/cgit"; | 20 | char *cgit_cache_root = "/var/cache/cgit"; |
21 | 21 | ||
22 | int cgit_nocache = 0; | 22 | int cgit_nocache = 0; |
23 | int cgit_snapshots = 0; | ||
23 | int cgit_max_lock_attempts = 5; | 24 | int cgit_max_lock_attempts = 5; |
24 | int cgit_cache_root_ttl = 5; | 25 | int cgit_cache_root_ttl = 5; |
25 | int cgit_cache_repo_ttl = 5; | 26 | int cgit_cache_repo_ttl = 5; |
26 | int cgit_cache_dynamic_ttl = 5; | 27 | int cgit_cache_dynamic_ttl = 5; |
27 | int cgit_cache_static_ttl = -1; | 28 | int cgit_cache_static_ttl = -1; |
28 | int cgit_cache_max_create_time = 5; | 29 | int cgit_cache_max_create_time = 5; |
29 | 30 | ||
30 | int cgit_max_msg_len = 60; | 31 | int cgit_max_msg_len = 60; |
31 | 32 | ||
32 | char *cgit_repo_name = NULL; | 33 | char *cgit_repo_name = NULL; |
33 | char *cgit_repo_desc = NULL; | 34 | char *cgit_repo_desc = NULL; |
34 | char *cgit_repo_owner = NULL; | 35 | char *cgit_repo_owner = NULL; |
35 | 36 | ||
36 | int cgit_query_has_symref = 0; | 37 | int cgit_query_has_symref = 0; |
37 | int cgit_query_has_sha1 = 0; | 38 | int cgit_query_has_sha1 = 0; |
38 | 39 | ||
39 | char *cgit_querystring = NULL; | 40 | char *cgit_querystring = NULL; |
40 | char *cgit_query_repo = NULL; | 41 | char *cgit_query_repo = NULL; |
41 | char *cgit_query_page = NULL; | 42 | char *cgit_query_page = NULL; |
42 | char *cgit_query_head = NULL; | 43 | char *cgit_query_head = NULL; |
43 | char *cgit_query_search = NULL; | 44 | char *cgit_query_search = NULL; |
44 | char *cgit_query_sha1 = NULL; | 45 | char *cgit_query_sha1 = NULL; |
45 | char *cgit_query_sha2 = NULL; | 46 | char *cgit_query_sha2 = NULL; |
46 | char *cgit_query_path = NULL; | 47 | char *cgit_query_path = NULL; |
47 | char *cgit_query_name = NULL; | 48 | char *cgit_query_name = NULL; |
48 | int cgit_query_ofs = 0; | 49 | int cgit_query_ofs = 0; |
49 | 50 | ||
50 | int htmlfd = 0; | 51 | int htmlfd = 0; |
51 | 52 | ||
52 | int chk_zero(int result, char *msg) | 53 | int chk_zero(int result, char *msg) |
53 | { | 54 | { |
54 | if (result != 0) | 55 | if (result != 0) |
55 | die("%s: %s", msg, strerror(errno)); | 56 | die("%s: %s", msg, strerror(errno)); |
56 | return result; | 57 | return result; |
57 | } | 58 | } |
58 | 59 | ||
59 | int chk_positive(int result, char *msg) | 60 | int chk_positive(int result, char *msg) |
60 | { | 61 | { |
61 | if (result <= 0) | 62 | if (result <= 0) |
62 | die("%s: %s", msg, strerror(errno)); | 63 | die("%s: %s", msg, strerror(errno)); |
63 | return result; | 64 | return result; |
64 | } | 65 | } |
65 | 66 | ||
66 | struct repoinfo *add_repo(const char *url) | 67 | struct repoinfo *add_repo(const char *url) |
67 | { | 68 | { |
68 | struct repoinfo *ret; | 69 | struct repoinfo *ret; |
69 | 70 | ||
70 | if (++cgit_repolist.count > cgit_repolist.length) { | 71 | if (++cgit_repolist.count > cgit_repolist.length) { |
71 | if (cgit_repolist.length == 0) | 72 | if (cgit_repolist.length == 0) |
72 | cgit_repolist.length = 8; | 73 | cgit_repolist.length = 8; |
73 | else | 74 | else |
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 | ||
89 | void cgit_global_config_cb(const char *name, const char *value) | 91 | void 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 | ||
127 | void cgit_repo_config_cb(const char *name, const char *value) | 133 | void 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 | ||
137 | void cgit_querystring_cb(const char *name, const char *value) | 143 | void cgit_querystring_cb(const char *name, const char *value) |
138 | { | 144 | { |
139 | if (!strcmp(name,"r")) { | 145 | if (!strcmp(name,"r")) { |
140 | cgit_query_repo = xstrdup(value); | 146 | cgit_query_repo = xstrdup(value); |
141 | } else if (!strcmp(name, "p")) { | 147 | } else if (!strcmp(name, "p")) { |
142 | cgit_query_page = xstrdup(value); | 148 | cgit_query_page = xstrdup(value); |
143 | } else if (!strcmp(name, "q")) { | 149 | } else if (!strcmp(name, "q")) { |
144 | cgit_query_search = xstrdup(value); | 150 | cgit_query_search = xstrdup(value); |
145 | } else if (!strcmp(name, "h")) { | 151 | } else if (!strcmp(name, "h")) { |
146 | cgit_query_head = xstrdup(value); | 152 | cgit_query_head = xstrdup(value); |
147 | cgit_query_has_symref = 1; | 153 | cgit_query_has_symref = 1; |
148 | } else if (!strcmp(name, "id")) { | 154 | } else if (!strcmp(name, "id")) { |
149 | cgit_query_sha1 = xstrdup(value); | 155 | cgit_query_sha1 = xstrdup(value); |
150 | cgit_query_has_sha1 = 1; | 156 | cgit_query_has_sha1 = 1; |
151 | } else if (!strcmp(name, "id2")) { | 157 | } else if (!strcmp(name, "id2")) { |
152 | cgit_query_sha2 = xstrdup(value); | 158 | cgit_query_sha2 = xstrdup(value); |
153 | cgit_query_has_sha1 = 1; | 159 | cgit_query_has_sha1 = 1; |
154 | } else if (!strcmp(name, "ofs")) { | 160 | } else if (!strcmp(name, "ofs")) { |
155 | cgit_query_ofs = atoi(value); | 161 | cgit_query_ofs = atoi(value); |
156 | } else if (!strcmp(name, "path")) { | 162 | } else if (!strcmp(name, "path")) { |
157 | cgit_query_path = xstrdup(value); | 163 | cgit_query_path = xstrdup(value); |
158 | } else if (!strcmp(name, "name")) { | 164 | } else if (!strcmp(name, "name")) { |
159 | cgit_query_name = xstrdup(value); | 165 | cgit_query_name = xstrdup(value); |
160 | } | 166 | } |
161 | } | 167 | } |
162 | 168 | ||
163 | void *cgit_free_commitinfo(struct commitinfo *info) | 169 | void *cgit_free_commitinfo(struct commitinfo *info) |
164 | { | 170 | { |
165 | free(info->author); | 171 | free(info->author); |
166 | free(info->author_email); | 172 | free(info->author_email); |
167 | free(info->committer); | 173 | free(info->committer); |
168 | free(info->committer_email); | 174 | free(info->committer_email); |
169 | free(info->subject); | 175 | free(info->subject); |
170 | free(info); | 176 | free(info); |
171 | return NULL; | 177 | return NULL; |
172 | } | 178 | } |
diff --git a/ui-commit.c b/ui-commit.c index de3f2cf..3618800 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -124,69 +124,71 @@ void cgit_diffstat(struct commit *commit) | |||
124 | void cgit_print_commit(const char *hex) | 124 | void cgit_print_commit(const char *hex) |
125 | { | 125 | { |
126 | struct commit *commit; | 126 | struct commit *commit; |
127 | struct commitinfo *info; | 127 | struct commitinfo *info; |
128 | struct commit_list *p; | 128 | struct commit_list *p; |
129 | unsigned char sha1[20]; | 129 | unsigned char sha1[20]; |
130 | char *query; | 130 | char *query; |
131 | char *filename; | 131 | char *filename; |
132 | 132 | ||
133 | if (get_sha1(hex, sha1)) { | 133 | if (get_sha1(hex, sha1)) { |
134 | cgit_print_error(fmt("Bad object id: %s", hex)); | 134 | cgit_print_error(fmt("Bad object id: %s", hex)); |
135 | return; | 135 | return; |
136 | } | 136 | } |
137 | commit = lookup_commit_reference(sha1); | 137 | commit = lookup_commit_reference(sha1); |
138 | if (!commit) { | 138 | if (!commit) { |
139 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 139 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
140 | return; | 140 | return; |
141 | } | 141 | } |
142 | info = cgit_parse_commit(commit); | 142 | info = cgit_parse_commit(commit); |
143 | 143 | ||
144 | html("<table class='commit-info'>\n"); | 144 | html("<table class='commit-info'>\n"); |
145 | html("<tr><th>author</th><td>"); | 145 | html("<tr><th>author</th><td>"); |
146 | html_txt(info->author); | 146 | html_txt(info->author); |
147 | html(" "); | 147 | html(" "); |
148 | html_txt(info->author_email); | 148 | html_txt(info->author_email); |
149 | html("</td><td class='right'>"); | 149 | html("</td><td class='right'>"); |
150 | cgit_print_date(info->author_date); | 150 | cgit_print_date(info->author_date); |
151 | html("</td></tr>\n"); | 151 | html("</td></tr>\n"); |
152 | html("<tr><th>committer</th><td>"); | 152 | html("<tr><th>committer</th><td>"); |
153 | html_txt(info->committer); | 153 | html_txt(info->committer); |
154 | html(" "); | 154 | html(" "); |
155 | html_txt(info->committer_email); | 155 | html_txt(info->committer_email); |
156 | html("</td><td class='right'>"); | 156 | html("</td><td class='right'>"); |
157 | cgit_print_date(info->committer_date); | 157 | cgit_print_date(info->committer_date); |
158 | html("</td></tr>\n"); | 158 | html("</td></tr>\n"); |
159 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); | 159 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); |
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'>" |
189 | "%d file%s changed</td></tr>\n", files, files > 1 ? "s" : ""); | 191 | "%d file%s changed</td></tr>\n", files, files > 1 ? "s" : ""); |
190 | html("</table>"); | 192 | html("</table>"); |
191 | cgit_free_commitinfo(info); | 193 | cgit_free_commitinfo(info); |
192 | } | 194 | } |