|
diff --git a/html.c b/html.c index 33a956f..76fa6c4 100644 --- a/ html.c+++ b/ html.c |
|
@@ -97,86 +97,86 @@ void html_ntxt(int len, char *txt) |
97 | void html_attr(char *txt) |
97 | void html_attr(char *txt) |
98 | { |
98 | { |
99 | char *t = txt; |
99 | char *t = txt; |
100 | while(t && *t){ |
100 | while(t && *t){ |
101 | int c = *t; |
101 | int c = *t; |
102 | if (c=='<' || c=='>' || c=='\'') { |
102 | if (c=='<' || c=='>' || c=='\'') { |
103 | *t = '\0'; |
103 | *t = '\0'; |
104 | html(txt); |
104 | html(txt); |
105 | *t = c; |
105 | *t = c; |
106 | if (c=='>') |
106 | if (c=='>') |
107 | html(">"); |
107 | html(">"); |
108 | else if (c=='<') |
108 | else if (c=='<') |
109 | html("<"); |
109 | html("<"); |
110 | else if (c=='\'') |
110 | else if (c=='\'') |
111 | html(""e;"); |
111 | html(""e;"); |
112 | txt = t+1; |
112 | txt = t+1; |
113 | } |
113 | } |
114 | t++; |
114 | t++; |
115 | } |
115 | } |
116 | if (t!=txt) |
116 | if (t!=txt) |
117 | html(txt); |
117 | html(txt); |
118 | } |
118 | } |
119 | |
119 | |
120 | void html_hidden(char *name, char *value) |
120 | void html_hidden(char *name, char *value) |
121 | { |
121 | { |
122 | html("<input type='hidden' name='"); |
122 | html("<input type='hidden' name='"); |
123 | html_attr(name); |
123 | html_attr(name); |
124 | html("' value='"); |
124 | html("' value='"); |
125 | html_attr(value); |
125 | html_attr(value); |
126 | html("'/>"); |
126 | html("'/>"); |
127 | } |
127 | } |
128 | |
128 | |
129 | void html_link_open(char *url, char *title, char *class) |
129 | void html_link_open(char *url, char *title, char *class) |
130 | { |
130 | { |
131 | html("<a href='"); |
131 | html("<a href='"); |
132 | html_attr(url); |
132 | html_attr(url); |
133 | if (title) { |
133 | if (title) { |
134 | html("' title='"); |
134 | html("' title='"); |
135 | html_attr(title); |
135 | html_attr(title); |
136 | } |
136 | } |
137 | if (class) { |
137 | if (class) { |
138 | html("' class='"); |
138 | html("' class='"); |
139 | html_attr(class); |
139 | html_attr(class); |
140 | } |
140 | } |
141 | html("'>"); |
141 | html("'>"); |
142 | } |
142 | } |
143 | |
143 | |
144 | void html_link_close(void) |
144 | void html_link_close(void) |
145 | { |
145 | { |
146 | html("</a>"); |
146 | html("</a>"); |
147 | } |
147 | } |
148 | |
148 | |
149 | void html_fileperm(unsigned short mode) |
149 | void html_fileperm(unsigned short mode) |
150 | { |
150 | { |
151 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
151 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
152 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
152 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
153 | } |
153 | } |
154 | |
154 | |
155 | void html_filemode(unsigned short mode) |
155 | void html_filemode(unsigned short mode) |
156 | { |
156 | { |
157 | if (S_ISDIR(mode)) |
157 | if (S_ISDIR(mode)) |
158 | html("d"); |
158 | html("d"); |
159 | else if (S_ISLNK(mode)) |
159 | else if (S_ISLNK(mode)) |
160 | html("l"); |
160 | html("l"); |
161 | else if (S_ISDIRLNK(mode)) |
161 | else if (S_ISGITLINK(mode)) |
162 | html("m"); |
162 | html("m"); |
163 | else |
163 | else |
164 | html("-"); |
164 | html("-"); |
165 | html_fileperm(mode >> 6); |
165 | html_fileperm(mode >> 6); |
166 | html_fileperm(mode >> 3); |
166 | html_fileperm(mode >> 3); |
167 | html_fileperm(mode); |
167 | html_fileperm(mode); |
168 | } |
168 | } |
169 | |
169 | |
170 | int html_include(const char *filename) |
170 | int html_include(const char *filename) |
171 | { |
171 | { |
172 | FILE *f; |
172 | FILE *f; |
173 | char buf[4096]; |
173 | char buf[4096]; |
174 | size_t len; |
174 | size_t len; |
175 | |
175 | |
176 | if (!(f = fopen(filename, "r"))) |
176 | if (!(f = fopen(filename, "r"))) |
177 | return -1; |
177 | return -1; |
178 | while((len = fread(buf, 1, 4096, f)) > 0) |
178 | while((len = fread(buf, 1, 4096, f)) > 0) |
179 | write(htmlfd, buf, len); |
179 | write(htmlfd, buf, len); |
180 | fclose(f); |
180 | fclose(f); |
181 | return 0; |
181 | return 0; |
182 | } |
182 | } |
|
|
diff --git a/ui-diff.c b/ui-diff.c index e6b957c..4695e3a 100644 --- a/ ui-diff.c+++ b/ ui-diff.c |
|
@@ -1,142 +1,142 @@ |
1 | /* ui-diff.c: show diff between two blobs |
1 | /* ui-diff.c: show diff between two blobs |
2 | * |
2 | * |
3 | * Copyright (C) 2006 Lars Hjemli |
3 | * Copyright (C) 2006 Lars Hjemli |
4 | * |
4 | * |
5 | * Licensed under GNU General Public License v2 |
5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) |
6 | * (see COPYING for full license text) |
7 | */ |
7 | */ |
8 | |
8 | |
9 | #include "cgit.h" |
9 | #include "cgit.h" |
10 | |
10 | |
11 | |
11 | |
12 | /* |
12 | /* |
13 | * print a single line returned from xdiff |
13 | * print a single line returned from xdiff |
14 | */ |
14 | */ |
15 | static void print_line(char *line, int len) |
15 | static void print_line(char *line, int len) |
16 | { |
16 | { |
17 | char *class = "ctx"; |
17 | char *class = "ctx"; |
18 | char c = line[len-1]; |
18 | char c = line[len-1]; |
19 | |
19 | |
20 | if (line[0] == '+') |
20 | if (line[0] == '+') |
21 | class = "add"; |
21 | class = "add"; |
22 | else if (line[0] == '-') |
22 | else if (line[0] == '-') |
23 | class = "del"; |
23 | class = "del"; |
24 | else if (line[0] == '@') |
24 | else if (line[0] == '@') |
25 | class = "hunk"; |
25 | class = "hunk"; |
26 | |
26 | |
27 | htmlf("<div class='%s'>", class); |
27 | htmlf("<div class='%s'>", class); |
28 | line[len-1] = '\0'; |
28 | line[len-1] = '\0'; |
29 | html_txt(line); |
29 | html_txt(line); |
30 | html("</div>"); |
30 | html("</div>"); |
31 | line[len-1] = c; |
31 | line[len-1] = c; |
32 | } |
32 | } |
33 | |
33 | |
34 | static void header(unsigned char *sha1, char *path1, int mode1, |
34 | static void header(unsigned char *sha1, char *path1, int mode1, |
35 | unsigned char *sha2, char *path2, int mode2) |
35 | unsigned char *sha2, char *path2, int mode2) |
36 | { |
36 | { |
37 | char *abbrev1, *abbrev2; |
37 | char *abbrev1, *abbrev2; |
38 | int subproject; |
38 | int subproject; |
39 | |
39 | |
40 | subproject = (S_ISDIRLNK(mode1) || S_ISDIRLNK(mode2)); |
40 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); |
41 | html("<div class='head'>"); |
41 | html("<div class='head'>"); |
42 | html("diff --git a/"); |
42 | html("diff --git a/"); |
43 | html_txt(path1); |
43 | html_txt(path1); |
44 | html(" b/"); |
44 | html(" b/"); |
45 | html_txt(path2); |
45 | html_txt(path2); |
46 | |
46 | |
47 | if (is_null_sha1(sha1)) |
47 | if (is_null_sha1(sha1)) |
48 | path1 = "dev/null"; |
48 | path1 = "dev/null"; |
49 | if (is_null_sha1(sha2)) |
49 | if (is_null_sha1(sha2)) |
50 | path2 = "dev/null"; |
50 | path2 = "dev/null"; |
51 | |
51 | |
52 | if (mode1 == 0) |
52 | if (mode1 == 0) |
53 | htmlf("<br/>new file mode %.6o", mode2); |
53 | htmlf("<br/>new file mode %.6o", mode2); |
54 | |
54 | |
55 | if (mode2 == 0) |
55 | if (mode2 == 0) |
56 | htmlf("<br/>deleted file mode %.6o", mode1); |
56 | htmlf("<br/>deleted file mode %.6o", mode1); |
57 | |
57 | |
58 | if (!subproject) { |
58 | if (!subproject) { |
59 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
59 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
60 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
60 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
61 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); |
61 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); |
62 | free(abbrev1); |
62 | free(abbrev1); |
63 | free(abbrev2); |
63 | free(abbrev2); |
64 | if (mode1 != 0 && mode2 != 0) { |
64 | if (mode1 != 0 && mode2 != 0) { |
65 | htmlf(" %.6o", mode1); |
65 | htmlf(" %.6o", mode1); |
66 | if (mode2 != mode1) |
66 | if (mode2 != mode1) |
67 | htmlf("..%.6o", mode2); |
67 | htmlf("..%.6o", mode2); |
68 | } |
68 | } |
69 | html("<br/>--- a/"); |
69 | html("<br/>--- a/"); |
70 | html_txt(path1); |
70 | html_txt(path1); |
71 | html("<br/>+++ b/"); |
71 | html("<br/>+++ b/"); |
72 | html_txt(path2); |
72 | html_txt(path2); |
73 | } |
73 | } |
74 | html("</div>"); |
74 | html("</div>"); |
75 | } |
75 | } |
76 | |
76 | |
77 | static void filepair_cb(struct diff_filepair *pair) |
77 | static void filepair_cb(struct diff_filepair *pair) |
78 | { |
78 | { |
79 | header(pair->one->sha1, pair->one->path, pair->one->mode, |
79 | header(pair->one->sha1, pair->one->path, pair->one->mode, |
80 | pair->two->sha1, pair->two->path, pair->two->mode); |
80 | pair->two->sha1, pair->two->path, pair->two->mode); |
81 | if (S_ISDIRLNK(pair->one->mode) || S_ISDIRLNK(pair->two->mode)) { |
81 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { |
82 | if (S_ISDIRLNK(pair->one->mode)) |
82 | if (S_ISGITLINK(pair->one->mode)) |
83 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
83 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
84 | if (S_ISDIRLNK(pair->two->mode)) |
84 | if (S_ISGITLINK(pair->two->mode)) |
85 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
85 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
86 | return; |
86 | return; |
87 | } |
87 | } |
88 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) |
88 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) |
89 | cgit_print_error("Error running diff"); |
89 | cgit_print_error("Error running diff"); |
90 | } |
90 | } |
91 | |
91 | |
92 | void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path) |
92 | void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path) |
93 | { |
93 | { |
94 | unsigned char sha1[20], sha2[20]; |
94 | unsigned char sha1[20], sha2[20]; |
95 | enum object_type type; |
95 | enum object_type type; |
96 | unsigned long size; |
96 | unsigned long size; |
97 | struct commit *commit; |
97 | struct commit *commit; |
98 | |
98 | |
99 | if (head && !old_hex && !new_hex) { |
99 | if (head && !old_hex && !new_hex) { |
100 | get_sha1(head, sha1); |
100 | get_sha1(head, sha1); |
101 | commit = lookup_commit_reference(sha1); |
101 | commit = lookup_commit_reference(sha1); |
102 | if (commit && !parse_commit(commit)) { |
102 | if (commit && !parse_commit(commit)) { |
103 | html("<table class='diff'>"); |
103 | html("<table class='diff'>"); |
104 | html("<tr><td>"); |
104 | html("<tr><td>"); |
105 | cgit_diff_commit(commit, filepair_cb); |
105 | cgit_diff_commit(commit, filepair_cb); |
106 | html("</td></tr>"); |
106 | html("</td></tr>"); |
107 | html("</table>"); |
107 | html("</table>"); |
108 | } |
108 | } |
109 | return; |
109 | return; |
110 | } |
110 | } |
111 | |
111 | |
112 | get_sha1(old_hex, sha1); |
112 | get_sha1(old_hex, sha1); |
113 | get_sha1(new_hex, sha2); |
113 | get_sha1(new_hex, sha2); |
114 | |
114 | |
115 | type = sha1_object_info(sha1, &size); |
115 | type = sha1_object_info(sha1, &size); |
116 | if (type == OBJ_BAD) { |
116 | if (type == OBJ_BAD) { |
117 | type = sha1_object_info(sha2, &size); |
117 | type = sha1_object_info(sha2, &size); |
118 | if (type == OBJ_BAD) { |
118 | if (type == OBJ_BAD) { |
119 | cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex)); |
119 | cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex)); |
120 | return; |
120 | return; |
121 | } |
121 | } |
122 | } |
122 | } |
123 | |
123 | |
124 | html("<table class='diff'>"); |
124 | html("<table class='diff'>"); |
125 | switch(type) { |
125 | switch(type) { |
126 | case OBJ_BLOB: |
126 | case OBJ_BLOB: |
127 | html("<tr><td>"); |
127 | html("<tr><td>"); |
128 | header(sha1, path, 0644, sha2, path, 0644); |
128 | header(sha1, path, 0644, sha2, path, 0644); |
129 | if (cgit_diff_files(sha1, sha2, print_line)) |
129 | if (cgit_diff_files(sha1, sha2, print_line)) |
130 | cgit_print_error("Error running diff"); |
130 | cgit_print_error("Error running diff"); |
131 | html("</td></tr>"); |
131 | html("</td></tr>"); |
132 | break; |
132 | break; |
133 | case OBJ_TREE: |
133 | case OBJ_TREE: |
134 | cgit_diff_tree(sha1, sha2, filepair_cb); |
134 | cgit_diff_tree(sha1, sha2, filepair_cb); |
135 | break; |
135 | break; |
136 | default: |
136 | default: |
137 | cgit_print_error(fmt("Unhandled object type: %s", |
137 | cgit_print_error(fmt("Unhandled object type: %s", |
138 | typename(type))); |
138 | typename(type))); |
139 | break; |
139 | break; |
140 | } |
140 | } |
141 | html("</table>"); |
141 | html("</table>"); |
142 | } |
142 | } |
|
|
diff --git a/ui-tree.c b/ui-tree.c index cb57d8d..21dd533 100644 --- a/ ui-tree.c+++ b/ ui-tree.c |
|
@@ -1,96 +1,96 @@ |
1 | /* ui-tree.c: functions for tree output |
1 | /* ui-tree.c: functions for tree output |
2 | * |
2 | * |
3 | * Copyright (C) 2006 Lars Hjemli |
3 | * Copyright (C) 2006 Lars Hjemli |
4 | * |
4 | * |
5 | * Licensed under GNU General Public License v2 |
5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) |
6 | * (see COPYING for full license text) |
7 | */ |
7 | */ |
8 | |
8 | |
9 | #include "cgit.h" |
9 | #include "cgit.h" |
10 | |
10 | |
11 | char *curr_rev; |
11 | char *curr_rev; |
12 | |
12 | |
13 | static int print_entry(const unsigned char *sha1, const char *base, |
13 | static int print_entry(const unsigned char *sha1, const char *base, |
14 | int baselen, const char *pathname, unsigned int mode, |
14 | int baselen, const char *pathname, unsigned int mode, |
15 | int stage) |
15 | int stage) |
16 | { |
16 | { |
17 | char *name; |
17 | char *name; |
18 | enum object_type type; |
18 | enum object_type type; |
19 | unsigned long size = 0; |
19 | unsigned long size = 0; |
20 | |
20 | |
21 | name = xstrdup(pathname); |
21 | name = xstrdup(pathname); |
22 | type = sha1_object_info(sha1, &size); |
22 | type = sha1_object_info(sha1, &size); |
23 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { |
23 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { |
24 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
24 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
25 | name, |
25 | name, |
26 | sha1_to_hex(sha1)); |
26 | sha1_to_hex(sha1)); |
27 | return 0; |
27 | return 0; |
28 | } |
28 | } |
29 | html("<tr><td class='filemode'>"); |
29 | html("<tr><td class='filemode'>"); |
30 | html_filemode(mode); |
30 | html_filemode(mode); |
31 | html("</td><td "); |
31 | html("</td><td "); |
32 | if (S_ISDIRLNK(mode)) { |
32 | if (S_ISGITLINK(mode)) { |
33 | htmlf("class='ls-mod'><a href='"); |
33 | htmlf("class='ls-mod'><a href='"); |
34 | html_attr(fmt(cgit_repo->module_link, |
34 | html_attr(fmt(cgit_repo->module_link, |
35 | name, |
35 | name, |
36 | sha1_to_hex(sha1))); |
36 | sha1_to_hex(sha1))); |
37 | } else if (S_ISDIR(mode)) { |
37 | } else if (S_ISDIR(mode)) { |
38 | html("class='ls-dir'><a href='"); |
38 | html("class='ls-dir'><a href='"); |
39 | html_attr(cgit_pageurl(cgit_query_repo, "tree", |
39 | html_attr(cgit_pageurl(cgit_query_repo, "tree", |
40 | fmt("h=%s&id=%s&path=%s%s/", |
40 | fmt("h=%s&id=%s&path=%s%s/", |
41 | curr_rev, |
41 | curr_rev, |
42 | sha1_to_hex(sha1), |
42 | sha1_to_hex(sha1), |
43 | cgit_query_path ? cgit_query_path : "", |
43 | cgit_query_path ? cgit_query_path : "", |
44 | pathname))); |
44 | pathname))); |
45 | } else { |
45 | } else { |
46 | html("class='ls-blob'><a href='"); |
46 | html("class='ls-blob'><a href='"); |
47 | html_attr(cgit_pageurl(cgit_query_repo, "view", |
47 | html_attr(cgit_pageurl(cgit_query_repo, "view", |
48 | fmt("h=%s&id=%s&path=%s%s", curr_rev, |
48 | fmt("h=%s&id=%s&path=%s%s", curr_rev, |
49 | sha1_to_hex(sha1), |
49 | sha1_to_hex(sha1), |
50 | cgit_query_path ? cgit_query_path : "", |
50 | cgit_query_path ? cgit_query_path : "", |
51 | pathname))); |
51 | pathname))); |
52 | } |
52 | } |
53 | htmlf("'>%s</a></td>", name); |
53 | htmlf("'>%s</a></td>", name); |
54 | htmlf("<td class='filesize'>%li</td>", size); |
54 | htmlf("<td class='filesize'>%li</td>", size); |
55 | |
55 | |
56 | html("<td class='links'><a href='"); |
56 | html("<td class='links'><a href='"); |
57 | html_attr(cgit_pageurl(cgit_query_repo, "log", |
57 | html_attr(cgit_pageurl(cgit_query_repo, "log", |
58 | fmt("h=%s&path=%s%s", |
58 | fmt("h=%s&path=%s%s", |
59 | curr_rev, |
59 | curr_rev, |
60 | cgit_query_path ? cgit_query_path : "", |
60 | cgit_query_path ? cgit_query_path : "", |
61 | pathname))); |
61 | pathname))); |
62 | html("'>history</a></td>"); |
62 | html("'>history</a></td>"); |
63 | html("</tr>\n"); |
63 | html("</tr>\n"); |
64 | free(name); |
64 | free(name); |
65 | return 0; |
65 | return 0; |
66 | } |
66 | } |
67 | |
67 | |
68 | void cgit_print_tree(const char *rev, const char *hex, char *path) |
68 | void cgit_print_tree(const char *rev, const char *hex, char *path) |
69 | { |
69 | { |
70 | struct tree *tree; |
70 | struct tree *tree; |
71 | unsigned char sha1[20]; |
71 | unsigned char sha1[20]; |
72 | struct commit *commit; |
72 | struct commit *commit; |
73 | |
73 | |
74 | curr_rev = xstrdup(rev); |
74 | curr_rev = xstrdup(rev); |
75 | get_sha1(rev, sha1); |
75 | get_sha1(rev, sha1); |
76 | commit = lookup_commit_reference(sha1); |
76 | commit = lookup_commit_reference(sha1); |
77 | if (!commit || parse_commit(commit)) { |
77 | if (!commit || parse_commit(commit)) { |
78 | cgit_print_error(fmt("Invalid head: %s", rev)); |
78 | cgit_print_error(fmt("Invalid head: %s", rev)); |
79 | return; |
79 | return; |
80 | } |
80 | } |
81 | if (!hex) |
81 | if (!hex) |
82 | hex = sha1_to_hex(commit->tree->object.sha1); |
82 | hex = sha1_to_hex(commit->tree->object.sha1); |
83 | |
83 | |
84 | if (get_sha1_hex(hex, sha1)) { |
84 | if (get_sha1_hex(hex, sha1)) { |
85 | cgit_print_error(fmt("Invalid object id: %s", hex)); |
85 | cgit_print_error(fmt("Invalid object id: %s", hex)); |
86 | return; |
86 | return; |
87 | } |
87 | } |
88 | tree = parse_tree_indirect(sha1); |
88 | tree = parse_tree_indirect(sha1); |
89 | if (!tree) { |
89 | if (!tree) { |
90 | cgit_print_error(fmt("Not a tree object: %s", hex)); |
90 | cgit_print_error(fmt("Not a tree object: %s", hex)); |
91 | return; |
91 | return; |
92 | } |
92 | } |
93 | |
93 | |
94 | html_txt(path); |
94 | html_txt(path); |
95 | html("<table class='list'>\n"); |
95 | html("<table class='list'>\n"); |
96 | html("<tr class='nohover'>"); |
96 | html("<tr class='nohover'>"); |
|