@@ -1548,16 +1548,17 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)
15481548 return fd ;
15491549}
15501550
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 )
15531554{
15541555 int fd , ret ;
15551556 unsigned char compressed [4096 ];
15561557 git_zstream stream ;
15571558 git_SHA_CTX c ;
1558- unsigned char parano_sha1 [ 20 ] ;
1559+ struct object_id parano_oid ;
15591560 static struct strbuf tmp_file = STRBUF_INIT ;
1560- const char * filename = sha1_file_name (sha1 );
1561+ const char * filename = sha1_file_name (oid -> hash );
15611562
15621563 fd = create_tmpfile (& tmp_file , filename );
15631564 if (fd < 0 ) {
@@ -1594,13 +1595,16 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
15941595 } while (ret == Z_OK );
15951596
15961597 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 );
15981600 ret = git_deflate_end_gently (& stream );
15991601 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 ));
16041608
16051609 close_sha1_file (fd );
16061610
@@ -1645,7 +1649,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type,
16451649 write_object_file_prepare (buf , len , type , oid , hdr , & hdrlen );
16461650 if (freshen_packed_object (oid -> hash ) || freshen_loose_object (oid -> hash ))
16471651 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 );
16491653}
16501654
16511655int 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
16631667 goto cleanup ;
16641668 if (freshen_packed_object (oid -> hash ) || freshen_loose_object (oid -> hash ))
16651669 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 );
16671671
16681672cleanup :
16691673 free (header );
@@ -1685,7 +1689,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
16851689 if (!buf )
16861690 return error ("cannot read sha1_file for %s" , oid_to_hex (oid ));
16871691 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 );
16891693 free (buf );
16901694
16911695 return ret ;
0 commit comments