author | Ondrej Jirman <ondrej.jirman@zonio.net> | 2007-05-26 01:26:14 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-31 08:24:37 (UTC) |
commit | a922615dae5d1f7b932dd1fc5a5f121748d96c5a (patch) (unidiff) | |
tree | 05fec55980234a64658f6612499212f923206d29 | |
parent | 3ce6fc16ef4670c535c6e35d48c7f980ff8a5532 (diff) | |
download | cgit-a922615dae5d1f7b932dd1fc5a5f121748d96c5a.zip cgit-a922615dae5d1f7b932dd1fc5a5f121748d96c5a.tar.gz cgit-a922615dae5d1f7b932dd1fc5a5f121748d96c5a.tar.bz2 |
Add option to disable pager to cgit_print_log().
This is needed for upcomming shortlog on summary page
patch.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-log.c | 32 |
3 files changed, 19 insertions, 17 deletions
@@ -1,225 +1,225 @@ | |||
1 | /* cgit.c: cgi for the git scm | 1 | /* cgit.c: cgi for the git scm |
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 | const char cgit_version[] = CGIT_VERSION; | 11 | const char cgit_version[] = CGIT_VERSION; |
12 | 12 | ||
13 | 13 | ||
14 | static int cgit_prepare_cache(struct cacheitem *item) | 14 | static int cgit_prepare_cache(struct cacheitem *item) |
15 | { | 15 | { |
16 | if (!cgit_repo && cgit_query_repo) { | 16 | if (!cgit_repo && cgit_query_repo) { |
17 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 17 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
18 | cgit_print_docstart(title, item); | 18 | cgit_print_docstart(title, item); |
19 | cgit_print_pageheader(title, 0); | 19 | cgit_print_pageheader(title, 0); |
20 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | 20 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); |
21 | cgit_print_docend(); | 21 | cgit_print_docend(); |
22 | return 0; | 22 | return 0; |
23 | } | 23 | } |
24 | 24 | ||
25 | if (!cgit_repo) { | 25 | if (!cgit_repo) { |
26 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 26 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); |
27 | item->ttl = cgit_cache_root_ttl; | 27 | item->ttl = cgit_cache_root_ttl; |
28 | return 1; | 28 | return 1; |
29 | } | 29 | } |
30 | 30 | ||
31 | if (!cgit_cmd) { | 31 | if (!cgit_cmd) { |
32 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, | 32 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, |
33 | cache_safe_filename(cgit_repo->url))); | 33 | cache_safe_filename(cgit_repo->url))); |
34 | item->ttl = cgit_cache_repo_ttl; | 34 | item->ttl = cgit_cache_repo_ttl; |
35 | } else { | 35 | } else { |
36 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 36 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
37 | cache_safe_filename(cgit_repo->url), cgit_query_page, | 37 | cache_safe_filename(cgit_repo->url), cgit_query_page, |
38 | cache_safe_filename(cgit_querystring))); | 38 | cache_safe_filename(cgit_querystring))); |
39 | if (cgit_query_has_symref) | 39 | if (cgit_query_has_symref) |
40 | item->ttl = cgit_cache_dynamic_ttl; | 40 | item->ttl = cgit_cache_dynamic_ttl; |
41 | else if (cgit_query_has_sha1) | 41 | else if (cgit_query_has_sha1) |
42 | item->ttl = cgit_cache_static_ttl; | 42 | item->ttl = cgit_cache_static_ttl; |
43 | else | 43 | else |
44 | item->ttl = cgit_cache_repo_ttl; | 44 | item->ttl = cgit_cache_repo_ttl; |
45 | } | 45 | } |
46 | return 1; | 46 | return 1; |
47 | } | 47 | } |
48 | 48 | ||
49 | static void cgit_print_repo_page(struct cacheitem *item) | 49 | static void cgit_print_repo_page(struct cacheitem *item) |
50 | { | 50 | { |
51 | char *title; | 51 | char *title; |
52 | int show_search; | 52 | int show_search; |
53 | 53 | ||
54 | if (!cgit_query_head) | 54 | if (!cgit_query_head) |
55 | cgit_query_head = cgit_repo->defbranch; | 55 | cgit_query_head = cgit_repo->defbranch; |
56 | 56 | ||
57 | if (chdir(cgit_repo->path)) { | 57 | if (chdir(cgit_repo->path)) { |
58 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 58 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
59 | cgit_print_docstart(title, item); | 59 | cgit_print_docstart(title, item); |
60 | cgit_print_pageheader(title, 0); | 60 | cgit_print_pageheader(title, 0); |
61 | cgit_print_error(fmt("Unable to scan repository: %s", | 61 | cgit_print_error(fmt("Unable to scan repository: %s", |
62 | strerror(errno))); | 62 | strerror(errno))); |
63 | cgit_print_docend(); | 63 | cgit_print_docend(); |
64 | return; | 64 | return; |
65 | } | 65 | } |
66 | 66 | ||
67 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 67 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
68 | show_search = 0; | 68 | show_search = 0; |
69 | setenv("GIT_DIR", cgit_repo->path, 1); | 69 | setenv("GIT_DIR", cgit_repo->path, 1); |
70 | 70 | ||
71 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { | 71 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
72 | cgit_print_snapshot(item, cgit_query_sha1, "zip", | 72 | cgit_print_snapshot(item, cgit_query_sha1, "zip", |
73 | cgit_repo->url, cgit_query_name); | 73 | cgit_repo->url, cgit_query_name); |
74 | return; | 74 | return; |
75 | } | 75 | } |
76 | 76 | ||
77 | if (cgit_cmd == CMD_BLOB) { | 77 | if (cgit_cmd == CMD_BLOB) { |
78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
79 | return; | 79 | return; |
80 | } | 80 | } |
81 | 81 | ||
82 | show_search = (cgit_cmd == CMD_LOG); | 82 | show_search = (cgit_cmd == CMD_LOG); |
83 | cgit_print_docstart(title, item); | 83 | cgit_print_docstart(title, item); |
84 | if (!cgit_cmd) { | 84 | if (!cgit_cmd) { |
85 | cgit_print_pageheader("summary", show_search); | 85 | cgit_print_pageheader("summary", show_search); |
86 | cgit_print_summary(); | 86 | cgit_print_summary(); |
87 | cgit_print_docend(); | 87 | cgit_print_docend(); |
88 | return; | 88 | return; |
89 | } | 89 | } |
90 | 90 | ||
91 | cgit_print_pageheader(cgit_query_page, show_search); | 91 | cgit_print_pageheader(cgit_query_page, show_search); |
92 | 92 | ||
93 | switch(cgit_cmd) { | 93 | switch(cgit_cmd) { |
94 | case CMD_LOG: | 94 | case CMD_LOG: |
95 | cgit_print_log(cgit_query_head, cgit_query_ofs, | 95 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
96 | cgit_max_commit_count, cgit_query_search, | 96 | cgit_max_commit_count, cgit_query_search, |
97 | cgit_query_path); | 97 | cgit_query_path, 1); |
98 | break; | 98 | break; |
99 | case CMD_TREE: | 99 | case CMD_TREE: |
100 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); | 100 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); |
101 | break; | 101 | break; |
102 | case CMD_COMMIT: | 102 | case CMD_COMMIT: |
103 | cgit_print_commit(cgit_query_head); | 103 | cgit_print_commit(cgit_query_head); |
104 | break; | 104 | break; |
105 | case CMD_VIEW: | 105 | case CMD_VIEW: |
106 | cgit_print_view(cgit_query_sha1, cgit_query_path); | 106 | cgit_print_view(cgit_query_sha1, cgit_query_path); |
107 | break; | 107 | break; |
108 | case CMD_DIFF: | 108 | case CMD_DIFF: |
109 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, | 109 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, |
110 | cgit_query_path); | 110 | cgit_query_path); |
111 | break; | 111 | break; |
112 | default: | 112 | default: |
113 | cgit_print_error("Invalid request"); | 113 | cgit_print_error("Invalid request"); |
114 | } | 114 | } |
115 | cgit_print_docend(); | 115 | cgit_print_docend(); |
116 | } | 116 | } |
117 | 117 | ||
118 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 118 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
119 | { | 119 | { |
120 | static char buf[PATH_MAX]; | 120 | static char buf[PATH_MAX]; |
121 | int stdout2; | 121 | int stdout2; |
122 | 122 | ||
123 | getcwd(buf, sizeof(buf)); | 123 | getcwd(buf, sizeof(buf)); |
124 | item->st.st_mtime = time(NULL); | 124 | item->st.st_mtime = time(NULL); |
125 | 125 | ||
126 | if (use_cache) { | 126 | if (use_cache) { |
127 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 127 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
128 | "Preserving STDOUT"); | 128 | "Preserving STDOUT"); |
129 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 129 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
130 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 130 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
131 | } | 131 | } |
132 | 132 | ||
133 | if (cgit_repo) | 133 | if (cgit_repo) |
134 | cgit_print_repo_page(item); | 134 | cgit_print_repo_page(item); |
135 | else | 135 | else |
136 | cgit_print_repolist(item); | 136 | cgit_print_repolist(item); |
137 | 137 | ||
138 | if (use_cache) { | 138 | if (use_cache) { |
139 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 139 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
140 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 140 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
141 | "Restoring original STDOUT"); | 141 | "Restoring original STDOUT"); |
142 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 142 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
143 | } | 143 | } |
144 | 144 | ||
145 | chdir(buf); | 145 | chdir(buf); |
146 | } | 146 | } |
147 | 147 | ||
148 | static void cgit_check_cache(struct cacheitem *item) | 148 | static void cgit_check_cache(struct cacheitem *item) |
149 | { | 149 | { |
150 | int i = 0; | 150 | int i = 0; |
151 | 151 | ||
152 | top: | 152 | top: |
153 | if (++i > cgit_max_lock_attempts) { | 153 | if (++i > cgit_max_lock_attempts) { |
154 | die("cgit_refresh_cache: unable to lock %s: %s", | 154 | die("cgit_refresh_cache: unable to lock %s: %s", |
155 | item->name, strerror(errno)); | 155 | item->name, strerror(errno)); |
156 | } | 156 | } |
157 | if (!cache_exist(item)) { | 157 | if (!cache_exist(item)) { |
158 | if (!cache_lock(item)) { | 158 | if (!cache_lock(item)) { |
159 | sleep(1); | 159 | sleep(1); |
160 | goto top; | 160 | goto top; |
161 | } | 161 | } |
162 | if (!cache_exist(item)) { | 162 | if (!cache_exist(item)) { |
163 | cgit_fill_cache(item, 1); | 163 | cgit_fill_cache(item, 1); |
164 | cache_unlock(item); | 164 | cache_unlock(item); |
165 | } else { | 165 | } else { |
166 | cache_cancel_lock(item); | 166 | cache_cancel_lock(item); |
167 | } | 167 | } |
168 | } else if (cache_expired(item) && cache_lock(item)) { | 168 | } else if (cache_expired(item) && cache_lock(item)) { |
169 | if (cache_expired(item)) { | 169 | if (cache_expired(item)) { |
170 | cgit_fill_cache(item, 1); | 170 | cgit_fill_cache(item, 1); |
171 | cache_unlock(item); | 171 | cache_unlock(item); |
172 | } else { | 172 | } else { |
173 | cache_cancel_lock(item); | 173 | cache_cancel_lock(item); |
174 | } | 174 | } |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | static void cgit_print_cache(struct cacheitem *item) | 178 | static void cgit_print_cache(struct cacheitem *item) |
179 | { | 179 | { |
180 | static char buf[4096]; | 180 | static char buf[4096]; |
181 | ssize_t i; | 181 | ssize_t i; |
182 | 182 | ||
183 | int fd = open(item->name, O_RDONLY); | 183 | int fd = open(item->name, O_RDONLY); |
184 | if (fd<0) | 184 | if (fd<0) |
185 | die("Unable to open cached file %s", item->name); | 185 | die("Unable to open cached file %s", item->name); |
186 | 186 | ||
187 | while((i=read(fd, buf, sizeof(buf))) > 0) | 187 | while((i=read(fd, buf, sizeof(buf))) > 0) |
188 | write(STDOUT_FILENO, buf, i); | 188 | write(STDOUT_FILENO, buf, i); |
189 | 189 | ||
190 | close(fd); | 190 | close(fd); |
191 | } | 191 | } |
192 | 192 | ||
193 | static void cgit_parse_args(int argc, const char **argv) | 193 | static void cgit_parse_args(int argc, const char **argv) |
194 | { | 194 | { |
195 | int i; | 195 | int i; |
196 | 196 | ||
197 | for (i = 1; i < argc; i++) { | 197 | for (i = 1; i < argc; i++) { |
198 | if (!strncmp(argv[i], "--cache=", 8)) { | 198 | if (!strncmp(argv[i], "--cache=", 8)) { |
199 | cgit_cache_root = xstrdup(argv[i]+8); | 199 | cgit_cache_root = xstrdup(argv[i]+8); |
200 | } | 200 | } |
201 | if (!strcmp(argv[i], "--nocache")) { | 201 | if (!strcmp(argv[i], "--nocache")) { |
202 | cgit_nocache = 1; | 202 | cgit_nocache = 1; |
203 | } | 203 | } |
204 | if (!strncmp(argv[i], "--query=", 8)) { | 204 | if (!strncmp(argv[i], "--query=", 8)) { |
205 | cgit_querystring = xstrdup(argv[i]+8); | 205 | cgit_querystring = xstrdup(argv[i]+8); |
206 | } | 206 | } |
207 | if (!strncmp(argv[i], "--repo=", 7)) { | 207 | if (!strncmp(argv[i], "--repo=", 7)) { |
208 | cgit_query_repo = xstrdup(argv[i]+7); | 208 | cgit_query_repo = xstrdup(argv[i]+7); |
209 | } | 209 | } |
210 | if (!strncmp(argv[i], "--page=", 7)) { | 210 | if (!strncmp(argv[i], "--page=", 7)) { |
211 | cgit_query_page = xstrdup(argv[i]+7); | 211 | cgit_query_page = xstrdup(argv[i]+7); |
212 | } | 212 | } |
213 | if (!strncmp(argv[i], "--head=", 7)) { | 213 | if (!strncmp(argv[i], "--head=", 7)) { |
214 | cgit_query_head = xstrdup(argv[i]+7); | 214 | cgit_query_head = xstrdup(argv[i]+7); |
215 | cgit_query_has_symref = 1; | 215 | cgit_query_has_symref = 1; |
216 | } | 216 | } |
217 | if (!strncmp(argv[i], "--sha1=", 7)) { | 217 | if (!strncmp(argv[i], "--sha1=", 7)) { |
218 | cgit_query_sha1 = xstrdup(argv[i]+7); | 218 | cgit_query_sha1 = xstrdup(argv[i]+7); |
219 | cgit_query_has_sha1 = 1; | 219 | cgit_query_has_sha1 = 1; |
220 | } | 220 | } |
221 | if (!strncmp(argv[i], "--ofs=", 6)) { | 221 | if (!strncmp(argv[i], "--ofs=", 6)) { |
222 | cgit_query_ofs = atoi(argv[i]+6); | 222 | cgit_query_ofs = atoi(argv[i]+6); |
223 | } | 223 | } |
224 | } | 224 | } |
225 | } | 225 | } |
@@ -88,140 +88,140 @@ struct commitinfo { | |||
88 | char *committer; | 88 | char *committer; |
89 | char *committer_email; | 89 | char *committer_email; |
90 | unsigned long committer_date; | 90 | unsigned long committer_date; |
91 | char *subject; | 91 | char *subject; |
92 | char *msg; | 92 | char *msg; |
93 | }; | 93 | }; |
94 | 94 | ||
95 | struct taginfo { | 95 | struct taginfo { |
96 | char *tagger; | 96 | char *tagger; |
97 | char *tagger_email; | 97 | char *tagger_email; |
98 | int tagger_date; | 98 | int tagger_date; |
99 | char *msg; | 99 | char *msg; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | extern const char cgit_version[]; | 102 | extern const char cgit_version[]; |
103 | 103 | ||
104 | extern struct repolist cgit_repolist; | 104 | extern struct repolist cgit_repolist; |
105 | extern struct repoinfo *cgit_repo; | 105 | extern struct repoinfo *cgit_repo; |
106 | extern int cgit_cmd; | 106 | extern int cgit_cmd; |
107 | 107 | ||
108 | extern char *cgit_root_title; | 108 | extern char *cgit_root_title; |
109 | extern char *cgit_css; | 109 | extern char *cgit_css; |
110 | extern char *cgit_logo; | 110 | extern char *cgit_logo; |
111 | extern char *cgit_index_header; | 111 | extern char *cgit_index_header; |
112 | extern char *cgit_logo_link; | 112 | extern char *cgit_logo_link; |
113 | extern char *cgit_module_link; | 113 | extern char *cgit_module_link; |
114 | extern char *cgit_agefile; | 114 | extern char *cgit_agefile; |
115 | extern char *cgit_virtual_root; | 115 | extern char *cgit_virtual_root; |
116 | extern char *cgit_script_name; | 116 | extern char *cgit_script_name; |
117 | extern char *cgit_cache_root; | 117 | extern char *cgit_cache_root; |
118 | extern char *cgit_repo_group; | 118 | extern char *cgit_repo_group; |
119 | 119 | ||
120 | extern int cgit_nocache; | 120 | extern int cgit_nocache; |
121 | extern int cgit_snapshots; | 121 | extern int cgit_snapshots; |
122 | extern int cgit_enable_log_filecount; | 122 | extern int cgit_enable_log_filecount; |
123 | extern int cgit_enable_log_linecount; | 123 | extern int cgit_enable_log_linecount; |
124 | extern int cgit_max_lock_attempts; | 124 | extern int cgit_max_lock_attempts; |
125 | extern int cgit_cache_root_ttl; | 125 | extern int cgit_cache_root_ttl; |
126 | extern int cgit_cache_repo_ttl; | 126 | extern int cgit_cache_repo_ttl; |
127 | extern int cgit_cache_dynamic_ttl; | 127 | extern int cgit_cache_dynamic_ttl; |
128 | extern int cgit_cache_static_ttl; | 128 | extern int cgit_cache_static_ttl; |
129 | extern int cgit_cache_max_create_time; | 129 | extern int cgit_cache_max_create_time; |
130 | 130 | ||
131 | extern int cgit_max_msg_len; | 131 | extern int cgit_max_msg_len; |
132 | extern int cgit_max_repodesc_len; | 132 | extern int cgit_max_repodesc_len; |
133 | extern int cgit_max_commit_count; | 133 | extern int cgit_max_commit_count; |
134 | 134 | ||
135 | extern int cgit_query_has_symref; | 135 | extern int cgit_query_has_symref; |
136 | extern int cgit_query_has_sha1; | 136 | extern int cgit_query_has_sha1; |
137 | 137 | ||
138 | extern char *cgit_querystring; | 138 | extern char *cgit_querystring; |
139 | extern char *cgit_query_repo; | 139 | extern char *cgit_query_repo; |
140 | extern char *cgit_query_page; | 140 | extern char *cgit_query_page; |
141 | extern char *cgit_query_search; | 141 | extern char *cgit_query_search; |
142 | extern char *cgit_query_head; | 142 | extern char *cgit_query_head; |
143 | extern char *cgit_query_sha1; | 143 | extern char *cgit_query_sha1; |
144 | extern char *cgit_query_sha2; | 144 | extern char *cgit_query_sha2; |
145 | extern char *cgit_query_path; | 145 | extern char *cgit_query_path; |
146 | extern char *cgit_query_name; | 146 | extern char *cgit_query_name; |
147 | extern int cgit_query_ofs; | 147 | extern int cgit_query_ofs; |
148 | 148 | ||
149 | extern int htmlfd; | 149 | extern int htmlfd; |
150 | 150 | ||
151 | extern int cgit_get_cmd_index(const char *cmd); | 151 | extern int cgit_get_cmd_index(const char *cmd); |
152 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 152 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
153 | extern void cgit_global_config_cb(const char *name, const char *value); | 153 | extern void cgit_global_config_cb(const char *name, const char *value); |
154 | extern void cgit_repo_config_cb(const char *name, const char *value); | 154 | extern void cgit_repo_config_cb(const char *name, const char *value); |
155 | extern void cgit_querystring_cb(const char *name, const char *value); | 155 | extern void cgit_querystring_cb(const char *name, const char *value); |
156 | 156 | ||
157 | extern int chk_zero(int result, char *msg); | 157 | extern int chk_zero(int result, char *msg); |
158 | extern int chk_positive(int result, char *msg); | 158 | extern int chk_positive(int result, char *msg); |
159 | 159 | ||
160 | extern int hextoint(char c); | 160 | extern int hextoint(char c); |
161 | 161 | ||
162 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 162 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
163 | 163 | ||
164 | extern int cgit_diff_files(const unsigned char *old_sha1, | 164 | extern int cgit_diff_files(const unsigned char *old_sha1, |
165 | const unsigned char *new_sha1, | 165 | const unsigned char *new_sha1, |
166 | linediff_fn fn); | 166 | linediff_fn fn); |
167 | 167 | ||
168 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 168 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
169 | const unsigned char *new_sha1, | 169 | const unsigned char *new_sha1, |
170 | filepair_fn fn); | 170 | filepair_fn fn); |
171 | 171 | ||
172 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 172 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
173 | 173 | ||
174 | extern char *fmt(const char *format,...); | 174 | extern char *fmt(const char *format,...); |
175 | 175 | ||
176 | extern void html(const char *txt); | 176 | extern void html(const char *txt); |
177 | extern void htmlf(const char *format,...); | 177 | extern void htmlf(const char *format,...); |
178 | extern void html_txt(char *txt); | 178 | extern void html_txt(char *txt); |
179 | extern void html_ntxt(int len, char *txt); | 179 | extern void html_ntxt(int len, char *txt); |
180 | extern void html_attr(char *txt); | 180 | extern void html_attr(char *txt); |
181 | extern void html_hidden(char *name, char *value); | 181 | extern void html_hidden(char *name, char *value); |
182 | extern void html_link_open(char *url, char *title, char *class); | 182 | extern void html_link_open(char *url, char *title, char *class); |
183 | extern void html_link_close(void); | 183 | extern void html_link_close(void); |
184 | extern void html_filemode(unsigned short mode); | 184 | extern void html_filemode(unsigned short mode); |
185 | extern int html_include(const char *filename); | 185 | extern int html_include(const char *filename); |
186 | 186 | ||
187 | extern int cgit_read_config(const char *filename, configfn fn); | 187 | extern int cgit_read_config(const char *filename, configfn fn); |
188 | extern int cgit_parse_query(char *txt, configfn fn); | 188 | extern int cgit_parse_query(char *txt, configfn fn); |
189 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 189 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
190 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 190 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
191 | extern void cgit_parse_url(const char *url); | 191 | extern void cgit_parse_url(const char *url); |
192 | 192 | ||
193 | extern char *cache_safe_filename(const char *unsafe); | 193 | extern char *cache_safe_filename(const char *unsafe); |
194 | extern int cache_lock(struct cacheitem *item); | 194 | extern int cache_lock(struct cacheitem *item); |
195 | extern int cache_unlock(struct cacheitem *item); | 195 | extern int cache_unlock(struct cacheitem *item); |
196 | extern int cache_cancel_lock(struct cacheitem *item); | 196 | extern int cache_cancel_lock(struct cacheitem *item); |
197 | extern int cache_exist(struct cacheitem *item); | 197 | extern int cache_exist(struct cacheitem *item); |
198 | extern int cache_expired(struct cacheitem *item); | 198 | extern int cache_expired(struct cacheitem *item); |
199 | 199 | ||
200 | extern char *cgit_repourl(const char *reponame); | 200 | extern char *cgit_repourl(const char *reponame); |
201 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 201 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
202 | const char *query); | 202 | const char *query); |
203 | 203 | ||
204 | extern void cgit_print_error(char *msg); | 204 | extern void cgit_print_error(char *msg); |
205 | extern void cgit_print_date(time_t secs, char *format); | 205 | extern void cgit_print_date(time_t secs, char *format); |
206 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 206 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
207 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 207 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
208 | extern void cgit_print_docend(); | 208 | extern void cgit_print_docend(); |
209 | extern void cgit_print_pageheader(char *title, int show_search); | 209 | extern void cgit_print_pageheader(char *title, int show_search); |
210 | extern void cgit_print_snapshot_start(const char *mimetype, | 210 | extern void cgit_print_snapshot_start(const char *mimetype, |
211 | const char *filename, | 211 | const char *filename, |
212 | struct cacheitem *item); | 212 | struct cacheitem *item); |
213 | 213 | ||
214 | extern void cgit_print_repolist(struct cacheitem *item); | 214 | extern void cgit_print_repolist(struct cacheitem *item); |
215 | extern void cgit_print_summary(); | 215 | extern void cgit_print_summary(); |
216 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path); | 216 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
217 | extern void cgit_print_view(const char *hex, char *path); | 217 | extern void cgit_print_view(const char *hex, char *path); |
218 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 218 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
219 | extern void cgit_print_tree(const char *rev, const char *hex, char *path); | 219 | extern void cgit_print_tree(const char *rev, const char *hex, char *path); |
220 | extern void cgit_print_commit(const char *hex); | 220 | extern void cgit_print_commit(const char *hex); |
221 | extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, | 221 | extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, |
222 | char *path); | 222 | char *path); |
223 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 223 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
224 | const char *format, const char *prefix, | 224 | const char *format, const char *prefix, |
225 | const char *filename); | 225 | const char *filename); |
226 | 226 | ||
227 | #endif /* CGIT_H */ | 227 | #endif /* CGIT_H */ |
@@ -1,128 +1,130 @@ | |||
1 | /* ui-log.c: functions for log output | 1 | /* ui-log.c: functions for log output |
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 | int files, lines; | 11 | int files, lines; |
12 | 12 | ||
13 | void count_lines(char *line, int size) | 13 | void count_lines(char *line, int size) |
14 | { | 14 | { |
15 | if (size>0 && (line[0] == '+' || line[0] == '-')) | 15 | if (size>0 && (line[0] == '+' || line[0] == '-')) |
16 | lines++; | 16 | lines++; |
17 | } | 17 | } |
18 | 18 | ||
19 | void inspect_files(struct diff_filepair *pair) | 19 | void inspect_files(struct diff_filepair *pair) |
20 | { | 20 | { |
21 | files++; | 21 | files++; |
22 | if (cgit_repo->enable_log_linecount) | 22 | if (cgit_repo->enable_log_linecount) |
23 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 23 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); |
24 | } | 24 | } |
25 | 25 | ||
26 | void print_commit(struct commit *commit) | 26 | void print_commit(struct commit *commit) |
27 | { | 27 | { |
28 | struct commitinfo *info; | 28 | struct commitinfo *info; |
29 | 29 | ||
30 | info = cgit_parse_commit(commit); | 30 | info = cgit_parse_commit(commit); |
31 | html("<tr><td>"); | 31 | html("<tr><td>"); |
32 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 32 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
33 | html("</td><td>"); | 33 | html("</td><td>"); |
34 | char *qry = fmt("h=%s", sha1_to_hex(commit->object.sha1)); | 34 | char *qry = fmt("h=%s", sha1_to_hex(commit->object.sha1)); |
35 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); | 35 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); |
36 | html_link_open(url, NULL, NULL); | 36 | html_link_open(url, NULL, NULL); |
37 | html_ntxt(cgit_max_msg_len, info->subject); | 37 | html_ntxt(cgit_max_msg_len, info->subject); |
38 | html_link_close(); | 38 | html_link_close(); |
39 | if (cgit_repo->enable_log_filecount) { | 39 | if (cgit_repo->enable_log_filecount) { |
40 | files = 0; | 40 | files = 0; |
41 | lines = 0; | 41 | lines = 0; |
42 | cgit_diff_commit(commit, inspect_files); | 42 | cgit_diff_commit(commit, inspect_files); |
43 | html("</td><td class='right'>"); | 43 | html("</td><td class='right'>"); |
44 | htmlf("%d", files); | 44 | htmlf("%d", files); |
45 | if (cgit_repo->enable_log_linecount) { | 45 | if (cgit_repo->enable_log_linecount) { |
46 | html("</td><td class='right'>"); | 46 | html("</td><td class='right'>"); |
47 | htmlf("%d", lines); | 47 | htmlf("%d", lines); |
48 | } | 48 | } |
49 | } | 49 | } |
50 | html("</td><td>"); | 50 | html("</td><td>"); |
51 | html_txt(info->author); | 51 | html_txt(info->author); |
52 | html("</td></tr>\n"); | 52 | html("</td></tr>\n"); |
53 | cgit_free_commitinfo(info); | 53 | cgit_free_commitinfo(info); |
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path) | 57 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager) |
58 | { | 58 | { |
59 | struct rev_info rev; | 59 | struct rev_info rev; |
60 | struct commit *commit; | 60 | struct commit *commit; |
61 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | 61 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
62 | int argc = 2; | 62 | int argc = 2; |
63 | int i; | 63 | int i; |
64 | 64 | ||
65 | if (grep) | 65 | if (grep) |
66 | argv[argc++] = fmt("--grep=%s", grep); | 66 | argv[argc++] = fmt("--grep=%s", grep); |
67 | if (path) { | 67 | if (path) { |
68 | argv[argc++] = "--"; | 68 | argv[argc++] = "--"; |
69 | argv[argc++] = path; | 69 | argv[argc++] = path; |
70 | } | 70 | } |
71 | init_revisions(&rev, NULL); | 71 | init_revisions(&rev, NULL); |
72 | rev.abbrev = DEFAULT_ABBREV; | 72 | rev.abbrev = DEFAULT_ABBREV; |
73 | rev.commit_format = CMIT_FMT_DEFAULT; | 73 | rev.commit_format = CMIT_FMT_DEFAULT; |
74 | rev.verbose_header = 1; | 74 | rev.verbose_header = 1; |
75 | rev.show_root_diff = 0; | 75 | rev.show_root_diff = 0; |
76 | setup_revisions(argc, argv, &rev, NULL); | 76 | setup_revisions(argc, argv, &rev, NULL); |
77 | if (rev.grep_filter) { | 77 | if (rev.grep_filter) { |
78 | rev.grep_filter->regflags |= REG_ICASE; | 78 | rev.grep_filter->regflags |= REG_ICASE; |
79 | compile_grep_patterns(rev.grep_filter); | 79 | compile_grep_patterns(rev.grep_filter); |
80 | } | 80 | } |
81 | prepare_revision_walk(&rev); | 81 | prepare_revision_walk(&rev); |
82 | 82 | ||
83 | html("<table class='list nowrap'>"); | 83 | html("<table class='list nowrap'>"); |
84 | html("<tr class='nohover'><th class='left'>Age</th>" | 84 | html("<tr class='nohover'><th class='left'>Age</th>" |
85 | "<th class='left'>Message</th>"); | 85 | "<th class='left'>Message</th>"); |
86 | 86 | ||
87 | if (cgit_repo->enable_log_filecount) { | 87 | if (cgit_repo->enable_log_filecount) { |
88 | html("<th class='left'>Files</th>"); | 88 | html("<th class='left'>Files</th>"); |
89 | if (cgit_repo->enable_log_linecount) | 89 | if (cgit_repo->enable_log_linecount) |
90 | html("<th class='left'>Lines</th>"); | 90 | html("<th class='left'>Lines</th>"); |
91 | } | 91 | } |
92 | html("<th class='left'>Author</th></tr>\n"); | 92 | html("<th class='left'>Author</th></tr>\n"); |
93 | 93 | ||
94 | if (ofs<0) | 94 | if (ofs<0) |
95 | ofs = 0; | 95 | ofs = 0; |
96 | 96 | ||
97 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 97 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
98 | free(commit->buffer); | 98 | free(commit->buffer); |
99 | commit->buffer = NULL; | 99 | commit->buffer = NULL; |
100 | free_commit_list(commit->parents); | 100 | free_commit_list(commit->parents); |
101 | commit->parents = NULL; | 101 | commit->parents = NULL; |
102 | } | 102 | } |
103 | 103 | ||
104 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 104 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
105 | print_commit(commit); | 105 | print_commit(commit); |
106 | free(commit->buffer); | 106 | free(commit->buffer); |
107 | commit->buffer = NULL; | 107 | commit->buffer = NULL; |
108 | free_commit_list(commit->parents); | 108 | free_commit_list(commit->parents); |
109 | commit->parents = NULL; | 109 | commit->parents = NULL; |
110 | } | 110 | } |
111 | html("</table>\n"); | 111 | html("</table>\n"); |
112 | 112 | ||
113 | html("<div class='pager'>"); | 113 | if (pager) { |
114 | if (ofs > 0) { | 114 | html("<div class='pager'>"); |
115 | html(" <a href='"); | 115 | if (ofs > 0) { |
116 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, | 116 | html(" <a href='"); |
117 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); | 117 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, |
118 | html("'>[prev]</a> "); | 118 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); |
119 | } | 119 | html("'>[prev]</a> "); |
120 | 120 | } | |
121 | if ((commit = get_revision(&rev)) != NULL) { | 121 | |
122 | html(" <a href='"); | 122 | if ((commit = get_revision(&rev)) != NULL) { |
123 | html(cgit_pageurl(cgit_query_repo, "log", | 123 | html(" <a href='"); |
124 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); | 124 | html(cgit_pageurl(cgit_query_repo, "log", |
125 | html("'>[next]</a> "); | 125 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); |
126 | html("'>[next]</a> "); | ||
127 | } | ||
128 | html("</div>"); | ||
126 | } | 129 | } |
127 | html("</div>"); | ||
128 | } | 130 | } |