about summary refs log tree commit diff stats
path: root/ui-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-tree.c')
-rw-r--r--ui-tree.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/ui-tree.c b/ui-tree.c index b61f6f5..21e0b88 100644 --- a/ui-tree.c +++ b/ui-tree.c
@@ -89,6 +89,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
89 enum object_type type; 89 enum object_type type;
90 char *buf; 90 char *buf;
91 unsigned long size; 91 unsigned long size;
92 int is_binary;
92 93
93 type = oid_object_info(the_repository, oid, &size); 94 type = oid_object_info(the_repository, oid, &size);
94 if (type == OBJ_BAD) { 95 if (type == OBJ_BAD) {
@@ -103,6 +104,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
103 "Error reading object %s", oid_to_hex(oid)); 104 "Error reading object %s", oid_to_hex(oid));
104 return; 105 return;
105 } 106 }
107 is_binary = buffer_is_binary(buf, size);
106 108
107 cgit_set_title_from_path(path); 109 cgit_set_title_from_path(path);
108 110
@@ -110,7 +112,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
110 htmlf("blob: %s (", oid_to_hex(oid)); 112 htmlf("blob: %s (", oid_to_hex(oid));
111 cgit_plain_link("plain", NULL, NULL, ctx.qry.head, 113 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
112 rev, path); 114 rev, path);
113 if (ctx.repo->enable_blame) { 115 if (ctx.repo->enable_blame && !is_binary) {
114 html(") ("); 116 html(") (");
115 cgit_blame_link("blame", NULL, NULL, ctx.qry.head, 117 cgit_blame_link("blame", NULL, NULL, ctx.qry.head,
116 rev, path); 118 rev, path);
@@ -123,7 +125,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
123 return; 125 return;
124 } 126 }
125 127
126 if (buffer_is_binary(buf, size)) 128 if (is_binary)
127 print_binary_buffer(buf, size); 129 print_binary_buffer(buf, size);
128 else 130 else
129 print_text_buffer(basename, buf, size); 131 print_text_buffer(basename, buf, size);
@@ -202,9 +204,11 @@ static int ls_item(const struct object_id *oid, struct strbuf *base,
202 struct walk_tree_context *walk_tree_ctx = cbdata; 204 struct walk_tree_context *walk_tree_ctx = cbdata;
203 char *name; 205 char *name;
204 struct strbuf fullpath = STRBUF_INIT; 206 struct strbuf fullpath = STRBUF_INIT;
207 struct strbuf linkpath = STRBUF_INIT;
205 struct strbuf class = STRBUF_INIT; 208 struct strbuf class = STRBUF_INIT;
206 enum object_type type; 209 enum object_type type;
207 unsigned long size = 0; 210 unsigned long size = 0;
211 char *buf;
208 212
209 name = xstrdup(pathname); 213 name = xstrdup(pathname);
210 strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "", 214 strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "",
@@ -216,8 +220,7 @@ static int ls_item(const struct object_id *oid, struct strbuf *base,
216 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 220 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
217 name, 221 name,
218 oid_to_hex(oid)); 222 oid_to_hex(oid));
219 free(name); 223 goto cleanup;
220 return 0;
221 } 224 }
222 } 225 }
223 226
@@ -237,22 +240,45 @@ static int ls_item(const struct object_id *oid, struct strbuf *base,
237 cgit_tree_link(name, NULL, class.buf, ctx.qry.head, 240 cgit_tree_link(name, NULL, class.buf, ctx.qry.head,
238 walk_tree_ctx->curr_rev, fullpath.buf); 241 walk_tree_ctx->curr_rev, fullpath.buf);
239 } 242 }
243 if (S_ISLNK(mode)) {
244 html(" -> ");
245 buf = read_object_file(oid, &type, &size);
246 if (!buf) {
247 htmlf("Error reading object: %s", oid_to_hex(oid));
248 goto cleanup;
249 }
250 strbuf_addbuf(&linkpath, &fullpath);
251 strbuf_addf(&linkpath, "/../%s", buf);
252 strbuf_normalize_path(&linkpath);
253 cgit_tree_link(buf, NULL, class.buf, ctx.qry.head,
254 walk_tree_ctx->curr_rev, linkpath.buf);
255 free(buf);
256 strbuf_release(&linkpath);
257 }
240 htmlf("</td><td class='ls-size'>%li</td>", size); 258 htmlf("</td><td class='ls-size'>%li</td>", size);
241 259
242 html("<td>"); 260 html("<td>");
243 cgit_log_link("log", NULL, "button", ctx.qry.head, 261 cgit_log_link("log", NULL, "button", ctx.qry.head,
244 walk_tree_ctx->curr_rev, fullpath.buf, 0, NULL, NULL, 262 walk_tree_ctx->curr_rev, fullpath.buf, 0, NULL, NULL,
245 ctx.qry.showmsg, 0); 263 ctx.qry.showmsg, 0);
246 if (ctx.repo->max_stats) 264 if (ctx.repo->max_stats) {
265 html(" ");
247 cgit_stats_link("stats", NULL, "button", ctx.qry.head, 266 cgit_stats_link("stats", NULL, "button", ctx.qry.head,
248 fullpath.buf); 267 fullpath.buf);
249 if (!S_ISGITLINK(mode)) 268 }
269 if (!S_ISGITLINK(mode)) {
270 html(" ");
250 cgit_plain_link("plain", NULL, "button", ctx.qry.head, 271 cgit_plain_link("plain", NULL, "button", ctx.qry.head,
251 walk_tree_ctx->curr_rev, fullpath.buf); 272 walk_tree_ctx->curr_rev, fullpath.buf);
252 if (!S_ISDIR(mode) && ctx.repo->enable_blame) 273 }
274 if (!S_ISDIR(mode) && ctx.repo->enable_blame) {
275 html(" ");
253 cgit_blame_link("blame", NULL, "button", ctx.qry.head, 276 cgit_blame_link("blame", NULL, "button", ctx.qry.head,
254 walk_tree_ctx->curr_rev, fullpath.buf); 277 walk_tree_ctx->curr_rev, fullpath.buf);
278 }
255 html("</td></tr>\n"); 279 html("</td></tr>\n");
280
281cleanup:
256 free(name); 282 free(name);
257 strbuf_release(&fullpath); 283 strbuf_release(&fullpath);
258 strbuf_release(&class); 284 strbuf_release(&class);