summaryrefslogtreecommitdiffabout
path: root/ui-tree.c
Unidiff
Diffstat (limited to 'ui-tree.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-tree.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/ui-tree.c b/ui-tree.c
index df05ad3..7912784 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,41 +1,42 @@
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#include "html.h"
10 11
11char *curr_rev; 12char *curr_rev;
12char *match_path; 13char *match_path;
13int header = 0; 14int header = 0;
14 15
15static void print_object(const unsigned char *sha1, char *path) 16static void print_object(const unsigned char *sha1, char *path)
16{ 17{
17 enum object_type type; 18 enum object_type type;
18 char *buf; 19 char *buf;
19 unsigned long size, lineno, start, idx; 20 unsigned long size, lineno, start, idx;
20 const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>"; 21 const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>";
21 22
22 type = sha1_object_info(sha1, &size); 23 type = sha1_object_info(sha1, &size);
23 if (type == OBJ_BAD) { 24 if (type == OBJ_BAD) {
24 cgit_print_error(fmt("Bad object name: %s", 25 cgit_print_error(fmt("Bad object name: %s",
25 sha1_to_hex(sha1))); 26 sha1_to_hex(sha1)));
26 return; 27 return;
27 } 28 }
28 29
29 buf = read_sha1_file(sha1, &type, &size); 30 buf = read_sha1_file(sha1, &type, &size);
30 if (!buf) { 31 if (!buf) {
31 cgit_print_error(fmt("Error reading object %s", 32 cgit_print_error(fmt("Error reading object %s",
32 sha1_to_hex(sha1))); 33 sha1_to_hex(sha1)));
33 return; 34 return;
34 } 35 }
35 36
36 html(" blob: <a href='"); 37 html(" blob: <a href='");
37 html_attr(cgit_pageurl(ctx.qry.repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); 38 html_attr(cgit_pageurl(ctx.qry.repo, "blob", fmt("id=%s", sha1_to_hex(sha1))));
38 htmlf("'>%s</a>",sha1_to_hex(sha1)); 39 htmlf("'>%s</a>",sha1_to_hex(sha1));
39 40
40 html("<table summary='blob content' class='blob'>\n"); 41 html("<table summary='blob content' class='blob'>\n");
41 idx = 0; 42 idx = 0;
@@ -50,65 +51,65 @@ static void print_object(const unsigned char *sha1, char *path)
50 start = idx + 1; 51 start = idx + 1;
51 } 52 }
52 idx++; 53 idx++;
53 } 54 }
54 htmlf(linefmt, ++lineno); 55 htmlf(linefmt, ++lineno);
55 html_txt(buf + start); 56 html_txt(buf + start);
56 html("</td></tr>\n"); 57 html("</td></tr>\n");
57 html("</table>\n"); 58 html("</table>\n");
58} 59}
59 60
60 61
61static int ls_item(const unsigned char *sha1, const char *base, int baselen, 62static int ls_item(const unsigned char *sha1, const char *base, int baselen,
62 const char *pathname, unsigned int mode, int stage) 63 const char *pathname, unsigned int mode, int stage)
63{ 64{
64 char *name; 65 char *name;
65 char *fullpath; 66 char *fullpath;
66 enum object_type type; 67 enum object_type type;
67 unsigned long size = 0; 68 unsigned long size = 0;
68 69
69 name = xstrdup(pathname); 70 name = xstrdup(pathname);
70 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", 71 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "",
71 ctx.qry.path ? "/" : "", name); 72 ctx.qry.path ? "/" : "", name);
72 73
73 type = sha1_object_info(sha1, &size); 74 type = sha1_object_info(sha1, &size);
74 if (type == OBJ_BAD && !S_ISGITLINK(mode)) { 75 if (type == OBJ_BAD && !S_ISGITLINK(mode)) {
75 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 76 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
76 name, 77 name,
77 sha1_to_hex(sha1)); 78 sha1_to_hex(sha1));
78 return 0; 79 return 0;
79 } 80 }
80 81
81 html("<tr><td class='ls-mode'>"); 82 html("<tr><td class='ls-mode'>");
82 html_filemode(mode); 83 cgit_print_filemode(mode);
83 html("</td><td>"); 84 html("</td><td>");
84 if (S_ISGITLINK(mode)) { 85 if (S_ISGITLINK(mode)) {
85 htmlf("<a class='ls-mod' href='"); 86 htmlf("<a class='ls-mod' href='");
86 html_attr(fmt(ctx.repo->module_link, 87 html_attr(fmt(ctx.repo->module_link,
87 name, 88 name,
88 sha1_to_hex(sha1))); 89 sha1_to_hex(sha1)));
89 html("'>"); 90 html("'>");
90 html_txt(name); 91 html_txt(name);
91 html("</a>"); 92 html("</a>");
92 } else if (S_ISDIR(mode)) { 93 } else if (S_ISDIR(mode)) {
93 cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, 94 cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
94 curr_rev, fullpath); 95 curr_rev, fullpath);
95 } else { 96 } else {
96 cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, 97 cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head,
97 curr_rev, fullpath); 98 curr_rev, fullpath);
98 } 99 }
99 htmlf("</td><td class='ls-size'>%li</td>", size); 100 htmlf("</td><td class='ls-size'>%li</td>", size);
100 101
101 html("<td>"); 102 html("<td>");
102 cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, 103 cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev,
103 fullpath, 0, NULL, NULL); 104 fullpath, 0, NULL, NULL);
104 html("</td></tr>\n"); 105 html("</td></tr>\n");
105 free(name); 106 free(name);
106 return 0; 107 return 0;
107} 108}
108 109
109static void ls_head() 110static void ls_head()
110{ 111{
111 html("<table summary='tree listing' class='list'>\n"); 112 html("<table summary='tree listing' class='list'>\n");
112 html("<tr class='nohover'>"); 113 html("<tr class='nohover'>");
113 html("<th class='left'>Mode</th>"); 114 html("<th class='left'>Mode</th>");
114 html("<th class='left'>Name</th>"); 115 html("<th class='left'>Name</th>");