about summary refs log tree commit diff stats
path: root/ui-blob.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-blob.c')
-rw-r--r--ui-blob.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/ui-blob.c b/ui-blob.c index 8f6989f..b4be139 100644 --- a/ui-blob.c +++ b/ui-blob.c
@@ -13,7 +13,7 @@
13#include "ui-shared.h" 13#include "ui-shared.h"
14 14
15struct walk_tree_context { 15struct 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
34int 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
34int cgit_print_file(char *path, const char *head) 60int cgit_print_file(char *path, const char *head)
35{ 61{
36 unsigned char sha1[20]; 62 unsigned char sha1[20];