Lars Hjemli | ca8eb8f | 2007-05-09 00:48:09 +0200 | [diff] [blame] | 1 | #include "cgit.h" |
| 2 | |
| 3 | void cgit_print_blob(struct cacheitem *item, const char *hex, char *path) |
| 4 | { |
| 5 | |
| 6 | unsigned char sha1[20]; |
| 7 | enum object_type type; |
| 8 | unsigned char *buf; |
| 9 | unsigned long size; |
| 10 | |
| 11 | if (get_sha1_hex(hex, sha1)){ |
| 12 | cgit_print_error(fmt("Bad hex value: %s", hex)); |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | type = sha1_object_info(sha1, &size); |
| 17 | if (type == OBJ_BAD) { |
| 18 | cgit_print_error(fmt("Bad object name: %s", hex)); |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | buf = read_sha1_file(sha1, &type, &size); |
| 23 | if (!buf) { |
| 24 | cgit_print_error(fmt("Error reading object %s", hex)); |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | buf[size] = '\0'; |
| 29 | cgit_print_snapshot_start("text/plain", path, item); |
| 30 | write(htmlfd, buf, size); |
| 31 | } |