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