blob: 7d022fdf501dc06b1bf9f641b29715466967d98a [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(")");
43 html("</th></tr>\n");
Lars Hjemli9c2e8632006-12-13 00:36:22 +010044 html("<tr><td class='blob'>\n");
Lars Hjemlidf631192006-12-11 17:12:26 +010045 html_txt(buf);
Lars Hjemli9c2e8632006-12-13 00:36:22 +010046 html("\n</td></tr>\n");
47 html("</table>\n");
Lars Hjemlidf631192006-12-11 17:12:26 +010048}