25
25
#include "pack.h"
26
26
#include "packfile.h"
27
27
#include "path.h"
28
+ #include "read-cache-ll.h"
28
29
#include "setup.h"
29
30
#include "streaming.h"
30
31
@@ -41,9 +42,11 @@ static int get_conv_flags(unsigned flags)
41
42
return 0 ;
42
43
}
43
44
44
- static void fill_loose_path (struct strbuf * buf , const struct object_id * oid )
45
+ static void fill_loose_path (struct strbuf * buf ,
46
+ const struct object_id * oid ,
47
+ const struct git_hash_algo * algop )
45
48
{
46
- for (size_t i = 0 ; i < the_hash_algo -> rawsz ; i ++ ) {
49
+ for (size_t i = 0 ; i < algop -> rawsz ; i ++ ) {
47
50
static char hex [] = "0123456789abcdef" ;
48
51
unsigned int val = oid -> hash [i ];
49
52
strbuf_addch (buf , hex [val >> 4 ]);
@@ -60,7 +63,7 @@ const char *odb_loose_path(struct odb_source *source,
60
63
strbuf_reset (buf );
61
64
strbuf_addstr (buf , source -> path );
62
65
strbuf_addch (buf , '/' );
63
- fill_loose_path (buf , oid );
66
+ fill_loose_path (buf , oid , source -> odb -> repo -> hash_algo );
64
67
return buf -> buf ;
65
68
}
66
69
@@ -1165,15 +1168,15 @@ static int index_mem(struct index_state *istate,
1165
1168
1166
1169
opts .strict = 1 ;
1167
1170
opts .error_func = hash_format_check_report ;
1168
- if (fsck_buffer (null_oid (the_hash_algo ), type , buf , size , & opts ))
1171
+ if (fsck_buffer (null_oid (istate -> repo -> hash_algo ), type , buf , size , & opts ))
1169
1172
die (_ ("refusing to create malformed object" ));
1170
1173
fsck_finish (& opts );
1171
1174
}
1172
1175
1173
1176
if (write_object )
1174
1177
ret = write_object_file (buf , size , type , oid );
1175
1178
else
1176
- hash_object_file (the_hash_algo , buf , size , type , oid );
1179
+ hash_object_file (istate -> repo -> hash_algo , buf , size , type , oid );
1177
1180
1178
1181
strbuf_release (& nbuf );
1179
1182
return ret ;
@@ -1199,7 +1202,7 @@ static int index_stream_convert_blob(struct index_state *istate,
1199
1202
ret = write_object_file (sbuf .buf , sbuf .len , OBJ_BLOB ,
1200
1203
oid );
1201
1204
else
1202
- hash_object_file (the_hash_algo , sbuf .buf , sbuf .len , OBJ_BLOB ,
1205
+ hash_object_file (istate -> repo -> hash_algo , sbuf .buf , sbuf .len , OBJ_BLOB ,
1203
1206
oid );
1204
1207
strbuf_release (& sbuf );
1205
1208
return ret ;
@@ -1297,7 +1300,7 @@ int index_path(struct index_state *istate, struct object_id *oid,
1297
1300
if (strbuf_readlink (& sb , path , st -> st_size ))
1298
1301
return error_errno ("readlink(\"%s\")" , path );
1299
1302
if (!(flags & INDEX_WRITE_OBJECT ))
1300
- hash_object_file (the_hash_algo , sb .buf , sb .len ,
1303
+ hash_object_file (istate -> repo -> hash_algo , sb .buf , sb .len ,
1301
1304
OBJ_BLOB , oid );
1302
1305
else if (write_object_file (sb .buf , sb .len , OBJ_BLOB , oid ))
1303
1306
rc = error (_ ("%s: failed to insert into database" ), path );
@@ -1328,6 +1331,7 @@ int read_pack_header(int fd, struct pack_header *header)
1328
1331
1329
1332
int for_each_file_in_obj_subdir (unsigned int subdir_nr ,
1330
1333
struct strbuf * path ,
1334
+ const struct git_hash_algo * algop ,
1331
1335
each_loose_object_fn obj_cb ,
1332
1336
each_loose_cruft_fn cruft_cb ,
1333
1337
each_loose_subdir_fn subdir_cb ,
@@ -1364,12 +1368,12 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
1364
1368
namelen = strlen (de -> d_name );
1365
1369
strbuf_setlen (path , baselen );
1366
1370
strbuf_add (path , de -> d_name , namelen );
1367
- if (namelen == the_hash_algo -> hexsz - 2 &&
1371
+ if (namelen == algop -> hexsz - 2 &&
1368
1372
!hex_to_bytes (oid .hash + 1 , de -> d_name ,
1369
- the_hash_algo -> rawsz - 1 )) {
1370
- oid_set_algo (& oid , the_hash_algo );
1371
- memset (oid .hash + the_hash_algo -> rawsz , 0 ,
1372
- GIT_MAX_RAWSZ - the_hash_algo -> rawsz );
1373
+ algop -> rawsz - 1 )) {
1374
+ oid_set_algo (& oid , algop );
1375
+ memset (oid .hash + algop -> rawsz , 0 ,
1376
+ GIT_MAX_RAWSZ - algop -> rawsz );
1373
1377
if (obj_cb ) {
1374
1378
r = obj_cb (& oid , path -> buf , data );
1375
1379
if (r )
@@ -1405,7 +1409,8 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
1405
1409
int i ;
1406
1410
1407
1411
for (i = 0 ; i < 256 ; i ++ ) {
1408
- r = for_each_file_in_obj_subdir (i , path , obj_cb , cruft_cb ,
1412
+ r = for_each_file_in_obj_subdir (i , path , the_repository -> hash_algo ,
1413
+ obj_cb , cruft_cb ,
1409
1414
subdir_cb , data );
1410
1415
if (r )
1411
1416
break ;
@@ -1481,6 +1486,7 @@ struct oidtree *odb_loose_cache(struct odb_source *source,
1481
1486
}
1482
1487
strbuf_addstr (& buf , source -> path );
1483
1488
for_each_file_in_obj_subdir (subdir_nr , & buf ,
1489
+ source -> odb -> repo -> hash_algo ,
1484
1490
append_loose_object ,
1485
1491
NULL , NULL ,
1486
1492
source -> loose_objects_cache );
@@ -1501,15 +1507,16 @@ static int check_stream_oid(git_zstream *stream,
1501
1507
const char * hdr ,
1502
1508
unsigned long size ,
1503
1509
const char * path ,
1504
- const struct object_id * expected_oid )
1510
+ const struct object_id * expected_oid ,
1511
+ const struct git_hash_algo * algop )
1505
1512
{
1506
1513
struct git_hash_ctx c ;
1507
1514
struct object_id real_oid ;
1508
1515
unsigned char buf [4096 ];
1509
1516
unsigned long total_read ;
1510
1517
int status = Z_OK ;
1511
1518
1512
- the_hash_algo -> init_fn (& c );
1519
+ algop -> init_fn (& c );
1513
1520
git_hash_update (& c , hdr , stream -> total_out );
1514
1521
1515
1522
/*
@@ -1594,7 +1601,8 @@ int read_loose_object(const char *path,
1594
1601
1595
1602
if (* oi -> typep == OBJ_BLOB &&
1596
1603
* size > repo_settings_get_big_file_threshold (the_repository )) {
1597
- if (check_stream_oid (& stream , hdr , * size , path , expected_oid ) < 0 )
1604
+ if (check_stream_oid (& stream , hdr , * size , path , expected_oid ,
1605
+ the_repository -> hash_algo ) < 0 )
1598
1606
goto out_inflate ;
1599
1607
} else {
1600
1608
* contents = unpack_loose_rest (& stream , hdr , * size , expected_oid );
0 commit comments