blob: 85e223cbc0398cede8851aa963a1fd7e278dfe5f [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];
14 char type[20];
15 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 Hjemli06fe0c22006-12-13 00:13:27 +010023 if (sha1_object_info(sha1, type, &size)){
Lars Hjemlidf631192006-12-11 17:12:26 +010024 cgit_print_error("Bad object name");
25 return;
26 }
27
28 buf = read_sha1_file(sha1, type, &size);
29 if (!buf) {
30 cgit_print_error("Error reading object");
31 return;
32 }
33
34 buf[size] = '\0';
Lars Hjemli9c2e8632006-12-13 00:36:22 +010035 html("<table class='list'>\n");
Lars Hjemli777faf72007-01-28 00:39:26 +010036 htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", type, hex, size);
Lars Hjemli9c2e8632006-12-13 00:36:22 +010037 html("<tr><td class='blob'>\n");
Lars Hjemlidf631192006-12-11 17:12:26 +010038 html_txt(buf);
Lars Hjemli9c2e8632006-12-13 00:36:22 +010039 html("\n</td></tr>\n");
40 html("</table>\n");
Lars Hjemlidf631192006-12-11 17:12:26 +010041}