@@ -1548,16 +1548,17 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)
1548
1548
return fd ;
1549
1549
}
1550
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 )
1553
1554
{
1554
1555
int fd , ret ;
1555
1556
unsigned char compressed [4096 ];
1556
1557
git_zstream stream ;
1557
1558
git_SHA_CTX c ;
1558
- unsigned char parano_sha1 [ 20 ] ;
1559
+ struct object_id parano_oid ;
1559
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 );
1561
1562
1562
1563
fd = create_tmpfile (& tmp_file , filename );
1563
1564
if (fd < 0 ) {
@@ -1594,13 +1595,16 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
1594
1595
} while (ret == Z_OK );
1595
1596
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 );
1598
1600
ret = git_deflate_end_gently (& stream );
1599
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 , & parano_oid ) != 0 )
1606
+ die ("confused by unstable object source data for %s" ,
1607
+ oid_to_hex (oid ));
1604
1608
1605
1609
close_sha1_file (fd );
1606
1610
@@ -1645,7 +1649,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type,
1645
1649
write_object_file_prepare (buf , len , type , oid , hdr , & hdrlen );
1646
1650
if (freshen_packed_object (oid -> hash ) || freshen_loose_object (oid -> hash ))
1647
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 );
1649
1653
}
1650
1654
1651
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
1663
1667
goto cleanup ;
1664
1668
if (freshen_packed_object (oid -> hash ) || freshen_loose_object (oid -> hash ))
1665
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 );
1667
1671
1668
1672
cleanup :
1669
1673
free (header );
@@ -1685,7 +1689,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
1685
1689
if (!buf )
1686
1690
return error ("cannot read sha1_file for %s" , oid_to_hex (oid ));
1687
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 );
1689
1693
free (buf );
1690
1694
1691
1695
return ret ;
0 commit comments