@@ -1784,21 +1784,40 @@ void *read_object_with_reference(struct repository *r,
1784
1784
}
1785
1785
}
1786
1786
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
+
1787
1798
static void write_object_file_prepare (const struct git_hash_algo * algo ,
1788
1799
const void * buf , unsigned long len ,
1789
- const char * type , struct object_id * oid ,
1800
+ enum object_type type , struct object_id * oid ,
1790
1801
char * hdr , int * hdrlen )
1791
1802
{
1792
1803
git_hash_ctx c ;
1793
1804
1794
1805
/* Generate the header */
1795
- * hdrlen = format_object_header_literally (hdr , * hdrlen , type , len );
1806
+ * hdrlen = format_object_header (hdr , * hdrlen , type , len );
1796
1807
1797
1808
/* 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 );
1802
1821
}
1803
1822
1804
1823
/*
@@ -1858,7 +1877,7 @@ static void hash_object_file_literally(const struct git_hash_algo *algo,
1858
1877
char hdr [MAX_HEADER_LEN ];
1859
1878
int hdrlen = sizeof (hdr );
1860
1879
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 );
1862
1881
}
1863
1882
1864
1883
void 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,
2029
2048
/* Normally if we have it in the pack then we do not bother writing
2030
2049
* it out into .git/objects/??/?{38} file.
2031
2050
*/
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 ,
2033
2052
& hdrlen );
2034
2053
if (freshen_packed_object (oid ) || freshen_loose_object (oid ))
2035
2054
return 0 ;
@@ -2046,8 +2065,8 @@ int write_object_file_literally(const void *buf, unsigned long len,
2046
2065
/* type string, SP, %lu of the length plus NUL must fit this */
2047
2066
hdrlen = strlen (type ) + MAX_HEADER_LEN ;
2048
2067
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 );
2051
2070
2052
2071
if (!(flags & HASH_WRITE_OBJECT ))
2053
2072
goto cleanup ;
0 commit comments