aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2007-05-09 07:48:09 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2007-05-09 07:48:09 (JST)
commitca8eb8fc8f71ee0a40015c323619f776840b6503 (patch)
treef74a114ba19c215bffe8362bf8e63495155ebef4
parent7250a154678477a1e8260efbc9810ec389754ef9 (diff)
downloadcgit-ca8eb8fc8f71ee0a40015c323619f776840b6503.zip
cgit-ca8eb8fc8f71ee0a40015c323619f776840b6503.tar.gz
Add support for downloading single blobs
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r--Makefile2
-rw-r--r--cgit.c9
-rw-r--r--cgit.h1
-rw-r--r--ui-blob.c31
-rw-r--r--ui-view.c7
5 files changed, 47 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 24c3963..7c0527b 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ CACHE_ROOT = /var/cache/cgit
9EXTLIBS = $(gitsrc)/libgit.a $(gitsrc)/xdiff/lib.a -lz -lcrypto 9EXTLIBS = $(gitsrc)/libgit.a $(gitsrc)/xdiff/lib.a -lz -lcrypto
10OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ 10OBJECTS = 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
14CFLAGS += -Wall 14CFLAGS += -Wall
15 15
diff --git a/cgit.c b/cgit.c
index 6dddcbb..28bab8d 100644
--- a/cgit.c
+++ b/cgit.c
@@ -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"))
diff --git a/cgit.h b/cgit.h
index 2615231..292e488 100644
--- a/cgit.h
+++ b/cgit.h
@@ -156,6 +156,7 @@ extern void cgit_print_repolist(struct cacheitem *item);
156extern void cgit_print_summary(); 156extern void cgit_print_summary();
157extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); 157extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep);
158extern void cgit_print_view(const char *hex, char *path); 158extern void cgit_print_view(const char *hex, char *path);
159extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
159extern void cgit_print_tree(const char *hex, char *path); 160extern void cgit_print_tree(const char *hex, char *path);
160extern void cgit_print_commit(const char *hex); 161extern void cgit_print_commit(const char *hex);
161extern void cgit_print_diff(const char *old_hex, const char *new_hex); 162extern 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
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}
diff --git a/ui-view.c b/ui-view.c
index 7d022fd..dbe4b29 100644
--- a/ui-view.c
+++ b/ui-view.c
@@ -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);