diff options
Diffstat (limited to 'ui-blob.c')
-rw-r--r-- | ui-blob.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/ui-blob.c b/ui-blob.c new file mode 100644 index 0000000..f5b844b --- /dev/null +++ b/ui-blob.c | |||
@@ -0,0 +1,31 @@ | |||
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 | } | ||