Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 1 | /* 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 Hjemli | 9a8f886 | 2006-12-16 00:19:56 +0100 | [diff] [blame] | 11 | void cgit_print_view(const char *hex) |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 12 | { |
| 13 | unsigned char sha1[20]; |
Lars Hjemli | 61c3ca9 | 2007-05-08 22:40:59 +0200 | [diff] [blame^] | 14 | enum object_type type; |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 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 Hjemli | 61c3ca9 | 2007-05-08 22:40:59 +0200 | [diff] [blame^] | 23 | type = sha1_object_info(sha1, &size); |
| 24 | if (type == OBJ_BAD) { |
| 25 | cgit_print_error(fmt("Bad object name: %s", hex)); |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 26 | return; |
| 27 | } |
| 28 | |
Lars Hjemli | 61c3ca9 | 2007-05-08 22:40:59 +0200 | [diff] [blame^] | 29 | buf = read_sha1_file(sha1, &type, &size); |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 30 | if (!buf) { |
Lars Hjemli | 61c3ca9 | 2007-05-08 22:40:59 +0200 | [diff] [blame^] | 31 | cgit_print_error(fmt("Error reading object %s", hex)); |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 32 | return; |
| 33 | } |
| 34 | |
| 35 | buf[size] = '\0'; |
Lars Hjemli | 9c2e863 | 2006-12-13 00:36:22 +0100 | [diff] [blame] | 36 | html("<table class='list'>\n"); |
Lars Hjemli | 61c3ca9 | 2007-05-08 22:40:59 +0200 | [diff] [blame^] | 37 | htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", |
| 38 | typename(type), hex, size); |
Lars Hjemli | 9c2e863 | 2006-12-13 00:36:22 +0100 | [diff] [blame] | 39 | html("<tr><td class='blob'>\n"); |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 40 | html_txt(buf); |
Lars Hjemli | 9c2e863 | 2006-12-13 00:36:22 +0100 | [diff] [blame] | 41 | html("\n</td></tr>\n"); |
| 42 | html("</table>\n"); |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 43 | } |