aboutsummaryrefslogtreecommitdiffstats
path: root/ui-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-tree.c')
-rw-r--r--ui-tree.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/ui-tree.c b/ui-tree.c
index 553dbaa..f53ab64 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -15,26 +15,43 @@ char *curr_rev;
15char *match_path; 15char *match_path;
16int header = 0; 16int header = 0;
17 17
18static void print_text_buffer(char *buf, unsigned long size) 18static 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");
@@ -65,7 +82,7 @@ static void print_binary_buffer(char *buf, unsigned long size)
65 html("</table>\n"); 82 html("</table>\n");
66} 83}
67 84
68static void print_object(const unsigned char *sha1, char *path) 85static 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;
@@ -93,7 +110,7 @@ static void print_object(const unsigned char *sha1, char *path)
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
@@ -103,6 +120,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
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
@@ -135,7 +153,12 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
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);
@@ -213,7 +236,7 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
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 }