author | Lars Hjemli <hjemli@gmail.com> | 2009-07-25 09:59:22 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-07-25 09:59:22 (UTC) |
commit | 681fdc45473143de3f3c5f69fbc7b94f5d6b0b75 (patch) (unidiff) | |
tree | 3bfca05875524bee0e5444fb791707bc3e593dbd /ui-plain.c | |
parent | 7e5c048505efe1902fb476cc2cb3160ff7df013d (diff) | |
parent | 3ff58ddd51bcbcbc9b7649bad1a39aa98af4b49f (diff) | |
download | cgit-681fdc45473143de3f3c5f69fbc7b94f5d6b0b75.zip cgit-681fdc45473143de3f3c5f69fbc7b94f5d6b0b75.tar.gz cgit-681fdc45473143de3f3c5f69fbc7b94f5d6b0b75.tar.bz2 |
Merge branch 'plain-etag'
Conflicts:
ui-shared.c
-rw-r--r-- | ui-plain.c | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -1,82 +1,83 @@ | |||
1 | /* ui-plain.c: functions for output of plain blobs by path | 1 | /* ui-plain.c: functions for output of plain blobs by path |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | char *curr_rev; | 13 | char *curr_rev; |
14 | char *match_path; | 14 | char *match_path; |
15 | int match; | 15 | int match; |
16 | 16 | ||
17 | static void print_object(const unsigned char *sha1, const char *path) | 17 | static void print_object(const unsigned char *sha1, const char *path) |
18 | { | 18 | { |
19 | enum object_type type; | 19 | enum object_type type; |
20 | char *buf; | 20 | char *buf; |
21 | unsigned long size; | 21 | unsigned long size; |
22 | 22 | ||
23 | type = sha1_object_info(sha1, &size); | 23 | type = sha1_object_info(sha1, &size); |
24 | if (type == OBJ_BAD) { | 24 | if (type == OBJ_BAD) { |
25 | html_status(404, "Not found", 0); | 25 | html_status(404, "Not found", 0); |
26 | return; | 26 | return; |
27 | } | 27 | } |
28 | 28 | ||
29 | buf = read_sha1_file(sha1, &type, &size); | 29 | buf = read_sha1_file(sha1, &type, &size); |
30 | if (!buf) { | 30 | if (!buf) { |
31 | html_status(404, "Not found", 0); | 31 | html_status(404, "Not found", 0); |
32 | return; | 32 | return; |
33 | } | 33 | } |
34 | if (buffer_is_binary(buf, size)) | 34 | if (buffer_is_binary(buf, size)) |
35 | ctx.page.mimetype = "application/octet-stream"; | 35 | ctx.page.mimetype = "application/octet-stream"; |
36 | else | 36 | else |
37 | ctx.page.mimetype = "text/plain"; | 37 | ctx.page.mimetype = "text/plain"; |
38 | ctx.page.filename = fmt("%s", path); | 38 | ctx.page.filename = fmt("%s", path); |
39 | ctx.page.size = size; | 39 | ctx.page.size = size; |
40 | ctx.page.etag = sha1_to_hex(sha1); | ||
40 | cgit_print_http_headers(&ctx); | 41 | cgit_print_http_headers(&ctx); |
41 | html_raw(buf, size); | 42 | html_raw(buf, size); |
42 | match = 1; | 43 | match = 1; |
43 | } | 44 | } |
44 | 45 | ||
45 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 46 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
46 | const char *pathname, unsigned mode, int stage, | 47 | const char *pathname, unsigned mode, int stage, |
47 | void *cbdata) | 48 | void *cbdata) |
48 | { | 49 | { |
49 | if (S_ISDIR(mode)) | 50 | if (S_ISDIR(mode)) |
50 | return READ_TREE_RECURSIVE; | 51 | return READ_TREE_RECURSIVE; |
51 | 52 | ||
52 | if (S_ISREG(mode)) | 53 | if (S_ISREG(mode)) |
53 | print_object(sha1, pathname); | 54 | print_object(sha1, pathname); |
54 | 55 | ||
55 | return 0; | 56 | return 0; |
56 | } | 57 | } |
57 | 58 | ||
58 | void cgit_print_plain(struct cgit_context *ctx) | 59 | void cgit_print_plain(struct cgit_context *ctx) |
59 | { | 60 | { |
60 | const char *rev = ctx->qry.sha1; | 61 | const char *rev = ctx->qry.sha1; |
61 | unsigned char sha1[20]; | 62 | unsigned char sha1[20]; |
62 | struct commit *commit; | 63 | struct commit *commit; |
63 | const char *paths[] = {ctx->qry.path, NULL}; | 64 | const char *paths[] = {ctx->qry.path, NULL}; |
64 | 65 | ||
65 | if (!rev) | 66 | if (!rev) |
66 | rev = ctx->qry.head; | 67 | rev = ctx->qry.head; |
67 | 68 | ||
68 | curr_rev = xstrdup(rev); | 69 | curr_rev = xstrdup(rev); |
69 | if (get_sha1(rev, sha1)) { | 70 | if (get_sha1(rev, sha1)) { |
70 | html_status(404, "Not found", 0); | 71 | html_status(404, "Not found", 0); |
71 | return; | 72 | return; |
72 | } | 73 | } |
73 | commit = lookup_commit_reference(sha1); | 74 | commit = lookup_commit_reference(sha1); |
74 | if (!commit || parse_commit(commit)) { | 75 | if (!commit || parse_commit(commit)) { |
75 | html_status(404, "Not found", 0); | 76 | html_status(404, "Not found", 0); |
76 | return; | 77 | return; |
77 | } | 78 | } |
78 | match_path = ctx->qry.path; | 79 | match_path = ctx->qry.path; |
79 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL); | 80 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL); |
80 | if (!match) | 81 | if (!match) |
81 | html_status(404, "Not found", 0); | 82 | html_status(404, "Not found", 0); |
82 | } | 83 | } |