sha1_file: convert write_loose_object to object_id
Convert the definition and declaration of static write_loose_object function to struct object_id. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patryk Obara committed
Jan 28, 2018 at 01:13 UTC
3fc7281ffa2533820d26809223c7181256b88fe2
1 file changed
+16
-12
sha1_file.c
+16
-12
@@ -1548,16 +1548,17 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)
1548
return fd;
1549
}
1550
1551
-static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
1552
- const void *buf, unsigned long len, time_t mtime)
1551
+static int write_loose_object(const struct object_id *oid, char *hdr,
1552
+ int hdrlen, const void *buf, unsigned long len,
1553
+ time_t mtime)
1554
{
1555
int fd, ret;
1556
unsigned char compressed[4096];
1557
git_zstream stream;
1558
git_SHA_CTX c;
1558
- unsigned char parano_sha1[20];
1559
+ struct object_id parano_oid;
1560
static struct strbuf tmp_file = STRBUF_INIT;
1560
- const char *filename = sha1_file_name(sha1);
1561
+ const char *filename = sha1_file_name(oid->hash);
1562
1563
fd = create_tmpfile(&tmp_file, filename);
1564
if (fd < 0) {
@@ -1594,13 +1595,16 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
1595
} while (ret == Z_OK);
1596
1597
if (ret != Z_STREAM_END)
1597
- die("unable to deflate new object %s (%d)", sha1_to_hex(sha1), ret);
1598
+ die("unable to deflate new object %s (%d)", oid_to_hex(oid),
1599
+ ret);
1600
ret = git_deflate_end_gently(&stream);
1601
if (ret != Z_OK)
1600
- die("deflateEnd on object %s failed (%d)", sha1_to_hex(sha1), ret);
1601
- git_SHA1_Final(parano_sha1, &c);
1602
- if (hashcmp(sha1, parano_sha1) != 0)
1603
- die("confused by unstable object source data for %s", sha1_to_hex(sha1));
1602
+ die("deflateEnd on object %s failed (%d)", oid_to_hex(oid),
1603
+ ret);
1604
+ git_SHA1_Final(parano_oid.hash, &c);
1605
+ if (oidcmp(oid, ¶no_oid) != 0)
1606
+ die("confused by unstable object source data for %s",
1607
+ oid_to_hex(oid));
1608
1609
close_sha1_file(fd);
1610
@@ -1645,7 +1649,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type,
1649
write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
1650
if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
1651
return 0;
1648
- return write_loose_object(oid->hash, hdr, hdrlen, buf, len, 0);
1652
+ return write_loose_object(oid, hdr, hdrlen, buf, len, 0);
1653
}
1654
1655
int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type,
@@ -1663,7 +1667,7 @@ int hash_sha1_file_literally(const void *buf, unsigned long len, const char *typ
1667
goto cleanup;
1668
if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
1669
goto cleanup;
1666
- status = write_loose_object(oid->hash, header, hdrlen, buf, len, 0);
1670
+ status = write_loose_object(oid, header, hdrlen, buf, len, 0);
1671
1672
cleanup:
1673
free(header);
@@ -1685,7 +1689,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
1689
if (!buf)
1690
return error("cannot read sha1_file for %s", oid_to_hex(oid));
1691
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
1688
- ret = write_loose_object(oid->hash, hdr, hdrlen, buf, len, mtime);
1692
+ ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime);
1693
free(buf);
1694
1695
return ret;