8000 sha256: refactoring in preparation for sha256 by ethomson · Pull Request #6265 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

sha256: refactoring in preparation for sha256 #6265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
oid: hashcmp is now raw_cmp
We will talk about "raw" oids as untyped blobs of data; use a name for
the comparison function that is in keeping with that.
  • Loading branch information
ethomson committed Apr 10, 2022
commit 526e8869bf5f3d111b427d58d79d849f9f3df211
4 changes: 2 additions & 2 deletions src/libgit2/commit_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ static int commit_graph_parse_oid_lookup(
if (chunk_oid_lookup->length != file->num_commits * GIT_OID_RAWSZ)
return commit_graph_error("OID Lookup chunk has wrong length");

file->oid_lookup = oid = (git_oid *)(data + chunk_oid_lookup->offset);
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_cmp(prev_oid, oid) >= 0)
if (git_oid_raw_cmp(prev_oid, oid) >= 0)
return commit_graph_error("OID Lookup index is non-monotonic");
prev_oid = oid;
}
Expand Down
6 changes: 4 additions & 2 deletions src/libgit2/oid.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ extern const git_oid git_oid__empty_tree_sha1;
*/
char *git_oid_allocfmt(const git_oid *id);

GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char *sha2)
GIT_INLINE(int) git_oid_raw_cmp(
const unsigned char *sha1,
const unsigned char *sha2)
{
return memcmp(sha1, sha2, GIT_OID_RAWSZ);
}
Expand All @@ -39,7 +41,7 @@ GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char
*/
GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
{
return git_oid__hashcmp(a->id, b->id);
return git_oid_raw_cmp(a->id, b->id);
}

GIT_INLINE(void) git_oid__cpy_prefix(
Expand Down
2 changes: 1 addition & 1 deletion src/libgit2/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned

while (lo < hi) {
unsigned mi = (lo + hi) / 2;
int cmp = git_oid__hashcmp(base + mi * stride, oid_prefix);
int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix);

if (!cmp)
return mi;
Expand Down
0