summaryrefslogtreecommitdiff
path: root/object-file.c
diff options
context:
space:
mode:
Diffstat (limited to 'object-file.c')
-rw-r--r--object-file.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/object-file.c b/object-file.c
index 9e5b849693..b1cb78c441 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1067,7 +1067,8 @@ int format_object_header(char *str, size_t size, enum object_type type,
}
int check_object_signature(struct repository *r, const struct object_id *oid,
- void *buf, unsigned long size, const char *type)
+ void *buf, unsigned long size,
+ enum object_type type)
{
struct object_id real_oid;
@@ -1676,7 +1677,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
{
struct cached_object *co;
- hash_object_file(the_hash_algo, buf, len, type_name(type), oid);
+ hash_object_file(the_hash_algo, buf, len, type, oid);
if (has_object_file_with_flags(oid, OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT) ||
find_cached_object(oid))
return 0;
@@ -1850,15 +1851,23 @@ static int write_buffer(int fd, const void *buf, size_t len)
return 0;
}
-void hash_object_file(const struct git_hash_algo *algo, const void *buf,
- unsigned long len, const char *type,
- struct object_id *oid)
+static void hash_object_file_literally(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(algo, buf, len, type, oid, hdr, &hdrlen);
}
+void hash_object_file(const struct git_hash_algo *algo, const void *buf,
+ unsigned long len, enum object_type type,
+ struct object_id *oid)
+{
+ hash_object_file_literally(algo, buf, len, type_name(type), oid);
+}
+
/* Finalize a file on disk, and close it. */
static void close_loose_object(int fd)
{
@@ -2161,9 +2170,7 @@ static int index_mem(struct index_state *istate,
if (write_object)
ret = write_object_file(buf, size, type, oid);
else
- hash_object_file(the_hash_algo, buf, size, type_name(type),
- oid);
-
+ hash_object_file(the_hash_algo, buf, size, type, oid);
if (re_allocated)
free(buf);
return ret;
@@ -2189,8 +2196,8 @@ static int index_stream_convert_blob(struct index_state *istate,
ret = write_object_file(sbuf.buf, sbuf.len, OBJ_BLOB,
oid);
else
- hash_object_file(the_hash_algo, sbuf.buf, sbuf.len,
- type_name(OBJ_BLOB), oid);
+ hash_object_file(the_hash_algo, sbuf.buf, sbuf.len, OBJ_BLOB,
+ oid);
strbuf_release(&sbuf);
return ret;
}
@@ -2309,7 +2316,7 @@ int index_path(struct index_state *istate, struct object_id *oid,
return error_errno("readlink(\"%s\")", path);
if (!(flags & HASH_WRITE_OBJECT))
hash_object_file(the_hash_algo, sb.buf, sb.len,
- blob_type, oid);
+ OBJ_BLOB, oid);
else if (write_object_file(sb.buf, sb.len, OBJ_BLOB, oid))
rc = error(_("%s: failed to insert into database"), path);
strbuf_release(&sb);
@@ -2614,9 +2621,9 @@ int read_loose_object(const char *path,
git_inflate_end(&stream);
goto out;
}
- hash_object_file(the_repository->hash_algo,
- *contents, *size, oi->type_name->buf,
- real_oid);
+ hash_object_file_literally(the_repository->hash_algo,
+ *contents, *size,
+ oi->type_name->buf, real_oid);
if (!oideq(expected_oid, real_oid))
goto out;
}