author | Jeffrey C. Ollie <jeff@ocjtech.us> | 2007-06-04 17:28:56 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-06-04 17:58:32 (UTC) |
commit | e651cb0d2dc2dbd458c51cdba8ae56e8629348cc (patch) (unidiff) | |
tree | da70e147ef829797f0c152883abc59f8b40b1407 | |
parent | 51a960a3ca6b0cade97db287a342996c3e1de48d (diff) | |
download | cgit-e651cb0d2dc2dbd458c51cdba8ae56e8629348cc.zip cgit-e651cb0d2dc2dbd458c51cdba8ae56e8629348cc.tar.gz cgit-e651cb0d2dc2dbd458c51cdba8ae56e8629348cc.tar.bz2 |
Rename dirlink to gitlink.
Git changed from dirlink to gitlink in
302b9282c9ddfcc704ca759bdc98c1d5f75eba2f.
Signed-off-by: Jeffrey C. Ollie <jeff@ocjtech.us>
-rw-r--r-- | html.c | 2 | ||||
-rw-r--r-- | ui-diff.c | 8 | ||||
-rw-r--r-- | ui-tree.c | 4 |
3 files changed, 7 insertions, 7 deletions
@@ -1,182 +1,182 @@ | |||
1 | /* html.c: helper functions for html output | 1 | /* html.c: helper functions for html 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 *fmt(const char *format, ...) | 11 | char *fmt(const char *format, ...) |
12 | { | 12 | { |
13 | static char buf[8][1024]; | 13 | static char buf[8][1024]; |
14 | static int bufidx; | 14 | static int bufidx; |
15 | int len; | 15 | int len; |
16 | va_list args; | 16 | va_list args; |
17 | 17 | ||
18 | bufidx++; | 18 | bufidx++; |
19 | bufidx &= 7; | 19 | bufidx &= 7; |
20 | 20 | ||
21 | va_start(args, format); | 21 | va_start(args, format); |
22 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); | 22 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
23 | va_end(args); | 23 | va_end(args); |
24 | if (len>sizeof(buf[bufidx])) | 24 | if (len>sizeof(buf[bufidx])) |
25 | die("[html.c] string truncated: %s", format); | 25 | die("[html.c] string truncated: %s", format); |
26 | return buf[bufidx]; | 26 | return buf[bufidx]; |
27 | } | 27 | } |
28 | 28 | ||
29 | void html(const char *txt) | 29 | void html(const char *txt) |
30 | { | 30 | { |
31 | write(htmlfd, txt, strlen(txt)); | 31 | write(htmlfd, txt, strlen(txt)); |
32 | } | 32 | } |
33 | 33 | ||
34 | void htmlf(const char *format, ...) | 34 | void htmlf(const char *format, ...) |
35 | { | 35 | { |
36 | static char buf[65536]; | 36 | static char buf[65536]; |
37 | va_list args; | 37 | va_list args; |
38 | 38 | ||
39 | va_start(args, format); | 39 | va_start(args, format); |
40 | vsnprintf(buf, sizeof(buf), format, args); | 40 | vsnprintf(buf, sizeof(buf), format, args); |
41 | va_end(args); | 41 | va_end(args); |
42 | html(buf); | 42 | html(buf); |
43 | } | 43 | } |
44 | 44 | ||
45 | void html_txt(char *txt) | 45 | void html_txt(char *txt) |
46 | { | 46 | { |
47 | char *t = txt; | 47 | char *t = txt; |
48 | while(t && *t){ | 48 | while(t && *t){ |
49 | int c = *t; | 49 | int c = *t; |
50 | if (c=='<' || c=='>' || c=='&') { | 50 | if (c=='<' || c=='>' || c=='&') { |
51 | *t = '\0'; | 51 | *t = '\0'; |
52 | html(txt); | 52 | html(txt); |
53 | *t = c; | 53 | *t = c; |
54 | if (c=='>') | 54 | if (c=='>') |
55 | html(">"); | 55 | html(">"); |
56 | else if (c=='<') | 56 | else if (c=='<') |
57 | html("<"); | 57 | html("<"); |
58 | else if (c=='&') | 58 | else if (c=='&') |
59 | html("&"); | 59 | html("&"); |
60 | txt = t+1; | 60 | txt = t+1; |
61 | } | 61 | } |
62 | t++; | 62 | t++; |
63 | } | 63 | } |
64 | if (t!=txt) | 64 | if (t!=txt) |
65 | html(txt); | 65 | html(txt); |
66 | } | 66 | } |
67 | 67 | ||
68 | void html_ntxt(int len, char *txt) | 68 | void html_ntxt(int len, char *txt) |
69 | { | 69 | { |
70 | char *t = txt; | 70 | char *t = txt; |
71 | while(t && *t && len--){ | 71 | while(t && *t && len--){ |
72 | int c = *t; | 72 | int c = *t; |
73 | if (c=='<' || c=='>' || c=='&') { | 73 | if (c=='<' || c=='>' || c=='&') { |
74 | *t = '\0'; | 74 | *t = '\0'; |
75 | html(txt); | 75 | html(txt); |
76 | *t = c; | 76 | *t = c; |
77 | if (c=='>') | 77 | if (c=='>') |
78 | html(">"); | 78 | html(">"); |
79 | else if (c=='<') | 79 | else if (c=='<') |
80 | html("<"); | 80 | html("<"); |
81 | else if (c=='&') | 81 | else if (c=='&') |
82 | html("&"); | 82 | html("&"); |
83 | txt = t+1; | 83 | txt = t+1; |
84 | } | 84 | } |
85 | t++; | 85 | t++; |
86 | } | 86 | } |
87 | if (t!=txt) { | 87 | if (t!=txt) { |
88 | char c = *t; | 88 | char c = *t; |
89 | *t = '\0'; | 89 | *t = '\0'; |
90 | html(txt); | 90 | html(txt); |
91 | *t = c; | 91 | *t = c; |
92 | } | 92 | } |
93 | if (len<0) | 93 | if (len<0) |
94 | html("..."); | 94 | html("..."); |
95 | } | 95 | } |
96 | 96 | ||
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 | } |
@@ -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 | } |
@@ -1,104 +1,104 @@ | |||
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'>"); |
97 | html("<th class='left'>Mode</th>"); | 97 | html("<th class='left'>Mode</th>"); |
98 | html("<th class='left'>Name</th>"); | 98 | html("<th class='left'>Name</th>"); |
99 | html("<th class='right'>Size</th>"); | 99 | html("<th class='right'>Size</th>"); |
100 | html("<th/>"); | 100 | html("<th/>"); |
101 | html("</tr>\n"); | 101 | html("</tr>\n"); |
102 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); | 102 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); |
103 | html("</table>\n"); | 103 | html("</table>\n"); |
104 | } | 104 | } |