summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.h3
-rw-r--r--ui-commit.c10
-rw-r--r--ui-repolist.c35
-rw-r--r--ui-shared.c64
-rw-r--r--ui-tree.c33
5 files changed, 107 insertions, 38 deletions
diff --git a/cgit.h b/cgit.h
index b93e2e8..9a19c97 100644
--- a/cgit.h
+++ b/cgit.h
@@ -192,24 +192,27 @@ extern 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,
205 char *rev, char *path);
206
204extern void cgit_print_error(char *msg); 207extern void cgit_print_error(char *msg);
205extern void cgit_print_date(time_t secs, char *format); 208extern void cgit_print_date(time_t secs, char *format);
206extern void cgit_print_age(time_t t, time_t max_relative, char *format); 209extern void cgit_print_age(time_t t, time_t max_relative, char *format);
207extern void cgit_print_docstart(char *title, struct cacheitem *item); 210extern void cgit_print_docstart(char *title, struct cacheitem *item);
208extern void cgit_print_docend(); 211extern void cgit_print_docend();
209extern void cgit_print_pageheader(char *title, int show_search); 212extern void cgit_print_pageheader(char *title, int show_search);
210extern void cgit_print_snapshot_start(const char *mimetype, 213extern void cgit_print_snapshot_start(const char *mimetype,
211 const char *filename, 214 const char *filename,
212 struct cacheitem *item); 215 struct cacheitem *item);
213 216
214extern void cgit_print_repolist(struct cacheitem *item); 217extern void cgit_print_repolist(struct cacheitem *item);
215extern void cgit_print_summary(); 218extern void cgit_print_summary();
diff --git a/ui-commit.c b/ui-commit.c
index ed5384d..885f870 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -144,24 +144,25 @@ void inspect_filepair(struct diff_filepair *pair)
144 total_rems += lines_removed; 144 total_rems += lines_removed;
145} 145}
146 146
147 147
148void cgit_print_commit(const char *hex) 148void 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 int i; 157 int i;
157 158
158 if (get_sha1(hex, sha1)) { 159 if (get_sha1(hex, sha1)) {
159 cgit_print_error(fmt("Bad object id: %s", hex)); 160 cgit_print_error(fmt("Bad object id: %s", hex));
160 return; 161 return;
161 } 162 }
162 commit = lookup_commit_reference(sha1); 163 commit = lookup_commit_reference(sha1);
163 if (!commit) { 164 if (!commit) {
164 cgit_print_error(fmt("Bad commit reference: %s", hex)); 165 cgit_print_error(fmt("Bad commit reference: %s", hex));
165 return; 166 return;
166 } 167 }
167 info = cgit_parse_commit(commit); 168 info = cgit_parse_commit(commit);
@@ -172,28 +173,29 @@ void cgit_print_commit(const char *hex)
172 html(" "); 173 html(" ");
173 html_txt(info->author_email); 174 html_txt(info->author_email);
174 html("</td><td class='right'>"); 175 html("</td><td class='right'>");
175 cgit_print_date(info->author_date, FMT_LONGDATE); 176 cgit_print_date(info->author_date, FMT_LONGDATE);
176 html("</td></tr>\n"); 177 html("</td></tr>\n");
177 html("<tr><th>committer</th><td>"); 178 html("<tr><th>committer</th><td>");
178 html_txt(info->committer); 179 html_txt(info->committer);
179 html(" "); 180 html(" ");
180 html_txt(info->committer_email); 181 html_txt(info->committer_email);
181 html("</td><td class='right'>"); 182 html("</td><td class='right'>");
182 cgit_print_date(info->committer_date, FMT_LONGDATE); 183 cgit_print_date(info->committer_date, FMT_LONGDATE);
183 html("</td></tr>\n"); 184 html("</td></tr>\n");
184 html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); 185 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
185 query = fmt("h=%s", sha1_to_hex(commit->object.sha1)); 186 tmp = xstrdup(hex);
186 html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); 187 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
187 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); 188 cgit_query_head, tmp, NULL);
189 html("</td></tr>\n");
188 for (p = commit->parents; p ; p = p->next) { 190 for (p = commit->parents; p ; p = p->next) {
189 parent = lookup_commit_reference(p->item->object.sha1); 191 parent = lookup_commit_reference(p->item->object.sha1);
190 if (!parent) { 192 if (!parent) {
191 html("<tr><td colspan='3'>"); 193 html("<tr><td colspan='3'>");
192 cgit_print_error("Error reading parent commit"); 194 cgit_print_error("Error reading parent commit");
193 html("</td></tr>"); 195 html("</td></tr>");
194 continue; 196 continue;
195 } 197 }
196 html("<tr><th>parent</th>" 198 html("<tr><th>parent</th>"
197 "<td colspan='2' class='sha1'>" 199 "<td colspan='2' class='sha1'>"
198 "<a href='"); 200 "<a href='");
199 query = fmt("h=%s", sha1_to_hex(p->item->object.sha1)); 201 query = fmt("h=%s", sha1_to_hex(p->item->object.sha1));
diff --git a/ui-repolist.c b/ui-repolist.c
index e5c6c20..8ade91a 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -35,69 +35,66 @@ static void print_modtime(struct repoinfo *repo)
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 struct repoinfo *repo;
48 int i; 47 int i;
49 char *last_group = NULL; 48 char *last_group = NULL;
50 49
51 cgit_print_docstart(cgit_root_title, item); 50 cgit_print_docstart(cgit_root_title, item);
52 cgit_print_pageheader(cgit_root_title, 0); 51 cgit_print_pageheader(cgit_root_title, 0);
53 52
54 html("<table class='list nowrap'>"); 53 html("<table class='list nowrap'>");
55 if (cgit_index_header) { 54 if (cgit_index_header) {
56 html("<tr class='nohover'><td colspan='5' class='include-block'>"); 55 html("<tr class='nohover'><td colspan='5' class='include-block'>");
57 html_include(cgit_index_header); 56 html_include(cgit_index_header);
58 html("</td></tr>"); 57 html("</td></tr>");
59 } 58 }
60 html("<tr class='nohover'>" 59 html("<tr class='nohover'>"
61 "<th class='left'>Name</th>" 60 "<th class='left'>Name</th>"
62 "<th class='left'>Description</th>" 61 "<th class='left'>Description</th>"
63 "<th class='left'>Owner</th>" 62 "<th class='left'>Owner</th>"
64 "<th class='left'>Idle</th>" 63 "<th class='left'>Idle</th>"
65 "<th>Links</th></tr>\n"); 64 "<th>Links</th></tr>\n");
66 65
67 for (i=0; i<cgit_repolist.count; i++) { 66 for (i=0; i<cgit_repolist.count; i++) {
68 repo = &cgit_repolist.repos[i]; 67 cgit_repo = &cgit_repolist.repos[i];
69 if ((last_group == NULL && repo->group != NULL) || 68 if ((last_group == NULL && cgit_repo->group != NULL) ||
70 (last_group != NULL && repo->group == NULL) || 69 (last_group != NULL && cgit_repo->group == NULL) ||
71 (last_group != NULL && repo->group!= NULL && 70 (last_group != NULL && cgit_repo->group != NULL &&
72 strcmp(repo->group, last_group))) { 71 strcmp(cgit_repo->group, last_group))) {
73 html("<tr class='nohover'><td colspan='4' class='repogroup'>"); 72 html("<tr class='nohover'><td colspan='4' class='repogroup'>");
74 html_txt(repo->group); 73 html_txt(cgit_repo->group);
75 html("</td></tr>"); 74 html("</td></tr>");
76 last_group = repo->group; 75 last_group = cgit_repo->group;
77 } 76 }
78 htmlf("<tr><td class='%s'>", 77 htmlf("<tr><td class='%s'>",
79 repo->group ? "sublevel-repo" : "toplevel-repo"); 78 cgit_repo->group ? "sublevel-repo" : "toplevel-repo");
80 html_link_open(cgit_repourl(repo->url), repo->desc, NULL); 79 html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL);
81 html_txt(repo->name); 80 html_txt(cgit_repo->name);
82 html_link_close(); 81 html_link_close();
83 html("</td><td>"); 82 html("</td><td>");
84 html_ntxt(cgit_max_repodesc_len, repo->desc); 83 html_ntxt(cgit_max_repodesc_len, cgit_repo->desc);
85 html("</td><td>"); 84 html("</td><td>");
86 html_txt(repo->owner); 85 html_txt(cgit_repo->owner);
87 html("</td><td>"); 86 html("</td><td>");
88 print_modtime(repo); 87 print_modtime(cgit_repo);
89 html("</td><td>"); 88 html("</td><td>");
90 html_link_open(cgit_repourl(repo->url), 89 html_link_open(cgit_repourl(cgit_repo->url),
91 "Summary", "button"); 90 "Summary", "button");
92 html("S</a>"); 91 html("S</a>");
93 html_link_open(cgit_pageurl(repo->name, "log", NULL), 92 html_link_open(cgit_pageurl(cgit_repo->name, "log", NULL),
94 "Log", "button"); 93 "Log", "button");
95 html("L</a>"); 94 html("L</a>");
96 html_link_open(cgit_pageurl(repo->name, "tree", NULL), 95 cgit_tree_link("F", "Files", "button", NULL, NULL, NULL);
97 "Files", "button");
98 html("F</a>");
99 html("</td></tr>\n"); 96 html("</td></tr>\n");
100 } 97 }
101 html("</table>"); 98 html("</table>");
102 cgit_print_docend(); 99 cgit_print_docend();
103} 100}
diff --git a/ui-shared.c b/ui-shared.c
index aba93e8..9ab6409 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -78,24 +78,88 @@ char *cgit_pageurl(const char *reponame, const char *pagename,
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,
91 char *path)
92{
93 char *delim = "?";
94
95 html("<a");
96 if (title) {
97 html(" title='");
98 html_attr(title);
99 html("'");
100 }
101 if (class) {
102 html(" class='");
103 html_attr(class);
104 html("'");
105 }
106 html(" href='");
107 if (cgit_virtual_root) {
108 html_attr(cgit_virtual_root);
109 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/')
110 html("/");
111 html_attr(cgit_repo->url);
112 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
113 html("/");
114 html(page);
115 html("/");
116 if (path)
117 html_attr(path);
118 } else {
119 html(cgit_script_name);
120 html("?url=");
121 html_attr(cgit_repo->url);
122 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
123 html("/");
124 html(page);
125 html("/");
126 if (path)
127 html_attr(path);
128 delim = "&amp;";
129 }
130 if (head && head != cgit_query_head) {
131 html(delim);
132 html("h=");
133 html_attr(head);
134 delim = "&amp;";
135 }
136 return fmt("%s", delim);
137}
138
139void cgit_tree_link(char *name, char *title, char *class, char *head,
140 char *rev, char *path)
141{
142 char *delim;
143
144 delim = repolink(title, class, "tree", head, path);
145 if (rev && rev != cgit_query_head) {
146 html(delim);
147 html("id=");
148 html_attr(rev);
149 }
150 html("'>");
151 html_txt(name);
152 html("</a>");
153}
90 154
91void cgit_print_date(time_t secs, char *format) 155void cgit_print_date(time_t secs, char *format)
92{ 156{
93 char buf[64]; 157 char buf[64];
94 struct tm *time; 158 struct tm *time;
95 159
96 time = gmtime(&secs); 160 time = gmtime(&secs);
97 strftime(buf, sizeof(buf)-1, format, time); 161 strftime(buf, sizeof(buf)-1, format, time);
98 html_txt(buf); 162 html_txt(buf);
99} 163}
100 164
101void cgit_print_age(time_t t, time_t max_relative, char *format) 165void cgit_print_age(time_t t, time_t max_relative, char *format)
diff --git a/ui-tree.c b/ui-tree.c
index db0bef6..3b82374 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -46,57 +46,62 @@ static void print_object(const unsigned char *sha1, char *path)
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 enum object_type type; 59 enum object_type type;
59 unsigned long size = 0; 60 unsigned long size = 0;
60 char *url, *qry; 61 char *url, *qry;
61 62
62 name = xstrdup(pathname); 63 name = xstrdup(pathname);
64 fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "",
65 cgit_query_path ? "/" : "", name);
66
63 type = sha1_object_info(sha1, &size); 67 type = sha1_object_info(sha1, &size);
64 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { 68 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
65 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 69 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
66 name, 70 name,
67 sha1_to_hex(sha1)); 71 sha1_to_hex(sha1));
68 return 0; 72 return 0;
69 } 73 }
70 qry = fmt("h=%s&amp;path=%s%s%s", curr_rev, 74
71 cgit_query_path ? cgit_query_path : "",
72 cgit_query_path ? "/" : "", pathname);
73 url = cgit_pageurl(cgit_query_repo, "tree", qry);
74 html("<tr><td class='filemode'>"); 75 html("<tr><td class='filemode'>");
75 html_filemode(mode); 76 html_filemode(mode);
76 html("</td><td "); 77 html("</td><td ");
77 if (S_ISDIRLNK(mode)) { 78 if (S_ISDIRLNK(mode)) {
78 htmlf("class='ls-mod'><a href='"); 79 htmlf("class='ls-mod'><a href='");
79 html_attr(fmt(cgit_repo->module_link, 80 html_attr(fmt(cgit_repo->module_link,
80 name, 81 name,
81 sha1_to_hex(sha1))); 82 sha1_to_hex(sha1)));
83 html("'>");
84 html_txt(name);
85 html("</a>");
82 } else if (S_ISDIR(mode)) { 86 } else if (S_ISDIR(mode)) {
83 html("class='ls-dir'><a href='"); 87 html("class='ls-dir'>");
84 html_attr(url); 88 cgit_tree_link(name, NULL, NULL, cgit_query_head,
89 curr_rev, fullpath);
85 } else { 90 } else {
86 html("class='ls-blob'><a href='"); 91 html("class='ls-blob'>");
87 html_attr(url); 92 cgit_tree_link(name, NULL, NULL, cgit_query_head,
93 curr_rev, fullpath);
88 } 94 }
89 htmlf("'>%s</a></td>", name); 95 htmlf("</td><td class='filesize'>%li</td>", size);
90 htmlf("<td class='filesize'>%li</td>", size);
91 96
92 html("<td class='links'><a href='"); 97 html("<td class='links'><a href='");
93 qry = fmt("h=%s&amp;path=%s%s%s", curr_rev, 98 qry = fmt("h=%s&amp;path=%s%s%s", curr_rev,
94 cgit_query_path ? cgit_query_path : "", 99 cgit_query_path ? cgit_query_path : "",
95 cgit_query_path ? "/" : "", pathname); 100 cgit_query_path ? "/" : "", pathname);
96 url = cgit_pageurl(cgit_query_repo, "log", qry); 101 url = cgit_pageurl(cgit_query_repo, "log", qry);
97 html_attr(url); 102 html_attr(url);
98 html("' class='button'>H</a></td>"); 103 html("' class='button'>H</a></td>");
99 html("</tr>\n"); 104 html("</tr>\n");
100 free(name); 105 free(name);
101 return 0; 106 return 0;
102} 107}
@@ -141,29 +146,27 @@ static void ls_tree(const unsigned char *sha1, char *path)
141static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 146static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
142 const char *pathname, unsigned mode, int stage) 147 const char *pathname, unsigned mode, int stage)
143{ 148{
144 static int state; 149 static int state;
145 static char buffer[PATH_MAX]; 150 static char buffer[PATH_MAX];
146 char *url; 151 char *url;
147 152
148 if (state == 0) { 153 if (state == 0) {
149 memcpy(buffer, base, baselen); 154 memcpy(buffer, base, baselen);
150 strcpy(buffer+baselen, pathname); 155 strcpy(buffer+baselen, pathname);
151 url = cgit_pageurl(cgit_query_repo, "tree", 156 url = cgit_pageurl(cgit_query_repo, "tree",
152 fmt("h=%s&amp;path=%s", curr_rev, buffer)); 157 fmt("h=%s&amp;path=%s", curr_rev, buffer));
153 htmlf(" / <a href='"); 158 html("/");
154 html_attr(url); 159 cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head,
155 html("'>"); 160 curr_rev, buffer);
156 html_txt(xstrdup(pathname));
157 html("</a>");
158 161
159 if (strcmp(match_path, buffer)) 162 if (strcmp(match_path, buffer))
160 return READ_TREE_RECURSIVE; 163 return READ_TREE_RECURSIVE;
161 164
162 if (S_ISDIR(mode)) { 165 if (S_ISDIR(mode)) {
163 state = 1; 166 state = 1;
164 ls_head(); 167 ls_head();
165 return READ_TREE_RECURSIVE; 168 return READ_TREE_RECURSIVE;
166 } else { 169 } else {
167 print_object(sha1, buffer); 170 print_object(sha1, buffer);
168 return 0; 171 return 0;
169 } 172 }