Unverified Commit 3b52e5f5 by Edward Thomson Committed by GitHub

Merge pull request #6265 from libgit2/ethomson/sha256_two

sha256: refactoring in preparation for sha256
parents 63970244 f8821405
......@@ -94,7 +94,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
fprintf(stderr, "Failed to compute the SHA1 hash\n");
abort();
}
if (git_indexer_append(indexer, &oid, sizeof(oid), &stats) < 0) {
if (git_indexer_append(indexer, &oid.id, GIT_OID_RAWSZ, &stats) < 0) {
goto cleanup;
}
}
......
......@@ -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}};
unsigned char *oid, *prev_oid, zero_oid[GIT_OID_RAWSZ] = {0};
if (chunk_oid_lookup->offset == 0)
return commit_graph_error("missing OID Lookup chunk");
......@@ -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);
prev_oid = &zero_oid;
for (i = 0; i < file->num_commits; ++i, ++oid) {
if (git_oid_cmp(prev_oid, oid) >= 0)
file->oid_lookup = oid = (unsigned char *)(data + chunk_oid_lookup->offset);
prev_oid = zero_oid;
for (i = 0; i < file->num_commits; ++i, oid += GIT_OID_RAWSZ) {
if (git_oid_raw_cmp(prev_oid, oid) >= 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 * GIT_OID_RAWSZ]);
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 unsigned char *current = NULL;
GIT_ASSERT_ARG(e);
GIT_ASSERT_ARG(file);
......@@ -528,26 +529,25 @@ int git_commit_graph_entry_find(
if (pos >= 0) {
/* An object matching exactly the oid was found */
found = 1;
current = file->oid_lookup + pos;
current = file->oid_lookup + (pos * GIT_OID_RAWSZ);
} else {
/* No object was found */
/* pos refers to the object with the "closest" oid to short_oid */
pos = -1 - pos;
if (pos < (int)file->num_commits) {
current = file->oid_lookup + pos;
current = file->oid_lookup + (pos * GIT_OID_RAWSZ);
if (!git_oid_ncmp(short_oid, current, len))
if (!git_oid_raw_ncmp(short_oid->id, current, 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 unsigned char *next = current + GIT_OID_RAWSZ;
if (!git_oid_ncmp(short_oid, next, len)) {
if (!git_oid_raw_ncmp(short_oid->id, next, 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,
GIT_OID_RAWSZ);
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,
GIT_OID_RAWSZ);
if (error < 0)
goto cleanup;
......
......@@ -36,7 +36,7 @@ typedef struct git_commit_graph_file {
uint32_t num_commits;
/* The OID Lookup table. */
git_oid *oid_lookup;
unsigned char *oid_lookup;
/*
* The Commit Data table. Each entry contains the OID of the commit followed
......
......@@ -74,7 +74,7 @@ struct entry_short {
uint32_t uid;
uint32_t gid;
uint32_t file_size;
git_oid oid;
unsigned char oid[GIT_OID_RAWSZ];
uint16_t flags;
char path[1]; /* arbitrary length */
};
......@@ -88,7 +88,7 @@ struct entry_long {
uint32_t uid;
uint32_t gid;
uint32_t file_size;
git_oid oid;
unsigned char oid[GIT_OID_RAWSZ];
uint16_t flags;
uint16_t flags_extended;
char path[1]; /* arbitrary length */
......@@ -2480,9 +2480,11 @@ static int read_entry(
entry.uid = ntohl(source.uid);
entry.gid = ntohl(source.gid);
entry.file_size = ntohl(source.file_size);
git_oid_cpy(&entry.id, &source.oid);
entry.flags = ntohs(source.flags);
if (git_oid_fromraw(&entry.id, source.oid) < 0)
return -1;
if (entry.flags & GIT_INDEX_ENTRY_EXTENDED) {
uint16_t flags_raw;
size_t flags_offset;
......@@ -2803,9 +2805,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
ondisk.uid = htonl(entry->uid);
ondisk.gid = htonl(entry->gid);
ondisk.file_size = htonl((uint32_t)entry->file_size);
git_oid_cpy(&ondisk.oid, &entry->id);
git_oid_raw_cpy(ondisk.oid, entry->id.id);
ondisk.flags = htons(entry->flags);
if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) {
......
......@@ -385,7 +385,7 @@ static int check_object_connectivity(git_indexer *idx, const git_rawobj *obj)
size_t i;
git_array_foreach(tree->entries, i, entry)
if (add_expected_oid(idx, entry->oid) < 0)
if (add_expected_oid(idx, &entry->oid) < 0)
goto out;
break;
......@@ -1269,7 +1269,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
/* Write out the object names (SHA-1 hashes) */
git_vector_foreach(&idx->objects, i, entry) {
git_filebuf_write(&index_file, &entry->oid, sizeof(git_oid));
git_filebuf_write(&index_file, &entry->oid.id, GIT_OID_RAWSZ);
}
/* Write out the CRC32 values */
......
......@@ -613,7 +613,7 @@ GIT_INLINE(int) tree_iterator_frame_push_neighbors(
break;
if ((error = git_tree_lookup(&tree,
iter->base.repo, entry->tree_entry->oid)) < 0)
iter->base.repo, &entry->tree_entry->oid)) < 0)
break;
if (git_vector_insert(&parent_frame->similar_trees, tree) < 0)
......@@ -659,7 +659,7 @@ GIT_INLINE(int) tree_iterator_frame_push(
int error;
if ((error = git_tree_lookup(&tree,
iter->base.repo, entry->tree_entry->oid)) < 0 ||
iter->base.repo, &entry->tree_entry->oid)) < 0 ||
(error = tree_iterator_frame_init(iter, tree, entry)) < 0)
goto done;
......@@ -740,7 +740,7 @@ static void tree_iterator_set_current(
iter->entry.mode = tree_entry->attr;
iter->entry.path = iter->entry_path.ptr;
git_oid_cpy(&iter->entry.id, tree_entry->oid);
git_oid_cpy(&iter->entry.id, &tree_entry->oid);
}
static int tree_iterator_advance(const git_index_entry **out, git_iterator *i)
......
......@@ -115,7 +115,7 @@ static int midx_parse_oid_lookup(
struct git_midx_chunk *chunk_oid_lookup)
{
uint32_t i;
git_oid *oid, *prev_oid, zero_oid = {{0}};
unsigned char *oid, *prev_oid, zero_oid[GIT_OID_RAWSZ] = {0};
if (chunk_oid_lookup->offset == 0)
return midx_error("missing OID Lookup chunk");
......@@ -124,10 +124,10 @@ static int midx_parse_oid_lookup(
if (chunk_oid_lookup->length != idx->num_objects * GIT_OID_RAWSZ)
return midx_error("OID Lookup chunk has wrong length");
idx->oid_lookup = oid = (git_oid *)(data + chunk_oid_lookup->offset);
prev_oid = &zero_oid;
for (i = 0; i < idx->num_objects; ++i, ++oid) {
if (git_oid_cmp(prev_oid, oid) >= 0)
idx->oid_lookup = oid = (unsigned char *)(data + chunk_oid_lookup->offset);
prev_oid = zero_oid;
for (i = 0; i < idx->num_objects; ++i, oid += GIT_OID_RAWSZ) {
if (git_oid_raw_cmp(prev_oid, oid) >= 0)
return midx_error("OID Lookup index is non-monotonic");
prev_oid = oid;
}
......@@ -389,7 +389,7 @@ int git_midx_entry_find(
int pos, found = 0;
size_t pack_index;
uint32_t hi, lo;
const git_oid *current = NULL;
unsigned char *current = NULL;
const unsigned char *object_offset;
off64_t offset;
......@@ -403,26 +403,25 @@ int git_midx_entry_find(
if (pos >= 0) {
/* An object matching exactly the oid was found */
found = 1;
current = idx->oid_lookup + pos;
current = idx->oid_lookup + (pos * GIT_OID_RAWSZ);
} else {
/* No object was found */
/* pos refers to the object with the "closest" oid to short_oid */
pos = -1 - pos;
if (pos < (int)idx->num_objects) {
current = idx->oid_lookup + pos;
current = idx->oid_lookup + (pos * GIT_OID_RAWSZ);
if (!git_oid_ncmp(short_oid, current, len))
if (!git_oid_raw_ncmp(short_oid->id, current, len))
found = 1;
}
}
if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)idx->num_objects) {
/* Check for ambiguousity */
const git_oid *next = current + 1;
const unsigned char *next = current + GIT_OID_RAWSZ;
if (!git_oid_ncmp(short_oid, next, len)) {
if (!git_oid_raw_ncmp(short_oid->id, next, len))
found = 2;
}
}
if (!found)
......@@ -450,7 +449,7 @@ int git_midx_entry_find(
return midx_error("invalid index into the packfile names table");
e->pack_index = pack_index;
e->offset = offset;
git_oid_cpy(&e->sha1, current);
git_oid_fromraw(&e->sha1, current);
return 0;
}
......@@ -459,13 +458,17 @@ int git_midx_foreach_entry(
git_odb_foreach_cb cb,
void *data)
{
git_oid oid;
size_t i;
int error;
GIT_ASSERT_ARG(idx);
for (i = 0; i < idx->num_objects; ++i) {
if ((error = cb(&idx->oid_lookup[i], data)) != 0)
if ((error = git_oid_fromraw(&oid, &idx->oid_lookup[i * GIT_OID_RAWSZ])) < 0)
return error;
if ((error = cb(&oid, data)) != 0)
return git_error_set_after_callback(error);
}
......@@ -751,7 +754,7 @@ static int midx_write(
/* Fill the OID Lookup table. */
git_vector_foreach (&object_entries, i, entry) {
error = git_str_put(&oid_lookup, (const char *)&entry->sha1, sizeof(entry->sha1));
error = git_str_put(&oid_lookup, (char *)&entry->sha1.id, GIT_OID_RAWSZ);
if (error < 0)
goto cleanup;
}
......
......@@ -17,6 +17,7 @@
#include "map.h"
#include "mwindow.h"
#include "odb.h"
#include "oid.h"
/*
* A multi-pack-index file.
......@@ -40,7 +41,7 @@ typedef struct git_midx_file {
uint32_t num_objects;
/* The OID Lookup table. */
git_oid *oid_lookup;
unsigned char *oid_lookup;
/* The Object Offsets table. Each entry has two 4-byte fields with the pack index and the offset. */
const unsigned char *object_offsets;
......
......@@ -187,8 +187,7 @@ int git_oid_fromraw(git_oid *out, const unsigned char *raw)
int git_oid_cpy(git_oid *out, const git_oid *src)
{
memcpy(out->id, src->id, sizeof(out->id));
return 0;
return git_oid_raw_cpy(out->id, src->id);
}
int git_oid_cmp(const git_oid *a, const git_oid *b)
......@@ -203,25 +202,7 @@ int git_oid_equal(const git_oid *a, const git_oid *b)
int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
{
const unsigned char *a = oid_a->id;
const unsigned char *b = oid_b->id;
if (len > GIT_OID_HEXSZ)
len = GIT_OID_HEXSZ;
while (len > 1) {
if (*a != *b)
return 1;
a++;
b++;
len -= 2;
};
if (len)
if ((*a ^ *b) & 0xf0)
return 1;
return 0;
return git_oid_raw_ncmp(oid_a->id, oid_b->id, len);
}
int git_oid_strcmp(const git_oid *oid_a, const char *str)
......
......@@ -25,11 +25,44 @@ 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_ncmp(
const unsigned char *sha1,
const unsigned char *sha2,
size_t len)
{
if (len > GIT_OID_HEXSZ)
len = GIT_OID_HEXSZ;
while (len > 1) {
if (*sha1 != *sha2)
return 1;
sha1++;
sha2++;
len -= 2;
};
if (len)
if ((*sha1 ^ *sha2) & 0xf0)
return 1;
return 0;
}
GIT_INLINE(int) git_oid_raw_cmp(
const unsigned char *sha1,
const unsigned char *sha2)
{
return memcmp(sha1, sha2, GIT_OID_RAWSZ);
}
GIT_INLINE(int) git_oid_raw_cpy(
unsigned char *dst,
const unsigned char *src)
{
memcpy(dst, src, GIT_OID_RAWSZ);
return 0;
}
/*
* Compare two oid structures.
*
......@@ -39,7 +72,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(
......
......@@ -19,7 +19,7 @@ __KHASH_TYPE(oid, const git_oid *, void *)
GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
{
khint_t h;
memcpy(&h, oid, sizeof(khint_t));
memcpy(&h, oid->id, sizeof(khint_t));
return h;
}
......
......@@ -1001,13 +1001,14 @@ int get_delta_base(
base_offset = delta_obj_offset - unsigned_base_offset;
*curpos += used;
} else if (type == GIT_OBJECT_REF_DELTA) {
git_oid base_oid;
git_oid_fromraw(&base_oid, base_info);
/* If we have the cooperative cache, search in it first */
if (p->has_cache) {
struct git_pack_entry *entry;
git_oid oid;
git_oid_fromraw(&oid, base_info);
if ((entry = git_oidmap_get(p->idx_cache, &oid)) != NULL) {
if ((entry = git_oidmap_get(p->idx_cache, &base_oid)) != NULL) {
if (entry->offset == 0)
return packfile_error("delta offset is zero");
......@@ -1024,7 +1025,7 @@ int get_delta_base(
}
/* The base entry _must_ be in the same pack */
if (pack_entry_find_offset(&base_offset, &unused, p, (git_oid *)base_info, GIT_OID_HEXSZ) < 0)
if (pack_entry_find_offset(&base_offset, &unused, p, &base_oid, GIT_OID_HEXSZ) < 0)
return packfile_error("base entry delta is not in the same pack");
*curpos += 20;
} else
......@@ -1082,7 +1083,7 @@ static int packfile_open_locked(struct git_pack_file *p)
{
struct stat st;
struct git_pack_header hdr;
git_oid sha1;
unsigned char sha1[GIT_OID_RAWSZ];
unsigned char *idx_sha1;
if (pack_index_open_locked(p) < 0)
......@@ -1130,12 +1131,12 @@ static int packfile_open_locked(struct git_pack_file *p)
/* Verify the pack matches its index. */
if (p->num_objects != ntohl(hdr.hdr_entries) ||
p_pread(p->mwf.fd, sha1.id, GIT_OID_RAWSZ, p->mwf.size - GIT_OID_RAWSZ) < 0)
p_pread(p->mwf.fd, sha1, GIT_OID_RAWSZ, p->mwf.size - GIT_OID_RAWSZ) < 0)
goto cleanup;
idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40;
if (git_oid__cmp(&sha1, (git_oid *)idx_sha1) != 0)
if (git_oid_raw_cmp(sha1, idx_sha1) != 0)
goto cleanup;
if (git_mwindow_file_register(&p->mwf) < 0)
......@@ -1340,10 +1341,14 @@ int git_pack_foreach_entry(
}
git_vector_free(&offsets);
p->oids = (git_oid **)git_vector_detach(NULL, NULL, &oids);
p->oids = (unsigned char **)git_vector_detach(NULL, NULL, &oids);
}
/* We need to copy the OIDs to another array before we relinquish the lock to avoid races. */
/*
* We need to copy the OIDs to another array before we
* relinquish the lock to avoid races. We can also take
* this opportunity to put them into normal form.
*/
git_array_init_to_size(oids, p->num_objects);
if (!oids.ptr) {
git_mutex_unlock(&p->lock);
......@@ -1357,7 +1362,7 @@ int git_pack_foreach_entry(
git_array_clear(oids);
GIT_ERROR_CHECK_ALLOC(oid);
}
git_oid_cpy(oid, p->oids[i]);
git_oid_fromraw(oid, p->oids[i]);
}
git_mutex_unlock(&p->lock);
......@@ -1380,7 +1385,7 @@ int git_pack_foreach_entry_offset(
{
const unsigned char *index;
off64_t current_offset;
const git_oid *current_oid;
git_oid current_oid;
uint32_t i;
int error = 0;
......@@ -1422,8 +1427,9 @@ int git_pack_foreach_entry_offset(
current_offset = (((off64_t)ntohl(*((uint32_t *)(large_offset_ptr + 0)))) << 32) |
ntohl(*((uint32_t *)(large_offset_ptr + 4)));
}
current_oid = (const git_oid *)(index + 20 * i);
if ((error = cb(current_oid, current_offset, data)) != 0) {
git_oid_fromraw(&current_oid, (index + 20 * i));
if ((error = cb(&current_oid, current_offset, data)) != 0) {
error = git_error_set_after_callback(error);
goto cleanup;
}
......@@ -1431,8 +1437,8 @@ int git_pack_foreach_entry_offset(
} else {
for (i = 0; i < p->num_objects; i++) {
current_offset = ntohl(*(const uint32_t *)(index + 24 * i));
current_oid = (const git_oid *)(index + 24 * i + 4);
if ((error = cb(current_oid, current_offset, data)) != 0) {
git_oid_fromraw(&current_oid, (index + 24 * i + 4));
if ((error = cb(&current_oid, current_offset, data)) != 0) {
error = git_error_set_after_callback(error);
goto cleanup;
}
......@@ -1451,7 +1457,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;
......@@ -1530,7 +1536,7 @@ static int pack_entry_find_offset(
if (pos < (int)p->num_objects) {
current = index + pos * stride;
if (!git_oid_ncmp(short_oid, (const git_oid *)current, len))
if (!git_oid_raw_ncmp(short_oid->id, current, len))
found = 1;
}
}
......@@ -1539,7 +1545,7 @@ static int pack_entry_find_offset(
/* Check for ambiguousity */
const unsigned char *next = current + stride;
if (!git_oid_ncmp(short_oid, (const git_oid *)next, len)) {
if (!git_oid_raw_ncmp(short_oid->id, next, len)) {
found = 2;
}
}
......
......@@ -19,6 +19,7 @@
#include "offmap.h"
#include "oidmap.h"
#include "zstream.h"
#include "oid.h"
/**
* Function type for callbacks from git_pack_foreach_entry_offset.
......@@ -104,7 +105,7 @@ struct git_pack_file {
git_time_t mtime;
unsigned pack_local:1, pack_keep:1, has_cache:1;
git_oidmap *idx_cache;
git_oid **oids;
unsigned char **oids;
git_pack_cache bases; /* delta base cache */
......
......@@ -1830,7 +1830,7 @@ static int update_one_tip(
}
if (error == GIT_ENOTFOUND) {
memset(&old, 0, GIT_OID_RAWSZ);
memset(&old, 0, sizeof(git_oid));
error = 0;
if (autotag && (error = git_vector_insert(update_heads, head)) < 0)
......
......@@ -263,7 +263,7 @@ static void write_tree(git_str *out, git_tree_cache *tree)
git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
if (tree->entry_count != -1)
git_str_put(out, (const char *) &tree->oid, GIT_OID_RAWSZ);
git_str_put(out, (char *)&tree->oid.id, GIT_OID_RAWSZ);
for (i = 0; i < tree->children_count; i++)
write_tree(out, tree->children[i]);
......
......@@ -82,6 +82,7 @@ int git_tree_entry_cmp(const git_tree_entry *e1, const git_tree_entry *e2)
static git_tree_entry *alloc_entry(const char *filename, size_t filename_len, const git_oid *id)
{
git_tree_entry *entry = NULL;
char *filename_ptr;
size_t tree_len;
TREE_ENTRY_CHECK_NAMELEN(filename_len);
......@@ -95,21 +96,13 @@ static git_tree_entry *alloc_entry(const char *filename, size_t filename_len, co
if (!entry)
return NULL;
{
char *filename_ptr;
void *id_ptr;
filename_ptr = ((char *) entry) + sizeof(git_tree_entry);
memcpy(filename_ptr, filename, filename_len);
entry->filename = filename_ptr;
id_ptr = filename_ptr + filename_len + 1;
git_oid_cpy(id_ptr, id);
entry->oid = id_ptr;
}
filename_ptr = ((char *) entry) + sizeof(git_tree_entry);
memcpy(filename_ptr, filename, filename_len);
entry->filename = filename_ptr;
entry->filename_len = (uint16_t)filename_len;
git_oid_cpy(&entry->oid, id);
return entry;
}
......@@ -231,7 +224,7 @@ int git_tree_entry_dup(git_tree_entry **dest, const git_tree_entry *source)
GIT_ASSERT_ARG(source);
cpy = alloc_entry(source->filename, source->filename_len, source->oid);
cpy = alloc_entry(source->filename, source->filename_len, &source->oid);
if (cpy == NULL)
return -1;
......@@ -269,7 +262,7 @@ const char *git_tree_entry_name(const git_tree_entry *entry)
const git_oid *git_tree_entry_id(const git_tree_entry *entry)
{
GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL);
return entry->oid;
return &entry->oid;
}
git_object_t git_tree_entry_type(const git_tree_entry *entry)
......@@ -292,7 +285,7 @@ int git_tree_entry_to_object(
GIT_ASSERT_ARG(entry);
GIT_ASSERT_ARG(object_out);
return git_object_lookup(object_out, repo, entry->oid, GIT_OBJECT_ANY);
return git_object_lookup(object_out, repo, &entry->oid, GIT_OBJECT_ANY);
}
static const git_tree_entry *entry_fromname(
......@@ -331,7 +324,7 @@ const git_tree_entry *git_tree_entry_byid(
GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL);
git_array_foreach(tree->entries, i, e) {
if (memcmp(&e->oid->id, &id->id, sizeof(id->id)) == 0)
if (git_oid_equal(&e->oid, id))
return e;
}
......@@ -432,7 +425,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size)
entry->attr = attr;
entry->filename_len = (uint16_t)filename_len;
entry->filename = buffer;
entry->oid = (git_oid *) ((char *) buffer + filename_len + 1);
git_oid_fromraw(&entry->oid, ((unsigned char *) buffer + filename_len + 1));
}
buffer += filename_len + 1;
......@@ -536,7 +529,7 @@ static int git_treebuilder__write_with_buffer(
git_str_printf(buf, "%o ", entry->attr);
git_str_put(buf, entry->filename, entry->filename_len + 1);
git_str_put(buf, (char *)entry->oid->id, GIT_OID_RAWSZ);
git_str_put(buf, (char *)entry->oid.id, GIT_OID_RAWSZ);
if (git_str_oom(buf)) {
error = -1;
......@@ -765,7 +758,7 @@ int git_treebuilder_new(
git_array_foreach(source->entries, i, entry_src) {
if (append_entry(
bld, entry_src->filename,
entry_src->oid,
&entry_src->oid,
entry_src->attr,
false) < 0)
goto on_error;
......@@ -798,7 +791,7 @@ int git_treebuilder_insert(
return error;
if ((entry = git_strmap_get(bld->map, filename)) != NULL) {
git_oid_cpy((git_oid *) entry->oid, id);
git_oid_cpy(&entry->oid, id);
} else {
entry = alloc_entry(filename, strlen(filename), id);
GIT_ERROR_CHECK_ALLOC(entry);
......@@ -954,7 +947,7 @@ int git_tree_entry_bypath(
return git_tree_entry_dup(entry_out, entry);
}
if (git_tree_lookup(&subtree, root->object.repo, entry->oid) < 0)
if (git_tree_lookup(&subtree, root->object.repo, &entry->oid) < 0)
return -1;
error = git_tree_entry_bypath(
......@@ -995,7 +988,7 @@ static int tree_walk(
git_tree *subtree;
size_t path_len = git_str_len(path);
error = git_tree_lookup(&subtree, tree->object.repo, entry->oid);
error = git_tree_lookup(&subtree, tree->object.repo, &entry->oid);
if (error < 0)
break;
......
......@@ -19,7 +19,7 @@
struct git_tree_entry {
uint16_t attr;
uint16_t filename_len;
const git_oid *oid;
git_oid oid;
const char *filename;
};
......
......@@ -268,7 +268,7 @@ static void check_tree_entry(
cl_git_pass(git_iterator_current_tree_entry(&te, i));
cl_assert(te);
cl_assert(git_oid_streq(te->oid, oid) == 0);
cl_assert(git_oid_streq(&te->oid, oid) == 0);
cl_git_pass(git_iterator_current(&ie, i));
......
......@@ -24,20 +24,23 @@ static char *bye_text = "bye world\n";
void test_object_raw_hash__hash_by_blocks(void)
{
git_hash_ctx ctx;
unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid id1, id2;
cl_git_pass(git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1));
/* should already be init'd */
cl_git_pass(git_hash_update(&ctx, hello_text, strlen(hello_text)));
cl_git_pass(git_hash_final(id2.id, &ctx));
cl_git_pass(git_hash_final(hash, &ctx));
cl_git_pass(git_oid_fromraw(&id2, hash));
cl_git_pass(git_oid_fromstr(&id1, hello_id));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
/* reinit should permit reuse */
cl_git_pass(git_hash_init(&ctx));
cl_git_pass(git_hash_update(&ctx, bye_text, strlen(bye_text)));
cl_git_pass(git_hash_final(id2.id, &ctx));
cl_git_pass(git_hash_final(hash, &ctx));
cl_git_pass(git_oid_fromraw(&id2, hash));
cl_git_pass(git_oid_fromstr(&id1, bye_id));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
......@@ -47,9 +50,11 @@ void test_object_raw_hash__hash_by_blocks(void)
void test_object_raw_hash__hash_buffer_in_single_call(void)
{
git_oid id1, id2;
unsigned char hash[GIT_HASH_SHA1_SIZE];
cl_git_pass(git_oid_fromstr(&id1, hello_id));
git_hash_buf(id2.id, hello_text, strlen(hello_text), GIT_HASH_ALGORITHM_SHA1);
cl_git_pass(git_hash_buf(hash, hello_text, strlen(hello_text), GIT_HASH_ALGORITHM_SHA1));
cl_git_pass(git_oid_fromraw(&id2, hash));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
......
......@@ -28,12 +28,15 @@ static int insert_sequential_oids(
int i, min_len = 0;
char numbuf[16];
git_oid oid;
unsigned char hashbuf[GIT_HASH_SHA1_SIZE];
char **oids = git__calloc(n, sizeof(char *));
cl_assert(oids != NULL);
for (i = 0; i < n; ++i) {
p_snprintf(numbuf, sizeof(numbuf), "%u", (unsigned int)i);
git_hash_buf(oid.id, numbuf, strlen(numbuf), GIT_HASH_ALGORITHM_SHA1);
git_hash_buf(hashbuf, numbuf, strlen(numbuf), GIT_HASH_ALGORITHM_SHA1);
git_oid_fromraw(&oid, hashbuf);
oids[i] = git__malloc(GIT_OID_HEXSZ + 1);
cl_assert(oids[i]);
......
......@@ -40,7 +40,7 @@ static void assert_tree_parses(const char *data, size_t datalen,
cl_assert(entry = git_tree_entry_byname(tree, expected->filename));
cl_assert_equal_s(expected->filename, entry->filename);
cl_assert_equal_i(expected->attr, entry->attr);
cl_assert_equal_oid(&oid, entry->oid);
cl_assert_equal_oid(&oid, &entry->oid);
}
git_object_free(&tree->object);
......
......@@ -68,7 +68,7 @@ static void seed_packbuilder(void)
cl_git_pass(git_revwalk_push_ref(_revwalker, "HEAD"));
while (git_revwalk_next(&oid, _revwalker) == 0) {
o = git__malloc(GIT_OID_RAWSZ);
o = git__malloc(sizeof(git_oid));
cl_assert(o != NULL);
git_oid_cpy(o, &oid);
cl_git_pass(git_vector_insert(&_commits, o));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment