summaryrefslogtreecommitdiff
path: root/sha1-file.c
diff options
context:
space:
mode:
authorMatheus Tavares <matheus.bernardino@usp.br>2020-01-30 20:32:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-01-31 18:45:39 (GMT)
commit2dcde20e1c55fc2e3f9e9e6d48e93c39ec5661d2 (patch)
tree9039d3dd520e915bf531c8f2f32190a4a87d9ccd /sha1-file.c
parent7ad5c44d9ce559703245d389aa71c4445dc9359c (diff)
downloadgit-2dcde20e1c55fc2e3f9e9e6d48e93c39ec5661d2.zip
git-2dcde20e1c55fc2e3f9e9e6d48e93c39ec5661d2.tar.gz
git-2dcde20e1c55fc2e3f9e9e6d48e93c39ec5661d2.tar.bz2
sha1-file: pass git_hash_algo to hash_object_file()
Allow hash_object_file() to work on arbitrary repos by introducing a git_hash_algo parameter. Change callers which have a struct repository pointer in their scope to pass on the git_hash_algo from the said repo. For all other callers, pass on the_hash_algo, which was already being used internally at hash_object_file(). This functionality will be used in the following patch to make check_object_signature() be able to work on arbitrary repos (which, in turn, will be used to fix an inconsistency at object.c:parse_object()). Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1-file.c')
-rw-r--r--sha1-file.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/sha1-file.c b/sha1-file.c
index 1ca3f9f..46a79e7 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -982,7 +982,7 @@ int check_object_signature(const struct object_id *oid, void *map,
int hdrlen;
if (map) {
- hash_object_file(map, size, type, &real_oid);
+ hash_object_file(the_hash_algo, map, size, type, &real_oid);
return !oideq(oid, &real_oid) ? -1 : 0;
}
@@ -1544,7 +1544,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
{
struct cached_object *co;
- hash_object_file(buf, len, type_name(type), oid);
+ hash_object_file(the_hash_algo, buf, len, type_name(type), oid);
if (has_object_file(oid) || find_cached_object(oid))
return 0;
ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
@@ -1715,13 +1715,13 @@ static int write_buffer(int fd, const void *buf, size_t len)
return 0;
}
-int hash_object_file(const void *buf, unsigned long len, const char *type,
+int hash_object_file(const struct git_hash_algo *algo, const void *buf,
+ unsigned long len, const char *type,
struct object_id *oid)
{
char hdr[MAX_HEADER_LEN];
int hdrlen = sizeof(hdr);
- write_object_file_prepare(the_hash_algo, buf, len, type, oid, hdr,
- &hdrlen);
+ write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
return 0;
}
@@ -2008,7 +2008,8 @@ static int index_mem(struct index_state *istate,
if (write_object)
ret = write_object_file(buf, size, type_name(type), oid);
else
- ret = hash_object_file(buf, size, type_name(type), oid);
+ ret = hash_object_file(the_hash_algo, buf, size,
+ type_name(type), oid);
if (re_allocated)
free(buf);
return ret;
@@ -2034,8 +2035,8 @@ static int index_stream_convert_blob(struct index_state *istate,
ret = write_object_file(sbuf.buf, sbuf.len, type_name(OBJ_BLOB),
oid);
else
- ret = hash_object_file(sbuf.buf, sbuf.len, type_name(OBJ_BLOB),
- oid);
+ ret = hash_object_file(the_hash_algo, sbuf.buf, sbuf.len,
+ type_name(OBJ_BLOB), oid);
strbuf_release(&sbuf);
return ret;
}
@@ -2153,7 +2154,8 @@ int index_path(struct index_state *istate, struct object_id *oid,
if (strbuf_readlink(&sb, path, st->st_size))
return error_errno("readlink(\"%s\")", path);
if (!(flags & HASH_WRITE_OBJECT))
- hash_object_file(sb.buf, sb.len, blob_type, oid);
+ hash_object_file(the_hash_algo, sb.buf, sb.len,
+ blob_type, oid);
else if (write_object_file(sb.buf, sb.len, blob_type, oid))
rc = error(_("%s: failed to insert into database"), path);
strbuf_release(&sb);