summaryrefslogtreecommitdiff
path: root/src/libgit2/indexer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libgit2/indexer.c')
-rw-r--r--src/libgit2/indexer.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/libgit2/indexer.c b/src/libgit2/indexer.c
index afb9ce81a..62bb70393 100644
--- a/src/libgit2/indexer.c
+++ b/src/libgit2/indexer.c
@@ -68,7 +68,7 @@ struct git_indexer {
git_odb *odb;
/* Fields for calculating the packfile trailer (hash of everything before it) */
- char inbuf[GIT_OID_RAWSZ];
+ char inbuf[GIT_OID_SHA1_SIZE];
size_t inbuf_len;
git_hash_ctx trailer;
};
@@ -272,7 +272,7 @@ static int advance_delta_offset(git_indexer *idx, git_object_t type)
GIT_ASSERT_ARG(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA);
if (type == GIT_OBJECT_REF_DELTA) {
- idx->off += GIT_OID_RAWSZ;
+ idx->off += GIT_OID_SHA1_SIZE;
} else {
off64_t base_off;
int error = get_delta_base(&base_off, idx->pack, &w, &idx->off, type, idx->entry_start);
@@ -444,6 +444,11 @@ static int store_object(git_indexer *idx)
git__free(pentry);
goto on_error;
}
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+ oid.type = GIT_OID_SHA1;
+#endif
+
entry_size = idx->off - entry_start;
if (entry_start > UINT31_MAX) {
entry->offset = UINT32_MAX;
@@ -544,7 +549,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start)
entry = git__calloc(1, sizeof(*entry));
GIT_ERROR_CHECK_ALLOC(entry);
- if (git_odb__hashobj(&oid, obj) < 0) {
+ if (git_odb__hashobj(&oid, obj, GIT_OID_SHA1) < 0) {
git_error_set(GIT_ERROR_INDEXER, "failed to hash object");
goto on_error;
}
@@ -587,25 +592,25 @@ static void hash_partially(git_indexer *idx, const uint8_t *data, size_t size)
return;
/* Easy case, dump the buffer and the data minus the last 20 bytes */
- if (size >= GIT_OID_RAWSZ) {
+ if (size >= GIT_OID_SHA1_SIZE) {
git_hash_update(&idx->trailer, idx->inbuf, idx->inbuf_len);
- git_hash_update(&idx->trailer, data, size - GIT_OID_RAWSZ);
+ git_hash_update(&idx->trailer, data, size - GIT_OID_SHA1_SIZE);
- data += size - GIT_OID_RAWSZ;
- memcpy(idx->inbuf, data, GIT_OID_RAWSZ);
- idx->inbuf_len = GIT_OID_RAWSZ;
+ data += size - GIT_OID_SHA1_SIZE;
+ memcpy(idx->inbuf, data, GIT_OID_SHA1_SIZE);
+ idx->inbuf_len = GIT_OID_SHA1_SIZE;
return;
}
/* We can just append */
- if (idx->inbuf_len + size <= GIT_OID_RAWSZ) {
+ if (idx->inbuf_len + size <= GIT_OID_SHA1_SIZE) {
memcpy(idx->inbuf + idx->inbuf_len, data, size);
idx->inbuf_len += size;
return;
}
/* We need to partially drain the buffer and then append */
- to_keep = GIT_OID_RAWSZ - size;
+ to_keep = GIT_OID_SHA1_SIZE - size;
to_expell = idx->inbuf_len - to_keep;
git_hash_update(&idx->trailer, idx->inbuf, to_expell);
@@ -900,7 +905,7 @@ static int index_path(git_str *path, git_indexer *idx, const char *suffix)
slash--;
if (git_str_grow(path, slash + 1 + strlen(prefix) +
- GIT_OID_HEXSZ + strlen(suffix) + 1) < 0)
+ GIT_OID_SHA1_HEXSIZE + strlen(suffix) + 1) < 0)
return -1;
git_str_truncate(path, slash);
@@ -917,7 +922,7 @@ static int index_path(git_str *path, git_indexer *idx, const char *suffix)
*/
static int seek_back_trailer(git_indexer *idx)
{
- idx->pack->mwf.size -= GIT_OID_RAWSZ;
+ idx->pack->mwf.size -= GIT_OID_SHA1_SIZE;
return git_mwindow_free_all(&idx->pack->mwf);
}
@@ -977,7 +982,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
if ((error = append_to_pack(idx, empty_checksum, checksum_size)) < 0)
goto cleanup;
- idx->pack->mwf.size += GIT_OID_RAWSZ;
+ idx->pack->mwf.size += GIT_OID_SHA1_SIZE;
pentry = git__calloc(1, sizeof(struct git_pack_entry));
GIT_ERROR_CHECK_ALLOC(pentry);
@@ -1040,13 +1045,13 @@ static int fix_thin_pack(git_indexer *idx, git_indexer_progress *stats)
}
/* curpos now points to the base information, which is an OID */
- base_info = git_mwindow_open(&idx->pack->mwf, &w, curpos, GIT_OID_RAWSZ, &left);
+ base_info = git_mwindow_open(&idx->pack->mwf, &w, curpos, GIT_OID_SHA1_SIZE, &left);
if (base_info == NULL) {
git_error_set(GIT_ERROR_INDEXER, "failed to map delta information");
return -1;
}
- git_oid_fromraw(&base, base_info);
+ git_oid__fromraw(&base, base_info, GIT_OID_SHA1);
git_mwindow_close(&w);
if (has_entry(idx, &base))
@@ -1269,7 +1274,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.id, GIT_OID_RAWSZ);
+ git_filebuf_write(&index_file, &entry->oid.id, GIT_OID_SHA1_SIZE);
}
/* Write out the CRC32 values */