1- #define USE_THE_REPOSITORY_VARIABLE
2-
31#include "git-compat-util.h"
42#include "date.h"
53#include "dir.h"
@@ -207,7 +205,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
207205 if (equal == len )
208206 die ("skiplist requires a path" );
209207 oidset_parse_file (& options -> skip_oids , buf + equal + 1 ,
210- the_repository -> hash_algo );
208+ options -> repo -> hash_algo );
211209 buf += len + 1 ;
212210 continue ;
213211 }
@@ -360,7 +358,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
360358 int res = 0 ;
361359 const char * name ;
362360
363- if (repo_parse_tree (the_repository , tree ))
361+ if (repo_parse_tree (options -> repo , tree ))
364362 return -1 ;
365363
366364 name = fsck_get_object_name (options , & tree -> object .oid );
@@ -375,14 +373,14 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
375373 continue ;
376374
377375 if (S_ISDIR (entry .mode )) {
378- obj = (struct object * )lookup_tree (the_repository , & entry .oid );
376+ obj = (struct object * )lookup_tree (options -> repo , & entry .oid );
379377 if (name && obj )
380378 fsck_put_object_name (options , & entry .oid , "%s%s/" ,
381379 name , entry .path );
382380 result = options -> walk (obj , OBJ_TREE , data , options );
383381 }
384382 else if (S_ISREG (entry .mode ) || S_ISLNK (entry .mode )) {
385- obj = (struct object * )lookup_blob (the_repository , & entry .oid );
383+ obj = (struct object * )lookup_blob (options -> repo , & entry .oid );
386384 if (name && obj )
387385 fsck_put_object_name (options , & entry .oid , "%s%s" ,
388386 name , entry .path );
@@ -409,15 +407,15 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio
409407 int result ;
410408 const char * name ;
411409
412- if (repo_parse_commit (the_repository , commit ))
410+ if (repo_parse_commit (options -> repo , commit ))
413411 return -1 ;
414412
415413 name = fsck_get_object_name (options , & commit -> object .oid );
416414 if (name )
417415 fsck_put_object_name (options , get_commit_tree_oid (commit ),
418416 "%s:" , name );
419417
420- result = options -> walk ((struct object * ) repo_get_commit_tree (the_repository , commit ),
418+ result = options -> walk ((struct object * ) repo_get_commit_tree (options -> repo , commit ),
421419 OBJ_TREE , data , options );
422420 if (result < 0 )
423421 return result ;
@@ -474,7 +472,7 @@ static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *optio
474472{
475473 const char * name = fsck_get_object_name (options , & tag -> object .oid );
476474
477- if (parse_tag (the_repository , tag ))
475+ if (parse_tag (options -> repo , tag ))
478476 return -1 ;
479477 if (name )
480478 fsck_put_object_name (options , & tag -> tagged -> oid , "%s" , name );
@@ -487,7 +485,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
487485 return -1 ;
488486
489487 if (obj -> type == OBJ_NONE )
490- parse_object (the_repository , & obj -> oid );
488+ parse_object (options -> repo , & obj -> oid );
491489
492490 switch (obj -> type ) {
493491 case OBJ_BLOB :
@@ -970,14 +968,14 @@ static int fsck_commit(const struct object_id *oid,
970968
971969 if (buffer >= buffer_end || !skip_prefix (buffer , "tree " , & buffer ))
972970 return report (options , oid , OBJ_COMMIT , FSCK_MSG_MISSING_TREE , "invalid format - expected 'tree' line" );
973- if (parse_oid_hex (buffer , & tree_oid , & p ) || * p != '\n' ) {
971+ if (parse_oid_hex_algop (buffer , & tree_oid , & p , options -> repo -> hash_algo ) || * p != '\n' ) {
974972 err = report (options , oid , OBJ_COMMIT , FSCK_MSG_BAD_TREE_SHA1 , "invalid 'tree' line format - bad sha1" );
975973 if (err )
976974 return err ;
977975 }
978976 buffer = p + 1 ;
979977 while (buffer < buffer_end && skip_prefix (buffer , "parent " , & buffer )) {
980- if (parse_oid_hex (buffer , & parent_oid , & p ) || * p != '\n' ) {
978+ if (parse_oid_hex_algop (buffer , & parent_oid , & p , options -> repo -> hash_algo ) || * p != '\n' ) {
981979 err = report (options , oid , OBJ_COMMIT , FSCK_MSG_BAD_PARENT_SHA1 , "invalid 'parent' line format - bad sha1" );
982980 if (err )
983981 return err ;
@@ -1044,7 +1042,7 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer,
10441042 ret = report (options , oid , OBJ_TAG , FSCK_MSG_MISSING_OBJECT , "invalid format - expected 'object' line" );
10451043 goto done ;
10461044 }
1047- if (parse_oid_hex (buffer , tagged_oid , & p ) || * p != '\n' ) {
1045+ if (parse_oid_hex_algop (buffer , tagged_oid , & p , options -> repo -> hash_algo ) || * p != '\n' ) {
10481046 ret = report (options , oid , OBJ_TAG , FSCK_MSG_BAD_OBJECT_SHA1 , "invalid 'object' line format - bad sha1" );
10491047 if (ret )
10501048 goto done ;
@@ -1336,9 +1334,9 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
13361334 if (oidset_contains (blobs_done , oid ))
13371335 continue ;
13381336
1339- buf = odb_read_object (the_repository -> objects , oid , & type , & size );
1337+ buf = odb_read_object (options -> repo -> objects , oid , & type , & size );
13401338 if (!buf ) {
1341- if (is_promisor_object (the_repository , oid ))
1339+ if (is_promisor_object (options -> repo , oid ))
13421340 continue ;
13431341 ret |= report (options ,
13441342 oid , OBJ_BLOB , msg_missing ,
@@ -1380,6 +1378,54 @@ bool fsck_has_queued_checks(struct fsck_options *options)
13801378 !oidset_equal (& options -> gitattributes_found , & options -> gitattributes_done );
13811379}
13821380
1381+ void fsck_options_init (struct fsck_options * options ,
1382+ struct repository * repo ,
1383+ enum fsck_options_type type )
1384+ {
1385+ static const struct fsck_options defaults [] = {
1386+ [FSCK_OPTIONS_DEFAULT ] = {
1387+ .skip_oids = OIDSET_INIT ,
1388+ .gitmodules_found = OIDSET_INIT ,
1389+ .gitmodules_done = OIDSET_INIT ,
1390+ .gitattributes_found = OIDSET_INIT ,
1391+ .gitattributes_done = OIDSET_INIT ,
1392+ .error_func = fsck_objects_error_function
1393+ },
1394+ [FSCK_OPTIONS_STRICT ] = {
1395+ .strict = 1 ,
1396+ .gitmodules_found = OIDSET_INIT ,
1397+ .gitmodules_done = OIDSET_INIT ,
1398+ .gitattributes_found = OIDSET_INIT ,
1399+ .gitattributes_done = OIDSET_INIT ,
1400+ .error_func = fsck_objects_error_function ,
1401+ },
1402+ [FSCK_OPTIONS_MISSING_GITMODULES ] = {
1403+ .strict = 1 ,
1404+ .gitmodules_found = OIDSET_INIT ,
1405+ .gitmodules_done = OIDSET_INIT ,
1406+ .gitattributes_found = OIDSET_INIT ,
1407+ .gitattributes_done = OIDSET_INIT ,
1408+ .error_func = fsck_objects_error_cb_print_missing_gitmodules ,
1409+ },
1410+ [FSCK_OPTIONS_REFS ] = {
1411+ .error_func = fsck_refs_error_function ,
1412+ },
1413+ };
1414+
1415+ switch (type ) {
1416+ case FSCK_OPTIONS_DEFAULT :
1417+ case FSCK_OPTIONS_STRICT :
1418+ case FSCK_OPTIONS_MISSING_GITMODULES :
1419+ case FSCK_OPTIONS_REFS :
1420+ memcpy (options , & defaults [type ], sizeof (* options ));
1421+ break ;
1422+ default :
1423+ BUG ("unknown fsck options type %d" , type );
1424+ }
1425+
1426+ options -> repo = repo ;
1427+ }
1428+
13831429void fsck_options_clear (struct fsck_options * options )
13841430{
13851431 free (options -> msg_type );
0 commit comments