mirror of
https://git.zx2c4.com/cgit
synced 2025-01-11 17:01:52 +00:00
Add a wrapper for get_sha1 called cgit_get_sha1
This will later be changed to include namespace resolution, but the call sites are changed now to keep the changes small. Signed-off-by: Richard Maw <richard.maw@gmail.com>
This commit is contained in:
parent
52a0eca64f
commit
b2ac89127a
2
cgit.c
2
cgit.c
@ -615,7 +615,7 @@ static int prepare_repo_cmd(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (get_sha1(ctx.qry.head, sha1)) {
|
||||
if (cgit_get_sha1(ctx.qry.head, sha1)) {
|
||||
char *old_head = ctx.qry.head;
|
||||
ctx.qry.head = xstrdup(ctx.repo->defbranch);
|
||||
cgit_print_error_page(404, "Not found",
|
||||
|
2
cgit.h
2
cgit.h
@ -391,4 +391,6 @@ extern char *expand_macros(const char *txt);
|
||||
|
||||
extern char *get_mimetype_for_filename(const char *filename);
|
||||
|
||||
extern int cgit_get_sha1(const char *name, unsigned char *sha1);
|
||||
|
||||
#endif /* CGIT_H */
|
||||
|
5
shared.c
5
shared.c
@ -601,3 +601,8 @@ char *get_mimetype_for_filename(const char *filename)
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int cgit_get_sha1(const char *name, unsigned char *sha1)
|
||||
{
|
||||
return get_sha1(name, sha1);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only)
|
||||
.file_only = file_only
|
||||
};
|
||||
|
||||
if (get_sha1(ref, sha1))
|
||||
if (cgit_get_sha1(ref, sha1))
|
||||
return 0;
|
||||
if (sha1_object_info(sha1, &size) != OBJ_COMMIT)
|
||||
return 0;
|
||||
@ -82,7 +82,7 @@ int cgit_print_file(char *path, const char *head, int file_only)
|
||||
.file_only = file_only
|
||||
};
|
||||
|
||||
if (get_sha1(head, sha1))
|
||||
if (cgit_get_sha1(head, sha1))
|
||||
return -1;
|
||||
type = sha1_object_info(sha1, &size);
|
||||
if (type == OBJ_COMMIT) {
|
||||
@ -132,7 +132,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (get_sha1(head, sha1)) {
|
||||
if (cgit_get_sha1(head, sha1)) {
|
||||
cgit_print_error_page(404, "Not found",
|
||||
"Bad ref: %s", head);
|
||||
return;
|
||||
|
@ -26,7 +26,7 @@ void cgit_print_commit(char *hex, const char *prefix)
|
||||
if (!hex)
|
||||
hex = ctx.qry.head;
|
||||
|
||||
if (get_sha1(hex, sha1)) {
|
||||
if (cgit_get_sha1(hex, sha1)) {
|
||||
cgit_print_error_page(400, "Bad request",
|
||||
"Bad object id: %s", hex);
|
||||
return;
|
||||
|
@ -402,7 +402,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
|
||||
|
||||
if (!new_rev)
|
||||
new_rev = ctx.qry.head;
|
||||
if (get_sha1(new_rev, new_rev_sha1)) {
|
||||
if (cgit_get_sha1(new_rev, new_rev_sha1)) {
|
||||
cgit_print_error_page(404, "Not found",
|
||||
"Bad object name: %s", new_rev);
|
||||
return;
|
||||
@ -416,7 +416,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
|
||||
new_tree_sha1 = commit->tree->object.oid.hash;
|
||||
|
||||
if (old_rev) {
|
||||
if (get_sha1(old_rev, old_rev_sha1)) {
|
||||
if (cgit_get_sha1(old_rev, old_rev_sha1)) {
|
||||
cgit_print_error_page(404, "Not found",
|
||||
"Bad object name: %s", old_rev);
|
||||
return;
|
||||
|
2
ui-log.c
2
ui-log.c
@ -325,7 +325,7 @@ static const char *disambiguate_ref(const char *ref, int *must_free_result)
|
||||
struct strbuf longref = STRBUF_INIT;
|
||||
|
||||
strbuf_addf(&longref, "refs/heads/%s", ref);
|
||||
if (get_sha1(longref.buf, oid.hash) == 0) {
|
||||
if (cgit_get_sha1(longref.buf, oid.hash) == 0) {
|
||||
*must_free_result = 1;
|
||||
return strbuf_detach(&longref, NULL);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
|
||||
if (!new_rev)
|
||||
new_rev = ctx.qry.head;
|
||||
|
||||
if (get_sha1(new_rev, new_rev_sha1)) {
|
||||
if (cgit_get_sha1(new_rev, new_rev_sha1)) {
|
||||
cgit_print_error_page(404, "Not found",
|
||||
"Bad object id: %s", new_rev);
|
||||
return;
|
||||
@ -37,7 +37,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
|
||||
}
|
||||
|
||||
if (old_rev) {
|
||||
if (get_sha1(old_rev, old_rev_sha1)) {
|
||||
if (cgit_get_sha1(old_rev, old_rev_sha1)) {
|
||||
cgit_print_error_page(404, "Not found",
|
||||
"Bad object id: %s", old_rev);
|
||||
return;
|
||||
|
@ -181,7 +181,7 @@ void cgit_print_plain(void)
|
||||
if (!rev)
|
||||
rev = ctx.qry.head;
|
||||
|
||||
if (get_sha1(rev, sha1)) {
|
||||
if (cgit_get_sha1(rev, sha1)) {
|
||||
cgit_print_error_page(404, "Not found", "Not found");
|
||||
return;
|
||||
}
|
||||
|
@ -1079,11 +1079,11 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base,
|
||||
* name starts with {v,V}[0-9] and the prettify mapping is injective,
|
||||
* i.e. each stripped tag can be inverted without ambiguities.
|
||||
*/
|
||||
if (get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 &&
|
||||
if (cgit_get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 &&
|
||||
(ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) &&
|
||||
((get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) +
|
||||
(get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) +
|
||||
(get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1))
|
||||
((cgit_get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) +
|
||||
(cgit_get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) +
|
||||
(cgit_get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1))
|
||||
ref++;
|
||||
|
||||
strbuf_addf(filename, "%s-%s", base, ref);
|
||||
|
@ -111,7 +111,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
|
||||
{
|
||||
unsigned char sha1[20];
|
||||
|
||||
if (get_sha1(hex, sha1)) {
|
||||
if (cgit_get_sha1(hex, sha1)) {
|
||||
cgit_print_error_page(404, "Not found",
|
||||
"Bad object id: %s", hex);
|
||||
return 1;
|
||||
@ -150,7 +150,7 @@ static const char *get_ref_from_filename(const char *url, const char *filename,
|
||||
strbuf_addstr(&snapshot, filename);
|
||||
strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix));
|
||||
|
||||
if (get_sha1(snapshot.buf, sha1) == 0)
|
||||
if (cgit_get_sha1(snapshot.buf, sha1) == 0)
|
||||
goto out;
|
||||
|
||||
reponame = cgit_repobasename(url);
|
||||
@ -162,15 +162,15 @@ static const char *get_ref_from_filename(const char *url, const char *filename,
|
||||
strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0);
|
||||
}
|
||||
|
||||
if (get_sha1(snapshot.buf, sha1) == 0)
|
||||
if (cgit_get_sha1(snapshot.buf, sha1) == 0)
|
||||
goto out;
|
||||
|
||||
strbuf_insert(&snapshot, 0, "v", 1);
|
||||
if (get_sha1(snapshot.buf, sha1) == 0)
|
||||
if (cgit_get_sha1(snapshot.buf, sha1) == 0)
|
||||
goto out;
|
||||
|
||||
strbuf_splice(&snapshot, 0, 1, "V", 1);
|
||||
if (get_sha1(snapshot.buf, sha1) == 0)
|
||||
if (cgit_get_sha1(snapshot.buf, sha1) == 0)
|
||||
goto out;
|
||||
|
||||
result = 0;
|
||||
|
2
ui-tag.c
2
ui-tag.c
@ -51,7 +51,7 @@ void cgit_print_tag(char *revname)
|
||||
revname = ctx.qry.head;
|
||||
|
||||
strbuf_addf(&fullref, "refs/tags/%s", revname);
|
||||
if (get_sha1(fullref.buf, sha1)) {
|
||||
if (cgit_get_sha1(fullref.buf, sha1)) {
|
||||
cgit_print_error_page(404, "Not found",
|
||||
"Bad tag reference: %s", revname);
|
||||
goto cleanup;
|
||||
|
Loading…
Reference in New Issue
Block a user