-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-shared.c | 24 |
2 files changed, 26 insertions, 0 deletions
@@ -161,79 +161,81 @@ extern int chk_non_negative(int result, char *msg); | |||
161 | 161 | ||
162 | extern int hextoint(char c); | 162 | extern int hextoint(char c); |
163 | extern char *trim_end(const char *str, char c); | 163 | extern char *trim_end(const char *str, char c); |
164 | 164 | ||
165 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 165 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
166 | 166 | ||
167 | extern int cgit_diff_files(const unsigned char *old_sha1, | 167 | extern int cgit_diff_files(const unsigned char *old_sha1, |
168 | const unsigned char *new_sha1, | 168 | const unsigned char *new_sha1, |
169 | linediff_fn fn); | 169 | linediff_fn fn); |
170 | 170 | ||
171 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 171 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
172 | const unsigned char *new_sha1, | 172 | const unsigned char *new_sha1, |
173 | filepair_fn fn); | 173 | filepair_fn fn); |
174 | 174 | ||
175 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 175 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
176 | 176 | ||
177 | extern char *fmt(const char *format,...); | 177 | extern char *fmt(const char *format,...); |
178 | 178 | ||
179 | extern void html(const char *txt); | 179 | extern void html(const char *txt); |
180 | extern void htmlf(const char *format,...); | 180 | extern void htmlf(const char *format,...); |
181 | extern void html_txt(char *txt); | 181 | extern void html_txt(char *txt); |
182 | extern void html_ntxt(int len, char *txt); | 182 | extern void html_ntxt(int len, char *txt); |
183 | extern void html_attr(char *txt); | 183 | extern void html_attr(char *txt); |
184 | extern void html_hidden(char *name, char *value); | 184 | extern void html_hidden(char *name, char *value); |
185 | extern void html_link_open(char *url, char *title, char *class); | 185 | extern void html_link_open(char *url, char *title, char *class); |
186 | extern void html_link_close(void); | 186 | extern void html_link_close(void); |
187 | extern void html_filemode(unsigned short mode); | 187 | extern void html_filemode(unsigned short mode); |
188 | extern int html_include(const char *filename); | 188 | extern int html_include(const char *filename); |
189 | 189 | ||
190 | extern int cgit_read_config(const char *filename, configfn fn); | 190 | extern int cgit_read_config(const char *filename, configfn fn); |
191 | extern int cgit_parse_query(char *txt, configfn fn); | 191 | extern int cgit_parse_query(char *txt, configfn fn); |
192 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 192 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
193 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 193 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
194 | extern void cgit_parse_url(const char *url); | 194 | extern void cgit_parse_url(const char *url); |
195 | 195 | ||
196 | extern char *cache_safe_filename(const char *unsafe); | 196 | extern char *cache_safe_filename(const char *unsafe); |
197 | extern int cache_lock(struct cacheitem *item); | 197 | extern int cache_lock(struct cacheitem *item); |
198 | extern int cache_unlock(struct cacheitem *item); | 198 | extern int cache_unlock(struct cacheitem *item); |
199 | extern int cache_cancel_lock(struct cacheitem *item); | 199 | extern int cache_cancel_lock(struct cacheitem *item); |
200 | extern int cache_exist(struct cacheitem *item); | 200 | extern int cache_exist(struct cacheitem *item); |
201 | extern int cache_expired(struct cacheitem *item); | 201 | extern int cache_expired(struct cacheitem *item); |
202 | 202 | ||
203 | extern char *cgit_repourl(const char *reponame); | 203 | extern char *cgit_repourl(const char *reponame); |
204 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 204 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
205 | const char *filename, const char *query); | 205 | const char *filename, const char *query); |
206 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 206 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
207 | const char *query); | 207 | const char *query); |
208 | 208 | ||
209 | extern const char *cgit_repobasename(const char *reponame); | ||
210 | |||
209 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 211 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
210 | char *rev, char *path); | 212 | char *rev, char *path); |
211 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 213 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
212 | char *rev, char *path, int ofs); | 214 | char *rev, char *path, int ofs); |
213 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 215 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
214 | char *rev); | 216 | char *rev); |
215 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 217 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
216 | char *new_rev, char *old_rev, char *path); | 218 | char *new_rev, char *old_rev, char *path); |
217 | 219 | ||
218 | extern void cgit_print_error(char *msg); | 220 | extern void cgit_print_error(char *msg); |
219 | extern void cgit_print_date(time_t secs, char *format); | 221 | extern void cgit_print_date(time_t secs, char *format); |
220 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 222 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
221 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 223 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
222 | extern void cgit_print_docend(); | 224 | extern void cgit_print_docend(); |
223 | extern void cgit_print_pageheader(char *title, int show_search); | 225 | extern void cgit_print_pageheader(char *title, int show_search); |
224 | extern void cgit_print_snapshot_start(const char *mimetype, | 226 | extern void cgit_print_snapshot_start(const char *mimetype, |
225 | const char *filename, | 227 | const char *filename, |
226 | struct cacheitem *item); | 228 | struct cacheitem *item); |
227 | 229 | ||
228 | extern void cgit_print_repolist(struct cacheitem *item); | 230 | extern void cgit_print_repolist(struct cacheitem *item); |
229 | extern void cgit_print_summary(); | 231 | extern void cgit_print_summary(); |
230 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 232 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
231 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 233 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
232 | extern void cgit_print_tree(const char *rev, char *path); | 234 | extern void cgit_print_tree(const char *rev, char *path); |
233 | extern void cgit_print_commit(char *hex); | 235 | extern void cgit_print_commit(char *hex); |
234 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); | 236 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); |
235 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 237 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
236 | const char *prefix, const char *filename); | 238 | const char *prefix, const char *filename); |
237 | extern void cgit_print_snapshot_links(const char *repo, const char *hex); | 239 | extern void cgit_print_snapshot_links(const char *repo, const char *hex); |
238 | 240 | ||
239 | #endif /* CGIT_H */ | 241 | #endif /* CGIT_H */ |
diff --git a/ui-shared.c b/ui-shared.c index 1c1415e..3e378a4 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -36,96 +36,120 @@ static long ttl_seconds(long ttl) | |||
36 | void cgit_print_error(char *msg) | 36 | void cgit_print_error(char *msg) |
37 | { | 37 | { |
38 | html("<div class='error'>"); | 38 | html("<div class='error'>"); |
39 | html_txt(msg); | 39 | html_txt(msg); |
40 | html("</div>\n"); | 40 | html("</div>\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | char *cgit_rooturl() | 43 | char *cgit_rooturl() |
44 | { | 44 | { |
45 | if (cgit_virtual_root) | 45 | if (cgit_virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 46 | return fmt("%s/", cgit_virtual_root); |
47 | else | 47 | else |
48 | return cgit_script_name; | 48 | return cgit_script_name; |
49 | } | 49 | } |
50 | 50 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
52 | { | 52 | { |
53 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | char *cgit_fileurl(const char *reponame, const char *pagename, | 60 | char *cgit_fileurl(const char *reponame, const char *pagename, |
61 | const char *filename, const char *query) | 61 | const char *filename, const char *query) |
62 | { | 62 | { |
63 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
64 | if (query) | 64 | if (query) |
65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, | 65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, |
66 | pagename, filename?filename:"", query); | 66 | pagename, filename?filename:"", query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | if (query) | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_pageurl(const char *reponame, const char *pagename, | 78 | char *cgit_pageurl(const char *reponame, const char *pagename, |
79 | const char *query) | 79 | const char *query) |
80 | { | 80 | { |
81 | return cgit_fileurl(reponame,pagename,0,query); | 81 | return cgit_fileurl(reponame,pagename,0,query); |
82 | } | 82 | } |
83 | 83 | ||
84 | const char *cgit_repobasename(const char *reponame) | ||
85 | { | ||
86 | /* I assume we don't need to store more than one repo basename */ | ||
87 | static char rvbuf[1024]; | ||
88 | int p; | ||
89 | const char *rv; | ||
90 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | ||
91 | if(rvbuf[sizeof(rvbuf)-1]) | ||
92 | die("cgit_repobasename: truncated repository name '%s'", reponame); | ||
93 | p = strlen(rvbuf)-1; | ||
94 | /* strip trailing slashes */ | ||
95 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | ||
96 | /* strip trailing .git */ | ||
97 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | ||
98 | p -= 3; rvbuf[p--] = 0; | ||
99 | } | ||
100 | /* strip more trailing slashes if any */ | ||
101 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | ||
102 | /* find last slash in the remaining string */ | ||
103 | rv = strrchr(rvbuf,'/'); | ||
104 | if(rv) | ||
105 | return ++rv; | ||
106 | return rvbuf; | ||
107 | } | ||
84 | 108 | ||
85 | char *cgit_currurl() | 109 | char *cgit_currurl() |
86 | { | 110 | { |
87 | if (!cgit_virtual_root) | 111 | if (!cgit_virtual_root) |
88 | return cgit_script_name; | 112 | return cgit_script_name; |
89 | else if (cgit_query_page) | 113 | else if (cgit_query_page) |
90 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 114 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
91 | else if (cgit_query_repo) | 115 | else if (cgit_query_repo) |
92 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 116 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
93 | else | 117 | else |
94 | return fmt("%s/", cgit_virtual_root); | 118 | return fmt("%s/", cgit_virtual_root); |
95 | } | 119 | } |
96 | 120 | ||
97 | static char *repolink(char *title, char *class, char *page, char *head, | 121 | static char *repolink(char *title, char *class, char *page, char *head, |
98 | char *path) | 122 | char *path) |
99 | { | 123 | { |
100 | char *delim = "?"; | 124 | char *delim = "?"; |
101 | 125 | ||
102 | html("<a"); | 126 | html("<a"); |
103 | if (title) { | 127 | if (title) { |
104 | html(" title='"); | 128 | html(" title='"); |
105 | html_attr(title); | 129 | html_attr(title); |
106 | html("'"); | 130 | html("'"); |
107 | } | 131 | } |
108 | if (class) { | 132 | if (class) { |
109 | html(" class='"); | 133 | html(" class='"); |
110 | html_attr(class); | 134 | html_attr(class); |
111 | html("'"); | 135 | html("'"); |
112 | } | 136 | } |
113 | html(" href='"); | 137 | html(" href='"); |
114 | if (cgit_virtual_root) { | 138 | if (cgit_virtual_root) { |
115 | html_attr(cgit_virtual_root); | 139 | html_attr(cgit_virtual_root); |
116 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') |
117 | html("/"); | 141 | html("/"); |
118 | html_attr(cgit_repo->url); | 142 | html_attr(cgit_repo->url); |
119 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
120 | html("/"); | 144 | html("/"); |
121 | if (page) { | 145 | if (page) { |
122 | html(page); | 146 | html(page); |
123 | html("/"); | 147 | html("/"); |
124 | if (path) | 148 | if (path) |
125 | html_attr(path); | 149 | html_attr(path); |
126 | } | 150 | } |
127 | } else { | 151 | } else { |
128 | html(cgit_script_name); | 152 | html(cgit_script_name); |
129 | html("?url="); | 153 | html("?url="); |
130 | html_attr(cgit_repo->url); | 154 | html_attr(cgit_repo->url); |
131 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |