diff options
author | Christian Hesse | 2016-09-29 21:38:49 +0200 |
---|---|---|
committer | Christian Hesse | 2016-10-04 09:47:18 +0200 |
commit | 6e4b7b6776eb994e795fa38b2619db6c55e10ecc (patch) | |
tree | 737cd43e1b6d174f0ad7c12793b51b8090d5ae1b | |
parent | cgit: replace 'unsigned char sha1[20]' with 'struct object_id oid' (diff) | |
download | cgit-6e4b7b6776eb994e795fa38b2619db6c55e10ecc.tar.gz cgit-6e4b7b6776eb994e795fa38b2619db6c55e10ecc.zip |
ui-blob: replace 'unsigned char sha1[20]' with 'struct object_id oid'
Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... In addition replace memmove() with hashcpy().
-rw-r--r-- | ui-blob.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/ui-blob.c b/ui-blob.c index d388489..2f8bb7a 100644 --- a/ui-blob.c +++ b/ui-blob.c | |||
@@ -13,7 +13,7 @@ | |||
13 | 13 | ||
14 | struct walk_tree_context { | 14 | struct walk_tree_context { |
15 | const char *match_path; | 15 | const char *match_path; |
16 | unsigned char *matched_sha1; | 16 | struct object_id matched_oid; |
17 | unsigned int found_path:1; | 17 | unsigned int found_path:1; |
18 | unsigned int file_only:1; | 18 | unsigned int file_only:1; |
19 | }; | 19 | }; |
@@ -28,14 +28,14 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, | |||
28 | if (strncmp(base->buf, walk_tree_ctx->match_path, base->len) | 28 | if (strncmp(base->buf, walk_tree_ctx->match_path, base->len) |
29 | || strcmp(walk_tree_ctx->match_path + base->len, pathname)) | 29 | || strcmp(walk_tree_ctx->match_path + base->len, pathname)) |
30 | return READ_TREE_RECURSIVE; | 30 | return READ_TREE_RECURSIVE; |
31 | memmove(walk_tree_ctx->matched_sha1, sha1, 20); | 31 | hashcpy(walk_tree_ctx->matched_oid.hash, sha1); |
32 | walk_tree_ctx->found_path = 1; | 32 | walk_tree_ctx->found_path = 1; |
33 | return 0; | 33 | return 0; |
34 | } | 34 | } |
35 | 35 | ||
36 | int cgit_ref_path_exists(const char *path, const char *ref, int file_only) | 36 | int cgit_ref_path_exists(const char *path, const char *ref, int file_only) |
37 | { | 37 | { |
38 | unsigned char sha1[20]; | 38 | struct object_id oid; |
39 | unsigned long size; | 39 | unsigned long size; |
40 | struct pathspec_item path_items = { | 40 | struct pathspec_item path_items = { |
41 | .match = path, | 41 | .match = path, |
@@ -47,22 +47,22 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) | |||
47 | }; | 47 | }; |
48 | struct walk_tree_context walk_tree_ctx = { | 48 | struct walk_tree_context walk_tree_ctx = { |
49 | .match_path = path, | 49 | .match_path = path, |
50 | .matched_sha1 = sha1, | 50 | .matched_oid = oid, |
51 | .found_path = 0, | 51 | .found_path = 0, |
52 | .file_only = file_only | 52 | .file_only = file_only |
53 | }; | 53 | }; |
54 | 54 | ||
55 | if (get_sha1(ref, sha1)) | 55 | if (get_oid(ref, &oid)) |
56 | return 0; | 56 | return 0; |
57 | if (sha1_object_info(sha1, &size) != OBJ_COMMIT) | 57 | if (sha1_object_info(oid.hash, &size) != OBJ_COMMIT) |
58 | return 0; | 58 | return 0; |
59 | read_tree_recursive(lookup_commit_reference(sha1)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); | 59 | read_tree_recursive(lookup_commit_reference(oid.hash)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); |
60 | return walk_tree_ctx.found_path; | 60 | return walk_tree_ctx.found_path; |
61 | } | 61 | } |
62 | 62 | ||
63 | int cgit_print_file(char *path, const char *head, int file_only) | 63 | int cgit_print_file(char *path, const char *head, int file_only) |
64 | { | 64 | { |
65 | unsigned char sha1[20]; | 65 | struct object_id oid; |
66 | enum object_type type; | 66 | enum object_type type; |
67 | char *buf; | 67 | char *buf; |
68 | unsigned long size; | 68 | unsigned long size; |
@@ -77,24 +77,24 @@ int cgit_print_file(char *path, const char *head, int file_only) | |||
77 | }; | 77 | }; |
78 | struct walk_tree_context walk_tree_ctx = { | 78 | struct walk_tree_context walk_tree_ctx = { |
79 | .match_path = path, | 79 | .match_path = path, |
80 | .matched_sha1 = sha1, | 80 | .matched_oid = oid, |
81 | .found_path = 0, | 81 | .found_path = 0, |
82 | .file_only = file_only | 82 | .file_only = file_only |
83 | }; | 83 | }; |
84 | 84 | ||
85 | if (get_sha1(head, sha1)) | 85 | if (get_oid(head, &oid)) |
86 | return -1; | 86 | return -1; |
87 | type = sha1_object_info(sha1, &size); | 87 | type = sha1_object_info(oid.hash, &size); |
88 | if (type == OBJ_COMMIT) { | 88 | if (type == OBJ_COMMIT) { |
89 | commit = lookup_commit_reference(sha1); | 89 | commit = lookup_commit_reference(oid.hash); |
90 | read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); | 90 | read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); |
91 | if (!walk_tree_ctx.found_path) | 91 | if (!walk_tree_ctx.found_path) |
92 | return -1; | 92 | return -1; |
93 | type = sha1_object_info(sha1, &size); | 93 | type = sha1_object_info(oid.hash, &size); |
94 | } | 94 | } |
95 | if (type == OBJ_BAD) | 95 | if (type == OBJ_BAD) |
96 | return -1; | 96 | return -1; |
97 | buf = read_sha1_file(sha1, &type, &size); | 97 | buf = read_sha1_file(oid.hash, &type, &size); |
98 | if (!buf) | 98 | if (!buf) |
99 | return -1; | 99 | return -1; |
100 | buf[size] = '\0'; | 100 | buf[size] = '\0'; |
@@ -105,7 +105,7 @@ int cgit_print_file(char *path, const char *head, int file_only) | |||
105 | 105 | ||
106 | void cgit_print_blob(const char *hex, char *path, const char *head, int file_only) | 106 | void cgit_print_blob(const char *hex, char *path, const char *head, int file_only) |
107 | { | 107 | { |
108 | unsigned char sha1[20]; | 108 | struct object_id oid; |
109 | enum object_type type; | 109 | enum object_type type; |
110 | char *buf; | 110 | char *buf; |
111 | unsigned long size; | 111 | unsigned long size; |
@@ -120,31 +120,31 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl | |||
120 | }; | 120 | }; |
121 | struct walk_tree_context walk_tree_ctx = { | 121 | struct walk_tree_context walk_tree_ctx = { |
122 | .match_path = path, | 122 | .match_path = path, |
123 | .matched_sha1 = sha1, | 123 | .matched_oid = oid, |
124 | .found_path = 0, | 124 | .found_path = 0, |
125 | .file_only = file_only | 125 | .file_only = file_only |
126 | }; | 126 | }; |
127 | 127 | ||
128 | if (hex) { | 128 | if (hex) { |
129 | if (get_sha1_hex(hex, sha1)) { | 129 | if (get_oid_hex(hex, &oid)) { |
130 | cgit_print_error_page(400, "Bad request", | 130 | cgit_print_error_page(400, "Bad request", |
131 | "Bad hex value: %s", hex); | 131 | "Bad hex value: %s", hex); |
132 | return; | 132 | return; |
133 | } | 133 | } |
134 | } else { | 134 | } else { |
135 | if (get_sha1(head, sha1)) { | 135 | if (get_oid(head, &oid)) { |
136 | cgit_print_error_page(404, "Not found", | 136 | cgit_print_error_page(404, "Not found", |
137 | "Bad ref: %s", head); | 137 | "Bad ref: %s", head); |
138 | return; | 138 | return; |
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
142 | type = sha1_object_info(sha1, &size); | 142 | type = sha1_object_info(oid.hash, &size); |
143 | 143 | ||
144 | if ((!hex) && type == OBJ_COMMIT && path) { | 144 | if ((!hex) && type == OBJ_COMMIT && path) { |
145 | commit = lookup_commit_reference(sha1); | 145 | commit = lookup_commit_reference(oid.hash); |
146 | read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); | 146 | read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); |
147 | type = sha1_object_info(sha1,&size); | 147 | type = sha1_object_info(oid.hash, &size); |
148 | } | 148 | } |
149 | 149 | ||
150 | if (type == OBJ_BAD) { | 150 | if (type == OBJ_BAD) { |
@@ -153,7 +153,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl | |||
153 | return; | 153 | return; |
154 | } | 154 | } |
155 | 155 | ||
156 | buf = read_sha1_file(sha1, &type, &size); | 156 | buf = read_sha1_file(oid.hash, &type, &size); |
157 | if (!buf) { | 157 | if (!buf) { |
158 | cgit_print_error_page(500, "Internal server error", | 158 | cgit_print_error_page(500, "Internal server error", |
159 | "Error reading object %s", hex); | 159 | "Error reading object %s", hex); |