]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit_graft_pos(): take an oid instead of a bare hash
authorJeff King <peff@peff.net>
Thu, 28 Jan 2021 06:12:35 +0000 (01:12 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 Jan 2021 19:21:07 +0000 (11:21 -0800)
All of our callers have an object_id, and are just dereferencing the
hash field to pass to us. Let's take the actual object_id instead. We
still access the hash to pass to hash_pos, but it's a step in the right
direction.

This makes the callers slightly simpler, but also gets rid of the
untyped pointer, as well as the now-inaccurate name "sha1".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit.c
commit.h
shallow.c

index bab8d5ab07c98f4e6fa67bb9469d896bd3d2d205..fa26729ba51666bbf09cf5a73b84e9315132bd9e 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -111,9 +111,9 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
        return commit_graft_table[index]->oid.hash;
 }
 
-int commit_graft_pos(struct repository *r, const unsigned char *sha1)
+int commit_graft_pos(struct repository *r, const struct object_id *oid)
 {
-       return hash_pos(sha1, r->parsed_objects->grafts,
+       return hash_pos(oid->hash, r->parsed_objects->grafts,
                        r->parsed_objects->grafts_nr,
                        commit_graft_sha1_access);
 }
@@ -121,7 +121,7 @@ int commit_graft_pos(struct repository *r, const unsigned char *sha1)
 int register_commit_graft(struct repository *r, struct commit_graft *graft,
                          int ignore_dups)
 {
-       int pos = commit_graft_pos(r, graft->oid.hash);
+       int pos = commit_graft_pos(r, &graft->oid);
 
        if (0 <= pos) {
                if (ignore_dups)
@@ -232,7 +232,7 @@ struct commit_graft *lookup_commit_graft(struct repository *r, const struct obje
 {
        int pos;
        prepare_commit_graft(r);
-       pos = commit_graft_pos(r, oid->hash);
+       pos = commit_graft_pos(r, oid);
        if (pos < 0)
                return NULL;
        return r->parsed_objects->grafts[pos];
index f4e7b0158e2595ec203ce4bc0fc14cd95192ab72..ecacf9ade36497d6d30dd14bc926fb7759db020d 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -239,7 +239,7 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
 
 struct commit_graft *read_graft_line(struct strbuf *line);
 /* commit_graft_pos returns an index into r->parsed_objects->grafts. */
-int commit_graft_pos(struct repository *r, const unsigned char *sha1);
+int commit_graft_pos(struct repository *r, const struct object_id *oid);
 int register_commit_graft(struct repository *r, struct commit_graft *, int);
 void prepare_commit_graft(struct repository *r);
 struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);
index 91b9e1073c9fb8427c42eb8a638e628f4a13c22a..9ed18eb8849b27856b8cc409921757f7f069b28b 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -41,7 +41,7 @@ int register_shallow(struct repository *r, const struct object_id *oid)
 
 int unregister_shallow(const struct object_id *oid)
 {
-       int pos = commit_graft_pos(the_repository, oid->hash);
+       int pos = commit_graft_pos(the_repository, oid);
        if (pos < 0)
                return -1;
        if (pos + 1 < the_repository->parsed_objects->grafts_nr)