-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-log.c | 7 | ||||
-rw-r--r-- | ui-shared.c | 16 | ||||
-rw-r--r-- | ui-summary.c | 18 | ||||
-rw-r--r-- | ui-tree.c | 1 |
7 files changed, 31 insertions, 18 deletions
@@ -7,193 +7,193 @@ | |||
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, 1); | 97 | cgit_query_path, 1); |
98 | break; | 98 | break; |
99 | case CMD_TREE: | 99 | case CMD_TREE: |
100 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 100 | cgit_print_tree(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_sha1); |
104 | break; | 104 | break; |
105 | case CMD_DIFF: | 105 | case CMD_DIFF: |
106 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, | 106 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, |
107 | cgit_query_path); | 107 | cgit_query_path); |
108 | break; | 108 | break; |
109 | default: | 109 | default: |
110 | cgit_print_error("Invalid request"); | 110 | cgit_print_error("Invalid request"); |
111 | } | 111 | } |
112 | cgit_print_docend(); | 112 | cgit_print_docend(); |
113 | } | 113 | } |
114 | 114 | ||
115 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 115 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
116 | { | 116 | { |
117 | static char buf[PATH_MAX]; | 117 | static char buf[PATH_MAX]; |
118 | int stdout2; | 118 | int stdout2; |
119 | 119 | ||
120 | getcwd(buf, sizeof(buf)); | 120 | getcwd(buf, sizeof(buf)); |
121 | item->st.st_mtime = time(NULL); | 121 | item->st.st_mtime = time(NULL); |
122 | 122 | ||
123 | if (use_cache) { | 123 | if (use_cache) { |
124 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 124 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
125 | "Preserving STDOUT"); | 125 | "Preserving STDOUT"); |
126 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 126 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
127 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 127 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
128 | } | 128 | } |
129 | 129 | ||
130 | if (cgit_repo) | 130 | if (cgit_repo) |
131 | cgit_print_repo_page(item); | 131 | cgit_print_repo_page(item); |
132 | else | 132 | else |
133 | cgit_print_repolist(item); | 133 | cgit_print_repolist(item); |
134 | 134 | ||
135 | if (use_cache) { | 135 | if (use_cache) { |
136 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 136 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
137 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 137 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
138 | "Restoring original STDOUT"); | 138 | "Restoring original STDOUT"); |
139 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 139 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
140 | } | 140 | } |
141 | 141 | ||
142 | chdir(buf); | 142 | chdir(buf); |
143 | } | 143 | } |
144 | 144 | ||
145 | static void cgit_check_cache(struct cacheitem *item) | 145 | static void cgit_check_cache(struct cacheitem *item) |
146 | { | 146 | { |
147 | int i = 0; | 147 | int i = 0; |
148 | 148 | ||
149 | top: | 149 | top: |
150 | if (++i > cgit_max_lock_attempts) { | 150 | if (++i > cgit_max_lock_attempts) { |
151 | die("cgit_refresh_cache: unable to lock %s: %s", | 151 | die("cgit_refresh_cache: unable to lock %s: %s", |
152 | item->name, strerror(errno)); | 152 | item->name, strerror(errno)); |
153 | } | 153 | } |
154 | if (!cache_exist(item)) { | 154 | if (!cache_exist(item)) { |
155 | if (!cache_lock(item)) { | 155 | if (!cache_lock(item)) { |
156 | sleep(1); | 156 | sleep(1); |
157 | goto top; | 157 | goto top; |
158 | } | 158 | } |
159 | if (!cache_exist(item)) { | 159 | if (!cache_exist(item)) { |
160 | cgit_fill_cache(item, 1); | 160 | cgit_fill_cache(item, 1); |
161 | cache_unlock(item); | 161 | cache_unlock(item); |
162 | } else { | 162 | } else { |
163 | cache_cancel_lock(item); | 163 | cache_cancel_lock(item); |
164 | } | 164 | } |
165 | } else if (cache_expired(item) && cache_lock(item)) { | 165 | } else if (cache_expired(item) && cache_lock(item)) { |
166 | if (cache_expired(item)) { | 166 | if (cache_expired(item)) { |
167 | cgit_fill_cache(item, 1); | 167 | cgit_fill_cache(item, 1); |
168 | cache_unlock(item); | 168 | cache_unlock(item); |
169 | } else { | 169 | } else { |
170 | cache_cancel_lock(item); | 170 | cache_cancel_lock(item); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | static void cgit_print_cache(struct cacheitem *item) | 175 | static void cgit_print_cache(struct cacheitem *item) |
176 | { | 176 | { |
177 | static char buf[4096]; | 177 | static char buf[4096]; |
178 | ssize_t i; | 178 | ssize_t i; |
179 | 179 | ||
180 | int fd = open(item->name, O_RDONLY); | 180 | int fd = open(item->name, O_RDONLY); |
181 | if (fd<0) | 181 | if (fd<0) |
182 | die("Unable to open cached file %s", item->name); | 182 | die("Unable to open cached file %s", item->name); |
183 | 183 | ||
184 | while((i=read(fd, buf, sizeof(buf))) > 0) | 184 | while((i=read(fd, buf, sizeof(buf))) > 0) |
185 | write(STDOUT_FILENO, buf, i); | 185 | write(STDOUT_FILENO, buf, i); |
186 | 186 | ||
187 | close(fd); | 187 | close(fd); |
188 | } | 188 | } |
189 | 189 | ||
190 | static void cgit_parse_args(int argc, const char **argv) | 190 | static void cgit_parse_args(int argc, const char **argv) |
191 | { | 191 | { |
192 | int i; | 192 | int i; |
193 | 193 | ||
194 | for (i = 1; i < argc; i++) { | 194 | for (i = 1; i < argc; i++) { |
195 | if (!strncmp(argv[i], "--cache=", 8)) { | 195 | if (!strncmp(argv[i], "--cache=", 8)) { |
196 | cgit_cache_root = xstrdup(argv[i]+8); | 196 | cgit_cache_root = xstrdup(argv[i]+8); |
197 | } | 197 | } |
198 | if (!strcmp(argv[i], "--nocache")) { | 198 | if (!strcmp(argv[i], "--nocache")) { |
199 | cgit_nocache = 1; | 199 | cgit_nocache = 1; |
@@ -112,120 +112,122 @@ extern char *cgit_logo_link; | |||
112 | extern char *cgit_module_link; | 112 | extern char *cgit_module_link; |
113 | extern char *cgit_agefile; | 113 | extern char *cgit_agefile; |
114 | extern char *cgit_virtual_root; | 114 | extern char *cgit_virtual_root; |
115 | extern char *cgit_script_name; | 115 | extern char *cgit_script_name; |
116 | extern char *cgit_cache_root; | 116 | extern char *cgit_cache_root; |
117 | extern char *cgit_repo_group; | 117 | extern char *cgit_repo_group; |
118 | 118 | ||
119 | extern int cgit_nocache; | 119 | extern int cgit_nocache; |
120 | extern int cgit_snapshots; | 120 | extern int cgit_snapshots; |
121 | extern int cgit_enable_log_filecount; | 121 | extern int cgit_enable_log_filecount; |
122 | extern int cgit_enable_log_linecount; | 122 | extern int cgit_enable_log_linecount; |
123 | extern int cgit_max_lock_attempts; | 123 | extern int cgit_max_lock_attempts; |
124 | extern int cgit_cache_root_ttl; | 124 | extern int cgit_cache_root_ttl; |
125 | extern int cgit_cache_repo_ttl; | 125 | extern int cgit_cache_repo_ttl; |
126 | extern int cgit_cache_dynamic_ttl; | 126 | extern int cgit_cache_dynamic_ttl; |
127 | extern int cgit_cache_static_ttl; | 127 | extern int cgit_cache_static_ttl; |
128 | extern int cgit_cache_max_create_time; | 128 | extern int cgit_cache_max_create_time; |
129 | extern int cgit_summary_log; | 129 | extern int cgit_summary_log; |
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_tree_link(char *name, char *title, char *class, char *head, | 204 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
205 | char *rev, char *path); | 205 | char *rev, char *path); |
206 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 206 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
207 | char *rev, char *path); | 207 | char *rev, char *path); |
208 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | ||
209 | char *rev); | ||
208 | 210 | ||
209 | extern void cgit_print_error(char *msg); | 211 | extern void cgit_print_error(char *msg); |
210 | extern void cgit_print_date(time_t secs, char *format); | 212 | extern void cgit_print_date(time_t secs, char *format); |
211 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 213 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
212 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 214 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
213 | extern void cgit_print_docend(); | 215 | extern void cgit_print_docend(); |
214 | extern void cgit_print_pageheader(char *title, int show_search); | 216 | extern void cgit_print_pageheader(char *title, int show_search); |
215 | extern void cgit_print_snapshot_start(const char *mimetype, | 217 | extern void cgit_print_snapshot_start(const char *mimetype, |
216 | const char *filename, | 218 | const char *filename, |
217 | struct cacheitem *item); | 219 | struct cacheitem *item); |
218 | 220 | ||
219 | extern void cgit_print_repolist(struct cacheitem *item); | 221 | extern void cgit_print_repolist(struct cacheitem *item); |
220 | extern void cgit_print_summary(); | 222 | extern void cgit_print_summary(); |
221 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 223 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
222 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 224 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
223 | extern void cgit_print_tree(const char *rev, char *path); | 225 | extern void cgit_print_tree(const char *rev, char *path); |
224 | extern void cgit_print_commit(const char *hex); | 226 | extern void cgit_print_commit(const char *hex); |
225 | extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, | 227 | extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, |
226 | char *path); | 228 | char *path); |
227 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 229 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
228 | const char *format, const char *prefix, | 230 | const char *format, const char *prefix, |
229 | const char *filename); | 231 | const char *filename); |
230 | 232 | ||
231 | #endif /* CGIT_H */ | 233 | #endif /* CGIT_H */ |
diff --git a/ui-commit.c b/ui-commit.c index 885f870..8864fc6 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -63,179 +63,182 @@ void print_fileinfo(struct fileinfo *info) | |||
63 | htmlf("<td class='mode'>"); | 63 | htmlf("<td class='mode'>"); |
64 | if (is_null_sha1(info->new_sha1)) { | 64 | if (is_null_sha1(info->new_sha1)) { |
65 | html_filemode(info->old_mode); | 65 | html_filemode(info->old_mode); |
66 | } else { | 66 | } else { |
67 | html_filemode(info->new_mode); | 67 | html_filemode(info->new_mode); |
68 | } | 68 | } |
69 | 69 | ||
70 | if (info->old_mode != info->new_mode && | 70 | if (info->old_mode != info->new_mode && |
71 | !is_null_sha1(info->old_sha1) && | 71 | !is_null_sha1(info->old_sha1) && |
72 | !is_null_sha1(info->new_sha1)) { | 72 | !is_null_sha1(info->new_sha1)) { |
73 | html("<span class='modechange'>["); | 73 | html("<span class='modechange'>["); |
74 | html_filemode(info->old_mode); | 74 | html_filemode(info->old_mode); |
75 | html("]</span>"); | 75 | html("]</span>"); |
76 | } | 76 | } |
77 | htmlf("</td><td class='%s'>", class); | 77 | htmlf("</td><td class='%s'>", class); |
78 | query = fmt("id=%s&id2=%s&path=%s", sha1_to_hex(info->old_sha1), | 78 | query = fmt("id=%s&id2=%s&path=%s", sha1_to_hex(info->old_sha1), |
79 | sha1_to_hex(info->new_sha1), info->new_path); | 79 | sha1_to_hex(info->new_sha1), info->new_path); |
80 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), | 80 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), |
81 | NULL, NULL); | 81 | NULL, NULL); |
82 | if (info->status == DIFF_STATUS_COPIED || | 82 | if (info->status == DIFF_STATUS_COPIED || |
83 | info->status == DIFF_STATUS_RENAMED) { | 83 | info->status == DIFF_STATUS_RENAMED) { |
84 | html_txt(info->new_path); | 84 | html_txt(info->new_path); |
85 | htmlf("</a> (%s from ", info->status == DIFF_STATUS_COPIED ? | 85 | htmlf("</a> (%s from ", info->status == DIFF_STATUS_COPIED ? |
86 | "copied" : "renamed"); | 86 | "copied" : "renamed"); |
87 | query2 = fmt("id=%s", sha1_to_hex(info->old_sha1)); | 87 | query2 = fmt("id=%s", sha1_to_hex(info->old_sha1)); |
88 | html_link_open(cgit_pageurl(cgit_query_repo, "view", query2), | 88 | html_link_open(cgit_pageurl(cgit_query_repo, "view", query2), |
89 | NULL, NULL); | 89 | NULL, NULL); |
90 | html_txt(info->old_path); | 90 | html_txt(info->old_path); |
91 | html("</a>)"); | 91 | html("</a>)"); |
92 | } else { | 92 | } else { |
93 | html_txt(info->new_path); | 93 | html_txt(info->new_path); |
94 | html("</a>"); | 94 | html("</a>"); |
95 | } | 95 | } |
96 | html("</td><td class='right'>"); | 96 | html("</td><td class='right'>"); |
97 | htmlf("%d", info->added + info->removed); | 97 | htmlf("%d", info->added + info->removed); |
98 | html("</td><td class='graph'>"); | 98 | html("</td><td class='graph'>"); |
99 | htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); | 99 | htmlf("<table width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); |
100 | htmlf("<td class='add' style='width: %.1f%%;'/>", | 100 | htmlf("<td class='add' style='width: %.1f%%;'/>", |
101 | info->added * 100.0 / max_changes); | 101 | info->added * 100.0 / max_changes); |
102 | htmlf("<td class='rem' style='width: %.1f%%;'/>", | 102 | htmlf("<td class='rem' style='width: %.1f%%;'/>", |
103 | info->removed * 100.0 / max_changes); | 103 | info->removed * 100.0 / max_changes); |
104 | htmlf("<td class='none' style='width: %.1f%%;'/>", | 104 | htmlf("<td class='none' style='width: %.1f%%;'/>", |
105 | (max_changes - info->removed - info->added) * 100.0 / max_changes); | 105 | (max_changes - info->removed - info->added) * 100.0 / max_changes); |
106 | html("</tr></table></td></tr>\n"); | 106 | html("</tr></table></td></tr>\n"); |
107 | } | 107 | } |
108 | 108 | ||
109 | void cgit_count_diff_lines(char *line, int len) | 109 | void cgit_count_diff_lines(char *line, int len) |
110 | { | 110 | { |
111 | if (line && (len > 0)) { | 111 | if (line && (len > 0)) { |
112 | if (line[0] == '+') | 112 | if (line[0] == '+') |
113 | lines_added++; | 113 | lines_added++; |
114 | else if (line[0] == '-') | 114 | else if (line[0] == '-') |
115 | lines_removed++; | 115 | lines_removed++; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | void inspect_filepair(struct diff_filepair *pair) | 119 | void inspect_filepair(struct diff_filepair *pair) |
120 | { | 120 | { |
121 | files++; | 121 | files++; |
122 | lines_added = 0; | 122 | lines_added = 0; |
123 | lines_removed = 0; | 123 | lines_removed = 0; |
124 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); | 124 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); |
125 | if (files >= slots) { | 125 | if (files >= slots) { |
126 | if (slots == 0) | 126 | if (slots == 0) |
127 | slots = 4; | 127 | slots = 4; |
128 | else | 128 | else |
129 | slots = slots * 2; | 129 | slots = slots * 2; |
130 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 130 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
131 | } | 131 | } |
132 | items[files-1].status = pair->status; | 132 | items[files-1].status = pair->status; |
133 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 133 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
134 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 134 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
135 | items[files-1].old_mode = pair->one->mode; | 135 | items[files-1].old_mode = pair->one->mode; |
136 | items[files-1].new_mode = pair->two->mode; | 136 | items[files-1].new_mode = pair->two->mode; |
137 | items[files-1].old_path = xstrdup(pair->one->path); | 137 | items[files-1].old_path = xstrdup(pair->one->path); |
138 | items[files-1].new_path = xstrdup(pair->two->path); | 138 | items[files-1].new_path = xstrdup(pair->two->path); |
139 | items[files-1].added = lines_added; | 139 | items[files-1].added = lines_added; |
140 | items[files-1].removed = lines_removed; | 140 | items[files-1].removed = lines_removed; |
141 | if (lines_added + lines_removed > max_changes) | 141 | if (lines_added + lines_removed > max_changes) |
142 | max_changes = lines_added + lines_removed; | 142 | max_changes = lines_added + lines_removed; |
143 | total_adds += lines_added; | 143 | total_adds += lines_added; |
144 | total_rems += lines_removed; | 144 | total_rems += lines_removed; |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void cgit_print_commit(const char *hex) | 148 | void cgit_print_commit(const char *hex) |
149 | { | 149 | { |
150 | struct commit *commit, *parent; | 150 | struct commit *commit, *parent; |
151 | struct commitinfo *info; | 151 | struct commitinfo *info; |
152 | struct commit_list *p; | 152 | struct commit_list *p; |
153 | unsigned char sha1[20]; | 153 | unsigned char sha1[20]; |
154 | char *query; | 154 | char *query; |
155 | char *filename; | 155 | char *filename; |
156 | char *tmp; | 156 | char *tmp; |
157 | int i; | 157 | int i; |
158 | 158 | ||
159 | if (!hex) | ||
160 | hex = cgit_query_head; | ||
161 | |||
159 | if (get_sha1(hex, sha1)) { | 162 | if (get_sha1(hex, sha1)) { |
160 | cgit_print_error(fmt("Bad object id: %s", hex)); | 163 | cgit_print_error(fmt("Bad object id: %s", hex)); |
161 | return; | 164 | return; |
162 | } | 165 | } |
163 | commit = lookup_commit_reference(sha1); | 166 | commit = lookup_commit_reference(sha1); |
164 | if (!commit) { | 167 | if (!commit) { |
165 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 168 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
166 | return; | 169 | return; |
167 | } | 170 | } |
168 | info = cgit_parse_commit(commit); | 171 | info = cgit_parse_commit(commit); |
169 | 172 | ||
170 | html("<table class='commit-info'>\n"); | 173 | html("<table class='commit-info'>\n"); |
171 | html("<tr><th>author</th><td>"); | 174 | html("<tr><th>author</th><td>"); |
172 | html_txt(info->author); | 175 | html_txt(info->author); |
173 | html(" "); | 176 | html(" "); |
174 | html_txt(info->author_email); | 177 | html_txt(info->author_email); |
175 | html("</td><td class='right'>"); | 178 | html("</td><td class='right'>"); |
176 | cgit_print_date(info->author_date, FMT_LONGDATE); | 179 | cgit_print_date(info->author_date, FMT_LONGDATE); |
177 | html("</td></tr>\n"); | 180 | html("</td></tr>\n"); |
178 | html("<tr><th>committer</th><td>"); | 181 | html("<tr><th>committer</th><td>"); |
179 | html_txt(info->committer); | 182 | html_txt(info->committer); |
180 | html(" "); | 183 | html(" "); |
181 | html_txt(info->committer_email); | 184 | html_txt(info->committer_email); |
182 | html("</td><td class='right'>"); | 185 | html("</td><td class='right'>"); |
183 | cgit_print_date(info->committer_date, FMT_LONGDATE); | 186 | cgit_print_date(info->committer_date, FMT_LONGDATE); |
184 | html("</td></tr>\n"); | 187 | html("</td></tr>\n"); |
185 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 188 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
186 | tmp = xstrdup(hex); | 189 | tmp = xstrdup(hex); |
187 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, | 190 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, |
188 | cgit_query_head, tmp, NULL); | 191 | cgit_query_head, tmp, NULL); |
189 | html("</td></tr>\n"); | 192 | html("</td></tr>\n"); |
190 | for (p = commit->parents; p ; p = p->next) { | 193 | for (p = commit->parents; p ; p = p->next) { |
191 | parent = lookup_commit_reference(p->item->object.sha1); | 194 | parent = lookup_commit_reference(p->item->object.sha1); |
192 | if (!parent) { | 195 | if (!parent) { |
193 | html("<tr><td colspan='3'>"); | 196 | html("<tr><td colspan='3'>"); |
194 | cgit_print_error("Error reading parent commit"); | 197 | cgit_print_error("Error reading parent commit"); |
195 | html("</td></tr>"); | 198 | html("</td></tr>"); |
196 | continue; | 199 | continue; |
197 | } | 200 | } |
198 | html("<tr><th>parent</th>" | 201 | html("<tr><th>parent</th>" |
199 | "<td colspan='2' class='sha1'>" | 202 | "<td colspan='2' class='sha1'>" |
200 | "<a href='"); | 203 | "<a href='"); |
201 | query = fmt("h=%s", sha1_to_hex(p->item->object.sha1)); | 204 | query = fmt("h=%s", sha1_to_hex(p->item->object.sha1)); |
202 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); | 205 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); |
203 | htmlf("'>%s</a> (<a href='", | 206 | htmlf("'>%s</a> (<a href='", |
204 | sha1_to_hex(p->item->object.sha1)); | 207 | sha1_to_hex(p->item->object.sha1)); |
205 | query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), | 208 | query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), |
206 | sha1_to_hex(commit->tree->object.sha1)); | 209 | sha1_to_hex(commit->tree->object.sha1)); |
207 | html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); | 210 | html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); |
208 | html("'>diff</a>)</td></tr>"); | 211 | html("'>diff</a>)</td></tr>"); |
209 | } | 212 | } |
210 | if (cgit_repo->snapshots) { | 213 | if (cgit_repo->snapshots) { |
211 | htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); | 214 | htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); |
212 | filename = fmt("%s-%s.zip", cgit_query_repo, hex); | 215 | filename = fmt("%s-%s.zip", cgit_query_repo, hex); |
213 | html_attr(cgit_pageurl(cgit_query_repo, "snapshot", | 216 | html_attr(cgit_pageurl(cgit_query_repo, "snapshot", |
214 | fmt("id=%s&name=%s", hex, filename))); | 217 | fmt("id=%s&name=%s", hex, filename))); |
215 | htmlf("'>%s</a></td></tr>", filename); | 218 | htmlf("'>%s</a></td></tr>", filename); |
216 | } | 219 | } |
217 | html("</table>\n"); | 220 | html("</table>\n"); |
218 | html("<div class='commit-subject'>"); | 221 | html("<div class='commit-subject'>"); |
219 | html_txt(info->subject); | 222 | html_txt(info->subject); |
220 | html("</div>"); | 223 | html("</div>"); |
221 | html("<div class='commit-msg'>"); | 224 | html("<div class='commit-msg'>"); |
222 | html_txt(info->msg); | 225 | html_txt(info->msg); |
223 | html("</div>"); | 226 | html("</div>"); |
224 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 227 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
225 | html("<div class='diffstat-header'>Diffstat</div>"); | 228 | html("<div class='diffstat-header'>Diffstat</div>"); |
226 | html("<table class='diffstat'>"); | 229 | html("<table class='diffstat'>"); |
227 | max_changes = 0; | 230 | max_changes = 0; |
228 | cgit_diff_commit(commit, inspect_filepair); | 231 | cgit_diff_commit(commit, inspect_filepair); |
229 | for(i = 0; i<files; i++) | 232 | for(i = 0; i<files; i++) |
230 | print_fileinfo(&items[i]); | 233 | print_fileinfo(&items[i]); |
231 | html("</table>"); | 234 | html("</table>"); |
232 | html("<div class='diffstat-summary'>"); | 235 | html("<div class='diffstat-summary'>"); |
233 | htmlf("%d files changed, %d insertions, %d deletions (", | 236 | htmlf("%d files changed, %d insertions, %d deletions (", |
234 | files, total_adds, total_rems); | 237 | files, total_adds, total_rems); |
235 | query = fmt("h=%s", hex); | 238 | query = fmt("h=%s", hex); |
236 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), NULL, NULL); | 239 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), NULL, NULL); |
237 | html("show diff</a>)"); | 240 | html("show diff</a>)"); |
238 | html("</div>"); | 241 | html("</div>"); |
239 | } | 242 | } |
240 | cgit_free_commitinfo(info); | 243 | cgit_free_commitinfo(info); |
241 | } | 244 | } |
@@ -1,130 +1,127 @@ | |||
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 | cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, |
35 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); | 35 | sha1_to_hex(commit->object.sha1)); |
36 | html_link_open(url, NULL, NULL); | ||
37 | html_ntxt(cgit_max_msg_len, info->subject); | ||
38 | html_link_close(); | ||
39 | if (cgit_repo->enable_log_filecount) { | 36 | if (cgit_repo->enable_log_filecount) { |
40 | files = 0; | 37 | files = 0; |
41 | lines = 0; | 38 | lines = 0; |
42 | cgit_diff_commit(commit, inspect_files); | 39 | cgit_diff_commit(commit, inspect_files); |
43 | html("</td><td class='right'>"); | 40 | html("</td><td class='right'>"); |
44 | htmlf("%d", files); | 41 | htmlf("%d", files); |
45 | if (cgit_repo->enable_log_linecount) { | 42 | if (cgit_repo->enable_log_linecount) { |
46 | html("</td><td class='right'>"); | 43 | html("</td><td class='right'>"); |
47 | htmlf("%d", lines); | 44 | htmlf("%d", lines); |
48 | } | 45 | } |
49 | } | 46 | } |
50 | html("</td><td>"); | 47 | html("</td><td>"); |
51 | html_txt(info->author); | 48 | html_txt(info->author); |
52 | html("</td></tr>\n"); | 49 | html("</td></tr>\n"); |
53 | cgit_free_commitinfo(info); | 50 | cgit_free_commitinfo(info); |
54 | } | 51 | } |
55 | 52 | ||
56 | 53 | ||
57 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager) | 54 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager) |
58 | { | 55 | { |
59 | struct rev_info rev; | 56 | struct rev_info rev; |
60 | struct commit *commit; | 57 | struct commit *commit; |
61 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | 58 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
62 | int argc = 2; | 59 | int argc = 2; |
63 | int i; | 60 | int i; |
64 | 61 | ||
65 | if (grep) | 62 | if (grep) |
66 | argv[argc++] = fmt("--grep=%s", grep); | 63 | argv[argc++] = fmt("--grep=%s", grep); |
67 | if (path) { | 64 | if (path) { |
68 | argv[argc++] = "--"; | 65 | argv[argc++] = "--"; |
69 | argv[argc++] = path; | 66 | argv[argc++] = path; |
70 | } | 67 | } |
71 | init_revisions(&rev, NULL); | 68 | init_revisions(&rev, NULL); |
72 | rev.abbrev = DEFAULT_ABBREV; | 69 | rev.abbrev = DEFAULT_ABBREV; |
73 | rev.commit_format = CMIT_FMT_DEFAULT; | 70 | rev.commit_format = CMIT_FMT_DEFAULT; |
74 | rev.verbose_header = 1; | 71 | rev.verbose_header = 1; |
75 | rev.show_root_diff = 0; | 72 | rev.show_root_diff = 0; |
76 | setup_revisions(argc, argv, &rev, NULL); | 73 | setup_revisions(argc, argv, &rev, NULL); |
77 | if (rev.grep_filter) { | 74 | if (rev.grep_filter) { |
78 | rev.grep_filter->regflags |= REG_ICASE; | 75 | rev.grep_filter->regflags |= REG_ICASE; |
79 | compile_grep_patterns(rev.grep_filter); | 76 | compile_grep_patterns(rev.grep_filter); |
80 | } | 77 | } |
81 | prepare_revision_walk(&rev); | 78 | prepare_revision_walk(&rev); |
82 | 79 | ||
83 | html("<table class='list nowrap'>"); | 80 | html("<table class='list nowrap'>"); |
84 | html("<tr class='nohover'><th class='left'>Age</th>" | 81 | html("<tr class='nohover'><th class='left'>Age</th>" |
85 | "<th class='left'>Message</th>"); | 82 | "<th class='left'>Message</th>"); |
86 | 83 | ||
87 | if (cgit_repo->enable_log_filecount) { | 84 | if (cgit_repo->enable_log_filecount) { |
88 | html("<th class='left'>Files</th>"); | 85 | html("<th class='left'>Files</th>"); |
89 | if (cgit_repo->enable_log_linecount) | 86 | if (cgit_repo->enable_log_linecount) |
90 | html("<th class='left'>Lines</th>"); | 87 | html("<th class='left'>Lines</th>"); |
91 | } | 88 | } |
92 | html("<th class='left'>Author</th></tr>\n"); | 89 | html("<th class='left'>Author</th></tr>\n"); |
93 | 90 | ||
94 | if (ofs<0) | 91 | if (ofs<0) |
95 | ofs = 0; | 92 | ofs = 0; |
96 | 93 | ||
97 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 94 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
98 | free(commit->buffer); | 95 | free(commit->buffer); |
99 | commit->buffer = NULL; | 96 | commit->buffer = NULL; |
100 | free_commit_list(commit->parents); | 97 | free_commit_list(commit->parents); |
101 | commit->parents = NULL; | 98 | commit->parents = NULL; |
102 | } | 99 | } |
103 | 100 | ||
104 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 101 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
105 | print_commit(commit); | 102 | print_commit(commit); |
106 | free(commit->buffer); | 103 | free(commit->buffer); |
107 | commit->buffer = NULL; | 104 | commit->buffer = NULL; |
108 | free_commit_list(commit->parents); | 105 | free_commit_list(commit->parents); |
109 | commit->parents = NULL; | 106 | commit->parents = NULL; |
110 | } | 107 | } |
111 | html("</table>\n"); | 108 | html("</table>\n"); |
112 | 109 | ||
113 | if (pager) { | 110 | if (pager) { |
114 | html("<div class='pager'>"); | 111 | html("<div class='pager'>"); |
115 | if (ofs > 0) { | 112 | if (ofs > 0) { |
116 | html(" <a href='"); | 113 | html(" <a href='"); |
117 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, | 114 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, |
118 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); | 115 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); |
119 | html("'>[prev]</a> "); | 116 | html("'>[prev]</a> "); |
120 | } | 117 | } |
121 | 118 | ||
122 | if ((commit = get_revision(&rev)) != NULL) { | 119 | if ((commit = get_revision(&rev)) != NULL) { |
123 | html(" <a href='"); | 120 | html(" <a href='"); |
124 | html(cgit_pageurl(cgit_query_repo, "log", | 121 | html(cgit_pageurl(cgit_query_repo, "log", |
125 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); | 122 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); |
126 | html("'>[next]</a> "); | 123 | html("'>[next]</a> "); |
127 | } | 124 | } |
128 | html("</div>"); | 125 | html("</div>"); |
129 | } | 126 | } |
130 | } | 127 | } |
diff --git a/ui-shared.c b/ui-shared.c index 64ee79c..71c899a 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -43,220 +43,232 @@ void cgit_print_error(char *msg) | |||
43 | char *cgit_rooturl() | 43 | char *cgit_rooturl() |
44 | { | 44 | { |
45 | if (cgit_virtual_root) | 45 | if (cgit_virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 46 | return fmt("%s/", cgit_virtual_root); |
47 | else | 47 | else |
48 | return cgit_script_name; | 48 | return cgit_script_name; |
49 | } | 49 | } |
50 | 50 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
52 | { | 52 | { |
53 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | char *cgit_pageurl(const char *reponame, const char *pagename, | 60 | char *cgit_pageurl(const char *reponame, const char *pagename, |
61 | const char *query) | 61 | const char *query) |
62 | { | 62 | { |
63 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
64 | if (query) | 64 | if (query) |
65 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, | 65 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, |
66 | pagename, query); | 66 | pagename, query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | if (query) | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_currurl() | 78 | char *cgit_currurl() |
79 | { | 79 | { |
80 | if (!cgit_virtual_root) | 80 | if (!cgit_virtual_root) |
81 | return cgit_script_name; | 81 | return cgit_script_name; |
82 | else if (cgit_query_page) | 82 | else if (cgit_query_page) |
83 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 83 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
84 | else if (cgit_query_repo) | 84 | else if (cgit_query_repo) |
85 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 85 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
86 | else | 86 | else |
87 | return fmt("%s/", cgit_virtual_root); | 87 | return fmt("%s/", cgit_virtual_root); |
88 | } | 88 | } |
89 | 89 | ||
90 | static char *repolink(char *title, char *class, char *page, char *head, | 90 | static char *repolink(char *title, char *class, char *page, char *head, |
91 | char *path) | 91 | char *path) |
92 | { | 92 | { |
93 | char *delim = "?"; | 93 | char *delim = "?"; |
94 | 94 | ||
95 | html("<a"); | 95 | html("<a"); |
96 | if (title) { | 96 | if (title) { |
97 | html(" title='"); | 97 | html(" title='"); |
98 | html_attr(title); | 98 | html_attr(title); |
99 | html("'"); | 99 | html("'"); |
100 | } | 100 | } |
101 | if (class) { | 101 | if (class) { |
102 | html(" class='"); | 102 | html(" class='"); |
103 | html_attr(class); | 103 | html_attr(class); |
104 | html("'"); | 104 | html("'"); |
105 | } | 105 | } |
106 | html(" href='"); | 106 | html(" href='"); |
107 | if (cgit_virtual_root) { | 107 | if (cgit_virtual_root) { |
108 | html_attr(cgit_virtual_root); | 108 | html_attr(cgit_virtual_root); |
109 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 109 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') |
110 | html("/"); | 110 | html("/"); |
111 | html_attr(cgit_repo->url); | 111 | html_attr(cgit_repo->url); |
112 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 112 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
113 | html("/"); | 113 | html("/"); |
114 | html(page); | 114 | html(page); |
115 | html("/"); | 115 | html("/"); |
116 | if (path) | 116 | if (path) |
117 | html_attr(path); | 117 | html_attr(path); |
118 | } else { | 118 | } else { |
119 | html(cgit_script_name); | 119 | html(cgit_script_name); |
120 | html("?url="); | 120 | html("?url="); |
121 | html_attr(cgit_repo->url); | 121 | html_attr(cgit_repo->url); |
122 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 122 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
123 | html("/"); | 123 | html("/"); |
124 | html(page); | 124 | html(page); |
125 | html("/"); | 125 | html("/"); |
126 | if (path) | 126 | if (path) |
127 | html_attr(path); | 127 | html_attr(path); |
128 | delim = "&"; | 128 | delim = "&"; |
129 | } | 129 | } |
130 | if (head && strcmp(head, cgit_repo->defbranch)) { | 130 | if (head && strcmp(head, cgit_repo->defbranch)) { |
131 | html(delim); | 131 | html(delim); |
132 | html("h="); | 132 | html("h="); |
133 | html_attr(head); | 133 | html_attr(head); |
134 | delim = "&"; | 134 | delim = "&"; |
135 | } | 135 | } |
136 | return fmt("%s", delim); | 136 | return fmt("%s", delim); |
137 | } | 137 | } |
138 | 138 | ||
139 | static char *reporevlink(char *page, char *name, char *title, char *class, | 139 | static void reporevlink(char *page, char *name, char *title, char *class, |
140 | char *head, char *rev, char *path) | 140 | char *head, char *rev, char *path) |
141 | { | 141 | { |
142 | char *delim; | 142 | char *delim; |
143 | 143 | ||
144 | delim = repolink(title, class, page, head, path); | 144 | delim = repolink(title, class, page, head, path); |
145 | if (rev && strcmp(rev, cgit_query_head)) { | 145 | if (rev && strcmp(rev, cgit_query_head)) { |
146 | html(delim); | 146 | html(delim); |
147 | html("id="); | 147 | html("id="); |
148 | html_attr(rev); | 148 | html_attr(rev); |
149 | } | 149 | } |
150 | html("'>"); | 150 | html("'>"); |
151 | html_txt(name); | 151 | html_txt(name); |
152 | html("</a>"); | 152 | html("</a>"); |
153 | } | 153 | } |
154 | 154 | ||
155 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 155 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
156 | char *rev, char *path) | 156 | char *rev, char *path) |
157 | { | 157 | { |
158 | reporevlink("tree", name, title, class, head, rev, path); | 158 | reporevlink("tree", name, title, class, head, rev, path); |
159 | } | 159 | } |
160 | 160 | ||
161 | void cgit_log_link(char *name, char *title, char *class, char *head, | 161 | void cgit_log_link(char *name, char *title, char *class, char *head, |
162 | char *rev, char *path) | 162 | char *rev, char *path) |
163 | { | 163 | { |
164 | reporevlink("log", name, title, class, head, rev, path); | 164 | reporevlink("log", name, title, class, head, rev, path); |
165 | } | 165 | } |
166 | 166 | ||
167 | void cgit_commit_link(char *name, char *title, char *class, char *head, | ||
168 | char *rev) | ||
169 | { | ||
170 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | ||
171 | name[cgit_max_msg_len] = '\0'; | ||
172 | name[cgit_max_msg_len - 1] = '.'; | ||
173 | name[cgit_max_msg_len - 2] = '.'; | ||
174 | name[cgit_max_msg_len - 3] = '.'; | ||
175 | } | ||
176 | reporevlink("commit", name, title, class, head, rev, NULL); | ||
177 | } | ||
178 | |||
167 | void cgit_print_date(time_t secs, char *format) | 179 | void cgit_print_date(time_t secs, char *format) |
168 | { | 180 | { |
169 | char buf[64]; | 181 | char buf[64]; |
170 | struct tm *time; | 182 | struct tm *time; |
171 | 183 | ||
172 | time = gmtime(&secs); | 184 | time = gmtime(&secs); |
173 | strftime(buf, sizeof(buf)-1, format, time); | 185 | strftime(buf, sizeof(buf)-1, format, time); |
174 | html_txt(buf); | 186 | html_txt(buf); |
175 | } | 187 | } |
176 | 188 | ||
177 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 189 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
178 | { | 190 | { |
179 | time_t now, secs; | 191 | time_t now, secs; |
180 | 192 | ||
181 | time(&now); | 193 | time(&now); |
182 | secs = now - t; | 194 | secs = now - t; |
183 | 195 | ||
184 | if (secs > max_relative && max_relative >= 0) { | 196 | if (secs > max_relative && max_relative >= 0) { |
185 | cgit_print_date(t, format); | 197 | cgit_print_date(t, format); |
186 | return; | 198 | return; |
187 | } | 199 | } |
188 | 200 | ||
189 | if (secs < TM_HOUR * 2) { | 201 | if (secs < TM_HOUR * 2) { |
190 | htmlf("<span class='age-mins'>%.0f min.</span>", | 202 | htmlf("<span class='age-mins'>%.0f min.</span>", |
191 | secs * 1.0 / TM_MIN); | 203 | secs * 1.0 / TM_MIN); |
192 | return; | 204 | return; |
193 | } | 205 | } |
194 | if (secs < TM_DAY * 2) { | 206 | if (secs < TM_DAY * 2) { |
195 | htmlf("<span class='age-hours'>%.0f hours</span>", | 207 | htmlf("<span class='age-hours'>%.0f hours</span>", |
196 | secs * 1.0 / TM_HOUR); | 208 | secs * 1.0 / TM_HOUR); |
197 | return; | 209 | return; |
198 | } | 210 | } |
199 | if (secs < TM_WEEK * 2) { | 211 | if (secs < TM_WEEK * 2) { |
200 | htmlf("<span class='age-days'>%.0f days</span>", | 212 | htmlf("<span class='age-days'>%.0f days</span>", |
201 | secs * 1.0 / TM_DAY); | 213 | secs * 1.0 / TM_DAY); |
202 | return; | 214 | return; |
203 | } | 215 | } |
204 | if (secs < TM_MONTH * 2) { | 216 | if (secs < TM_MONTH * 2) { |
205 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 217 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
206 | secs * 1.0 / TM_WEEK); | 218 | secs * 1.0 / TM_WEEK); |
207 | return; | 219 | return; |
208 | } | 220 | } |
209 | if (secs < TM_YEAR * 2) { | 221 | if (secs < TM_YEAR * 2) { |
210 | htmlf("<span class='age-months'>%.0f months</span>", | 222 | htmlf("<span class='age-months'>%.0f months</span>", |
211 | secs * 1.0 / TM_MONTH); | 223 | secs * 1.0 / TM_MONTH); |
212 | return; | 224 | return; |
213 | } | 225 | } |
214 | htmlf("<span class='age-years'>%.0f years</span>", | 226 | htmlf("<span class='age-years'>%.0f years</span>", |
215 | secs * 1.0 / TM_YEAR); | 227 | secs * 1.0 / TM_YEAR); |
216 | } | 228 | } |
217 | 229 | ||
218 | void cgit_print_docstart(char *title, struct cacheitem *item) | 230 | void cgit_print_docstart(char *title, struct cacheitem *item) |
219 | { | 231 | { |
220 | html("Content-Type: text/html; charset=utf-8\n"); | 232 | html("Content-Type: text/html; charset=utf-8\n"); |
221 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 233 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
222 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 234 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
223 | ttl_seconds(item->ttl))); | 235 | ttl_seconds(item->ttl))); |
224 | html("\n"); | 236 | html("\n"); |
225 | html(cgit_doctype); | 237 | html(cgit_doctype); |
226 | html("<html>\n"); | 238 | html("<html>\n"); |
227 | html("<head>\n"); | 239 | html("<head>\n"); |
228 | html("<title>"); | 240 | html("<title>"); |
229 | html_txt(title); | 241 | html_txt(title); |
230 | html("</title>\n"); | 242 | html("</title>\n"); |
231 | htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version); | 243 | htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version); |
232 | html("<link rel='stylesheet' type='text/css' href='"); | 244 | html("<link rel='stylesheet' type='text/css' href='"); |
233 | html_attr(cgit_css); | 245 | html_attr(cgit_css); |
234 | html("'/>\n"); | 246 | html("'/>\n"); |
235 | html("</head>\n"); | 247 | html("</head>\n"); |
236 | html("<body>\n"); | 248 | html("<body>\n"); |
237 | } | 249 | } |
238 | 250 | ||
239 | void cgit_print_docend() | 251 | void cgit_print_docend() |
240 | { | 252 | { |
241 | html("</td></tr></table>"); | 253 | html("</td></tr></table>"); |
242 | html("</body>\n</html>\n"); | 254 | html("</body>\n</html>\n"); |
243 | } | 255 | } |
244 | 256 | ||
245 | void cgit_print_pageheader(char *title, int show_search) | 257 | void cgit_print_pageheader(char *title, int show_search) |
246 | { | 258 | { |
247 | html("<table id='layout'>"); | 259 | html("<table id='layout'>"); |
248 | html("<tr><td id='header'>"); | 260 | html("<tr><td id='header'>"); |
249 | html(cgit_root_title); | 261 | html(cgit_root_title); |
250 | html("</td><td id='logo'>"); | 262 | html("</td><td id='logo'>"); |
251 | html("<a href='"); | 263 | html("<a href='"); |
252 | html_attr(cgit_logo_link); | 264 | html_attr(cgit_logo_link); |
253 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); | 265 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); |
254 | html("</td></tr>"); | 266 | html("</td></tr>"); |
255 | html("<tr><td id='crumb'>"); | 267 | html("<tr><td id='crumb'>"); |
256 | htmlf("<a href='%s'>root</a>", cgit_rooturl()); | 268 | htmlf("<a href='%s'>root</a>", cgit_rooturl()); |
257 | if (cgit_query_repo) { | 269 | if (cgit_query_repo) { |
258 | htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url)); | 270 | htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url)); |
259 | html_txt(cgit_repo->name); | 271 | html_txt(cgit_repo->name); |
260 | htmlf("</a> : %s", title); | 272 | htmlf("</a> : %s", title); |
261 | } | 273 | } |
262 | html("</td>"); | 274 | html("</td>"); |
diff --git a/ui-summary.c b/ui-summary.c index 29b76e3..03dd078 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,154 +1,154 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary page |
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 | static int header; | 11 | static int header; |
12 | 12 | ||
13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, |
14 | int flags, void *cb_data) | 14 | int flags, void *cb_data) |
15 | { | 15 | { |
16 | struct commit *commit; | 16 | struct commit *commit; |
17 | struct commitinfo *info; | 17 | struct commitinfo *info; |
18 | char buf[256], *url; | 18 | char buf[256]; |
19 | char *ref; | ||
19 | 20 | ||
21 | ref = xstrdup(refname); | ||
20 | strncpy(buf, refname, sizeof(buf)); | 22 | strncpy(buf, refname, sizeof(buf)); |
21 | commit = lookup_commit(sha1); | 23 | commit = lookup_commit(sha1); |
22 | // object is not really parsed at this point, because of some fallout | 24 | // object is not really parsed at this point, because of some fallout |
23 | // from previous calls to git functions in cgit_print_log() | 25 | // from previous calls to git functions in cgit_print_log() |
24 | commit->object.parsed = 0; | 26 | commit->object.parsed = 0; |
25 | if (commit && !parse_commit(commit)){ | 27 | if (commit && !parse_commit(commit)){ |
26 | info = cgit_parse_commit(commit); | 28 | info = cgit_parse_commit(commit); |
27 | html("<tr><td>"); | 29 | html("<tr><td>"); |
28 | cgit_log_link(refname, NULL, NULL, refname, NULL, NULL); | 30 | cgit_log_link(ref, NULL, NULL, ref, NULL, NULL); |
29 | html("</td><td>"); | 31 | html("</td><td>"); |
30 | cgit_print_age(commit->date, -1, NULL); | 32 | cgit_print_age(commit->date, -1, NULL); |
31 | html("</td><td>"); | 33 | html("</td><td>"); |
32 | html_txt(info->author); | 34 | html_txt(info->author); |
33 | html("</td><td>"); | 35 | html("</td><td>"); |
34 | url = cgit_pageurl(cgit_query_repo, "commit", | 36 | cgit_commit_link(info->subject, NULL, NULL, ref, NULL); |
35 | fmt("h=%s", sha1_to_hex(sha1))); | ||
36 | html_link_open(url, NULL, NULL); | ||
37 | html_ntxt(cgit_max_msg_len, info->subject); | ||
38 | html_link_close(); | ||
39 | html("</td></tr>\n"); | 37 | html("</td></tr>\n"); |
40 | cgit_free_commitinfo(info); | 38 | cgit_free_commitinfo(info); |
41 | } else { | 39 | } else { |
42 | html("<tr><td>"); | 40 | html("<tr><td>"); |
43 | html_txt(buf); | 41 | html_txt(buf); |
44 | html("</td><td colspan='3'>"); | 42 | html("</td><td colspan='3'>"); |
45 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 43 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); |
46 | html("</td></tr>\n"); | 44 | html("</td></tr>\n"); |
47 | } | 45 | } |
46 | free(ref); | ||
48 | return 0; | 47 | return 0; |
49 | } | 48 | } |
50 | 49 | ||
51 | 50 | ||
52 | static void cgit_print_object_ref(struct object *obj) | 51 | static void cgit_print_object_ref(struct object *obj) |
53 | { | 52 | { |
54 | char *page, *arg, *url; | 53 | char *page, *arg, *url; |
55 | 54 | ||
56 | if (obj->type == OBJ_COMMIT) { | 55 | if (obj->type == OBJ_COMMIT) { |
57 | page = "commit"; | 56 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
58 | arg = "h"; | 57 | cgit_query_head, sha1_to_hex(obj->sha1)); |
58 | return; | ||
59 | } else if (obj->type == OBJ_TREE) { | 59 | } else if (obj->type == OBJ_TREE) { |
60 | page = "tree"; | 60 | page = "tree"; |
61 | arg = "id"; | 61 | arg = "id"; |
62 | } else { | 62 | } else { |
63 | page = "view"; | 63 | page = "view"; |
64 | arg = "id"; | 64 | arg = "id"; |
65 | } | 65 | } |
66 | 66 | ||
67 | url = cgit_pageurl(cgit_query_repo, page, | 67 | url = cgit_pageurl(cgit_query_repo, page, |
68 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 68 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
69 | html_link_open(url, NULL, NULL); | 69 | html_link_open(url, NULL, NULL); |
70 | htmlf("%s %s", typename(obj->type), | 70 | htmlf("%s %s", typename(obj->type), |
71 | sha1_to_hex(obj->sha1)); | 71 | sha1_to_hex(obj->sha1)); |
72 | html_link_close(); | 72 | html_link_close(); |
73 | } | 73 | } |
74 | 74 | ||
75 | static void print_tag_header() | 75 | static void print_tag_header() |
76 | { | 76 | { |
77 | html("<tr class='nohover'><th class='left'>Tag</th>" | 77 | html("<tr class='nohover'><th class='left'>Tag</th>" |
78 | "<th class='left'>Age</th>" | 78 | "<th class='left'>Age</th>" |
79 | "<th class='left'>Author</th>" | 79 | "<th class='left'>Author</th>" |
80 | "<th class='left'>Reference</th></tr>\n"); | 80 | "<th class='left'>Reference</th></tr>\n"); |
81 | header = 1; | 81 | header = 1; |
82 | } | 82 | } |
83 | 83 | ||
84 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | 84 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, |
85 | int flags, void *cb_data) | 85 | int flags, void *cb_data) |
86 | { | 86 | { |
87 | struct tag *tag; | 87 | struct tag *tag; |
88 | struct taginfo *info; | 88 | struct taginfo *info; |
89 | struct object *obj; | 89 | struct object *obj; |
90 | char buf[256], *url; | 90 | char buf[256], *url; |
91 | 91 | ||
92 | strncpy(buf, refname, sizeof(buf)); | 92 | strncpy(buf, refname, sizeof(buf)); |
93 | obj = parse_object(sha1); | 93 | obj = parse_object(sha1); |
94 | if (!obj) | 94 | if (!obj) |
95 | return 1; | 95 | return 1; |
96 | if (obj->type == OBJ_TAG) { | 96 | if (obj->type == OBJ_TAG) { |
97 | tag = lookup_tag(sha1); | 97 | tag = lookup_tag(sha1); |
98 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 98 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
99 | return 2; | 99 | return 2; |
100 | if (!header) | 100 | if (!header) |
101 | print_tag_header(); | 101 | print_tag_header(); |
102 | html("<tr><td>"); | 102 | html("<tr><td>"); |
103 | url = cgit_pageurl(cgit_query_repo, "view", | 103 | url = cgit_pageurl(cgit_query_repo, "view", |
104 | fmt("id=%s", sha1_to_hex(sha1))); | 104 | fmt("id=%s", sha1_to_hex(sha1))); |
105 | html_link_open(url, NULL, NULL); | 105 | html_link_open(url, NULL, NULL); |
106 | html_txt(buf); | 106 | html_txt(buf); |
107 | html_link_close(); | 107 | html_link_close(); |
108 | html("</td><td>"); | 108 | html("</td><td>"); |
109 | if (info->tagger_date > 0) | 109 | if (info->tagger_date > 0) |
110 | cgit_print_age(info->tagger_date, -1, NULL); | 110 | cgit_print_age(info->tagger_date, -1, NULL); |
111 | html("</td><td>"); | 111 | html("</td><td>"); |
112 | if (info->tagger) | 112 | if (info->tagger) |
113 | html(info->tagger); | 113 | html(info->tagger); |
114 | html("</td><td>"); | 114 | html("</td><td>"); |
115 | cgit_print_object_ref(tag->tagged); | 115 | cgit_print_object_ref(tag->tagged); |
116 | html("</td></tr>\n"); | 116 | html("</td></tr>\n"); |
117 | } else { | 117 | } else { |
118 | if (!header) | 118 | if (!header) |
119 | print_tag_header(); | 119 | print_tag_header(); |
120 | html("<tr><td>"); | 120 | html("<tr><td>"); |
121 | html_txt(buf); | 121 | html_txt(buf); |
122 | html("</td><td colspan='2'/><td>"); | 122 | html("</td><td colspan='2'/><td>"); |
123 | cgit_print_object_ref(obj); | 123 | cgit_print_object_ref(obj); |
124 | html("</td></tr>\n"); | 124 | html("</td></tr>\n"); |
125 | } | 125 | } |
126 | return 0; | 126 | return 0; |
127 | } | 127 | } |
128 | 128 | ||
129 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | 129 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, |
130 | int flags, void *cb_data) | 130 | int flags, void *cb_data) |
131 | { | 131 | { |
132 | struct tag *tag; | 132 | struct tag *tag; |
133 | struct taginfo *info; | 133 | struct taginfo *info; |
134 | struct object *obj; | 134 | struct object *obj; |
135 | char buf[256], *url; | 135 | char buf[256], *url; |
136 | unsigned char fileid[20]; | 136 | unsigned char fileid[20]; |
137 | 137 | ||
138 | if (prefixcmp(refname, "refs/archives")) | 138 | if (prefixcmp(refname, "refs/archives")) |
139 | return 0; | 139 | return 0; |
140 | strncpy(buf, refname+14, sizeof(buf)); | 140 | strncpy(buf, refname+14, sizeof(buf)); |
141 | obj = parse_object(sha1); | 141 | obj = parse_object(sha1); |
142 | if (!obj) | 142 | if (!obj) |
143 | return 1; | 143 | return 1; |
144 | if (obj->type == OBJ_TAG) { | 144 | if (obj->type == OBJ_TAG) { |
145 | tag = lookup_tag(sha1); | 145 | tag = lookup_tag(sha1); |
146 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 146 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
147 | return 0; | 147 | return 0; |
148 | hashcpy(fileid, tag->tagged->sha1); | 148 | hashcpy(fileid, tag->tagged->sha1); |
149 | } else if (obj->type != OBJ_BLOB) { | 149 | } else if (obj->type != OBJ_BLOB) { |
150 | return 0; | 150 | return 0; |
151 | } else { | 151 | } else { |
152 | hashcpy(fileid, sha1); | 152 | hashcpy(fileid, sha1); |
153 | } | 153 | } |
154 | if (!header) { | 154 | if (!header) { |
@@ -1,157 +1,156 @@ | |||
1 | /* ui-tree.c: functions for tree output | 1 | /* ui-tree.c: functions for tree 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 | char *curr_rev; | 11 | char *curr_rev; |
12 | char *match_path; | 12 | char *match_path; |
13 | int header = 0; | 13 | int header = 0; |
14 | 14 | ||
15 | static void print_object(const unsigned char *sha1, char *path) | 15 | static void print_object(const unsigned char *sha1, char *path) |
16 | { | 16 | { |
17 | enum object_type type; | 17 | enum object_type type; |
18 | unsigned char *buf; | 18 | unsigned char *buf; |
19 | unsigned long size, lineno, start, idx; | 19 | unsigned long size, lineno, start, idx; |
20 | 20 | ||
21 | type = sha1_object_info(sha1, &size); | 21 | type = sha1_object_info(sha1, &size); |
22 | if (type == OBJ_BAD) { | 22 | if (type == OBJ_BAD) { |
23 | cgit_print_error(fmt("Bad object name: %s", | 23 | cgit_print_error(fmt("Bad object name: %s", |
24 | sha1_to_hex(sha1))); | 24 | sha1_to_hex(sha1))); |
25 | return; | 25 | return; |
26 | } | 26 | } |
27 | 27 | ||
28 | buf = read_sha1_file(sha1, &type, &size); | 28 | buf = read_sha1_file(sha1, &type, &size); |
29 | if (!buf) { | 29 | if (!buf) { |
30 | cgit_print_error(fmt("Error reading object %s", | 30 | cgit_print_error(fmt("Error reading object %s", |
31 | sha1_to_hex(sha1))); | 31 | sha1_to_hex(sha1))); |
32 | return; | 32 | return; |
33 | } | 33 | } |
34 | 34 | ||
35 | html("<table class='blob'>\n"); | 35 | html("<table class='blob'>\n"); |
36 | idx = 0; | 36 | idx = 0; |
37 | start = 0; | 37 | start = 0; |
38 | lineno = 0; | 38 | lineno = 0; |
39 | while(idx < size) { | 39 | while(idx < size) { |
40 | if (buf[idx] == '\n') { | 40 | if (buf[idx] == '\n') { |
41 | buf[idx] = '\0'; | 41 | buf[idx] = '\0'; |
42 | htmlf("<tr><td class='no'>%d</td><td class='txt'>", | 42 | htmlf("<tr><td class='no'>%d</td><td class='txt'>", |
43 | ++lineno); | 43 | ++lineno); |
44 | html_txt(buf + start); | 44 | html_txt(buf + start); |
45 | html("</td></tr>\n"); | 45 | html("</td></tr>\n"); |
46 | start = idx + 1; | 46 | start = idx + 1; |
47 | } | 47 | } |
48 | idx++; | 48 | idx++; |
49 | } | 49 | } |
50 | html("</table>\n"); | 50 | html("</table>\n"); |
51 | } | 51 | } |
52 | 52 | ||
53 | 53 | ||
54 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, | 54 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
55 | const char *pathname, unsigned int mode, int stage) | 55 | const char *pathname, unsigned int mode, int stage) |
56 | { | 56 | { |
57 | char *name; | 57 | char *name; |
58 | char *fullpath; | 58 | char *fullpath; |
59 | enum object_type type; | 59 | enum object_type type; |
60 | unsigned long size = 0; | 60 | unsigned long size = 0; |
61 | char *url, *qry; | ||
62 | 61 | ||
63 | name = xstrdup(pathname); | 62 | name = xstrdup(pathname); |
64 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", | 63 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", |
65 | cgit_query_path ? "/" : "", name); | 64 | cgit_query_path ? "/" : "", name); |
66 | 65 | ||
67 | type = sha1_object_info(sha1, &size); | 66 | type = sha1_object_info(sha1, &size); |
68 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { | 67 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { |
69 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 68 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
70 | name, | 69 | name, |
71 | sha1_to_hex(sha1)); | 70 | sha1_to_hex(sha1)); |
72 | return 0; | 71 | return 0; |
73 | } | 72 | } |
74 | 73 | ||
75 | html("<tr><td class='ls-mode'>"); | 74 | html("<tr><td class='ls-mode'>"); |
76 | html_filemode(mode); | 75 | html_filemode(mode); |
77 | html("</td><td>"); | 76 | html("</td><td>"); |
78 | if (S_ISDIRLNK(mode)) { | 77 | if (S_ISDIRLNK(mode)) { |
79 | htmlf("<a class='ls-mod' href='"); | 78 | htmlf("<a class='ls-mod' href='"); |
80 | html_attr(fmt(cgit_repo->module_link, | 79 | html_attr(fmt(cgit_repo->module_link, |
81 | name, | 80 | name, |
82 | sha1_to_hex(sha1))); | 81 | sha1_to_hex(sha1))); |
83 | html("'>"); | 82 | html("'>"); |
84 | html_txt(name); | 83 | html_txt(name); |
85 | html("</a>"); | 84 | html("</a>"); |
86 | } else if (S_ISDIR(mode)) { | 85 | } else if (S_ISDIR(mode)) { |
87 | cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, | 86 | cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, |
88 | curr_rev, fullpath); | 87 | curr_rev, fullpath); |
89 | } else { | 88 | } else { |
90 | cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, | 89 | cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, |
91 | curr_rev, fullpath); | 90 | curr_rev, fullpath); |
92 | } | 91 | } |
93 | htmlf("</td><td class='ls-size'>%li</td>", size); | 92 | htmlf("</td><td class='ls-size'>%li</td>", size); |
94 | 93 | ||
95 | html("<td>"); | 94 | html("<td>"); |
96 | cgit_log_link("L", "Log", "button", cgit_query_head, curr_rev, | 95 | cgit_log_link("L", "Log", "button", cgit_query_head, curr_rev, |
97 | fullpath); | 96 | fullpath); |
98 | html("</td></tr>\n"); | 97 | html("</td></tr>\n"); |
99 | free(name); | 98 | free(name); |
100 | return 0; | 99 | return 0; |
101 | } | 100 | } |
102 | 101 | ||
103 | static void ls_head() | 102 | static void ls_head() |
104 | { | 103 | { |
105 | html("<table class='list'>\n"); | 104 | html("<table class='list'>\n"); |
106 | html("<tr class='nohover'>"); | 105 | html("<tr class='nohover'>"); |
107 | html("<th class='left'>Mode</th>"); | 106 | html("<th class='left'>Mode</th>"); |
108 | html("<th class='left'>Name</th>"); | 107 | html("<th class='left'>Name</th>"); |
109 | html("<th class='right'>Size</th>"); | 108 | html("<th class='right'>Size</th>"); |
110 | html("<th/>"); | 109 | html("<th/>"); |
111 | html("</tr>\n"); | 110 | html("</tr>\n"); |
112 | header = 1; | 111 | header = 1; |
113 | } | 112 | } |
114 | 113 | ||
115 | static void ls_tail() | 114 | static void ls_tail() |
116 | { | 115 | { |
117 | if (!header) | 116 | if (!header) |
118 | return; | 117 | return; |
119 | html("</table>\n"); | 118 | html("</table>\n"); |
120 | header = 0; | 119 | header = 0; |
121 | } | 120 | } |
122 | 121 | ||
123 | static void ls_tree(const unsigned char *sha1, char *path) | 122 | static void ls_tree(const unsigned char *sha1, char *path) |
124 | { | 123 | { |
125 | struct tree *tree; | 124 | struct tree *tree; |
126 | 125 | ||
127 | tree = parse_tree_indirect(sha1); | 126 | tree = parse_tree_indirect(sha1); |
128 | if (!tree) { | 127 | if (!tree) { |
129 | cgit_print_error(fmt("Not a tree object: %s", | 128 | cgit_print_error(fmt("Not a tree object: %s", |
130 | sha1_to_hex(sha1))); | 129 | sha1_to_hex(sha1))); |
131 | return; | 130 | return; |
132 | } | 131 | } |
133 | 132 | ||
134 | ls_head(); | 133 | ls_head(); |
135 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); | 134 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); |
136 | ls_tail(); | 135 | ls_tail(); |
137 | } | 136 | } |
138 | 137 | ||
139 | 138 | ||
140 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 139 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
141 | const char *pathname, unsigned mode, int stage) | 140 | const char *pathname, unsigned mode, int stage) |
142 | { | 141 | { |
143 | static int state; | 142 | static int state; |
144 | static char buffer[PATH_MAX]; | 143 | static char buffer[PATH_MAX]; |
145 | char *url; | 144 | char *url; |
146 | 145 | ||
147 | if (state == 0) { | 146 | if (state == 0) { |
148 | memcpy(buffer, base, baselen); | 147 | memcpy(buffer, base, baselen); |
149 | strcpy(buffer+baselen, pathname); | 148 | strcpy(buffer+baselen, pathname); |
150 | url = cgit_pageurl(cgit_query_repo, "tree", | 149 | url = cgit_pageurl(cgit_query_repo, "tree", |
151 | fmt("h=%s&path=%s", curr_rev, buffer)); | 150 | fmt("h=%s&path=%s", curr_rev, buffer)); |
152 | html("/"); | 151 | html("/"); |
153 | cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, | 152 | cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, |
154 | curr_rev, buffer); | 153 | curr_rev, buffer); |
155 | 154 | ||
156 | if (strcmp(match_path, buffer)) | 155 | if (strcmp(match_path, buffer)) |
157 | return READ_TREE_RECURSIVE; | 156 | return READ_TREE_RECURSIVE; |