summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-01-21 19:38:13 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2022-01-22 17:36:31 -0500
commit3044162b5c8192627965eb0aa2e959d761d71dd2 (patch)
tree2717854f786b61f007373cc9affee2e485f003dc
parent2132705c4be6de7d85cfdcc4b7ada5fe5e659544 (diff)
downloadlibgit2-3044162b5c8192627965eb0aa2e959d761d71dd2.tar.gz
commit_graph: use `git_oid_raw`
The commit graph consists of raw oids in an array; use the `git_oid_raw` type to access them.
-rw-r--r--src/commit_graph.c27
-rw-r--r--src/commit_graph.h2
2 files changed, 16 insertions, 13 deletions
diff --git a/src/commit_graph.c b/src/commit_graph.c
index 36f667741..1b4df05db 100644
--- a/src/commit_graph.c
+++ b/src/commit_graph.c
@@ -138,7 +138,7 @@ static int commit_graph_parse_oid_lookup(
struct git_commit_graph_chunk *chunk_oid_lookup)
{
uint32_t i;
- git_oid *oid, *prev_oid, zero_oid = {{0}};
+ git_oid_raw *oid, *prev_oid, zero_oid = {{0}};
if (chunk_oid_lookup->offset == 0)
return commit_graph_error("missing OID Lookup chunk");
@@ -150,7 +150,7 @@ static int commit_graph_parse_oid_lookup(
file->oid_lookup = oid = (git_oid_raw *)(data + chunk_oid_lookup->offset);
prev_oid = &zero_oid;
for (i = 0; i < file->num_commits; ++i, ++oid) {
- if (git_oid_raw_cmp(prev_oid, oid) >= 0)
+ if (git_oid_raw_cmp(prev_oid->id, oid->id) >= 0)
return commit_graph_error("OID Lookup index is non-monotonic");
prev_oid = oid;
}
@@ -437,7 +437,7 @@ static int git_commit_graph_entry_get_byindex(
}
commit_data = file->commit_data + pos * (GIT_OID_RAWSZ + 4 * sizeof(uint32_t));
- git_oid_cpy(&e->tree_oid, (const git_oid *)commit_data);
+ git_oid_fromraw(&e->tree_oid, commit_data);
e->parent_indices[0] = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ)));
e->parent_indices[1] = ntohl(
*((uint32_t *)(commit_data + GIT_OID_RAWSZ + sizeof(uint32_t))));
@@ -470,7 +470,8 @@ static int git_commit_graph_entry_get_byindex(
e->parent_count++;
}
}
- git_oid_cpy(&e->sha1, &file->oid_lookup[pos]);
+
+ git_oid_fromraw(&e->sha1, file->oid_lookup[pos].id);
return 0;
}
@@ -514,7 +515,7 @@ int git_commit_graph_entry_find(
{
int pos, found = 0;
uint32_t hi, lo;
- const git_oid *current = NULL;
+ const git_oid_raw *current = NULL;
GIT_ASSERT_ARG(e);
GIT_ASSERT_ARG(file);
@@ -536,18 +537,17 @@ int git_commit_graph_entry_find(
if (pos < (int)file->num_commits) {
current = file->oid_lookup + pos;
- if (!git_oid_ncmp(short_oid, current, len))
+ if (!git_oid_raw_ncmp(short_oid->id, current->id, len))
found = 1;
}
}
if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)file->num_commits) {
/* Check for ambiguousity */
- const git_oid *next = current + 1;
+ const git_oid_raw *next = current + 1;
- if (!git_oid_ncmp(short_oid, next, len)) {
+ if (!git_oid_raw_ncmp(short_oid->id, next->id, len))
found = 2;
- }
}
if (!found)
@@ -1019,7 +1019,9 @@ static int commit_graph_write(
/* Fill the OID Lookup table. */
git_vector_foreach (&w->commits, i, packed_commit) {
error = git_str_put(&oid_lookup,
- (const char *)&packed_commit->sha1, sizeof(git_oid));
+ (const char *)&packed_commit->sha1.id,
+ sizeof(git_oid_raw));
+
if (error < 0)
goto cleanup;
}
@@ -1034,8 +1036,9 @@ static int commit_graph_write(
unsigned int parentcount = (unsigned int)git_array_size(packed_commit->parents);
error = git_str_put(&commit_data,
- (const char *)&packed_commit->tree_oid,
- sizeof(git_oid));
+ (const char *)&packed_commit->tree_oid.id,
+ sizeof(git_oid_raw));
+
if (error < 0)
goto cleanup;
diff --git a/src/commit_graph.h b/src/commit_graph.h
index 45e125b9e..65d223490 100644
--- a/src/commit_graph.h
+++ b/src/commit_graph.h
@@ -36,7 +36,7 @@ typedef struct git_commit_graph_file {
uint32_t num_commits;
/* The OID Lookup table. */
- git_oid *oid_lookup;
+ git_oid_raw *oid_lookup;
/*
* The Commit Data table. Each entry contains the OID of the commit followed