|
diff --git a/ui-tree.c b/ui-tree.c index d503bee..e16b638 100644 --- a/ ui-tree.c+++ b/ ui-tree.c |
|
@@ -31,136 +31,132 @@ static void print_object(const unsigned char *sha1, char *path) |
31 | sha1_to_hex(sha1))); |
31 | sha1_to_hex(sha1))); |
32 | return; |
32 | return; |
33 | } |
33 | } |
34 | |
34 | |
35 | html("<table class='blob'>\n"); |
35 | html("<table class='blob'>\n"); |
36 | idx = 0; |
36 | idx = 0; |
37 | start = 0; |
37 | start = 0; |
38 | lineno = 0; |
38 | lineno = 0; |
39 | while(idx < size) { |
39 | while(idx < size) { |
40 | if (buf[idx] == '\n') { |
40 | if (buf[idx] == '\n') { |
41 | buf[idx] = '\0'; |
41 | buf[idx] = '\0'; |
42 | htmlf("<tr><td class='no'>%d</td><td class='txt'>", |
42 | htmlf("<tr><td class='no'>%d</td><td class='txt'>", |
43 | ++lineno); |
43 | ++lineno); |
44 | html_txt(buf + start); |
44 | html_txt(buf + start); |
45 | html("</td></tr>\n"); |
45 | html("</td></tr>\n"); |
46 | start = idx + 1; |
46 | start = idx + 1; |
47 | } |
47 | } |
48 | idx++; |
48 | idx++; |
49 | } |
49 | } |
50 | html("</table>\n"); |
50 | html("</table>\n"); |
51 | } |
51 | } |
52 | |
52 | |
53 | |
53 | |
54 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
54 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
55 | const char *pathname, unsigned int mode, int stage) |
55 | const char *pathname, unsigned int mode, int stage) |
56 | { |
56 | { |
57 | char *name; |
57 | char *name; |
58 | char *fullpath; |
58 | char *fullpath; |
59 | enum object_type type; |
59 | enum object_type type; |
60 | unsigned long size = 0; |
60 | unsigned long size = 0; |
61 | char *url, *qry; |
61 | char *url, *qry; |
62 | |
62 | |
63 | name = xstrdup(pathname); |
63 | name = xstrdup(pathname); |
64 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", |
64 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", |
65 | cgit_query_path ? "/" : "", name); |
65 | cgit_query_path ? "/" : "", name); |
66 | |
66 | |
67 | type = sha1_object_info(sha1, &size); |
67 | type = sha1_object_info(sha1, &size); |
68 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { |
68 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { |
69 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
69 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
70 | name, |
70 | name, |
71 | sha1_to_hex(sha1)); |
71 | sha1_to_hex(sha1)); |
72 | return 0; |
72 | return 0; |
73 | } |
73 | } |
74 | |
74 | |
75 | html("<tr><td class='ls-mode'>"); |
75 | html("<tr><td class='ls-mode'>"); |
76 | html_filemode(mode); |
76 | html_filemode(mode); |
77 | html("</td><td>"); |
77 | html("</td><td>"); |
78 | if (S_ISDIRLNK(mode)) { |
78 | if (S_ISDIRLNK(mode)) { |
79 | htmlf("<a class='ls-mod' href='"); |
79 | htmlf("<a class='ls-mod' href='"); |
80 | html_attr(fmt(cgit_repo->module_link, |
80 | html_attr(fmt(cgit_repo->module_link, |
81 | name, |
81 | name, |
82 | sha1_to_hex(sha1))); |
82 | sha1_to_hex(sha1))); |
83 | html("'>"); |
83 | html("'>"); |
84 | html_txt(name); |
84 | html_txt(name); |
85 | html("</a>"); |
85 | html("</a>"); |
86 | } else if (S_ISDIR(mode)) { |
86 | } else if (S_ISDIR(mode)) { |
87 | cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, |
87 | cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, |
88 | curr_rev, fullpath); |
88 | curr_rev, fullpath); |
89 | } else { |
89 | } else { |
90 | cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, |
90 | cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, |
91 | curr_rev, fullpath); |
91 | curr_rev, fullpath); |
92 | } |
92 | } |
93 | htmlf("</td><td class='ls-size'>%li</td>", size); |
93 | htmlf("</td><td class='ls-size'>%li</td>", size); |
94 | |
94 | |
95 | html("<td><a href='"); |
95 | html("<td>"); |
96 | qry = fmt("h=%s&path=%s%s%s", curr_rev, |
96 | cgit_log_link("L", "Log", "button", cgit_query_head, curr_rev, |
97 | cgit_query_path ? cgit_query_path : "", |
97 | fullpath); |
98 | cgit_query_path ? "/" : "", pathname); |
98 | html("</td></tr>\n"); |
99 | url = cgit_pageurl(cgit_query_repo, "log", qry); |
| |
100 | html_attr(url); |
| |
101 | html("' title='Log' class='button'>L</a></td>"); |
| |
102 | html("</tr>\n"); |
| |
103 | free(name); |
99 | free(name); |
104 | return 0; |
100 | return 0; |
105 | } |
101 | } |
106 | |
102 | |
107 | static void ls_head() |
103 | static void ls_head() |
108 | { |
104 | { |
109 | html("<table class='list'>\n"); |
105 | html("<table class='list'>\n"); |
110 | html("<tr class='nohover'>"); |
106 | html("<tr class='nohover'>"); |
111 | html("<th class='left'>Mode</th>"); |
107 | html("<th class='left'>Mode</th>"); |
112 | html("<th class='left'>Name</th>"); |
108 | html("<th class='left'>Name</th>"); |
113 | html("<th class='right'>Size</th>"); |
109 | html("<th class='right'>Size</th>"); |
114 | html("<th/>"); |
110 | html("<th/>"); |
115 | html("</tr>\n"); |
111 | html("</tr>\n"); |
116 | header = 1; |
112 | header = 1; |
117 | } |
113 | } |
118 | |
114 | |
119 | static void ls_tail() |
115 | static void ls_tail() |
120 | { |
116 | { |
121 | if (!header) |
117 | if (!header) |
122 | return; |
118 | return; |
123 | html("</table>\n"); |
119 | html("</table>\n"); |
124 | header = 0; |
120 | header = 0; |
125 | } |
121 | } |
126 | |
122 | |
127 | static void ls_tree(const unsigned char *sha1, char *path) |
123 | static void ls_tree(const unsigned char *sha1, char *path) |
128 | { |
124 | { |
129 | struct tree *tree; |
125 | struct tree *tree; |
130 | |
126 | |
131 | tree = parse_tree_indirect(sha1); |
127 | tree = parse_tree_indirect(sha1); |
132 | if (!tree) { |
128 | if (!tree) { |
133 | cgit_print_error(fmt("Not a tree object: %s", |
129 | cgit_print_error(fmt("Not a tree object: %s", |
134 | sha1_to_hex(sha1))); |
130 | sha1_to_hex(sha1))); |
135 | return; |
131 | return; |
136 | } |
132 | } |
137 | |
133 | |
138 | ls_head(); |
134 | ls_head(); |
139 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); |
135 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); |
140 | ls_tail(); |
136 | ls_tail(); |
141 | } |
137 | } |
142 | |
138 | |
143 | |
139 | |
144 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
140 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
145 | const char *pathname, unsigned mode, int stage) |
141 | const char *pathname, unsigned mode, int stage) |
146 | { |
142 | { |
147 | static int state; |
143 | static int state; |
148 | static char buffer[PATH_MAX]; |
144 | static char buffer[PATH_MAX]; |
149 | char *url; |
145 | char *url; |
150 | |
146 | |
151 | if (state == 0) { |
147 | if (state == 0) { |
152 | memcpy(buffer, base, baselen); |
148 | memcpy(buffer, base, baselen); |
153 | strcpy(buffer+baselen, pathname); |
149 | strcpy(buffer+baselen, pathname); |
154 | url = cgit_pageurl(cgit_query_repo, "tree", |
150 | url = cgit_pageurl(cgit_query_repo, "tree", |
155 | fmt("h=%s&path=%s", curr_rev, buffer)); |
151 | fmt("h=%s&path=%s", curr_rev, buffer)); |
156 | html("/"); |
152 | html("/"); |
157 | cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, |
153 | cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, |
158 | curr_rev, buffer); |
154 | curr_rev, buffer); |
159 | |
155 | |
160 | if (strcmp(match_path, buffer)) |
156 | if (strcmp(match_path, buffer)) |
161 | return READ_TREE_RECURSIVE; |
157 | return READ_TREE_RECURSIVE; |
162 | |
158 | |
163 | if (S_ISDIR(mode)) { |
159 | if (S_ISDIR(mode)) { |
164 | state = 1; |
160 | state = 1; |
165 | ls_head(); |
161 | ls_head(); |
166 | return READ_TREE_RECURSIVE; |
162 | return READ_TREE_RECURSIVE; |
|