|
diff --git a/ui-tree.c b/ui-tree.c index 553dbaa..f53ab64 100644 --- a/ ui-tree.c+++ b/ ui-tree.c |
|
@@ -10,36 +10,53 @@ |
10 | #include "cgit.h" |
10 | #include "cgit.h" |
11 | #include "html.h" |
11 | #include "html.h" |
12 | #include "ui-shared.h" |
12 | #include "ui-shared.h" |
13 | |
13 | |
14 | char *curr_rev; |
14 | char *curr_rev; |
15 | char *match_path; |
15 | char *match_path; |
16 | int header = 0; |
16 | int header = 0; |
17 | |
17 | |
18 | static void print_text_buffer(char *buf, unsigned long size) |
18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) |
19 | { |
19 | { |
20 | unsigned long lineno, idx; |
20 | unsigned long lineno, idx; |
21 | const char *numberfmt = |
21 | const char *numberfmt = |
22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; |
22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; |
23 | |
23 | |
24 | html("<table summary='blob content' class='blob'>\n"); |
24 | html("<table summary='blob content' class='blob'>\n"); |
25 | html("<tr><td class='linenumbers'><pre>"); |
25 | |
26 | idx = 0; |
26 | if (ctx.cfg.enable_tree_linenumbers) { |
27 | lineno = 0; |
27 | html("<tr><td class='linenumbers'><pre>"); |
28 | |
28 | idx = 0; |
29 | if (size) { |
29 | lineno = 0; |
30 | htmlf(numberfmt, ++lineno); |
30 | |
31 | while(idx < size - 1) { // skip absolute last newline |
31 | if (size) { |
32 | if (buf[idx] == '\n') |
32 | htmlf(numberfmt, ++lineno); |
33 | htmlf(numberfmt, ++lineno); |
33 | while(idx < size - 1) { // skip absolute last newline |
34 | idx++; |
34 | if (buf[idx] == '\n') |
| |
35 | htmlf(numberfmt, ++lineno); |
| |
36 | idx++; |
| |
37 | } |
35 | } |
38 | } |
| |
39 | html("</pre></td>\n"); |
| |
40 | } |
| |
41 | else { |
| |
42 | html("<tr>\n"); |
| |
43 | } |
| |
44 | |
| |
45 | if (ctx.repo->source_filter) { |
| |
46 | html("<td class='lines'><pre><code>"); |
| |
47 | ctx.repo->source_filter->argv[1] = xstrdup(name); |
| |
48 | cgit_open_filter(ctx.repo->source_filter); |
| |
49 | write(STDOUT_FILENO, buf, size); |
| |
50 | cgit_close_filter(ctx.repo->source_filter); |
| |
51 | html("</code></pre></td></tr></table>\n"); |
| |
52 | return; |
36 | } |
53 | } |
37 | html("</pre></td>\n"); |
54 | |
38 | html("<td class='lines'><pre><code>"); |
55 | html("<td class='lines'><pre><code>"); |
39 | html_txt(buf); |
56 | html_txt(buf); |
40 | html("</code></pre></td></tr></table>\n"); |
57 | html("</code></pre></td></tr></table>\n"); |
41 | } |
58 | } |
42 | |
59 | |
43 | #define ROWLEN 32 |
60 | #define ROWLEN 32 |
44 | |
61 | |
45 | static void print_binary_buffer(char *buf, unsigned long size) |
62 | static void print_binary_buffer(char *buf, unsigned long size) |
@@ -60,17 +77,17 @@ static void print_binary_buffer(char *buf, unsigned long size) |
60 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; |
77 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; |
61 | ascii[idx] = '\0'; |
78 | ascii[idx] = '\0'; |
62 | html_txt(ascii); |
79 | html_txt(ascii); |
63 | html("</td></tr>\n"); |
80 | html("</td></tr>\n"); |
64 | } |
81 | } |
65 | html("</table>\n"); |
82 | html("</table>\n"); |
66 | } |
83 | } |
67 | |
84 | |
68 | static void print_object(const unsigned char *sha1, char *path) |
85 | static void print_object(const unsigned char *sha1, char *path, const char *basename) |
69 | { |
86 | { |
70 | enum object_type type; |
87 | enum object_type type; |
71 | char *buf; |
88 | char *buf; |
72 | unsigned long size; |
89 | unsigned long size; |
73 | |
90 | |
74 | type = sha1_object_info(sha1, &size); |
91 | type = sha1_object_info(sha1, &size); |
75 | if (type == OBJ_BAD) { |
92 | if (type == OBJ_BAD) { |
76 | cgit_print_error(fmt("Bad object name: %s", |
93 | cgit_print_error(fmt("Bad object name: %s", |
@@ -88,26 +105,27 @@ static void print_object(const unsigned char *sha1, char *path) |
88 | html(" ("); |
105 | html(" ("); |
89 | cgit_plain_link("plain", NULL, NULL, ctx.qry.head, |
106 | cgit_plain_link("plain", NULL, NULL, ctx.qry.head, |
90 | curr_rev, path); |
107 | curr_rev, path); |
91 | htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1)); |
108 | htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1)); |
92 | |
109 | |
93 | if (buffer_is_binary(buf, size)) |
110 | if (buffer_is_binary(buf, size)) |
94 | print_binary_buffer(buf, size); |
111 | print_binary_buffer(buf, size); |
95 | else |
112 | else |
96 | print_text_buffer(buf, size); |
113 | print_text_buffer(basename, buf, size); |
97 | } |
114 | } |
98 | |
115 | |
99 | |
116 | |
100 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
117 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
101 | const char *pathname, unsigned int mode, int stage, |
118 | const char *pathname, unsigned int mode, int stage, |
102 | void *cbdata) |
119 | void *cbdata) |
103 | { |
120 | { |
104 | char *name; |
121 | char *name; |
105 | char *fullpath; |
122 | char *fullpath; |
| |
123 | char *class; |
106 | enum object_type type; |
124 | enum object_type type; |
107 | unsigned long size = 0; |
125 | unsigned long size = 0; |
108 | |
126 | |
109 | name = xstrdup(pathname); |
127 | name = xstrdup(pathname); |
110 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
128 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
111 | ctx.qry.path ? "/" : "", name); |
129 | ctx.qry.path ? "/" : "", name); |
112 | |
130 | |
113 | if (!S_ISGITLINK(mode)) { |
131 | if (!S_ISGITLINK(mode)) { |
@@ -130,17 +148,22 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
130 | sha1_to_hex(sha1))); |
148 | sha1_to_hex(sha1))); |
131 | html("'>"); |
149 | html("'>"); |
132 | html_txt(name); |
150 | html_txt(name); |
133 | html("</a>"); |
151 | html("</a>"); |
134 | } else if (S_ISDIR(mode)) { |
152 | } else if (S_ISDIR(mode)) { |
135 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
153 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
136 | curr_rev, fullpath); |
154 | curr_rev, fullpath); |
137 | } else { |
155 | } else { |
138 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, |
156 | class = strrchr(name, '.'); |
| |
157 | if (class != NULL) { |
| |
158 | class = fmt("ls-blob %s", class + 1); |
| |
159 | } else |
| |
160 | class = "ls-blob"; |
| |
161 | cgit_tree_link(name, NULL, class, ctx.qry.head, |
139 | curr_rev, fullpath); |
162 | curr_rev, fullpath); |
140 | } |
163 | } |
141 | htmlf("</td><td class='ls-size'>%li</td>", size); |
164 | htmlf("</td><td class='ls-size'>%li</td>", size); |
142 | |
165 | |
143 | html("<td>"); |
166 | html("<td>"); |
144 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
167 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
145 | fullpath, 0, NULL, NULL, ctx.qry.showmsg); |
168 | fullpath, 0, NULL, NULL, ctx.qry.showmsg); |
146 | if (ctx.repo->max_stats) |
169 | if (ctx.repo->max_stats) |
@@ -208,17 +231,17 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
208 | if (strcmp(match_path, buffer)) |
231 | if (strcmp(match_path, buffer)) |
209 | return READ_TREE_RECURSIVE; |
232 | return READ_TREE_RECURSIVE; |
210 | |
233 | |
211 | if (S_ISDIR(mode)) { |
234 | if (S_ISDIR(mode)) { |
212 | state = 1; |
235 | state = 1; |
213 | ls_head(); |
236 | ls_head(); |
214 | return READ_TREE_RECURSIVE; |
237 | return READ_TREE_RECURSIVE; |
215 | } else { |
238 | } else { |
216 | print_object(sha1, buffer); |
239 | print_object(sha1, buffer, pathname); |
217 | return 0; |
240 | return 0; |
218 | } |
241 | } |
219 | } |
242 | } |
220 | ls_item(sha1, base, baselen, pathname, mode, stage, NULL); |
243 | ls_item(sha1, base, baselen, pathname, mode, stage, NULL); |
221 | return 0; |
244 | return 0; |
222 | } |
245 | } |
223 | |
246 | |
224 | |
247 | |
|