aboutsummaryrefslogtreecommitdiffstats
path: root/ui-blob.c
diff options
context:
space:
mode:
authorGravatar Jason A. Donenfeld <Jason@zx2c4.com>2013-05-26 22:20:02 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2013-05-26 23:30:03 (JST)
commitdcbc0438b2543a733858d62170f3110a89edbed6 (patch)
treebdacfe4546c88bf6b03860ea69a0cad885fa6af4 /ui-blob.c
parentfe36f84d843cd755c6dab629a0758264de5bcc00 (diff)
downloadcgit-dcbc0438b2543a733858d62170f3110a89edbed6.zip
cgit-dcbc0438b2543a733858d62170f3110a89edbed6.tar.gz
readme: use string_list instead of space deliminations
Now this is possible in cgitrc - readme=:README.md readme=:readme.md readme=:README.mkd readme=:readme.mkd readme=:README.rst readme=:readme.rst readme=:README.html readme=:readme.html readme=:README.htm readme=:readme.htm readme=:README.txt readme=:readme.txt readme=:README readme=:readme readme=:INSTALL.txt readme=:install.txt readme=:INSTALL readme=:install Suggested-by: John Keeping <john@keeping.me.uk> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui-blob.c')
-rw-r--r--ui-blob.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/ui-blob.c b/ui-blob.c
index b4be139..eb14a75 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -1,7 +1,7 @@
1/* ui-blob.c: show blob content 1/* ui-blob.c: show blob content
2 * 2 *
3 * Copyright (C) 2008 Lars Hjemli 3 * Copyright (C) 2008 Lars Hjemli
4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> 4 * Copyright (C) 2010-2013 Jason A. Donenfeld <Jason@zx2c4.com>
5 * 5 *
6 * Licensed under GNU General Public License v2 6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text) 7 * (see COPYING for full license text)
@@ -15,7 +15,8 @@
15struct walk_tree_context { 15struct walk_tree_context {
16 const char *match_path; 16 const char *match_path;
17 unsigned char *matched_sha1; 17 unsigned char *matched_sha1;
18 int found_path; 18 int found_path:1;
19 int file_only:1;
19}; 20};
20 21
21static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 22static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
@@ -23,6 +24,8 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
23{ 24{
24 struct walk_tree_context *walk_tree_ctx = cbdata; 25 struct walk_tree_context *walk_tree_ctx = cbdata;
25 26
27 if (walk_tree_ctx->file_only && !S_ISREG(mode))
28 return READ_TREE_RECURSIVE;
26 if (strncmp(base, walk_tree_ctx->match_path, baselen) 29 if (strncmp(base, walk_tree_ctx->match_path, baselen)
27 || strcmp(walk_tree_ctx->match_path + baselen, pathname)) 30 || strcmp(walk_tree_ctx->match_path + baselen, pathname))
28 return READ_TREE_RECURSIVE; 31 return READ_TREE_RECURSIVE;
@@ -31,33 +34,34 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
31 return 0; 34 return 0;
32} 35}
33 36
34int cgit_ref_path_exists(const char *path, const char *ref) 37int cgit_ref_path_exists(const char *path, const char *ref, int file_only)
35{ 38{
36 unsigned char sha1[20]; 39 unsigned char sha1[20];
37 unsigned long size; 40 unsigned long size;
38 struct pathspec_item path_items = { 41 struct pathspec_item path_items = {
39 .match = path, 42 .match = path,
40 .len = strlen(path) 43 .len = strlen(path)
41 }; 44 };
42 struct pathspec paths = { 45 struct pathspec paths = {
43 .nr = 1, 46 .nr = 1,
44 .items = &path_items 47 .items = &path_items
45 }; 48 };
46 struct walk_tree_context walk_tree_ctx = { 49 struct walk_tree_context walk_tree_ctx = {
47 .match_path = path, 50 .match_path = path,
48 .matched_sha1 = sha1, 51 .matched_sha1 = sha1,
49 .found_path = 0 52 .found_path = 0,
50 }; 53 .file_only = file_only
54 };
51 55
52 if (get_sha1(ref, sha1)) 56 if (get_sha1(ref, sha1))
53 return 0; 57 return 0;
54 if (sha1_object_info(sha1, &size) != OBJ_COMMIT) 58 if (sha1_object_info(sha1, &size) != OBJ_COMMIT)
55 return 0; 59 return 0;
56 read_tree_recursive(lookup_commit_reference(sha1)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); 60 read_tree_recursive(lookup_commit_reference(sha1)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
57 return walk_tree_ctx.found_path; 61 return walk_tree_ctx.found_path;
58} 62}
59 63
60int cgit_print_file(char *path, const char *head) 64int cgit_print_file(char *path, const char *head, int file_only)
61{ 65{
62 unsigned char sha1[20]; 66 unsigned char sha1[20];
63 enum object_type type; 67 enum object_type type;
@@ -75,7 +79,8 @@ int cgit_print_file(char *path, const char *head)
75 struct walk_tree_context walk_tree_ctx = { 79 struct walk_tree_context walk_tree_ctx = {
76 .match_path = path, 80 .match_path = path,
77 .matched_sha1 = sha1, 81 .matched_sha1 = sha1,
78 .found_path = 0 82 .found_path = 0,
83 .file_only = file_only
79 }; 84 };
80 85
81 if (get_sha1(head, sha1)) 86 if (get_sha1(head, sha1))
@@ -98,7 +103,7 @@ int cgit_print_file(char *path, const char *head)
98 return 0; 103 return 0;
99} 104}
100 105
101void cgit_print_blob(const char *hex, char *path, const char *head) 106void cgit_print_blob(const char *hex, char *path, const char *head, int file_only)
102{ 107{
103 unsigned char sha1[20]; 108 unsigned char sha1[20];
104 enum object_type type; 109 enum object_type type;
@@ -116,6 +121,8 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
116 struct walk_tree_context walk_tree_ctx = { 121 struct walk_tree_context walk_tree_ctx = {
117 .match_path = path, 122 .match_path = path,
118 .matched_sha1 = sha1, 123 .matched_sha1 = sha1,
124 .found_path = 0,
125 .file_only = file_only
119 }; 126 };
120 127
121 if (hex) { 128 if (hex) {