diff options
| author | 2007-05-09 07:48:09 (JST) | |
|---|---|---|
| committer | 2007-05-09 07:48:09 (JST) | |
| commit | ca8eb8fc8f71ee0a40015c323619f776840b6503 (patch) | |
| tree | f74a114ba19c215bffe8362bf8e63495155ebef4 | |
| parent | 7250a154678477a1e8260efbc9810ec389754ef9 (diff) | |
| download | cgit-ca8eb8fc8f71ee0a40015c323619f776840b6503.zip cgit-ca8eb8fc8f71ee0a40015c323619f776840b6503.tar.gz | |
Add support for downloading single blobs
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | cgit.c | 9 | ||||
| -rw-r--r-- | cgit.h | 1 | ||||
| -rw-r--r-- | ui-blob.c | 31 | ||||
| -rw-r--r-- | ui-view.c | 7 |
5 files changed, 47 insertions, 3 deletions
| @@ -9,7 +9,7 @@ CACHE_ROOT = /var/cache/cgit | |||
| 9 | EXTLIBS = $(gitsrc)/libgit.a $(gitsrc)/xdiff/lib.a -lz -lcrypto | 9 | EXTLIBS = $(gitsrc)/libgit.a $(gitsrc)/xdiff/lib.a -lz -lcrypto |
| 10 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 10 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
| 11 | ui-summary.o ui-log.o ui-view.o ui-tree.o ui-commit.o ui-diff.o \ | 11 | ui-summary.o ui-log.o ui-view.o ui-tree.o ui-commit.o ui-diff.o \ |
| 12 | ui-snapshot.o | 12 | ui-snapshot.o ui-blob.o |
| 13 | 13 | ||
| 14 | CFLAGS += -Wall | 14 | CFLAGS += -Wall |
| 15 | 15 | ||
| @@ -79,11 +79,16 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
| 79 | show_search = 0; | 79 | show_search = 0; |
| 80 | setenv("GIT_DIR", cgit_repo->path, 1); | 80 | setenv("GIT_DIR", cgit_repo->path, 1); |
| 81 | 81 | ||
| 82 | if (cgit_repo->snapshots && cgit_query_page && | 82 | if (cgit_query_page) { |
| 83 | !strcmp(cgit_query_page, "snapshot")) { | 83 | if (cgit_repo->snapshots && !strcmp(cgit_query_page, "snapshot")) { |
| 84 | cgit_print_snapshot(item, cgit_query_sha1, "zip", | 84 | cgit_print_snapshot(item, cgit_query_sha1, "zip", |
| 85 | cgit_repo->url, cgit_query_name); | 85 | cgit_repo->url, cgit_query_name); |
| 86 | return; | 86 | return; |
| 87 | } | ||
| 88 | if (!strcmp(cgit_query_page, "blob")) { | ||
| 89 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | ||
| 90 | return; | ||
| 91 | } | ||
| 87 | } | 92 | } |
| 88 | 93 | ||
| 89 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) | 94 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) |
| @@ -156,6 +156,7 @@ extern void cgit_print_repolist(struct cacheitem *item); | |||
| 156 | extern void cgit_print_summary(); | 156 | extern void cgit_print_summary(); |
| 157 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); | 157 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); |
| 158 | extern void cgit_print_view(const char *hex, char *path); | 158 | extern void cgit_print_view(const char *hex, char *path); |
| 159 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | ||
| 159 | extern void cgit_print_tree(const char *hex, char *path); | 160 | extern void cgit_print_tree(const char *hex, char *path); |
| 160 | extern void cgit_print_commit(const char *hex); | 161 | extern void cgit_print_commit(const char *hex); |
| 161 | extern void cgit_print_diff(const char *old_hex, const char *new_hex); | 162 | extern void cgit_print_diff(const char *old_hex, const char *new_hex); |
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 | } | ||
| @@ -40,6 +40,13 @@ void cgit_print_view(const char *hex, char *path) | |||
| 40 | htmlf("%s %s, %li bytes", typename(type), hex, size); | 40 | htmlf("%s %s, %li bytes", typename(type), hex, size); |
| 41 | if (path) | 41 | if (path) |
| 42 | html(")"); | 42 | html(")"); |
| 43 | |||
| 44 | html(" <a href='"); | ||
| 45 | html_attr(cgit_pageurl(cgit_query_repo, "blob", | ||
| 46 | fmt("id=%s&path=%s", | ||
| 47 | hex, | ||
| 48 | path))); | ||
| 49 | html("'>download</a>"); | ||
| 43 | html("</th></tr>\n"); | 50 | html("</th></tr>\n"); |
| 44 | html("<tr><td class='blob'>\n"); | 51 | html("<tr><td class='blob'>\n"); |
| 45 | html_txt(buf); | 52 | html_txt(buf); |
