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
@@ -198,12 +198,15 @@ extern 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);
diff --git a/ui-commit.c b/ui-commit.c
index ed5384d..885f870 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -150,12 +150,13 @@ void cgit_print_commit(const char *hex)
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 }
@@ -178,16 +179,17 @@ void cgit_print_commit(const char *hex)
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>");
diff --git a/ui-repolist.c b/ui-repolist.c
index e5c6c20..8ade91a 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -41,13 +41,12 @@ static void print_modtime(struct repoinfo *repo)
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
@@ -62,42 +61,40 @@ void cgit_print_repolist(struct cacheitem *item)
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
@@ -84,12 +84,76 @@ char *cgit_currurl()
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
diff --git a/ui-tree.c b/ui-tree.c
index db0bef6..3b82374 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -52,45 +52,50 @@ static void print_object(const unsigned char *sha1, char *path)
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);
@@ -147,17 +152,15 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
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;