Commit adcf638cca0a3b38f51a6d7c9b7ce479528cd854

Edward Thomson 2021-11-21T21:34:17

filebuf: use hashes not oids The filebuf functions should use hashes directly, not indirectly using the oid functions.

diff --git a/src/filebuf.c b/src/filebuf.c
index f0bd000..eafcba3 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -386,9 +386,9 @@ cleanup:
 	return error;
 }
 
-int git_filebuf_hash(git_oid *oid, git_filebuf *file)
+int git_filebuf_hash(unsigned char *out, git_filebuf *file)
 {
-	GIT_ASSERT_ARG(oid);
+	GIT_ASSERT_ARG(out);
 	GIT_ASSERT_ARG(file);
 	GIT_ASSERT_ARG(file->compute_digest);
 
@@ -397,7 +397,7 @@ int git_filebuf_hash(git_oid *oid, git_filebuf *file)
 	if (verify_last_error(file) < 0)
 		return -1;
 
-	git_hash_final(oid->id, &file->digest);
+	git_hash_final(out, &file->digest);
 	git_hash_ctx_cleanup(&file->digest);
 	file->compute_digest = 0;
 
diff --git a/src/filebuf.h b/src/filebuf.h
index 9d53bc3..adbb199 100644
--- a/src/filebuf.h
+++ b/src/filebuf.h
@@ -87,7 +87,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
 int git_filebuf_commit(git_filebuf *lock);
 int git_filebuf_commit_at(git_filebuf *lock, const char *path);
 void git_filebuf_cleanup(git_filebuf *lock);
-int git_filebuf_hash(git_oid *oid, git_filebuf *file);
+int git_filebuf_hash(unsigned char *out, git_filebuf *file);
 int git_filebuf_flush(git_filebuf *file);
 int git_filebuf_stats(time_t *mtime, size_t *size, git_filebuf *file);
 
diff --git a/src/index.c b/src/index.c
index 7ade434..a2d80bc 100644
--- a/src/index.c
+++ b/src/index.c
@@ -3080,7 +3080,7 @@ static int write_index(git_oid *checksum, git_index *index, git_filebuf *file)
 		return -1;
 
 	/* get out the hash for all the contents we've appended to the file */
-	git_filebuf_hash(&hash_final, file);
+	git_filebuf_hash(hash_final.id, file);
 	git_oid_cpy(checksum, &hash_final);
 
 	/* write it at the end of the file */
diff --git a/src/indexer.c b/src/indexer.c
index 213ad75..d9396e0 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -1289,7 +1289,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
 		goto on_error;
 
 	/* Write out the hash of the idx */
-	if (git_filebuf_hash(&trailer_hash, &index_file) < 0)
+	if (git_filebuf_hash(trailer_hash.id, &index_file) < 0)
 		goto on_error;
 
 	git_filebuf_write(&index_file, &trailer_hash, sizeof(git_oid));