]> granicus.if.org Git - cgit/commitdiff
Add a wrapper for get_sha1 called cgit_get_sha1
authorRichard Maw <richard.maw@gmail.com>
Sat, 25 Jun 2016 19:23:51 +0000 (20:23 +0100)
committerRichard Maw <richard.maw@gmail.com>
Wed, 13 Jul 2016 19:09:37 +0000 (20:09 +0100)
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>
13 files changed:
cgit.c
cgit.h
shared.c
ui-blob.c
ui-commit.c
ui-diff.c
ui-log.c
ui-patch.c
ui-plain.c
ui-shared.c
ui-snapshot.c
ui-tag.c
ui-tree.c

diff --git a/cgit.c b/cgit.c
index 9427c4a2752c9fe321da795ee279987afb12092f..94d452cbd8f76a8c9358ad5a90a89b4a427eccc7 100644 (file)
--- a/cgit.c
+++ b/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",
diff --git a/cgit.h b/cgit.h
index 325432bae774e06f0e3490cb317f01f4debedb4b..49f0557978943c5701e12f913cd266b1981cde8e 100644 (file)
--- a/cgit.h
+++ b/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 */
index a63633b295578cc9302b9842722a0184e4e02792..d82c07b7c3720eea61325724cc2319b510fa5278 100644 (file)
--- a/shared.c
+++ b/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);
+}
index d38848984cf4f6b433ba4530872eccb3c550f526..21d21edd75487c23d1b5fdd43331bd2eae3bcf23 100644 (file)
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -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;
index 099d294fa8fba261168cdc3091ebda97d6f97ab7..5ba07919ae7873120bbd319f76d75a4822f4f8a1 100644 (file)
@@ -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;
index edee79339b12d658e30041f0c2b7ff0cb1229b9b..9256d127e91ad7bbfee8e0c677f51e199e29d8ac 100644 (file)
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -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;
index c97b8e05e535740e3f73cb60dd515544d9dcce06..28ef3c0263375e36a2cf6c11d8f4ccae47a86eff 100644 (file)
--- a/ui-log.c
+++ b/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);
        }
index 4c051e8caa200fa30973338f0670cd77d685b975..ff09a8e8ff8bcb5996570a28c059b6cfbe1ff885 100644 (file)
@@ -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;
index 97cf6394e7021f6a2935b1d98a632eb1da8f81ba..88dd1a8e34cf5d103952d7cee4ae52e1818ad4fa 100644 (file)
@@ -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;
        }
index e39d004e5d74019a26a642d5e04443936fe6769b..ca40d420c8b93da02d0d54a20f51a49b5f132ae9 100644 (file)
@@ -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);
index c6c365683a8d2c8c45aa5cb1c4f9aba97ef06f52..93af28e8896aeadf44c0e5b553f1be336fa01e58 100644 (file)
@@ -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;
index 6b838cb7b238cd66308a78fb090f096389cd1e30..7372770b0ff28868ccbb849ce483a0f00904d888 100644 (file)
--- a/ui-tag.c
+++ b/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;
index 120066c425346f4b48d8061ed5f908da66138fc3..ae2acce5c0df05e93881117f99d369c6c5124422 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -306,7 +306,7 @@ void cgit_print_tree(const char *rev, char *path)
        if (!rev)
                rev = ctx.qry.head;
 
-       if (get_sha1(rev, sha1)) {
+       if (cgit_get_sha1(rev, sha1)) {
                cgit_print_error_page(404, "Not found",
                        "Invalid revision name: %s", rev);
                return;