summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index d4376ce..fd71c12 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -197,48 +197,72 @@ void cgit_commit_link(char *name, char *title, char *class, char *head,
197} 197}
198 198
199void cgit_diff_link(char *name, char *title, char *class, char *head, 199void cgit_diff_link(char *name, char *title, char *class, char *head,
200 char *new_rev, char *old_rev, char *path) 200 char *new_rev, char *old_rev, char *path)
201{ 201{
202 char *delim; 202 char *delim;
203 203
204 delim = repolink(title, class, "diff", head, path); 204 delim = repolink(title, class, "diff", head, path);
205 if (new_rev && strcmp(new_rev, cgit_query_head)) { 205 if (new_rev && strcmp(new_rev, cgit_query_head)) {
206 html(delim); 206 html(delim);
207 html("id="); 207 html("id=");
208 html_attr(new_rev); 208 html_attr(new_rev);
209 delim = "&"; 209 delim = "&";
210 } 210 }
211 if (old_rev) { 211 if (old_rev) {
212 html(delim); 212 html(delim);
213 html("id2="); 213 html("id2=");
214 html_attr(old_rev); 214 html_attr(old_rev);
215 } 215 }
216 html("'>"); 216 html("'>");
217 html_txt(name); 217 html_txt(name);
218 html("</a>"); 218 html("</a>");
219} 219}
220 220
221void cgit_object_link(struct object *obj)
222{
223 char *page, *arg, *url;
224
225 if (obj->type == OBJ_COMMIT) {
226 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
227 cgit_query_head, sha1_to_hex(obj->sha1));
228 return;
229 } else if (obj->type == OBJ_TREE) {
230 page = "tree";
231 arg = "id";
232 } else {
233 page = "blob";
234 arg = "id";
235 }
236
237 url = cgit_pageurl(cgit_query_repo, page,
238 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
239 html_link_open(url, NULL, NULL);
240 htmlf("%s %s", typename(obj->type),
241 sha1_to_hex(obj->sha1));
242 html_link_close();
243}
244
221void cgit_print_date(time_t secs, char *format) 245void cgit_print_date(time_t secs, char *format)
222{ 246{
223 char buf[64]; 247 char buf[64];
224 struct tm *time; 248 struct tm *time;
225 249
226 time = gmtime(&secs); 250 time = gmtime(&secs);
227 strftime(buf, sizeof(buf)-1, format, time); 251 strftime(buf, sizeof(buf)-1, format, time);
228 html_txt(buf); 252 html_txt(buf);
229} 253}
230 254
231void cgit_print_age(time_t t, time_t max_relative, char *format) 255void cgit_print_age(time_t t, time_t max_relative, char *format)
232{ 256{
233 time_t now, secs; 257 time_t now, secs;
234 258
235 time(&now); 259 time(&now);
236 secs = now - t; 260 secs = now - t;
237 261
238 if (secs > max_relative && max_relative >= 0) { 262 if (secs > max_relative && max_relative >= 0) {
239 cgit_print_date(t, format); 263 cgit_print_date(t, format);
240 return; 264 return;
241 } 265 }
242 266
243 if (secs < TM_HOUR * 2) { 267 if (secs < TM_HOUR * 2) {
244 htmlf("<span class='age-mins'>%.0f min.</span>", 268 htmlf("<span class='age-mins'>%.0f min.</span>",