diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-05-25 23:32:37 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-05-26 03:33:28 (JST) |
commit | cd4c77d989983778432363061e99219f034c3717 (patch) | |
tree | a394b7960e7105c7dbcb130721298a49d49b8a75 /ui-blob.c | |
parent | c0dfaf1c281d0697ce43131343d7a9f170a61ff9 (diff) | |
download | cgit-cd4c77d989983778432363061e99219f034c3717.zip cgit-cd4c77d989983778432363061e99219f034c3717.tar.gz |
readme: Accept multiple candidates and test them.
The readme variable may now contain multiple space deliminated entries,
which per usual are either a filepath or a git ref filepath. If multiple
are specified, cgit will now select the first one in the list that
exists. This is to make it easier to specify multiple default readme
types in the main cgitrc file and have them automatically get applied to
each repo based on what exists.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui-blob.c')
-rw-r--r-- | ui-blob.c | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -13,7 +13,7 @@ | |||
13 | #include "ui-shared.h" | 13 | #include "ui-shared.h" |
14 | 14 | ||
15 | struct walk_tree_context { | 15 | struct walk_tree_context { |
16 | 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; |
19 | }; | 19 | }; |
@@ -31,6 +31,32 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | |||
31 | return 0; | 31 | return 0; |
32 | } | 32 | } |
33 | 33 | ||
34 | int cgit_ref_path_exists(const char *path, const char *ref) | ||
35 | { | ||
36 | unsigned char sha1[20]; | ||
37 | unsigned long size; | ||
38 | struct pathspec_item path_items = { | ||
39 | .match = path, | ||
40 | .len = strlen(path) | ||
41 | }; | ||
42 | struct pathspec paths = { | ||
43 | .nr = 1, | ||
44 | .items = &path_items | ||
45 | }; | ||
46 | struct walk_tree_context walk_tree_ctx = { | ||
47 | .match_path = path, | ||
48 | .matched_sha1 = sha1, | ||
49 | .found_path = 0 | ||
50 | }; | ||
51 | |||
52 | if (get_sha1(ref, sha1)) | ||
53 | return 0; | ||
54 | if (sha1_object_info(sha1, &size) != OBJ_COMMIT) | ||
55 | return 0; | ||
56 | read_tree_recursive(lookup_commit_reference(sha1)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); | ||
57 | return walk_tree_ctx.found_path; | ||
58 | } | ||
59 | |||
34 | int cgit_print_file(char *path, const char *head) | 60 | int cgit_print_file(char *path, const char *head) |
35 | { | 61 | { |
36 | unsigned char sha1[20]; | 62 | unsigned char sha1[20]; |