summaryrefslogtreecommitdiffabout
path: root/ui-blob.c
authorLars Hjemli <hjemli@gmail.com>2007-05-08 22:48:09 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-05-08 22:48:09 (UTC)
commitca8eb8fc8f71ee0a40015c323619f776840b6503 (patch) (unidiff)
treef74a114ba19c215bffe8362bf8e63495155ebef4 /ui-blob.c
parent7250a154678477a1e8260efbc9810ec389754ef9 (diff)
downloadcgit-ca8eb8fc8f71ee0a40015c323619f776840b6503.zip
cgit-ca8eb8fc8f71ee0a40015c323619f776840b6503.tar.gz
cgit-ca8eb8fc8f71ee0a40015c323619f776840b6503.tar.bz2
Add support for downloading single blobs
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-blob.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-blob.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/ui-blob.c b/ui-blob.c
new file mode 100644
index 0000000..f5b844b
--- a/dev/null
+++ b/ui-blob.c
@@ -0,0 +1,31 @@
1#include "cgit.h"
2
3void 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}