summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorLibravatar Patryk Obara <patryk.obara@gmail.com>2018-01-28 01:13:19 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-01-30 10:42:36 -0800
commita09c985eae694db1cf31c72db0e2e1bf42f1274f (patch)
tree3acdfc26ab59d2ac822e4b4cf6ad93bf746fb65d /sha1_file.c
parentnotes: convert write_notes_tree to object_id (diff)
downloadtgif-a09c985eae694db1cf31c72db0e2e1bf42f1274f.tar.xz
sha1_file: convert write_sha1_file to object_id
Convert the definition and declaration of write_sha1_file to struct object_id and adjust usage of this function. This commit also converts static function write_sha1_file_prepare, as it is closely related. Rename these functions to write_object_file and write_object_file_prepare respectively. Replace sha1_to_hex, hashcpy and hashclr with their oid equivalents wherever possible. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 4c44c60cec..d1569b1b96 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1419,9 +1419,9 @@ void *read_object_with_reference(const unsigned char *sha1,
}
}
-static void write_sha1_file_prepare(const void *buf, unsigned long len,
- const char *type, unsigned char *sha1,
- char *hdr, int *hdrlen)
+static void write_object_file_prepare(const void *buf, unsigned long len,
+ const char *type, struct object_id *oid,
+ char *hdr, int *hdrlen)
{
git_SHA_CTX c;
@@ -1432,7 +1432,7 @@ static void write_sha1_file_prepare(const void *buf, unsigned long len,
git_SHA1_Init(&c);
git_SHA1_Update(&c, hdr, *hdrlen);
git_SHA1_Update(&c, buf, len);
- git_SHA1_Final(sha1, &c);
+ git_SHA1_Final(oid->hash, &c);
}
/*
@@ -1490,7 +1490,7 @@ int hash_object_file(const void *buf, unsigned long len, const char *type,
{
char hdr[32];
int hdrlen = sizeof(hdr);
- write_sha1_file_prepare(buf, len, type, oid->hash, hdr, &hdrlen);
+ write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
return 0;
}
@@ -1633,7 +1633,8 @@ static int freshen_packed_object(const unsigned char *sha1)
return 1;
}
-int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1)
+int write_object_file(const void *buf, unsigned long len, const char *type,
+ struct object_id *oid)
{
char hdr[32];
int hdrlen = sizeof(hdr);
@@ -1641,10 +1642,10 @@ int write_sha1_file(const void *buf, unsigned long len, const char *type, unsign
/* Normally if we have it in the pack then we do not bother writing
* it out into .git/objects/??/?{38} file.
*/
- write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
- if (freshen_packed_object(sha1) || freshen_loose_object(sha1))
+ write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
+ if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
return 0;
- return write_loose_object(sha1, hdr, hdrlen, buf, len, 0);
+ return write_loose_object(oid->hash, hdr, hdrlen, buf, len, 0);
}
int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type,
@@ -1656,7 +1657,7 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typ
/* type string, SP, %lu of the length plus NUL must fit this */
hdrlen = strlen(type) + 32;
header = xmalloc(hdrlen);
- write_sha1_file_prepare(buf, len, type, oid->hash, header, &hdrlen);
+ write_object_file_prepare(buf, len, type, oid, header, &hdrlen);
if (!(flags & HASH_WRITE_OBJECT))
goto cleanup;
@@ -1767,7 +1768,7 @@ static int index_mem(struct object_id *oid, void *buf, size_t size,
}
if (write_object)
- ret = write_sha1_file(buf, size, typename(type), oid->hash);
+ ret = write_object_file(buf, size, typename(type), oid);
else
ret = hash_object_file(buf, size, typename(type), oid);
if (re_allocated)
@@ -1789,8 +1790,8 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
get_safe_crlf(flags));
if (write_object)
- ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
- oid->hash);
+ ret = write_object_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
+ oid);
else
ret = hash_object_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
oid);
@@ -1908,7 +1909,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
return error_errno("readlink(\"%s\")", path);
if (!(flags & HASH_WRITE_OBJECT))
hash_object_file(sb.buf, sb.len, blob_type, oid);
- else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash))
+ else if (write_object_file(sb.buf, sb.len, blob_type, oid))
rc = error("%s: failed to insert into database", path);
strbuf_release(&sb);
break;