diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cgit.c | 5 | ||||
-rw-r--r-- | cgit.css | 16 | ||||
-rw-r--r-- | cgit.h | 8 | ||||
-rw-r--r-- | shared.c | 3 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-tree.c | 194 | ||||
-rw-r--r-- | ui-view.c | 55 |
8 files changed, 174 insertions, 112 deletions
@@ -14,7 +14,7 @@ CGIT_SCRIPT_NAME = cgit.cgi | |||
14 | 14 | ||
15 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 15 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto |
16 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 16 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
17 | ui-summary.o ui-log.o ui-view.o ui-tree.o ui-commit.o ui-diff.o \ | 17 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ |
18 | ui-snapshot.o ui-blob.o | 18 | ui-snapshot.o ui-blob.o |
19 | 19 | ||
20 | CFLAGS += -Wall | 20 | CFLAGS += -Wall |
@@ -97,14 +97,11 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
97 | cgit_query_path, 1); | 97 | cgit_query_path, 1); |
98 | break; | 98 | break; |
99 | case CMD_TREE: | 99 | case CMD_TREE: |
100 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); | 100 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
101 | break; | 101 | break; |
102 | case CMD_COMMIT: | 102 | case CMD_COMMIT: |
103 | cgit_print_commit(cgit_query_head); | 103 | cgit_print_commit(cgit_query_head); |
104 | break; | 104 | break; |
105 | case CMD_VIEW: | ||
106 | cgit_print_view(cgit_query_sha1, cgit_query_path); | ||
107 | break; | ||
108 | case CMD_DIFF: | 105 | case CMD_DIFF: |
109 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, | 106 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, |
110 | cgit_query_path); | 107 | cgit_query_path); |
@@ -199,10 +199,22 @@ td.filemode { | |||
199 | font-family: monospace; | 199 | font-family: monospace; |
200 | } | 200 | } |
201 | 201 | ||
202 | td.blob { | 202 | table.blob { |
203 | margin-top: 0.5em; | ||
204 | border-top: solid 1px black; | ||
205 | } | ||
206 | |||
207 | table.blob td.no { | ||
208 | border-right: solid 1px black; | ||
209 | color: black; | ||
210 | background-color: #eee; | ||
211 | text-align: right; | ||
212 | } | ||
213 | |||
214 | table.blob td.txt { | ||
203 | white-space: pre; | 215 | white-space: pre; |
204 | font-family: monospace; | 216 | font-family: monospace; |
205 | background-color: white; | 217 | padding-left: 0.5em; |
206 | } | 218 | } |
207 | 219 | ||
208 | table.nowrap td { | 220 | table.nowrap td { |
@@ -25,9 +25,8 @@ | |||
25 | #define CMD_COMMIT 2 | 25 | #define CMD_COMMIT 2 |
26 | #define CMD_DIFF 3 | 26 | #define CMD_DIFF 3 |
27 | #define CMD_TREE 4 | 27 | #define CMD_TREE 4 |
28 | #define CMD_VIEW 5 | 28 | #define CMD_BLOB 5 |
29 | #define CMD_BLOB 6 | 29 | #define CMD_SNAPSHOT 6 |
30 | #define CMD_SNAPSHOT 7 | ||
31 | 30 | ||
32 | 31 | ||
33 | /* | 32 | /* |
@@ -215,9 +214,8 @@ extern void cgit_print_snapshot_start(const char *mimetype, | |||
215 | extern void cgit_print_repolist(struct cacheitem *item); | 214 | extern void cgit_print_repolist(struct cacheitem *item); |
216 | extern void cgit_print_summary(); | 215 | extern void cgit_print_summary(); |
217 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 216 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
218 | extern void cgit_print_view(const char *hex, char *path); | ||
219 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 217 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
220 | extern void cgit_print_tree(const char *rev, const char *hex, char *path); | 218 | extern void cgit_print_tree(const char *rev, char *path); |
221 | extern void cgit_print_commit(const char *hex); | 219 | extern void cgit_print_commit(const char *hex); |
222 | extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, | 220 | extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, |
223 | char *path); | 221 | char *path); |
@@ -59,7 +59,8 @@ int htmlfd = 0; | |||
59 | 59 | ||
60 | int cgit_get_cmd_index(const char *cmd) | 60 | int cgit_get_cmd_index(const char *cmd) |
61 | { | 61 | { |
62 | static char *cmds[] = {"log", "commit", "diff", "tree", "view", "blob", "snapshot", NULL}; | 62 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
63 | "snapshot", NULL}; | ||
63 | int i; | 64 | int i; |
64 | 65 | ||
65 | for(i = 0; cmds[i]; i++) | 66 | for(i = 0; cmds[i]; i++) |
diff --git a/ui-commit.c b/ui-commit.c index 1d12bbb..ed5384d 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -182,8 +182,7 @@ void cgit_print_commit(const char *hex) | |||
182 | cgit_print_date(info->committer_date, FMT_LONGDATE); | 182 | cgit_print_date(info->committer_date, FMT_LONGDATE); |
183 | html("</td></tr>\n"); | 183 | html("</td></tr>\n"); |
184 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); | 184 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); |
185 | query = fmt("h=%s&id=%s", sha1_to_hex(commit->object.sha1), | 185 | query = fmt("h=%s", sha1_to_hex(commit->object.sha1)); |
186 | sha1_to_hex(commit->tree->object.sha1)); | ||
187 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); | 186 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); |
188 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); | 187 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); |
189 | for (p = commit->parents; p ; p = p->next) { | 188 | for (p = commit->parents; p ; p = p->next) { |
@@ -9,14 +9,56 @@ | |||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | char *curr_rev; | 11 | char *curr_rev; |
12 | char *match_path; | ||
13 | int header = 0; | ||
12 | 14 | ||
13 | static int print_entry(const unsigned char *sha1, const char *base, | 15 | static void print_object(const unsigned char *sha1, char *path) |
14 | int baselen, const char *pathname, unsigned int mode, | 16 | { |
15 | int stage) | 17 | enum object_type type; |
18 | unsigned char *buf; | ||
19 | unsigned long size, lineno, start, idx; | ||
20 | |||
21 | type = sha1_object_info(sha1, &size); | ||
22 | if (type == OBJ_BAD) { | ||
23 | cgit_print_error(fmt("Bad object name: %s", | ||
24 | sha1_to_hex(sha1))); | ||
25 | return; | ||
26 | } | ||
27 | |||
28 | buf = read_sha1_file(sha1, &type, &size); | ||
29 | if (!buf) { | ||
30 | cgit_print_error(fmt("Error reading object %s", | ||
31 | sha1_to_hex(sha1))); | ||
32 | return; | ||
33 | } | ||
34 | |||
35 | html("<table class='blob'>\n"); | ||
36 | idx = 0; | ||
37 | start = 0; | ||
38 | lineno = 0; | ||
39 | while(idx < size) { | ||
40 | if (buf[idx] == '\n') { | ||
41 | buf[idx] = '\0'; | ||
42 | htmlf("<tr><td class='no'>%d</td><td class='txt'>", | ||
43 | ++lineno); | ||
44 | html_txt(buf + start); | ||
45 | html("</td></tr>\n"); | ||
46 | start = idx + 1; | ||
47 | } | ||
48 | idx++; | ||
49 | } | ||
50 | html("\n</td></tr>\n"); | ||
51 | html("</table>\n"); | ||
52 | } | ||
53 | |||
54 | |||
55 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, | ||
56 | const char *pathname, unsigned int mode, int stage) | ||
16 | { | 57 | { |
17 | char *name; | 58 | char *name; |
18 | enum object_type type; | 59 | enum object_type type; |
19 | unsigned long size = 0; | 60 | unsigned long size = 0; |
61 | char *url, *qry; | ||
20 | 62 | ||
21 | name = xstrdup(pathname); | 63 | name = xstrdup(pathname); |
22 | type = sha1_object_info(sha1, &size); | 64 | type = sha1_object_info(sha1, &size); |
@@ -26,6 +68,10 @@ static int print_entry(const unsigned char *sha1, const char *base, | |||
26 | sha1_to_hex(sha1)); | 68 | sha1_to_hex(sha1)); |
27 | return 0; | 69 | return 0; |
28 | } | 70 | } |
71 | qry = fmt("h=%s&path=%s%s%s", curr_rev, | ||
72 | cgit_query_path ? cgit_query_path : "", | ||
73 | cgit_query_path ? "/" : "", pathname); | ||
74 | url = cgit_pageurl(cgit_query_repo, "tree", qry); | ||
29 | html("<tr><td class='filemode'>"); | 75 | html("<tr><td class='filemode'>"); |
30 | html_filemode(mode); | 76 | html_filemode(mode); |
31 | html("</td><td "); | 77 | html("</td><td "); |
@@ -36,69 +82,133 @@ static int print_entry(const unsigned char *sha1, const char *base, | |||
36 | sha1_to_hex(sha1))); | 82 | sha1_to_hex(sha1))); |
37 | } else if (S_ISDIR(mode)) { | 83 | } else if (S_ISDIR(mode)) { |
38 | html("class='ls-dir'><a href='"); | 84 | html("class='ls-dir'><a href='"); |
39 | html_attr(cgit_pageurl(cgit_query_repo, "tree", | 85 | html_attr(url); |
40 | fmt("h=%s&id=%s&path=%s%s/", | ||
41 | curr_rev, | ||
42 | sha1_to_hex(sha1), | ||
43 | cgit_query_path ? cgit_query_path : "", | ||
44 | pathname))); | ||
45 | } else { | 86 | } else { |
46 | html("class='ls-blob'><a href='"); | 87 | html("class='ls-blob'><a href='"); |
47 | html_attr(cgit_pageurl(cgit_query_repo, "view", | 88 | html_attr(url); |
48 | fmt("h=%s&id=%s&path=%s%s", curr_rev, | ||
49 | sha1_to_hex(sha1), | ||
50 | cgit_query_path ? cgit_query_path : "", | ||
51 | pathname))); | ||
52 | } | 89 | } |
53 | htmlf("'>%s</a></td>", name); | 90 | htmlf("'>%s</a></td>", name); |
54 | htmlf("<td class='filesize'>%li</td>", size); | 91 | htmlf("<td class='filesize'>%li</td>", size); |
55 | 92 | ||
56 | html("<td class='links'><a href='"); | 93 | html("<td class='links'><a href='"); |
57 | html_attr(cgit_pageurl(cgit_query_repo, "log", | 94 | qry = fmt("h=%s&path=%s%s%s", curr_rev, |
58 | fmt("h=%s&path=%s%s", | 95 | cgit_query_path ? cgit_query_path : "", |
59 | curr_rev, | 96 | cgit_query_path ? "/" : "", pathname); |
60 | cgit_query_path ? cgit_query_path : "", | 97 | url = cgit_pageurl(cgit_query_repo, "log", qry); |
61 | pathname))); | 98 | html_attr(url); |
62 | html("'>history</a></td>"); | 99 | html("' class='button'>H</a></td>"); |
63 | html("</tr>\n"); | 100 | html("</tr>\n"); |
64 | free(name); | 101 | free(name); |
65 | return 0; | 102 | return 0; |
66 | } | 103 | } |
67 | 104 | ||
68 | void cgit_print_tree(const char *rev, const char *hex, char *path) | 105 | static void ls_head() |
106 | { | ||
107 | html("<table class='list'>\n"); | ||
108 | html("<tr class='nohover'>"); | ||
109 | html("<th class='left'>Mode</th>"); | ||
110 | html("<th class='left'>Name</th>"); | ||
111 | html("<th class='right'>Size</th>"); | ||
112 | html("<th/>"); | ||
113 | html("</tr>\n"); | ||
114 | header = 1; | ||
115 | } | ||
116 | |||
117 | static void ls_tail() | ||
118 | { | ||
119 | if (!header) | ||
120 | return; | ||
121 | html("</table>\n"); | ||
122 | header = 0; | ||
123 | } | ||
124 | |||
125 | static void ls_tree(const unsigned char *sha1, char *path) | ||
69 | { | 126 | { |
70 | struct tree *tree; | 127 | struct tree *tree; |
128 | |||
129 | tree = parse_tree_indirect(sha1); | ||
130 | if (!tree) { | ||
131 | cgit_print_error(fmt("Not a tree object: %s", | ||
132 | sha1_to_hex(sha1))); | ||
133 | return; | ||
134 | } | ||
135 | |||
136 | ls_head(); | ||
137 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); | ||
138 | ls_tail(); | ||
139 | } | ||
140 | |||
141 | |||
142 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | ||
143 | const char *pathname, unsigned mode, int stage) | ||
144 | { | ||
145 | static int state; | ||
146 | static char buffer[PATH_MAX]; | ||
147 | char *url; | ||
148 | |||
149 | if (state == 0) { | ||
150 | memcpy(buffer, base, baselen); | ||