|
diff --git a/ui-tree.c b/ui-tree.c index 2f052c7..5a2dd3f 100644 --- a/ ui-tree.c+++ b/ ui-tree.c |
|
@@ -12,134 +12,136 @@ |
12 | |
12 | |
13 | char *curr_rev; |
13 | char *curr_rev; |
14 | char *match_path; |
14 | char *match_path; |
15 | int header = 0; |
15 | int header = 0; |
16 | |
16 | |
17 | static void print_object(const unsigned char *sha1, char *path) |
17 | static void print_object(const unsigned char *sha1, char *path) |
18 | { |
18 | { |
19 | enum object_type type; |
19 | enum object_type type; |
20 | char *buf; |
20 | char *buf; |
21 | unsigned long size, lineno, start, idx; |
21 | unsigned long size, lineno, start, idx; |
22 | 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'>"; |
22 | 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'>"; |
23 | |
23 | |
24 | type = sha1_object_info(sha1, &size); |
24 | type = sha1_object_info(sha1, &size); |
25 | if (type == OBJ_BAD) { |
25 | if (type == OBJ_BAD) { |
26 | cgit_print_error(fmt("Bad object name: %s", |
26 | cgit_print_error(fmt("Bad object name: %s", |
27 | sha1_to_hex(sha1))); |
27 | sha1_to_hex(sha1))); |
28 | return; |
28 | return; |
29 | } |
29 | } |
30 | |
30 | |
31 | buf = read_sha1_file(sha1, &type, &size); |
31 | buf = read_sha1_file(sha1, &type, &size); |
32 | if (!buf) { |
32 | if (!buf) { |
33 | cgit_print_error(fmt("Error reading object %s", |
33 | cgit_print_error(fmt("Error reading object %s", |
34 | sha1_to_hex(sha1))); |
34 | sha1_to_hex(sha1))); |
35 | return; |
35 | return; |
36 | } |
36 | } |
37 | |
37 | |
38 | html(" blob: <a href='"); |
38 | html(" blob: <a href='"); |
39 | html_attr(cgit_pageurl(ctx.qry.repo, "blob", |
39 | html_attr(cgit_pageurl(ctx.qry.repo, "blob", |
40 | fmt("id=%s&path=%s", sha1_to_hex(sha1), path))); |
40 | fmt("id=%s&path=%s", sha1_to_hex(sha1), path))); |
41 | htmlf("'>%s</a>",sha1_to_hex(sha1)); |
41 | htmlf("'>%s</a>",sha1_to_hex(sha1)); |
42 | |
42 | |
43 | html("<table summary='blob content' class='blob'>\n"); |
43 | html("<table summary='blob content' class='blob'>\n"); |
44 | idx = 0; |
44 | idx = 0; |
45 | start = 0; |
45 | start = 0; |
46 | lineno = 0; |
46 | lineno = 0; |
47 | while(idx < size) { |
47 | while(idx < size) { |
48 | if (buf[idx] == '\n') { |
48 | if (buf[idx] == '\n') { |
49 | buf[idx] = '\0'; |
49 | buf[idx] = '\0'; |
50 | htmlf(linefmt, ++lineno); |
50 | htmlf(linefmt, ++lineno); |
51 | html_txt(buf + start); |
51 | html_txt(buf + start); |
52 | html("</td></tr>\n"); |
52 | html("</td></tr>\n"); |
53 | start = idx + 1; |
53 | start = idx + 1; |
54 | } |
54 | } |
55 | idx++; |
55 | idx++; |
56 | } |
56 | } |
57 | htmlf(linefmt, ++lineno); |
57 | htmlf(linefmt, ++lineno); |
58 | html_txt(buf + start); |
58 | html_txt(buf + start); |
59 | html("</td></tr>\n"); |
59 | html("</td></tr>\n"); |
60 | html("</table>\n"); |
60 | html("</table>\n"); |
61 | } |
61 | } |
62 | |
62 | |
63 | |
63 | |
64 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
64 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
65 | const char *pathname, unsigned int mode, int stage) |
65 | const char *pathname, unsigned int mode, int stage) |
66 | { |
66 | { |
67 | char *name; |
67 | char *name; |
68 | char *fullpath; |
68 | char *fullpath; |
69 | enum object_type type; |
69 | enum object_type type; |
70 | unsigned long size = 0; |
70 | unsigned long size = 0; |
71 | |
71 | |
72 | name = xstrdup(pathname); |
72 | name = xstrdup(pathname); |
73 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
73 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
74 | ctx.qry.path ? "/" : "", name); |
74 | ctx.qry.path ? "/" : "", name); |
75 | |
75 | |
76 | type = sha1_object_info(sha1, &size); |
76 | if (!S_ISGITLINK(mode)) { |
77 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { |
77 | type = sha1_object_info(sha1, &size); |
78 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
78 | if (type == OBJ_BAD) { |
79 | name, |
79 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
80 | sha1_to_hex(sha1)); |
80 | name, |
81 | return 0; |
81 | sha1_to_hex(sha1)); |
| |
82 | return 0; |
| |
83 | } |
82 | } |
84 | } |
83 | |
85 | |
84 | html("<tr><td class='ls-mode'>"); |
86 | html("<tr><td class='ls-mode'>"); |
85 | cgit_print_filemode(mode); |
87 | cgit_print_filemode(mode); |
86 | html("</td><td>"); |
88 | html("</td><td>"); |
87 | if (S_ISGITLINK(mode)) { |
89 | if (S_ISGITLINK(mode)) { |
88 | htmlf("<a class='ls-mod' href='"); |
90 | htmlf("<a class='ls-mod' href='"); |
89 | html_attr(fmt(ctx.repo->module_link, |
91 | html_attr(fmt(ctx.repo->module_link, |
90 | name, |
92 | name, |
91 | sha1_to_hex(sha1))); |
93 | sha1_to_hex(sha1))); |
92 | html("'>"); |
94 | html("'>"); |
93 | html_txt(name); |
95 | html_txt(name); |
94 | html("</a>"); |
96 | html("</a>"); |
95 | } else if (S_ISDIR(mode)) { |
97 | } else if (S_ISDIR(mode)) { |
96 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
98 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
97 | curr_rev, fullpath); |
99 | curr_rev, fullpath); |
98 | } else { |
100 | } else { |
99 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, |
101 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, |
100 | curr_rev, fullpath); |
102 | curr_rev, fullpath); |
101 | } |
103 | } |
102 | htmlf("</td><td class='ls-size'>%li</td>", size); |
104 | htmlf("</td><td class='ls-size'>%li</td>", size); |
103 | |
105 | |
104 | html("<td>"); |
106 | html("<td>"); |
105 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
107 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
106 | fullpath, 0, NULL, NULL); |
108 | fullpath, 0, NULL, NULL); |
107 | html("</td></tr>\n"); |
109 | html("</td></tr>\n"); |
108 | free(name); |
110 | free(name); |
109 | return 0; |
111 | return 0; |
110 | } |
112 | } |
111 | |
113 | |
112 | static void ls_head() |
114 | static void ls_head() |
113 | { |
115 | { |
114 | html("<table summary='tree listing' class='list'>\n"); |
116 | html("<table summary='tree listing' class='list'>\n"); |
115 | html("<tr class='nohover'>"); |
117 | html("<tr class='nohover'>"); |
116 | html("<th class='left'>Mode</th>"); |
118 | html("<th class='left'>Mode</th>"); |
117 | html("<th class='left'>Name</th>"); |
119 | html("<th class='left'>Name</th>"); |
118 | html("<th class='right'>Size</th>"); |
120 | html("<th class='right'>Size</th>"); |
119 | html("<th/>"); |
121 | html("<th/>"); |
120 | html("</tr>\n"); |
122 | html("</tr>\n"); |
121 | header = 1; |
123 | header = 1; |
122 | } |
124 | } |
123 | |
125 | |
124 | static void ls_tail() |
126 | static void ls_tail() |
125 | { |
127 | { |
126 | if (!header) |
128 | if (!header) |
127 | return; |
129 | return; |
128 | html("</table>\n"); |
130 | html("</table>\n"); |
129 | header = 0; |
131 | header = 0; |
130 | } |
132 | } |
131 | |
133 | |
132 | static void ls_tree(const unsigned char *sha1, char *path) |
134 | static void ls_tree(const unsigned char *sha1, char *path) |
133 | { |
135 | { |
134 | struct tree *tree; |
136 | struct tree *tree; |
135 | |
137 | |
136 | tree = parse_tree_indirect(sha1); |
138 | tree = parse_tree_indirect(sha1); |
137 | if (!tree) { |
139 | if (!tree) { |
138 | cgit_print_error(fmt("Not a tree object: %s", |
140 | cgit_print_error(fmt("Not a tree object: %s", |
139 | sha1_to_hex(sha1))); |
141 | sha1_to_hex(sha1))); |
140 | return; |
142 | return; |
141 | } |
143 | } |
142 | |
144 | |
143 | ls_head(); |
145 | ls_head(); |
144 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); |
146 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); |
145 | ls_tail(); |
147 | ls_tail(); |
|