This will later be changed to include namespace resolution, but the call sites are changed now to keep the changes small.
Unified · Split
| @@ -615,7 +615,7 @@ static int prepare_repo_cmd(void) · 614 unmodified lines | |||
| 615 | return 1; | 615 | return 1; |
| 616 | } | 616 | } |
| 617 | 617 | ||
| 618 | if (get_sha1(ctx.qry.head, sha1)) { | 618 | if (cgit_get_sha1(ctx.qry.head, sha1)) { |
| 619 | char *old_head = ctx.qry.head; | 619 | char *old_head = ctx.qry.head; |
| 620 | ctx.qry.head = xstrdup(ctx.repo->defbranch); | 620 | ctx.qry.head = xstrdup(ctx.repo->defbranch); |
| 621 | cgit_print_error_page(404, "Not found", | 621 | cgit_print_error_page(404, "Not found", |
| @@ -391,4 +391,6 @@ extern char *expand_macros(const char *txt); · 390 unmodified lines | |||
| 391 | 391 | ||
| 392 | extern char *get_mimetype_for_filename(const char *filename); | 392 | extern char *get_mimetype_for_filename(const char *filename); |
| 393 | 393 | ||
| 394 | extern int cgit_get_sha1(const char *name, unsigned char *sha1); | ||
| 395 | |||
| 394 | #endif /* CGIT_H */ | 396 | #endif /* CGIT_H */ |
| @@ -601,3 +601,8 @@ char *get_mimetype_for_filename(const char *filename) · 600 unmodified lines | |||
| 601 | fclose(file); | 601 | fclose(file); |
| 602 | return NULL; | 602 | return NULL; |
| 603 | } | 603 | } |
| 604 | |||
| 605 | int cgit_get_sha1(const char *name, unsigned char *sha1) | ||
| 606 | { | ||
| 607 | return get_sha1(name, sha1); | ||
| 608 | } | ||
| @@ -52,7 +52,7 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) · 51 unmodified lines | |||
| 52 | .file_only = file_only | 52 | .file_only = file_only |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | if (get_sha1(ref, sha1)) | 55 | if (cgit_get_sha1(ref, sha1)) |
| 56 | return 0; | 56 | return 0; |
| 57 | if (sha1_object_info(sha1, &size) != OBJ_COMMIT) | 57 | if (sha1_object_info(sha1, &size) != OBJ_COMMIT) |
| 58 | return 0; | 58 | return 0; |
| @@ -82,7 +82,7 @@ int cgit_print_file(char *path, const char *head, int file_only) · 23 unmodified lines | |||
| 82 | .file_only = file_only | 82 | .file_only = file_only |
| 83 | }; | 83 | }; |
| 84 | 84 | ||
| 85 | if (get_sha1(head, sha1)) | 85 | if (cgit_get_sha1(head, sha1)) |
| 86 | return -1; | 86 | return -1; |
| 87 | type = sha1_object_info(sha1, &size); | 87 | type = sha1_object_info(sha1, &size); |
| 88 | if (type == OBJ_COMMIT) { | 88 | if (type == OBJ_COMMIT) { |
| @@ -132,7 +132,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl · 43 unmodified lines | |||
| 132 | return; | 132 | return; |
| 133 | } | 133 | } |
| 134 | } else { | 134 | } else { |
| 135 | if (get_sha1(head, sha1)) { | 135 | if (cgit_get_sha1(head, sha1)) { |
| 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; |
| @@ -26,7 +26,7 @@ void cgit_print_commit(char *hex, const char *prefix) · 25 unmodified lines | |||
| 26 | if (!hex) | 26 | if (!hex) |
| 27 | hex = ctx.qry.head; | 27 | hex = ctx.qry.head; |
| 28 | 28 | ||
| 29 | if (get_sha1(hex, sha1)) { | 29 | if (cgit_get_sha1(hex, sha1)) { |
| 30 | cgit_print_error_page(400, "Bad request", | 30 | cgit_print_error_page(400, "Bad request", |
| 31 | "Bad object id: %s", hex); | 31 | "Bad object id: %s", hex); |
| 32 | return; | 32 | return; |
| @@ -402,7 +402,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, · 401 unmodified lines | |||
| 402 | 402 | ||
| 403 | if (!new_rev) | 403 | if (!new_rev) |
| 404 | new_rev = ctx.qry.head; | 404 | new_rev = ctx.qry.head; |
| 405 | if (get_sha1(new_rev, new_rev_sha1)) { | 405 | if (cgit_get_sha1(new_rev, new_rev_sha1)) { |
| 406 | cgit_print_error_page(404, "Not found", | 406 | cgit_print_error_page(404, "Not found", |
| 407 | "Bad object name: %s", new_rev); | 407 | "Bad object name: %s", new_rev); |
| 408 | return; | 408 | return; |
| @@ -416,7 +416,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, · 7 unmodified lines | |||
| 416 | new_tree_sha1 = commit->tree->object.oid.hash; | 416 | new_tree_sha1 = commit->tree->object.oid.hash; |
| 417 | 417 | ||
| 418 | if (old_rev) { | 418 | if (old_rev) { |
| 419 | if (get_sha1(old_rev, old_rev_sha1)) { | 419 | if (cgit_get_sha1(old_rev, old_rev_sha1)) { |
| 420 | cgit_print_error_page(404, "Not found", | 420 | cgit_print_error_page(404, "Not found", |
| 421 | "Bad object name: %s", old_rev); | 421 | "Bad object name: %s", old_rev); |
| 422 | return; | 422 | return; |
| @@ -325,7 +325,7 @@ static const char *disambiguate_ref(const char *ref, int *must_free_result) · 324 unmodified lines | |||
| 325 | struct strbuf longref = STRBUF_INIT; | 325 | struct strbuf longref = STRBUF_INIT; |
| 326 | 326 | ||
| 327 | strbuf_addf(&longref, "refs/heads/%s", ref); | 327 | strbuf_addf(&longref, "refs/heads/%s", ref); |
| 328 | if (get_sha1(longref.buf, oid.hash) == 0) { | 328 | if (cgit_get_sha1(longref.buf, oid.hash) == 0) { |
| 329 | *must_free_result = 1; | 329 | *must_free_result = 1; |
| 330 | return strbuf_detach(&longref, NULL); | 330 | return strbuf_detach(&longref, NULL); |
| 331 | } | 331 | } |
| @@ -24,7 +24,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, · 23 unmodified lines | |||
| 24 | if (!new_rev) | 24 | if (!new_rev) |
| 25 | new_rev = ctx.qry.head; | 25 | new_rev = ctx.qry.head; |
| 26 | 26 | ||
| 27 | if (get_sha1(new_rev, new_rev_sha1)) { | 27 | if (cgit_get_sha1(new_rev, new_rev_sha1)) { |
| 28 | cgit_print_error_page(404, "Not found", | 28 | cgit_print_error_page(404, "Not found", |
| 29 | "Bad object id: %s", new_rev); | 29 | "Bad object id: %s", new_rev); |
| 30 | return; | 30 | return; |
| @@ -37,7 +37,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, · 6 unmodified lines | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | if (old_rev) { | 39 | if (old_rev) { |
| 40 | if (get_sha1(old_rev, old_rev_sha1)) { | 40 | if (cgit_get_sha1(old_rev, old_rev_sha1)) { |
| 41 | cgit_print_error_page(404, "Not found", | 41 | cgit_print_error_page(404, "Not found", |
| 42 | "Bad object id: %s", old_rev); | 42 | "Bad object id: %s", old_rev); |
| 43 | return; | 43 | return; |
| @@ -181,7 +181,7 @@ void cgit_print_plain(void) · 180 unmodified lines | |||
| 181 | if (!rev) | 181 | if (!rev) |
| 182 | rev = ctx.qry.head; | 182 | rev = ctx.qry.head; |
| 183 | 183 | ||
| 184 | if (get_sha1(rev, sha1)) { | 184 | if (cgit_get_sha1(rev, sha1)) { |
| 185 | cgit_print_error_page(404, "Not found", "Not found"); | 185 | cgit_print_error_page(404, "Not found", "Not found"); |
| 186 | return; | 186 | return; |
| 187 | } | 187 | } |
| @@ -1079,11 +1079,11 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, · 1078 unmodified lines | |||
| 1079 | * name starts with {v,V}[0-9] and the prettify mapping is injective, | 1079 | * name starts with {v,V}[0-9] and the prettify mapping is injective, |
| 1080 | * i.e. each stripped tag can be inverted without ambiguities. | 1080 | * i.e. each stripped tag can be inverted without ambiguities. |
| 1081 | */ | 1081 | */ |
| 1082 | if (get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 && | 1082 | if (cgit_get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 && |
| 1083 | (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) && | 1083 | (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) && |
| 1084 | ((get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) + | 1084 | ((cgit_get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) + |
| 1085 | (get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) + | 1085 | (cgit_get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) + |
| 1086 | (get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1)) | 1086 | (cgit_get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1)) |
| 1087 | ref++; | 1087 | ref++; |
| 1088 | 1088 | ||
| 1089 | strbuf_addf(filename, "%s-%s", base, ref); | 1089 | strbuf_addf(filename, "%s-%s", base, ref); |
| @@ -111,7 +111,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format, · 110 unmodified lines | |||
| 111 | { | 111 | { |
| 112 | unsigned char sha1[20]; | 112 | unsigned char sha1[20]; |
| 113 | 113 | ||
| 114 | if (get_sha1(hex, sha1)) { | 114 | if (cgit_get_sha1(hex, sha1)) { |
| 115 | cgit_print_error_page(404, "Not found", | 115 | cgit_print_error_page(404, "Not found", |
| 116 | "Bad object id: %s", hex); | 116 | "Bad object id: %s", hex); |
| 117 | return 1; | 117 | return 1; |
| @@ -150,7 +150,7 @@ static const char *get_ref_from_filename(const char *url, const char *filename, · 32 unmodified lines | |||
| 150 | strbuf_addstr(&snapshot, filename); | 150 | strbuf_addstr(&snapshot, filename); |
| 151 | strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix)); | 151 | strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix)); |
| 152 | 152 | ||
| 153 | if (get_sha1(snapshot.buf, sha1) == 0) | 153 | if (cgit_get_sha1(snapshot.buf, sha1) == 0) |
| 154 | goto out; | 154 | goto out; |
| 155 | 155 | ||
| 156 | reponame = cgit_repobasename(url); | 156 | reponame = cgit_repobasename(url); |
| @@ -162,15 +162,15 @@ static const char *get_ref_from_filename(const char *url, const char *filename, · 5 unmodified lines | |||
| 162 | strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0); | 162 | strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0); |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | if (get_sha1(snapshot.buf, sha1) == 0) | 165 | if (cgit_get_sha1(snapshot.buf, sha1) == 0) |
| 166 | goto out; | 166 | goto out; |
| 167 | 167 | ||
| 168 | strbuf_insert(&snapshot, 0, "v", 1); | 168 | strbuf_insert(&snapshot, 0, "v", 1); |
| 169 | if (get_sha1(snapshot.buf, sha1) == 0) | 169 | if (cgit_get_sha1(snapshot.buf, sha1) == 0) |
| 170 | goto out; | 170 | goto out; |
| 171 | 171 | ||
| 172 | strbuf_splice(&snapshot, 0, 1, "V", 1); | 172 | strbuf_splice(&snapshot, 0, 1, "V", 1); |
| 173 | if (get_sha1(snapshot.buf, sha1) == 0) | 173 | if (cgit_get_sha1(snapshot.buf, sha1) == 0) |
| 174 | goto out; | 174 | goto out; |
| 175 | 175 | ||
| 176 | result = 0; | 176 | result = 0; |
| @@ -51,7 +51,7 @@ void cgit_print_tag(char *revname) · 50 unmodified lines | |||
| 51 | revname = ctx.qry.head; | 51 | revname = ctx.qry.head; |
| 52 | 52 | ||
| 53 | strbuf_addf(&fullref, "refs/tags/%s", revname); | 53 | strbuf_addf(&fullref, "refs/tags/%s", revname); |
| 54 | if (get_sha1(fullref.buf, sha1)) { | 54 | if (cgit_get_sha1(fullref.buf, sha1)) { |
| 55 | cgit_print_error_page(404, "Not found", | 55 | cgit_print_error_page(404, "Not found", |
| 56 | "Bad tag reference: %s", revname); | 56 | "Bad tag reference: %s", revname); |
| 57 | goto cleanup; | 57 | goto cleanup; |
| @@ -306,7 +306,7 @@ void cgit_print_tree(const char *rev, char *path) · 305 unmodified lines | |||
| 306 | if (!rev) | 306 | if (!rev) |
| 307 | rev = ctx.qry.head; | 307 | rev = ctx.qry.head; |
| 308 | 308 | ||
| 309 | if (get_sha1(rev, sha1)) { | 309 | if (cgit_get_sha1(rev, sha1)) { |
| 310 | cgit_print_error_page(404, "Not found", | 310 | cgit_print_error_page(404, "Not found", |
| 311 | "Invalid revision name: %s", rev); | 311 | "Invalid revision name: %s", rev); |
| 312 | return; | 312 | return; |