From 45ee13b942b26925b33d827bda2856e1ed0af0b7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 28 Jan 2021 01:19:42 -0500 Subject: hash_pos(): convert to oid_pos() All of our callers are actually looking up an object_id, not a bare hash. Likewise, the arrays they are looking in are actual arrays of object_id (not just raw bytes of hashes, as we might find in a pack .idx; those are handled by bsearch_hash()). Using an object_id gives us more type safety, and makes the callers slightly shorter. It also gets rid of the word "sha1" from several access functions, though we could obviously also rename those with s/sha1/hash/. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- commit-graph.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'commit-graph.c') diff --git a/commit-graph.c b/commit-graph.c index f3486ec18f..248f1efb73 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1012,10 +1012,10 @@ static int write_graph_chunk_oids(struct hashfile *f, return 0; } -static const unsigned char *commit_to_sha1(size_t index, void *table) +static const struct object_id *commit_to_oid(size_t index, void *table) { struct commit **commits = table; - return commits[index]->object.oid.hash; + return &commits[index]->object.oid; } static int write_graph_chunk_data(struct hashfile *f, @@ -1043,10 +1043,10 @@ static int write_graph_chunk_data(struct hashfile *f, if (!parent) edge_value = GRAPH_PARENT_NONE; else { - edge_value = hash_pos(parent->item->object.oid.hash, - ctx->commits.list, - ctx->commits.nr, - commit_to_sha1); + edge_value = oid_pos(&parent->item->object.oid, + ctx->commits.list, + ctx->commits.nr, + commit_to_oid); if (edge_value >= 0) edge_value += ctx->new_num_commits_in_base; @@ -1074,10 +1074,10 @@ static int write_graph_chunk_data(struct hashfile *f, else if (parent->next) edge_value = GRAPH_EXTRA_EDGES_NEEDED | num_extra_edges; else { - edge_value = hash_pos(parent->item->object.oid.hash, - ctx->commits.list, - ctx->commits.nr, - commit_to_sha1); + edge_value = oid_pos(&parent->item->object.oid, + ctx->commits.list, + ctx->commits.nr, + commit_to_oid); if (edge_value >= 0) edge_value += ctx->new_num_commits_in_base; @@ -1143,10 +1143,10 @@ static int write_graph_chunk_extra_edges(struct hashfile *f, /* Since num_parents > 2, this initializer is safe. */ for (parent = (*list)->parents->next; parent; parent = parent->next) { - int edge_value = hash_pos(parent->item->object.oid.hash, - ctx->commits.list, - ctx->commits.nr, - commit_to_sha1); + int edge_value = oid_pos(&parent->item->object.oid, + ctx->commits.list, + ctx->commits.nr, + commit_to_oid); if (edge_value >= 0) edge_value += ctx->new_num_commits_in_base; -- cgit v1.2.3 From 8380dcd700e80cd22745bcffb3625f90f943950c Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 28 Jan 2021 01:20:23 -0500 Subject: oid_pos(): access table through const pointers When we are looking up an oid in an array, we obviously don't need to write to the array. Let's mark it as const in the function interfaces, as well as in the local variables we use to derference the void pointer (note a few cases use pointers-to-pointers, so we mark everything const). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- commit-graph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'commit-graph.c') diff --git a/commit-graph.c b/commit-graph.c index 248f1efb73..b09fce5f57 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1012,9 +1012,9 @@ static int write_graph_chunk_oids(struct hashfile *f, return 0; } -static const struct object_id *commit_to_oid(size_t index, void *table) +static const struct object_id *commit_to_oid(size_t index, const void *table) { - struct commit **commits = table; + const struct commit * const *commits = table; return &commits[index]->object.oid; } -- cgit v1.2.3