@@ -253,25 +253,24 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
253
253
return 1 ;
254
254
}
255
255
256
- struct commit_graph * load_commit_graph_one_fd_st (struct repository * r ,
257
- int fd , struct stat * st ,
258
- struct odb_source * source )
256
+ struct commit_graph * load_commit_graph_one_fd_st (struct odb_source * source ,
257
+ int fd , struct stat * st )
259
258
{
260
259
void * graph_map ;
261
260
size_t graph_size ;
262
261
struct commit_graph * ret ;
263
262
264
263
graph_size = xsize_t (st -> st_size );
265
264
266
- if (graph_size < graph_min_size (r -> hash_algo )) {
265
+ if (graph_size < graph_min_size (source -> odb -> repo -> hash_algo )) {
267
266
close (fd );
268
267
error (_ ("commit-graph file is too small" ));
269
268
return NULL ;
270
269
}
271
270
graph_map = xmmap (NULL , graph_size , PROT_READ , MAP_PRIVATE , fd , 0 );
272
271
close (fd );
273
272
274
- ret = parse_commit_graph (r , graph_map , graph_size );
273
+ ret = parse_commit_graph (source -> odb -> repo , graph_map , graph_size );
275
274
if (ret )
276
275
ret -> odb_source = source ;
277
276
else
@@ -491,11 +490,9 @@ struct commit_graph *parse_commit_graph(struct repository *r,
491
490
return NULL ;
492
491
}
493
492
494
- static struct commit_graph * load_commit_graph_one (struct repository * r ,
495
- const char * graph_file ,
496
- struct odb_source * source )
493
+ static struct commit_graph * load_commit_graph_one (struct odb_source * source ,
494
+ const char * graph_file )
497
495
{
498
-
499
496
struct stat st ;
500
497
int fd ;
501
498
struct commit_graph * g ;
@@ -504,19 +501,17 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
504
501
if (!open_ok )
505
502
return NULL ;
506
503
507
- g = load_commit_graph_one_fd_st (r , fd , & st , source );
508
-
504
+ g = load_commit_graph_one_fd_st (source , fd , & st );
509
505
if (g )
510
506
g -> filename = xstrdup (graph_file );
511
507
512
508
return g ;
513
509
}
514
510
515
- static struct commit_graph * load_commit_graph_v1 (struct repository * r ,
516
- struct odb_source * source )
511
+ static struct commit_graph * load_commit_graph_v1 (struct odb_source * source )
517
512
{
518
513
char * graph_name = get_commit_graph_filename (source );
519
- struct commit_graph * g = load_commit_graph_one (r , graph_name , source );
514
+ struct commit_graph * g = load_commit_graph_one (source , graph_name );
520
515
free (graph_name );
521
516
522
517
return g ;
@@ -643,7 +638,7 @@ int open_commit_graph_chain(const char *chain_file,
643
638
return 1 ;
644
639
}
645
640
646
- struct commit_graph * load_commit_graph_chain_fd_st (struct repository * r ,
641
+ struct commit_graph * load_commit_graph_chain_fd_st (struct object_database * odb ,
647
642
int fd , struct stat * st ,
648
643
int * incomplete_chain )
649
644
{
@@ -653,28 +648,28 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
653
648
int i = 0 , valid = 1 , count ;
654
649
FILE * fp = xfdopen (fd , "r" );
655
650
656
- count = st -> st_size / (r -> hash_algo -> hexsz + 1 );
651
+ count = st -> st_size / (odb -> repo -> hash_algo -> hexsz + 1 );
657
652
CALLOC_ARRAY (oids , count );
658
653
659
- odb_prepare_alternates (r -> objects );
654
+ odb_prepare_alternates (odb );
660
655
661
656
for (i = 0 ; i < count ; i ++ ) {
662
657
struct odb_source * source ;
663
658
664
659
if (strbuf_getline_lf (& line , fp ) == EOF )
665
660
break ;
666
661
667
- if (get_oid_hex_algop (line .buf , & oids [i ], r -> hash_algo )) {
662
+ if (get_oid_hex_algop (line .buf , & oids [i ], odb -> repo -> hash_algo )) {
668
663
warning (_ ("invalid commit-graph chain: line '%s' not a hash" ),
669
664
line .buf );
670
665
valid = 0 ;
671
666
break ;
672
667
}
673
668
674
669
valid = 0 ;
675
- for (source = r -> objects -> sources ; source ; source = source -> next ) {
670
+ for (source = odb -> sources ; source ; source = source -> next ) {
676
671
char * graph_name = get_split_graph_filename (source , line .buf );
677
- struct commit_graph * g = load_commit_graph_one (r , graph_name , source );
672
+ struct commit_graph * g = load_commit_graph_one (source , graph_name );
678
673
679
674
free (graph_name );
680
675
@@ -707,45 +702,33 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
707
702
return graph_chain ;
708
703
}
709
704
710
- static struct commit_graph * load_commit_graph_chain (struct repository * r ,
711
- struct odb_source * source )
705
+ static struct commit_graph * load_commit_graph_chain (struct odb_source * source )
712
706
{
713
707
char * chain_file = get_commit_graph_chain_filename (source );
714
708
struct stat st ;
715
709
int fd ;
716
710
struct commit_graph * g = NULL ;
717
711
718
- if (open_commit_graph_chain (chain_file , & fd , & st , r -> hash_algo )) {
712
+ if (open_commit_graph_chain (chain_file , & fd , & st , source -> odb -> repo -> hash_algo )) {
719
713
int incomplete ;
720
714
/* ownership of fd is taken over by load function */
721
- g = load_commit_graph_chain_fd_st (r , fd , & st , & incomplete );
715
+ g = load_commit_graph_chain_fd_st (source -> odb , fd , & st , & incomplete );
722
716
}
723
717
724
718
free (chain_file );
725
719
return g ;
726
720
}
727
721
728
- struct commit_graph * read_commit_graph_one (struct repository * r ,
729
- struct odb_source * source )
722
+ struct commit_graph * read_commit_graph_one (struct odb_source * source )
730
723
{
731
- struct commit_graph * g = load_commit_graph_v1 (r , source );
724
+ struct commit_graph * g = load_commit_graph_v1 (source );
732
725
733
726
if (!g )
734
- g = load_commit_graph_chain (r , source );
727
+ g = load_commit_graph_chain (source );
735
728
736
729
return g ;
737
730
}
738
731
739
- static void prepare_commit_graph_one (struct repository * r ,
740
- struct odb_source * source )
741
- {
742
-
743
- if (r -> objects -> commit_graph )
744
- return ;
745
-
746
- r -> objects -> commit_graph = read_commit_graph_one (r , source );
747
- }
748
-
749
732
/*
750
733
* Return 1 if commit_graph is non-NULL, and 0 otherwise.
751
734
*
@@ -786,10 +769,12 @@ static int prepare_commit_graph(struct repository *r)
786
769
return 0 ;
787
770
788
771
odb_prepare_alternates (r -> objects );
789
- for (source = r -> objects -> sources ;
790
- !r -> objects -> commit_graph && source ;
791
- source = source -> next )
792
- prepare_commit_graph_one (r , source );
772
+ for (source = r -> objects -> sources ; source ; source = source -> next ) {
773
+ r -> objects -> commit_graph = read_commit_graph_one (source );
774
+ if (r -> objects -> commit_graph )
775
+ break ;
776
+ }
777
+
793
778
return !!r -> objects -> commit_graph ;
794
779
}
795
780
@@ -874,8 +859,7 @@ static void load_oid_from_graph(struct commit_graph *g,
874
859
g -> hash_algo );
875
860
}
876
861
877
- static struct commit_list * * insert_parent_or_die (struct repository * r ,
878
- struct commit_graph * g ,
862
+ static struct commit_list * * insert_parent_or_die (struct commit_graph * g ,
879
863
uint32_t pos ,
880
864
struct commit_list * * pptr )
881
865
{
@@ -886,7 +870,7 @@ static struct commit_list **insert_parent_or_die(struct repository *r,
886
870
die ("invalid parent position %" PRIu32 , pos );
887
871
888
872
load_oid_from_graph (g , pos , & oid );
889
- c = lookup_commit (r , & oid );
873
+ c = lookup_commit (g -> odb_source -> odb -> repo , & oid );
890
874
if (!c )
891
875
die (_ ("could not find commit %s" ), oid_to_hex (& oid ));
892
876
commit_graph_data_at (c )-> graph_pos = pos ;
@@ -942,8 +926,7 @@ static inline void set_commit_tree(struct commit *c, struct tree *t)
942
926
c -> maybe_tree = t ;
943
927
}
944
928
945
- static int fill_commit_in_graph (struct repository * r ,
946
- struct commit * item ,
929
+ static int fill_commit_in_graph (struct commit * item ,
947
930
struct commit_graph * g , uint32_t pos )
948
931
{
949
932
uint32_t edge_value ;
@@ -969,13 +952,13 @@ static int fill_commit_in_graph(struct repository *r,
969
952
edge_value = get_be32 (commit_data + g -> hash_algo -> rawsz );
970
953
if (edge_value == GRAPH_PARENT_NONE )
971
954
return 1 ;
972
- pptr = insert_parent_or_die (r , g , edge_value , pptr );
955
+ pptr = insert_parent_or_die (g , edge_value , pptr );
973
956
974
957
edge_value = get_be32 (commit_data + g -> hash_algo -> rawsz + 4 );
975
958
if (edge_value == GRAPH_PARENT_NONE )
976
959
return 1 ;
977
960
if (!(edge_value & GRAPH_EXTRA_EDGES_NEEDED )) {
978
- pptr = insert_parent_or_die (r , g , edge_value , pptr );
961
+ pptr = insert_parent_or_die (g , edge_value , pptr );
979
962
return 1 ;
980
963
}
981
964
@@ -990,7 +973,7 @@ static int fill_commit_in_graph(struct repository *r,
990
973
}
991
974
edge_value = get_be32 (g -> chunk_extra_edges +
992
975
sizeof (uint32_t ) * parent_data_pos );
993
- pptr = insert_parent_or_die (r , g ,
976
+ pptr = insert_parent_or_die (g ,
994
977
edge_value & GRAPH_EDGE_LAST_MASK ,
995
978
pptr );
996
979
parent_data_pos ++ ;
@@ -1056,14 +1039,13 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
1056
1039
if (commit -> object .parsed )
1057
1040
return commit ;
1058
1041
1059
- if (!fill_commit_in_graph (repo , commit , repo -> objects -> commit_graph , pos ))
1042
+ if (!fill_commit_in_graph (commit , repo -> objects -> commit_graph , pos ))
1060
1043
return NULL ;
1061
1044
1062
1045
return commit ;
1063
1046
}
1064
1047
1065
- static int parse_commit_in_graph_one (struct repository * r ,
1066
- struct commit_graph * g ,
1048
+ static int parse_commit_in_graph_one (struct commit_graph * g ,
1067
1049
struct commit * item )
1068
1050
{
1069
1051
uint32_t pos ;
@@ -1072,7 +1054,7 @@ static int parse_commit_in_graph_one(struct repository *r,
1072
1054
return 1 ;
1073
1055
1074
1056
if (find_commit_pos_in_graph (item , g , & pos ))
1075
- return fill_commit_in_graph (r , item , g , pos );
1057
+ return fill_commit_in_graph (item , g , pos );
1076
1058
1077
1059
return 0 ;
1078
1060
}
@@ -1089,7 +1071,7 @@ int parse_commit_in_graph(struct repository *r, struct commit *item)
1089
1071
1090
1072
if (!prepare_commit_graph (r ))
1091
1073
return 0 ;
1092
- return parse_commit_in_graph_one (r , r -> objects -> commit_graph , item );
1074
+ return parse_commit_in_graph_one (r -> objects -> commit_graph , item );
1093
1075
}
1094
1076
1095
1077
void load_commit_graph_info (struct repository * r , struct commit * item )
@@ -1099,8 +1081,7 @@ void load_commit_graph_info(struct repository *r, struct commit *item)
1099
1081
fill_commit_graph_info (item , r -> objects -> commit_graph , pos );
1100
1082
}
1101
1083
1102
- static struct tree * load_tree_for_commit (struct repository * r ,
1103
- struct commit_graph * g ,
1084
+ static struct tree * load_tree_for_commit (struct commit_graph * g ,
1104
1085
struct commit * c )
1105
1086
{
1106
1087
struct object_id oid ;
@@ -1115,26 +1096,25 @@ static struct tree *load_tree_for_commit(struct repository *r,
1115
1096
graph_pos - g -> num_commits_in_base );
1116
1097
1117
1098
oidread (& oid , commit_data , g -> hash_algo );
1118
- set_commit_tree (c , lookup_tree (r , & oid ));
1099
+ set_commit_tree (c , lookup_tree (g -> odb_source -> odb -> repo , & oid ));
1119
1100
1120
1101
return c -> maybe_tree ;
1121
1102
}
1122
1103
1123
- static struct tree * get_commit_tree_in_graph_one (struct repository * r ,
1124
- struct commit_graph * g ,
1104
+ static struct tree * get_commit_tree_in_graph_one (struct commit_graph * g ,
1125
1105
const struct commit * c )
1126
1106
{
1127
1107
if (c -> maybe_tree )
1128
1108
return c -> maybe_tree ;
1129
1109
if (commit_graph_position (c ) == COMMIT_NOT_FROM_GRAPH )
1130
1110
BUG ("get_commit_tree_in_graph_one called from non-commit-graph commit" );
1131
1111
1132
- return load_tree_for_commit (r , g , (struct commit * )c );
1112
+ return load_tree_for_commit (g , (struct commit * )c );
1133
1113
}
1134
1114
1135
1115
struct tree * get_commit_tree_in_graph (struct repository * r , const struct commit * c )
1136
1116
{
1137
- return get_commit_tree_in_graph_one (r , r -> objects -> commit_graph , c );
1117
+ return get_commit_tree_in_graph_one (r -> objects -> commit_graph , c );
1138
1118
}
1139
1119
1140
1120
struct packed_commit_list {
@@ -2741,11 +2721,11 @@ static int commit_graph_checksum_valid(struct commit_graph *g)
2741
2721
g -> data , g -> data_len );
2742
2722
}
2743
2723
2744
- static int verify_one_commit_graph (struct repository * r ,
2745
- struct commit_graph * g ,
2724
+ static int verify_one_commit_graph (struct commit_graph * g ,
2746
2725
struct progress * progress ,
2747
2726
uint64_t * seen )
2748
2727
{
2728
+ struct repository * r = g -> odb_source -> odb -> repo ;
2749
2729
uint32_t i , cur_fanout_pos = 0 ;
2750
2730
struct object_id prev_oid , cur_oid ;
2751
2731
struct commit * seen_gen_zero = NULL ;
@@ -2779,7 +2759,7 @@ static int verify_one_commit_graph(struct repository *r,
2779
2759
}
2780
2760
2781
2761
graph_commit = lookup_commit (r , & cur_oid );
2782
- if (!parse_commit_in_graph_one (r , g , graph_commit ))
2762
+ if (!parse_commit_in_graph_one (g , graph_commit ))
2783
2763
graph_report (_ ("failed to parse commit %s from commit-graph" ),
2784
2764
oid_to_hex (& cur_oid ));
2785
2765
}
@@ -2815,7 +2795,7 @@ static int verify_one_commit_graph(struct repository *r,
2815
2795
continue ;
2816
2796
}
2817
2797
2818
- if (!oideq (& get_commit_tree_in_graph_one (r , g , graph_commit )-> object .oid ,
2798
+ if (!oideq (& get_commit_tree_in_graph_one (g , graph_commit )-> object .oid ,
2819
2799
get_commit_tree_oid (odb_commit )))
2820
2800
graph_report (_ ("root tree OID for commit %s in commit-graph is %s != %s" ),
2821
2801
oid_to_hex (& cur_oid ),
@@ -2833,7 +2813,7 @@ static int verify_one_commit_graph(struct repository *r,
2833
2813
}
2834
2814
2835
2815
/* parse parent in case it is in a base graph */
2836
- parse_commit_in_graph_one (r , g , graph_parents -> item );
2816
+ parse_commit_in_graph_one (g , graph_parents -> item );
2837
2817
2838
2818
if (!oideq (& graph_parents -> item -> object .oid , & odb_parents -> item -> object .oid ))
2839
2819
graph_report (_ ("commit-graph parent for %s is %s != %s" ),
@@ -2893,7 +2873,7 @@ static int verify_one_commit_graph(struct repository *r,
2893
2873
return verify_commit_graph_error ;
2894
2874
}
2895
2875
2896
- int verify_commit_graph (struct repository * r , struct commit_graph * g , int flags )
2876
+ int verify_commit_graph (struct commit_graph * g , int flags )
2897
2877
{
2898
2878
struct progress * progress = NULL ;
2899
2879
int local_error = 0 ;
@@ -2909,13 +2889,13 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2909
2889
if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW ))
2910
2890
total += g -> num_commits_in_base ;
2911
2891
2912
- progress = start_progress (r ,
2892
+ progress = start_progress (g -> odb_source -> odb -> repo ,
2913
2893
_ ("Verifying commits in commit graph" ),
2914
2894
total );
2915
2895
}
2916
2896
2917
2897
for (; g ; g = g -> base_graph ) {
2918
- local_error |= verify_one_commit_graph (r , g , progress , & seen );
2898
+ local_error |= verify_one_commit_graph (g , progress , & seen );
2919
2899
if (flags & COMMIT_GRAPH_VERIFY_SHALLOW )
2920
2900
break ;
2921
2901
}
0 commit comments