@@ -1784,21 +1784,40 @@ void *read_object_with_reference(struct repository *r,
17841784 }
17851785}
17861786
1787+ static void hash_object_body (const struct git_hash_algo * algo , git_hash_ctx * c ,
1788+ const void * buf , unsigned long len ,
1789+ struct object_id * oid ,
1790+ char * hdr , int * hdrlen )
1791+ {
1792+ algo -> init_fn (c );
1793+ algo -> update_fn (c , hdr , * hdrlen );
1794+ algo -> update_fn (c , buf , len );
1795+ algo -> final_oid_fn (oid , c );
1796+ }
1797+
17871798static void write_object_file_prepare (const struct git_hash_algo * algo ,
17881799 const void * buf , unsigned long len ,
1789- const char * type , struct object_id * oid ,
1800+ enum object_type type , struct object_id * oid ,
17901801 char * hdr , int * hdrlen )
17911802{
17921803 git_hash_ctx c ;
17931804
17941805 /* Generate the header */
1795- * hdrlen = format_object_header_literally (hdr , * hdrlen , type , len );
1806+ * hdrlen = format_object_header (hdr , * hdrlen , type , len );
17961807
17971808 /* Sha1.. */
1798- algo -> init_fn (& c );
1799- algo -> update_fn (& c , hdr , * hdrlen );
1800- algo -> update_fn (& c , buf , len );
1801- algo -> final_oid_fn (oid , & c );
1809+ hash_object_body (algo , & c , buf , len , oid , hdr , hdrlen );
1810+ }
1811+
1812+ static void write_object_file_prepare_literally (const struct git_hash_algo * algo ,
1813+ const void * buf , unsigned long len ,
1814+ const char * type , struct object_id * oid ,
1815+ char * hdr , int * hdrlen )
1816+ {
1817+ git_hash_ctx c ;
1818+
1819+ * hdrlen = format_object_header_literally (hdr , * hdrlen , type , len );
1820+ hash_object_body (algo , & c , buf , len , oid , hdr , hdrlen );
18021821}
18031822
18041823/*
@@ -1858,7 +1877,7 @@ static void hash_object_file_literally(const struct git_hash_algo *algo,
18581877 char hdr [MAX_HEADER_LEN ];
18591878 int hdrlen = sizeof (hdr );
18601879
1861- write_object_file_prepare (algo , buf , len , type , oid , hdr , & hdrlen );
1880+ write_object_file_prepare_literally (algo , buf , len , type , oid , hdr , & hdrlen );
18621881}
18631882
18641883void hash_object_file (const struct git_hash_algo * algo , const void * buf ,
@@ -2029,7 +2048,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
20292048 /* Normally if we have it in the pack then we do not bother writing
20302049 * it out into .git/objects/??/?{38} file.
20312050 */
2032- write_object_file_prepare (the_hash_algo , buf , len , type_name ( type ) , oid , hdr ,
2051+ write_object_file_prepare (the_hash_algo , buf , len , type , oid , hdr ,
20332052 & hdrlen );
20342053 if (freshen_packed_object (oid ) || freshen_loose_object (oid ))
20352054 return 0 ;
@@ -2046,8 +2065,8 @@ int write_object_file_literally(const void *buf, unsigned long len,
20462065 /* type string, SP, %lu of the length plus NUL must fit this */
20472066 hdrlen = strlen (type ) + MAX_HEADER_LEN ;
20482067 header = xmalloc (hdrlen );
2049- write_object_file_prepare (the_hash_algo , buf , len , type , oid , header ,
2050- & hdrlen );
2068+ write_object_file_prepare_literally (the_hash_algo , buf , len , type ,
2069+ oid , header , & hdrlen );
20512070
20522071 if (!(flags & HASH_WRITE_OBJECT ))
20532072 goto cleanup ;
0 commit comments