blob: 9d23c453d79cff971e35d074002099b2f6c3e22e [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 Hjemli9a8f8862006-12-16 00:19:56 +010011void cgit_print_view(const char *hex)
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 Hjemli61c3ca92007-05-08 22:40:59 +020037 htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n",
38 typename(type), hex, size);
Lars Hjemli9c2e8632006-12-13 00:36:22 +010039 html("<tr><td class='blob'>\n");
Lars Hjemlidf631192006-12-11 17:12:26 +010040 html_txt(buf);
Lars Hjemli9c2e8632006-12-13 00:36:22 +010041 html("\n</td></tr>\n");
42 html("</table>\n");
Lars Hjemlidf631192006-12-11 17:12:26 +010043}