aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2007-06-17 08:23:08 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2007-06-17 08:39:05 (JST)
commit44947bfcdc0d6e8c7d673bea0538cbf2a182f289 (patch)
tree3f65d6842738a8314ed72d5575a0b523061556b7
parentf91b9696a36008c245a3195800ba0c5fa3e890f9 (diff)
downloadcgit-44947bfcdc0d6e8c7d673bea0538cbf2a182f289.zip
cgit-44947bfcdc0d6e8c7d673bea0538cbf2a182f289.tar.gz
Add and use cgit_tree_link()
This creates a new function used to generate links to 'tree' page and uses the function everywhere a link to the 'tree' page is generated. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-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
@@ -201,6 +201,9 @@ extern 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);
diff --git a/ui-commit.c b/ui-commit.c
index ed5384d..885f870 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -153,6 +153,7 @@ void cgit_print_commit(const char *hex)
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)) {
@@ -181,10 +182,11 @@ void cgit_print_commit(const char *hex)
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) {
diff --git a/ui-repolist.c b/ui-repolist.c
index e5c6c20..8ade91a 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -44,7 +44,6 @@ static void print_modtime(struct repoinfo *repo)
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
@@ -65,37 +64,35 @@ void cgit_print_repolist(struct cacheitem *item)
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>");
diff --git a/ui-shared.c b/ui-shared.c
index aba93e8..9ab6409 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -87,6 +87,70 @@ char *cgit_currurl()
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{
diff --git a/ui-tree.c b/ui-tree.c
index db0bef6..3b82374 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -55,11 +55,15 @@ 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 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>",
@@ -67,10 +71,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
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 ");
@@ -79,15 +80,19 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
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,
@@ -150,11 +155,9 @@ static int walk_tree(const unsigned char *sha1, const char *base, int 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;