blob: 88734158ed95bb636c5ad10ad43e8f3cb7597881 [file] [log] [blame]
Lars Hjemlidf631192006-12-11 17:12:26 +01001/* ui-view.c: functions to output _any_ object, given it's sha1
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
10
Lars Hjemli7250a152007-05-08 23:52:56 +020011void cgit_print_view(const char *hex, char *path)
Lars Hjemlidf631192006-12-11 17:12:26 +010012{
13 unsigned char sha1[20];
Lars Hjemli61c3ca92007-05-08 22:40:59 +020014 enum object_type type;
Lars Hjemlidf631192006-12-11 17:12:26 +010015 unsigned char *buf;
16 unsigned long size;
17
18 if (get_sha1_hex(hex, sha1)){
19 cgit_print_error(fmt("Bad hex value: %s", hex));
20 return;
21 }
22
Lars Hjemli61c3ca92007-05-08 22:40:59 +020023 type = sha1_object_info(sha1, &size);
24 if (type == OBJ_BAD) {
25 cgit_print_error(fmt("Bad object name: %s", hex));
Lars Hjemlidf631192006-12-11 17:12:26 +010026 return;
27 }
28
Lars Hjemli61c3ca92007-05-08 22:40:59 +020029 buf = read_sha1_file(sha1, &type, &size);
Lars Hjemlidf631192006-12-11 17:12:26 +010030 if (!buf) {
Lars Hjemli61c3ca92007-05-08 22:40:59 +020031 cgit_print_error(fmt("Error reading object %s", hex));
Lars Hjemlidf631192006-12-11 17:12:26 +010032 return;
33 }
34
35 buf[size] = '\0';
Lars Hjemli9c2e8632006-12-13 00:36:22 +010036 html("<table class='list'>\n");
Lars Hjemli7250a152007-05-08 23:52:56 +020037 html("<tr class='nohover'><th class='left'>");
38 if (path)
39 htmlf("%s (", path);
40 htmlf("%s %s, %li bytes", typename(type), hex, size);
41 if (path)
42 html(")");
Lars Hjemlica8eb8f2007-05-09 00:48:09 +020043
44 html(" <a href='");
45 html_attr(cgit_pageurl(cgit_query_repo, "blob",
Ondrej Jirman1a63cfc2007-05-26 01:15:10 +020046 fmt("id=%s&amp;path=%s",
Lars Hjemlica8eb8f2007-05-09 00:48:09 +020047 hex,
48 path)));
49 html("'>download</a>");
Lars Hjemli7250a152007-05-08 23:52:56 +020050 html("</th></tr>\n");
Lars Hjemli9c2e8632006-12-13 00:36:22 +010051 html("<tr><td class='blob'>\n");
Lars Hjemlidf631192006-12-11 17:12:26 +010052 html_txt(buf);
Lars Hjemli9c2e8632006-12-13 00:36:22 +010053 html("\n</td></tr>\n");
54 html("</table>\n");
Lars Hjemlidf631192006-12-11 17:12:26 +010055}