summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.h2
-rw-r--r--ui-repolist.c4
-rw-r--r--ui-shared.c20
-rw-r--r--ui-summary.c6
-rw-r--r--ui-tree.c12
5 files changed, 24 insertions, 20 deletions
diff --git a/cgit.h b/cgit.h
index 9a19c97..b2f6361 100644
--- a/cgit.h
+++ b/cgit.h
@@ -1,229 +1,231 @@
1#ifndef CGIT_H 1#ifndef CGIT_H
2#define CGIT_H 2#define CGIT_H
3 3
4 4
5#include <git-compat-util.h> 5#include <git-compat-util.h>
6#include <cache.h> 6#include <cache.h>
7#include <grep.h> 7#include <grep.h>
8#include <object.h> 8#include <object.h>
9#include <tree.h> 9#include <tree.h>
10#include <commit.h> 10#include <commit.h>
11#include <tag.h> 11#include <tag.h>
12#include <diff.h> 12#include <diff.h>
13#include <diffcore.h> 13#include <diffcore.h>
14#include <refs.h> 14#include <refs.h>
15#include <revision.h> 15#include <revision.h>
16#include <log-tree.h> 16#include <log-tree.h>
17#include <archive.h> 17#include <archive.h>
18#include <xdiff/xdiff.h> 18#include <xdiff/xdiff.h>
19 19
20 20
21/* 21/*
22 * The valid cgit repo-commands 22 * The valid cgit repo-commands
23 */ 23 */
24#define CMD_LOG 1 24#define CMD_LOG 1
25#define CMD_COMMIT 2 25#define CMD_COMMIT 2
26#define CMD_DIFF 3 26#define CMD_DIFF 3
27#define CMD_TREE 4 27#define CMD_TREE 4
28#define CMD_BLOB 5 28#define CMD_BLOB 5
29#define CMD_SNAPSHOT 6 29#define CMD_SNAPSHOT 6
30 30
31 31
32/* 32/*
33 * Dateformats used on misc. pages 33 * Dateformats used on misc. pages
34 */ 34 */
35#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" 35#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S"
36#define FMT_SHORTDATE "%Y-%m-%d" 36#define FMT_SHORTDATE "%Y-%m-%d"
37 37
38 38
39/* 39/*
40 * Limits used for relative dates 40 * Limits used for relative dates
41 */ 41 */
42#define TM_MIN 60 42#define TM_MIN 60
43#define TM_HOUR (TM_MIN * 60) 43#define TM_HOUR (TM_MIN * 60)
44#define TM_DAY (TM_HOUR * 24) 44#define TM_DAY (TM_HOUR * 24)
45#define TM_WEEK (TM_DAY * 7) 45#define TM_WEEK (TM_DAY * 7)
46#define TM_YEAR (TM_DAY * 365) 46#define TM_YEAR (TM_DAY * 365)
47#define TM_MONTH (TM_YEAR / 12.0) 47#define TM_MONTH (TM_YEAR / 12.0)
48 48
49 49
50typedef void (*configfn)(const char *name, const char *value); 50typedef void (*configfn)(const char *name, const char *value);
51typedef void (*filepair_fn)(struct diff_filepair *pair); 51typedef void (*filepair_fn)(struct diff_filepair *pair);
52typedef void (*linediff_fn)(char *line, int len); 52typedef void (*linediff_fn)(char *line, int len);
53 53
54struct cacheitem { 54struct cacheitem {
55 char *name; 55 char *name;
56 struct stat st; 56 struct stat st;
57 int ttl; 57 int ttl;
58 int fd; 58 int fd;
59}; 59};
60 60
61struct repoinfo { 61struct repoinfo {
62 char *url; 62 char *url;
63 char *name; 63 char *name;
64 char *path; 64 char *path;
65 char *desc; 65 char *desc;
66 char *owner; 66 char *owner;
67 char *defbranch; 67 char *defbranch;
68 char *group; 68 char *group;
69 char *module_link; 69 char *module_link;
70 char *readme; 70 char *readme;
71 int snapshots; 71 int snapshots;
72 int enable_log_filecount; 72 int enable_log_filecount;
73 int enable_log_linecount; 73 int enable_log_linecount;
74}; 74};
75 75
76struct repolist { 76struct repolist {
77 int length; 77 int length;
78 int count; 78 int count;
79 struct repoinfo *repos; 79 struct repoinfo *repos;
80}; 80};
81 81
82struct commitinfo { 82struct commitinfo {
83 struct commit *commit; 83 struct commit *commit;
84 char *author; 84 char *author;
85 char *author_email; 85 char *author_email;
86 unsigned long author_date; 86 unsigned long author_date;
87 char *committer; 87 char *committer;
88 char *committer_email; 88 char *committer_email;
89 unsigned long committer_date; 89 unsigned long committer_date;
90 char *subject; 90 char *subject;
91 char *msg; 91 char *msg;
92}; 92};
93 93
94struct taginfo { 94struct taginfo {
95 char *tagger; 95 char *tagger;
96 char *tagger_email; 96 char *tagger_email;
97 int tagger_date; 97 int tagger_date;
98 char *msg; 98 char *msg;
99}; 99};
100 100
101extern const char cgit_version[]; 101extern const char cgit_version[];
102 102
103extern struct repolist cgit_repolist; 103extern struct repolist cgit_repolist;
104extern struct repoinfo *cgit_repo; 104extern struct repoinfo *cgit_repo;
105extern int cgit_cmd; 105extern int cgit_cmd;
106 106
107extern char *cgit_root_title; 107extern char *cgit_root_title;
108extern char *cgit_css; 108extern char *cgit_css;
109extern char *cgit_logo; 109extern char *cgit_logo;
110extern char *cgit_index_header; 110extern char *cgit_index_header;
111extern char *cgit_logo_link; 111extern char *cgit_logo_link;
112extern char *cgit_module_link; 112extern char *cgit_module_link;
113extern char *cgit_agefile; 113extern char *cgit_agefile;
114extern char *cgit_virtual_root; 114extern char *cgit_virtual_root;
115extern char *cgit_script_name; 115extern char *cgit_script_name;
116extern char *cgit_cache_root; 116extern char *cgit_cache_root;
117extern char *cgit_repo_group; 117extern char *cgit_repo_group;
118 118
119extern int cgit_nocache; 119extern int cgit_nocache;
120extern int cgit_snapshots; 120extern int cgit_snapshots;
121extern int cgit_enable_log_filecount; 121extern int cgit_enable_log_filecount;
122extern int cgit_enable_log_linecount; 122extern int cgit_enable_log_linecount;
123extern int cgit_max_lock_attempts; 123extern int cgit_max_lock_attempts;
124extern int cgit_cache_root_ttl; 124extern int cgit_cache_root_ttl;
125extern int cgit_cache_repo_ttl; 125extern int cgit_cache_repo_ttl;
126extern int cgit_cache_dynamic_ttl; 126extern int cgit_cache_dynamic_ttl;
127extern int cgit_cache_static_ttl; 127extern int cgit_cache_static_ttl;
128extern int cgit_cache_max_create_time; 128extern int cgit_cache_max_create_time;
129extern int cgit_summary_log; 129extern int cgit_summary_log;
130 130
131extern int cgit_max_msg_len; 131extern int cgit_max_msg_len;
132extern int cgit_max_repodesc_len; 132extern int cgit_max_repodesc_len;
133extern int cgit_max_commit_count; 133extern int cgit_max_commit_count;
134 134
135extern int cgit_query_has_symref; 135extern int cgit_query_has_symref;
136extern int cgit_query_has_sha1; 136extern int cgit_query_has_sha1;
137 137
138extern char *cgit_querystring; 138extern char *cgit_querystring;
139extern char *cgit_query_repo; 139extern char *cgit_query_repo;
140extern char *cgit_query_page; 140extern char *cgit_query_page;
141extern char *cgit_query_search; 141extern char *cgit_query_search;
142extern char *cgit_query_head; 142extern char *cgit_query_head;
143extern char *cgit_query_sha1; 143extern char *cgit_query_sha1;
144extern char *cgit_query_sha2; 144extern char *cgit_query_sha2;
145extern char *cgit_query_path; 145extern char *cgit_query_path;
146extern char *cgit_query_name; 146extern char *cgit_query_name;
147extern int cgit_query_ofs; 147extern int cgit_query_ofs;
148 148
149extern int htmlfd; 149extern int htmlfd;
150 150
151extern int cgit_get_cmd_index(const char *cmd); 151extern int cgit_get_cmd_index(const char *cmd);
152extern struct repoinfo *cgit_get_repoinfo(const char *url); 152extern struct repoinfo *cgit_get_repoinfo(const char *url);
153extern void cgit_global_config_cb(const char *name, const char *value); 153extern void cgit_global_config_cb(const char *name, const char *value);
154extern void cgit_repo_config_cb(const char *name, const char *value); 154extern void cgit_repo_config_cb(const char *name, const char *value);
155extern void cgit_querystring_cb(const char *name, const char *value); 155extern void cgit_querystring_cb(const char *name, const char *value);
156 156
157extern int chk_zero(int result, char *msg); 157extern int chk_zero(int result, char *msg);
158extern int chk_positive(int result, char *msg); 158extern int chk_positive(int result, char *msg);
159 159
160extern int hextoint(char c); 160extern int hextoint(char c);
161 161
162extern void *cgit_free_commitinfo(struct commitinfo *info); 162extern void *cgit_free_commitinfo(struct commitinfo *info);
163 163
164extern int cgit_diff_files(const unsigned char *old_sha1, 164extern 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
168extern void cgit_diff_tree(const unsigned char *old_sha1, 168extern 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
172extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 172extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
173 173
174extern char *fmt(const char *format,...); 174extern char *fmt(const char *format,...);
175 175
176extern void html(const char *txt); 176extern void html(const char *txt);
177extern void htmlf(const char *format,...); 177extern void htmlf(const char *format,...);
178extern void html_txt(char *txt); 178extern void html_txt(char *txt);
179extern void html_ntxt(int len, char *txt); 179extern void html_ntxt(int len, char *txt);
180extern void html_attr(char *txt); 180extern void html_attr(char *txt);
181extern void html_hidden(char *name, char *value); 181extern void html_hidden(char *name, char *value);
182extern void html_link_open(char *url, char *title, char *class); 182extern void html_link_open(char *url, char *title, char *class);
183extern void html_link_close(void); 183extern void html_link_close(void);
184extern void html_filemode(unsigned short mode); 184extern void html_filemode(unsigned short mode);
185extern int html_include(const char *filename); 185extern int html_include(const char *filename);
186 186
187extern int cgit_read_config(const char *filename, configfn fn); 187extern int cgit_read_config(const char *filename, configfn fn);
188extern int cgit_parse_query(char *txt, configfn fn); 188extern int cgit_parse_query(char *txt, configfn fn);
189extern struct commitinfo *cgit_parse_commit(struct commit *commit); 189extern struct commitinfo *cgit_parse_commit(struct commit *commit);
190extern struct taginfo *cgit_parse_tag(struct tag *tag); 190extern struct taginfo *cgit_parse_tag(struct tag *tag);
191extern void cgit_parse_url(const char *url); 191extern void cgit_parse_url(const char *url);
192 192
193extern char *cache_safe_filename(const char *unsafe); 193extern char *cache_safe_filename(const char *unsafe);
194extern int cache_lock(struct cacheitem *item); 194extern int cache_lock(struct cacheitem *item);
195extern int cache_unlock(struct cacheitem *item); 195extern int cache_unlock(struct cacheitem *item);
196extern int cache_cancel_lock(struct cacheitem *item); 196extern int cache_cancel_lock(struct cacheitem *item);
197extern int cache_exist(struct cacheitem *item); 197extern int cache_exist(struct cacheitem *item);
198extern int cache_expired(struct cacheitem *item); 198extern int cache_expired(struct cacheitem *item);
199 199
200extern char *cgit_repourl(const char *reponame); 200extern char *cgit_repourl(const char *reponame);
201extern char *cgit_pageurl(const char *reponame, const char *pagename, 201extern char *cgit_pageurl(const char *reponame, const char *pagename,
202 const char *query); 202 const char *query);
203 203
204extern void cgit_tree_link(char *name, char *title, char *class, char *head, 204extern void cgit_tree_link(char *name, char *title, char *class, char *head,
205 char *rev, char *path); 205 char *rev, char *path);
206extern void cgit_log_link(char *name, char *title, char *class, char *head,
207 char *rev, char *path);
206 208
207extern void cgit_print_error(char *msg); 209extern void cgit_print_error(char *msg);
208extern void cgit_print_date(time_t secs, char *format); 210extern void cgit_print_date(time_t secs, char *format);
209extern void cgit_print_age(time_t t, time_t max_relative, char *format); 211extern void cgit_print_age(time_t t, time_t max_relative, char *format);
210extern void cgit_print_docstart(char *title, struct cacheitem *item); 212extern void cgit_print_docstart(char *title, struct cacheitem *item);
211extern void cgit_print_docend(); 213extern void cgit_print_docend();
212extern void cgit_print_pageheader(char *title, int show_search); 214extern void cgit_print_pageheader(char *title, int show_search);
213extern void cgit_print_snapshot_start(const char *mimetype, 215extern void cgit_print_snapshot_start(const char *mimetype,
214 const char *filename, 216 const char *filename,
215 struct cacheitem *item); 217 struct cacheitem *item);
216 218
217extern void cgit_print_repolist(struct cacheitem *item); 219extern void cgit_print_repolist(struct cacheitem *item);
218extern void cgit_print_summary(); 220extern void cgit_print_summary();
219extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); 221extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager);
220extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 222extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
221extern void cgit_print_tree(const char *rev, char *path); 223extern void cgit_print_tree(const char *rev, char *path);
222extern void cgit_print_commit(const char *hex); 224extern void cgit_print_commit(const char *hex);
223extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, 225extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex,
224 char *path); 226 char *path);
225extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 227extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
226 const char *format, const char *prefix, 228 const char *format, const char *prefix,
227 const char *filename); 229 const char *filename);
228 230
229#endif /* CGIT_H */ 231#endif /* CGIT_H */
diff --git a/ui-repolist.c b/ui-repolist.c
index 8ade91a..2018dab 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -1,100 +1,98 @@
1/* ui-repolist.c: functions for generating the repolist page 1/* ui-repolist.c: functions for generating the repolist 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#include <time.h> 10#include <time.h>
11 11
12 12
13time_t read_agefile(char *path) 13time_t read_agefile(char *path)
14{ 14{
15 FILE *f; 15 FILE *f;
16 static char buf[64], buf2[64]; 16 static char buf[64], buf2[64];
17 17
18 if (!(f = fopen(path, "r"))) 18 if (!(f = fopen(path, "r")))
19 return -1; 19 return -1;
20 fgets(buf, sizeof(buf), f); 20 fgets(buf, sizeof(buf), f);
21 fclose(f); 21 fclose(f);
22 if (parse_date(buf, buf2, sizeof(buf2))) 22 if (parse_date(buf, buf2, sizeof(buf2)))
23 return strtoul(buf2, NULL, 10); 23 return strtoul(buf2, NULL, 10);
24 else 24 else
25 return 0; 25 return 0;
26} 26}
27 27
28static void print_modtime(struct repoinfo *repo) 28static void print_modtime(struct repoinfo *repo)
29{ 29{
30 char *path; 30 char *path;
31 struct stat s; 31 struct stat s;
32 32
33 path = fmt("%s/%s", repo->path, cgit_agefile); 33 path = fmt("%s/%s", repo->path, cgit_agefile);
34 if (stat(path, &s) == 0) { 34 if (stat(path, &s) == 0) {
35 cgit_print_age(read_agefile(path), -1, NULL); 35 cgit_print_age(read_agefile(path), -1, NULL);
36 return; 36 return;
37 } 37 }
38 38
39 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); 39 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
40 if (stat(path, &s) != 0) 40 if (stat(path, &s) != 0)
41 return; 41 return;
42 cgit_print_age(s.st_mtime, -1, NULL); 42 cgit_print_age(s.st_mtime, -1, NULL);
43} 43}
44 44
45void cgit_print_repolist(struct cacheitem *item) 45void cgit_print_repolist(struct cacheitem *item)
46{ 46{
47 int i; 47 int i;
48 char *last_group = NULL; 48 char *last_group = NULL;
49 49
50 cgit_print_docstart(cgit_root_title, item); 50 cgit_print_docstart(cgit_root_title, item);
51 cgit_print_pageheader(cgit_root_title, 0); 51 cgit_print_pageheader(cgit_root_title, 0);
52 52
53 html("<table class='list nowrap'>"); 53 html("<table class='list nowrap'>");
54 if (cgit_index_header) { 54 if (cgit_index_header) {
55 html("<tr class='nohover'><td colspan='5' class='include-block'>"); 55 html("<tr class='nohover'><td colspan='5' class='include-block'>");
56 html_include(cgit_index_header); 56 html_include(cgit_index_header);
57 html("</td></tr>"); 57 html("</td></tr>");
58 } 58 }
59 html("<tr class='nohover'>" 59 html("<tr class='nohover'>"
60 "<th class='left'>Name</th>" 60 "<th class='left'>Name</th>"
61 "<th class='left'>Description</th>" 61 "<th class='left'>Description</th>"
62 "<th class='left'>Owner</th>" 62 "<th class='left'>Owner</th>"
63 "<th class='left'>Idle</th>" 63 "<th class='left'>Idle</th>"
64 "<th>Links</th></tr>\n"); 64 "<th>Links</th></tr>\n");
65 65
66 for (i=0; i<cgit_repolist.count; i++) { 66 for (i=0; i<cgit_repolist.count; i++) {
67 cgit_repo = &cgit_repolist.repos[i]; 67 cgit_repo = &cgit_repolist.repos[i];
68 if ((last_group == NULL && cgit_repo->group != NULL) || 68 if ((last_group == NULL && cgit_repo->group != NULL) ||
69 (last_group != NULL && cgit_repo->group == NULL) || 69 (last_group != NULL && cgit_repo->group == NULL) ||
70 (last_group != NULL && cgit_repo->group != NULL && 70 (last_group != NULL && cgit_repo->group != NULL &&
71 strcmp(cgit_repo->group, last_group))) { 71 strcmp(cgit_repo->group, last_group))) {
72 html("<tr class='nohover'><td colspan='4' class='repogroup'>"); 72 html("<tr class='nohover'><td colspan='4' class='repogroup'>");
73 html_txt(cgit_repo->group); 73 html_txt(cgit_repo->group);
74 html("</td></tr>"); 74 html("</td></tr>");
75 last_group = cgit_repo->group; 75 last_group = cgit_repo->group;
76 } 76 }
77 htmlf("<tr><td class='%s'>", 77 htmlf("<tr><td class='%s'>",
78 cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); 78 cgit_repo->group ? "sublevel-repo" : "toplevel-repo");
79 html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); 79 html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL);
80 html_txt(cgit_repo->name); 80 html_txt(cgit_repo->name);
81 html_link_close(); 81 html_link_close();
82 html("</td><td>"); 82 html("</td><td>");
83 html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); 83 html_ntxt(cgit_max_repodesc_len, cgit_repo->desc);
84 html("</td><td>"); 84 html("</td><td>");
85 html_txt(cgit_repo->owner); 85 html_txt(cgit_repo->owner);
86 html("</td><td>"); 86 html("</td><td>");
87 print_modtime(cgit_repo); 87 print_modtime(cgit_repo);
88 html("</td><td>"); 88 html("</td><td>");
89 html_link_open(cgit_repourl(cgit_repo->url), 89 html_link_open(cgit_repourl(cgit_repo->url),
90 "Summary", "button"); 90 "Summary", "button");
91 html("S</a>"); 91 html("S</a>");
92 html_link_open(cgit_pageurl(cgit_repo->name, "log", NULL), 92 cgit_log_link("L", "Log", "button", NULL, NULL, NULL);
93 "Log", "button");
94 html("L</a>");
95 cgit_tree_link("F", "Files", "button", NULL, NULL, NULL); 93 cgit_tree_link("F", "Files", "button", NULL, NULL, NULL);
96 html("</td></tr>\n"); 94 html("</td></tr>\n");
97 } 95 }
98 html("</table>"); 96 html("</table>");
99 cgit_print_docend(); 97 cgit_print_docend();
100} 98}
diff --git a/ui-shared.c b/ui-shared.c
index 657e8af..64ee79c 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1,285 +1,297 @@
1/* ui-shared.c: common web output functions 1/* ui-shared.c: common web output functions
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11const char cgit_doctype[] = 11const char cgit_doctype[] =
12"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" 12"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
13" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 13" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
14 14
15static char *http_date(time_t t) 15static char *http_date(time_t t)
16{ 16{
17 static char day[][4] = 17 static char day[][4] =
18 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 18 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
19 static char month[][4] = 19 static char month[][4] =
20 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 20 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
21 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; 21 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"};
22 struct tm *tm = gmtime(&t); 22 struct tm *tm = gmtime(&t);
23 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], 23 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
24 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, 24 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
25 tm->tm_hour, tm->tm_min, tm->tm_sec); 25 tm->tm_hour, tm->tm_min, tm->tm_sec);
26} 26}
27 27
28static long ttl_seconds(long ttl) 28static long ttl_seconds(long ttl)
29{ 29{
30 if (ttl<0) 30 if (ttl<0)
31 return 60 * 60 * 24 * 365; 31 return 60 * 60 * 24 * 365;
32 else 32 else
33 return ttl * 60; 33 return ttl * 60;
34} 34}
35 35
36void cgit_print_error(char *msg) 36void cgit_print_error(char *msg)
37{ 37{
38 html("<div class='error'>"); 38 html("<div class='error'>");
39 html_txt(msg); 39 html_txt(msg);
40 html("</div>\n"); 40 html("</div>\n");
41} 41}
42 42
43char *cgit_rooturl() 43char *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
51char *cgit_repourl(const char *reponame) 51char *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
60char *cgit_pageurl(const char *reponame, const char *pagename, 60char *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&amp;p=%s&amp;%s", reponame, pagename, query); 72 return fmt("?r=%s&amp;p=%s&amp;%s", reponame, pagename, query);
73 else 73 else
74 return fmt("?r=%s&amp;p=%s", reponame, pagename); 74 return fmt("?r=%s&amp;p=%s", reponame, pagename);
75 } 75 }
76} 76}
77 77
78char *cgit_currurl() 78char *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
90static char *repolink(char *title, char *class, char *page, char *head, 90static 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 = "&amp;"; 128 delim = "&amp;";
129 } 129 }
130 if (head && strcmp(head, cgit_query_head)) { 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 = "&amp;"; 134 delim = "&amp;";
135 } 135 }
136 return fmt("%s", delim); 136 return fmt("%s", delim);
137} 137}
138 138
139void cgit_tree_link(char *name, char *title, char *class, char *head, 139static char *reporevlink(char *page, char *name, char *title, char *class,
140 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, "tree", 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
155void cgit_tree_link(char *name, char *title, char *class, char *head,
156 char *rev, char *path)
157{
158 reporevlink("tree", name, title, class, head, rev, path);
159}
160
161void cgit_log_link(char *name, char *title, char *class, char *head,
162 char *rev, char *path)
163{
164 reporevlink("log", name, title, class, head, rev, path);
165}
166
155void cgit_print_date(time_t secs, char *format) 167void cgit_print_date(time_t secs, char *format)
156{ 168{
157 char buf[64]; 169 char buf[64];
158 struct tm *time; 170 struct tm *time;
159 171
160 time = gmtime(&secs); 172 time = gmtime(&secs);
161 strftime(buf, sizeof(buf)-1, format, time); 173 strftime(buf, sizeof(buf)-1, format, time);
162 html_txt(buf); 174 html_txt(buf);
163} 175}
164 176
165void cgit_print_age(time_t t, time_t max_relative, char *format) 177void cgit_print_age(time_t t, time_t max_relative, char *format)
166{ 178{
167 time_t now, secs; 179 time_t now, secs;
168 180
169 time(&now); 181 time(&now);
170 secs = now - t; 182 secs = now - t;
171 183
172 if (secs > max_relative && max_relative >= 0) { 184 if (secs > max_relative && max_relative >= 0) {
173 cgit_print_date(t, format); 185 cgit_print_date(t, format);
174 return; 186 return;
175 } 187 }
176 188
177 if (secs < TM_HOUR * 2) { 189 if (secs < TM_HOUR * 2) {
178 htmlf("<span class='age-mins'>%.0f min.</span>", 190 htmlf("<span class='age-mins'>%.0f min.</span>",
179 secs * 1.0 / TM_MIN); 191 secs * 1.0 / TM_MIN);
180 return; 192 return;
181 } 193 }
182 if (secs < TM_DAY * 2) { 194 if (secs < TM_DAY * 2) {
183 htmlf("<span class='age-hours'>%.0f hours</span>", 195 htmlf("<span class='age-hours'>%.0f hours</span>",
184 secs * 1.0 / TM_HOUR); 196 secs * 1.0 / TM_HOUR);
185 return; 197 return;
186 } 198 }
187 if (secs < TM_WEEK * 2) { 199 if (secs < TM_WEEK * 2) {
188 htmlf("<span class='age-days'>%.0f days</span>", 200 htmlf("<span class='age-days'>%.0f days</span>",
189 secs * 1.0 / TM_DAY); 201 secs * 1.0 / TM_DAY);
190 return; 202 return;
191 } 203 }
192 if (secs < TM_MONTH * 2) { 204 if (secs < TM_MONTH * 2) {
193 htmlf("<span class='age-weeks'>%.0f weeks</span>", 205 htmlf("<span class='age-weeks'>%.0f weeks</span>",
194 secs * 1.0 / TM_WEEK); 206 secs * 1.0 / TM_WEEK);
195 return; 207 return;
196 } 208 }
197 if (secs < TM_YEAR * 2) { 209 if (secs < TM_YEAR * 2) {
198 htmlf("<span class='age-months'>%.0f months</span>", 210 htmlf("<span class='age-months'>%.0f months</span>",
199 secs * 1.0 / TM_MONTH); 211 secs * 1.0 / TM_MONTH);
200 return; 212 return;
201 } 213 }
202 htmlf("<span class='age-years'>%.0f years</span>", 214 htmlf("<span class='age-years'>%.0f years</span>",
203 secs * 1.0 / TM_YEAR); 215 secs * 1.0 / TM_YEAR);
204} 216}
205 217
206void cgit_print_docstart(char *title, struct cacheitem *item) 218void cgit_print_docstart(char *title, struct cacheitem *item)
207{ 219{
208 html("Content-Type: text/html; charset=utf-8\n"); 220 html("Content-Type: text/html; charset=utf-8\n");
209 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 221 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
210 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 222 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
211 ttl_seconds(item->ttl))); 223 ttl_seconds(item->ttl)));
212 html("\n"); 224 html("\n");
213 html(cgit_doctype); 225 html(cgit_doctype);
214 html("<html>\n"); 226 html("<html>\n");
215 html("<head>\n"); 227 html("<head>\n");
216 html("<title>"); 228 html("<title>");
217 html_txt(title); 229 html_txt(title);
218 html("</title>\n"); 230 html("</title>\n");
219 htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version); 231 htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version);
220 html("<link rel='stylesheet' type='text/css' href='"); 232 html("<link rel='stylesheet' type='text/css' href='");
221 html_attr(cgit_css); 233 html_attr(cgit_css);
222 html("'/>\n"); 234 html("'/>\n");
223 html("</head>\n"); 235 html("</head>\n");
224 html("<body>\n"); 236 html("<body>\n");
225} 237}
226 238
227void cgit_print_docend() 239void cgit_print_docend()
228{ 240{
229 html("</td></tr></table>"); 241 html("</td></tr></table>");
230 html("</body>\n</html>\n"); 242 html("</body>\n</html>\n");
231} 243}
232 244
233void cgit_print_pageheader(char *title, int show_search) 245void cgit_print_pageheader(char *title, int show_search)
234{ 246{
235 html("<table id='layout'>"); 247 html("<table id='layout'>");
236 html("<tr><td id='header'>"); 248 html("<tr><td id='header'>");
237 html(cgit_root_title); 249 html(cgit_root_title);
238 html("</td><td id='logo'>"); 250 html("</td><td id='logo'>");
239 html("<a href='"); 251 html("<a href='");
240 html_attr(cgit_logo_link); 252 html_attr(cgit_logo_link);
241 htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); 253 htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo);
242 html("</td></tr>"); 254 html("</td></tr>");
243 html("<tr><td id='crumb'>"); 255 html("<tr><td id='crumb'>");
244 htmlf("<a href='%s'>root</a>", cgit_rooturl()); 256 htmlf("<a href='%s'>root</a>", cgit_rooturl());
245 if (cgit_query_repo) { 257 if (cgit_query_repo) {
246 htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url)); 258 htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url));
247 html_txt(cgit_repo->name); 259 html_txt(cgit_repo->name);
248 htmlf("</a> : %s", title); 260 htmlf("</a> : %s", title);
249 } 261 }
250 html("</td>"); 262 html("</td>");
251 html("<td id='search'>"); 263 html("<td id='search'>");
252 if (show_search) { 264 if (show_search) {
253 html("<form method='get' action='"); 265 html("<form method='get' action='");
254 html_attr(cgit_currurl()); 266 html_attr(cgit_currurl());
255 html("'>"); 267 html("'>");
256 if (!cgit_virtual_root) { 268 if (!cgit_virtual_root) {
257 if (cgit_query_repo) 269 if (cgit_query_repo)
258 html_hidden("r", cgit_query_repo); 270 html_hidden("r", cgit_query_repo);
259 if (cgit_query_page) 271 if (cgit_query_page)
260 html_hidden("p", cgit_query_page); 272 html_hidden("p", cgit_query_page);
261 } 273 }
262 if (cgit_query_head) 274 if (cgit_query_head)
263 html_hidden("h", cgit_query_head); 275 html_hidden("h", cgit_query_head);
264 if (cgit_query_sha1) 276 if (cgit_query_sha1)
265 html_hidden("id", cgit_query_sha1); 277 html_hidden("id", cgit_query_sha1);
266 if (cgit_query_sha2) 278 if (cgit_query_sha2)
267 html_hidden("id2", cgit_query_sha2); 279 html_hidden("id2", cgit_query_sha2);
268 html("<input type='text' name='q' value='"); 280 html("<input type='text' name='q' value='");
269 html_attr(cgit_query_search); 281 html_attr(cgit_query_search);
270 html("'/></form>"); 282 html("'/></form>");
271 } 283 }
272 html("</td></tr>"); 284 html("</td></tr>");
273 html("<tr><td id='content' colspan='2'>"); 285 html("<tr><td id='content' colspan='2'>");
274} 286}
275 287
276void cgit_print_snapshot_start(const char *mimetype, const char *filename, 288void cgit_print_snapshot_start(const char *mimetype, const char *filename,
277 struct cacheitem *item) 289 struct cacheitem *item)
278{ 290{
279 htmlf("Content-Type: %s\n", mimetype); 291 htmlf("Content-Type: %s\n", mimetype);
280 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); 292 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
281 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 293 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
282 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 294 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
283 ttl_seconds(item->ttl))); 295 ttl_seconds(item->ttl)));
284 html("\n"); 296 html("\n");
285} 297}
diff --git a/ui-summary.c b/ui-summary.c
index 4bda4c2..29b76e3 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -1,218 +1,214 @@
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
11static int header; 11static int header;
12 12
13static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, 13static 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], *url;
19 19
20 strncpy(buf, refname, sizeof(buf)); 20 strncpy(buf, refname, sizeof(buf));
21 commit = lookup_commit(sha1); 21 commit = lookup_commit(sha1);
22 // object is not really parsed at this point, because of some fallout 22 // object is not really parsed at this point, because of some fallout
23 // from previous calls to git functions in cgit_print_log() 23 // from previous calls to git functions in cgit_print_log()
24 commit->object.parsed = 0; 24 commit->object.parsed = 0;
25 if (commit && !parse_commit(commit)){ 25 if (commit && !parse_commit(commit)){
26 info = cgit_parse_commit(commit); 26 info = cgit_parse_commit(commit);
27 html("<tr><td>"); 27 html("<tr><td>");
28 url = cgit_pageurl(cgit_query_repo, "log", 28 cgit_log_link(refname, NULL, NULL, refname, NULL, NULL);
29 fmt("h=%s", refname));
30 html_link_open(url, NULL, NULL);
31 html_txt(buf);
32 html_link_close();
33 html("</td><td>"); 29 html("</td><td>");
34 cgit_print_age(commit->date, -1, NULL); 30 cgit_print_age(commit->date, -1, NULL);
35 html("</td><td>"); 31 html("</td><td>");
36 html_txt(info->author); 32 html_txt(info->author);
37 html("</td><td>"); 33 html("</td><td>");
38 url = cgit_pageurl(cgit_query_repo, "commit", 34 url = cgit_pageurl(cgit_query_repo, "commit",
39 fmt("h=%s", sha1_to_hex(sha1))); 35 fmt("h=%s", sha1_to_hex(sha1)));
40 html_link_open(url, NULL, NULL); 36 html_link_open(url, NULL, NULL);
41 html_ntxt(cgit_max_msg_len, info->subject); 37 html_ntxt(cgit_max_msg_len, info->subject);
42 html_link_close(); 38 html_link_close();
43 html("</td></tr>\n"); 39 html("</td></tr>\n");
44 cgit_free_commitinfo(info); 40 cgit_free_commitinfo(info);
45 } else { 41 } else {
46 html("<tr><td>"); 42 html("<tr><td>");
47 html_txt(buf); 43 html_txt(buf);
48 html("</td><td colspan='3'>"); 44 html("</td><td colspan='3'>");
49 htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); 45 htmlf("*** bad ref %s ***", sha1_to_hex(sha1));
50 html("</td></tr>\n"); 46 html("</td></tr>\n");
51 } 47 }
52 return 0; 48 return 0;
53} 49}
54 50
55 51
56static void cgit_print_object_ref(struct object *obj) 52static void cgit_print_object_ref(struct object *obj)
57{ 53{
58 char *page, *arg, *url; 54 char *page, *arg, *url;
59 55
60 if (obj->type == OBJ_COMMIT) { 56 if (obj->type == OBJ_COMMIT) {
61 page = "commit"; 57 page = "commit";
62 arg = "h"; 58 arg = "h";
63 } else if (obj->type == OBJ_TREE) { 59 } else if (obj->type == OBJ_TREE) {
64 page = "tree"; 60 page = "tree";
65 arg = "id"; 61 arg = "id";
66 } else { 62 } else {
67 page = "view"; 63 page = "view";
68 arg = "id"; 64 arg = "id";
69 } 65 }
70 66
71 url = cgit_pageurl(cgit_query_repo, page, 67 url = cgit_pageurl(cgit_query_repo, page,
72 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 68 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
73 html_link_open(url, NULL, NULL); 69 html_link_open(url, NULL, NULL);
74 htmlf("%s %s", typename(obj->type), 70 htmlf("%s %s", typename(obj->type),
75 sha1_to_hex(obj->sha1)); 71 sha1_to_hex(obj->sha1));
76 html_link_close(); 72 html_link_close();
77} 73}
78 74
79static void print_tag_header() 75static void print_tag_header()
80{ 76{
81 html("<tr class='nohover'><th class='left'>Tag</th>" 77 html("<tr class='nohover'><th class='left'>Tag</th>"
82 "<th class='left'>Age</th>" 78 "<th class='left'>Age</th>"
83 "<th class='left'>Author</th>" 79 "<th class='left'>Author</th>"
84 "<th class='left'>Reference</th></tr>\n"); 80 "<th class='left'>Reference</th></tr>\n");
85 header = 1; 81 header = 1;
86} 82}
87 83
88static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, 84static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
89 int flags, void *cb_data) 85 int flags, void *cb_data)
90{ 86{
91 struct tag *tag; 87 struct tag *tag;
92 struct taginfo *info; 88 struct taginfo *info;
93 struct object *obj; 89 struct object *obj;
94 char buf[256], *url; 90 char buf[256], *url;
95 91
96 strncpy(buf, refname, sizeof(buf)); 92 strncpy(buf, refname, sizeof(buf));
97 obj = parse_object(sha1); 93 obj = parse_object(sha1);
98 if (!obj) 94 if (!obj)
99 return 1; 95 return 1;
100 if (obj->type == OBJ_TAG) { 96 if (obj->type == OBJ_TAG) {
101 tag = lookup_tag(sha1); 97 tag = lookup_tag(sha1);
102 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 98 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
103 return 2; 99 return 2;
104 if (!header) 100 if (!header)
105 print_tag_header(); 101 print_tag_header();
106 html("<tr><td>"); 102 html("<tr><td>");
107 url = cgit_pageurl(cgit_query_repo, "view", 103 url = cgit_pageurl(cgit_query_repo, "view",
108 fmt("id=%s", sha1_to_hex(sha1))); 104 fmt("id=%s", sha1_to_hex(sha1)));
109 html_link_open(url, NULL, NULL); 105 html_link_open(url, NULL, NULL);
110 html_txt(buf); 106 html_txt(buf);
111 html_link_close(); 107 html_link_close();
112 html("</td><td>"); 108 html("</td><td>");
113 if (info->tagger_date > 0) 109 if (info->tagger_date > 0)
114 cgit_print_age(info->tagger_date, -1, NULL); 110 cgit_print_age(info->tagger_date, -1, NULL);
115 html("</td><td>"); 111 html("</td><td>");
116 if (info->tagger) 112 if (info->tagger)
117 html(info->tagger); 113 html(info->tagger);
118 html("</td><td>"); 114 html("</td><td>");
119 cgit_print_object_ref(tag->tagged); 115 cgit_print_object_ref(tag->tagged);
120 html("</td></tr>\n"); 116 html("</td></tr>\n");
121 } else { 117 } else {
122 if (!header) 118 if (!header)
123 print_tag_header(); 119 print_tag_header();
124 html("<tr><td>"); 120 html("<tr><td>");
125 html_txt(buf); 121 html_txt(buf);
126 html("</td><td colspan='2'/><td>"); 122 html("</td><td colspan='2'/><td>");
127 cgit_print_object_ref(obj); 123 cgit_print_object_ref(obj);
128 html("</td></tr>\n"); 124 html("</td></tr>\n");
129 } 125 }
130 return 0; 126 return 0;
131} 127}
132 128
133static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, 129static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
134 int flags, void *cb_data) 130 int flags, void *cb_data)
135{ 131{
136 struct tag *tag; 132 struct tag *tag;
137 struct taginfo *info; 133 struct taginfo *info;
138 struct object *obj; 134 struct object *obj;
139 char buf[256], *url; 135 char buf[256], *url;
140 unsigned char fileid[20]; 136 unsigned char fileid[20];
141 137
142 if (prefixcmp(refname, "refs/archives")) 138 if (prefixcmp(refname, "refs/archives"))
143 return 0; 139 return 0;
144 strncpy(buf, refname+14, sizeof(buf)); 140 strncpy(buf, refname+14, sizeof(buf));
145 obj = parse_object(sha1); 141 obj = parse_object(sha1);
146 if (!obj) 142 if (!obj)
147 return 1; 143 return 1;
148 if (obj->type == OBJ_TAG) { 144 if (obj->type == OBJ_TAG) {
149 tag = lookup_tag(sha1); 145 tag = lookup_tag(sha1);
150 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 146 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
151 return 0; 147 return 0;
152 hashcpy(fileid, tag->tagged->sha1); 148 hashcpy(fileid, tag->tagged->sha1);
153 } else if (obj->type != OBJ_BLOB) { 149 } else if (obj->type != OBJ_BLOB) {
154 return 0; 150 return 0;
155 } else { 151 } else {
156 hashcpy(fileid, sha1); 152 hashcpy(fileid, sha1);
157 } 153 }
158 if (!header) { 154 if (!header) {
159 html("<table id='downloads'>"); 155 html("<table id='downloads'>");
160 html("<tr><th>Downloads</th></tr>"); 156 html("<tr><th>Downloads</th></tr>");
161 header = 1; 157 header = 1;
162 } 158 }
163 html("<tr><td>"); 159 html("<tr><td>");
164 url = cgit_pageurl(cgit_query_repo, "blob", 160 url = cgit_pageurl(cgit_query_repo, "blob",
165 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 161 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
166 buf)); 162 buf));
167 html_link_open(url, NULL, NULL); 163 html_link_open(url, NULL, NULL);
168 html_txt(buf); 164 html_txt(buf);
169 html_link_close(); 165 html_link_close();
170 html("</td></tr>"); 166 html("</td></tr>");
171 return 0; 167 return 0;
172} 168}
173 169
174static void cgit_print_branches() 170static void cgit_print_branches()
175{ 171{
176 html("<tr class='nohover'><th class='left'>Branch</th>" 172 html("<tr class='nohover'><th class='left'>Branch</th>"
177 "<th class='left'>Idle</th>" 173 "<th class='left'>Idle</th>"
178 "<th class='left'>Author</th>" 174 "<th class='left'>Author</th>"
179 "<th class='left'>Head commit</th></tr>\n"); 175 "<th class='left'>Head commit</th></tr>\n");
180 for_each_branch_ref(cgit_print_branch_cb, NULL); 176 for_each_branch_ref(cgit_print_branch_cb, NULL);
181} 177}
182 178
183static void cgit_print_tags() 179static void cgit_print_tags()
184{ 180{
185 header = 0; 181 header = 0;
186 for_each_tag_ref(cgit_print_tag_cb, NULL); 182 for_each_tag_ref(cgit_print_tag_cb, NULL);
187} 183}
188 184
189static void cgit_print_archives() 185static void cgit_print_archives()
190{ 186{
191 header = 0; 187 header = 0;
192 for_each_ref(cgit_print_archive_cb, NULL); 188 for_each_ref(cgit_print_archive_cb, NULL);
193 if (header) 189 if (header)
194 html("</table>"); 190 html("</table>");
195} 191}
196 192
197void cgit_print_summary() 193void cgit_print_summary()
198{ 194{
199 html("<div id='summary'>"); 195 html("<div id='summary'>");
200 cgit_print_archives(); 196 cgit_print_archives();
201 html("<h2>"); 197 html("<h2>");
202 html_txt(cgit_repo->name); 198 html_txt(cgit_repo->name);
203 html(" - "); 199 html(" - ");
204 html_txt(cgit_repo->desc); 200 html_txt(cgit_repo->desc);
205 html("</h2>"); 201 html("</h2>");
206 if (cgit_repo->readme) 202 if (cgit_repo->readme)
207 html_include(cgit_repo->readme); 203 html_include(cgit_repo->readme);
208 html("</div>"); 204 html("</div>");
209 if (cgit_summary_log > 0) 205 if (cgit_summary_log > 0)
210 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); 206 cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
211 html("<table class='list nowrap'>"); 207 html("<table class='list nowrap'>");
212 if (cgit_summary_log > 0) 208 if (cgit_summary_log > 0)
213 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 209 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
214 cgit_print_branches(); 210 cgit_print_branches();
215 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 211 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
216 cgit_print_tags(); 212 cgit_print_tags();
217 html("</table>"); 213 html("</table>");
218} 214}
diff --git a/ui-tree.c b/ui-tree.c
index d503bee..e16b638 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,214 +1,210 @@
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
11char *curr_rev; 11char *curr_rev;
12char *match_path; 12char *match_path;
13int header = 0; 13int header = 0;
14 14
15static void print_object(const unsigned char *sha1, char *path) 15static 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
54static int ls_item(const unsigned char *sha1, const char *base, int baselen, 54static 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; 61 char *url, *qry;
62 62
63 name = xstrdup(pathname); 63 name = xstrdup(pathname);
64 fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", 64 fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "",
65 cgit_query_path ? "/" : "", name); 65 cgit_query_path ? "/" : "", name);
66 66
67 type = sha1_object_info(sha1, &size); 67 type = sha1_object_info(sha1, &size);
68 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { 68 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
69 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 69 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
70 name, 70 name,
71 sha1_to_hex(sha1)); 71 sha1_to_hex(sha1));
72 return 0; 72 return 0;
73 } 73 }
74 74
75 html("<tr><td class='ls-mode'>"); 75 html("<tr><td class='ls-mode'>");
76 html_filemode(mode); 76 html_filemode(mode);
77 html("</td><td>"); 77 html("</td><td>");
78 if (S_ISDIRLNK(mode)) { 78 if (S_ISDIRLNK(mode)) {
79 htmlf("<a class='ls-mod' href='"); 79 htmlf("<a class='ls-mod' href='");
80 html_attr(fmt(cgit_repo->module_link, 80 html_attr(fmt(cgit_repo->module_link,
81 name, 81 name,
82 sha1_to_hex(sha1))); 82 sha1_to_hex(sha1)));
83 html("'>"); 83 html("'>");
84 html_txt(name); 84 html_txt(name);
85 html("</a>"); 85 html("</a>");
86 } else if (S_ISDIR(mode)) { 86 } else if (S_ISDIR(mode)) {
87 cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, 87 cgit_tree_link(name, NULL, "ls-dir", cgit_query_head,
88 curr_rev, fullpath); 88 curr_rev, fullpath);
89 } else { 89 } else {
90 cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, 90 cgit_tree_link(name, NULL, "ls-blob", cgit_query_head,
91 curr_rev, fullpath); 91 curr_rev, fullpath);
92 } 92 }
93 htmlf("</td><td class='ls-size'>%li</td>", size); 93 htmlf("</td><td class='ls-size'>%li</td>", size);
94 94
95 html("<td><a href='"); 95 html("<td>");
96 qry = fmt("h=%s&amp;path=%s%s%s", curr_rev, 96 cgit_log_link("L", "Log", "button", cgit_query_head, curr_rev,
97 cgit_query_path ? cgit_query_path : "", 97 fullpath);
98 cgit_query_path ? "/" : "", pathname); 98 html("</td></tr>\n");
99 url = cgit_pageurl(cgit_query_repo, "log", qry);
100 html_attr(url);
101 html("' title='Log' class='button'>L</a></td>");
102 html("</tr>\n");
103 free(name); 99 free(name);
104 return 0; 100 return 0;
105} 101}
106 102
107static void ls_head() 103static void ls_head()
108{ 104{
109 html("<table class='list'>\n"); 105 html("<table class='list'>\n");
110 html("<tr class='nohover'>"); 106 html("<tr class='nohover'>");
111 html("<th class='left'>Mode</th>"); 107 html("<th class='left'>Mode</th>");
112 html("<th class='left'>Name</th>"); 108 html("<th class='left'>Name</th>");
113 html("<th class='right'>Size</th>"); 109 html("<th class='right'>Size</th>");
114 html("<th/>"); 110 html("<th/>");
115 html("</tr>\n"); 111 html("</tr>\n");
116 header = 1; 112 header = 1;
117} 113}
118 114
119static void ls_tail() 115static void ls_tail()
120{ 116{
121 if (!header) 117 if (!header)
122 return; 118 return;
123 html("</table>\n"); 119 html("</table>\n");
124 header = 0; 120 header = 0;
125} 121}
126 122
127static void ls_tree(const unsigned char *sha1, char *path) 123static void ls_tree(const unsigned char *sha1, char *path)
128{ 124{
129 struct tree *tree; 125 struct tree *tree;
130 126
131 tree = parse_tree_indirect(sha1); 127 tree = parse_tree_indirect(sha1);
132 if (!tree) { 128 if (!tree) {
133 cgit_print_error(fmt("Not a tree object: %s", 129 cgit_print_error(fmt("Not a tree object: %s",
134 sha1_to_hex(sha1))); 130 sha1_to_hex(sha1)));
135 return; 131 return;
136 } 132 }
137 133
138 ls_head(); 134 ls_head();
139 read_tree_recursive(tree, "", 0, 1, NULL, ls_item); 135 read_tree_recursive(tree, "", 0, 1, NULL, ls_item);
140 ls_tail(); 136 ls_tail();
141} 137}
142 138
143 139
144static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 140static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
145 const char *pathname, unsigned mode, int stage) 141 const char *pathname, unsigned mode, int stage)
146{ 142{
147 static int state; 143 static int state;
148 static char buffer[PATH_MAX]; 144 static char buffer[PATH_MAX];
149 char *url; 145 char *url;
150 146
151 if (state == 0) { 147 if (state == 0) {
152 memcpy(buffer, base, baselen); 148 memcpy(buffer, base, baselen);
153 strcpy(buffer+baselen, pathname); 149 strcpy(buffer+baselen, pathname);
154 url = cgit_pageurl(cgit_query_repo, "tree", 150 url = cgit_pageurl(cgit_query_repo, "tree",
155 fmt("h=%s&amp;path=%s", curr_rev, buffer)); 151 fmt("h=%s&amp;path=%s", curr_rev, buffer));
156 html("/"); 152 html("/");
157 cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, 153 cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head,
158 curr_rev, buffer); 154 curr_rev, buffer);
159 155
160 if (strcmp(match_path, buffer)) 156 if (strcmp(match_path, buffer))
161 return READ_TREE_RECURSIVE; 157 return READ_TREE_RECURSIVE;
162 158
163 if (S_ISDIR(mode)) { 159 if (S_ISDIR(mode)) {
164 state = 1; 160 state = 1;
165 ls_head(); 161 ls_head();
166 return READ_TREE_RECURSIVE; 162 return READ_TREE_RECURSIVE;
167 } else { 163 } else {
168 print_object(sha1, buffer); 164 print_object(sha1, buffer);
169 return 0; 165 return 0;
170 } 166 }
171 } 167 }
172 ls_item(sha1, base, baselen, pathname, mode, stage); 168 ls_item(sha1, base, baselen, pathname, mode, stage);
173 return 0; 169 return 0;
174} 170}
175 171
176 172
177/* 173/*
178 * Show a tree or a blob 174 * Show a tree or a blob
179 * rev: the commit pointing at the root tree object 175 * rev: the commit pointing at the root tree object
180 * path: path to tree or blob 176 * path: path to tree or blob
181 */ 177 */
182void cgit_print_tree(const char *rev, char *path) 178void cgit_print_tree(const char *rev, char *path)
183{ 179{
184 unsigned char sha1[20]; 180 unsigned char sha1[20];
185 struct commit *commit; 181 struct commit *commit;
186 const char *paths[] = {path, NULL}; 182 const char *paths[] = {path, NULL};
187 183
188 if (!rev) 184 if (!rev)
189 rev = cgit_query_head; 185 rev = cgit_query_head;
190 186
191 curr_rev = xstrdup(rev); 187 curr_rev = xstrdup(rev);
192 if (get_sha1(rev, sha1)) { 188 if (get_sha1(rev, sha1)) {
193 cgit_print_error(fmt("Invalid revision name: %s", rev)); 189 cgit_print_error(fmt("Invalid revision name: %s", rev));
194 return; 190 return;
195 } 191 }
196 commit = lookup_commit_reference(sha1); 192 commit = lookup_commit_reference(sha1);
197 if (!commit || parse_commit(commit)) { 193 if (!commit || parse_commit(commit)) {
198 cgit_print_error(fmt("Invalid commit reference: %s", rev)); 194 cgit_print_error(fmt("Invalid commit reference: %s", rev));
199 return; 195 return;
200 } 196 }
201 197
202 html("path: <a href='"); 198 html("path: <a href='");
203 html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev))); 199 html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev)));
204 html("'>root</a>"); 200 html("'>root</a>");
205 201
206 if (path == NULL) { 202 if (path == NULL) {
207 ls_tree(commit->tree->object.sha1, NULL); 203 ls_tree(commit->tree->object.sha1, NULL);
208 return; 204 return;
209 } 205 }
210 206
211 match_path = path; 207 match_path = path;
212 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); 208 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree);
213 ls_tail(); 209 ls_tail();
214} 210}