@@ -851,27 +851,30 @@ static int add_ref_to_list(const char *refname,
851
851
return 0 ;
852
852
}
853
853
854
- void write_commit_graph_reachable (const char * obj_dir , int append ,
855
- int report_progress )
854
+ int write_commit_graph_reachable (const char * obj_dir , int append ,
855
+ int report_progress )
856
856
{
857
857
struct string_list list = STRING_LIST_INIT_DUP ;
858
+ int result ;
858
859
859
860
for_each_ref (add_ref_to_list , & list );
860
- write_commit_graph (obj_dir , NULL , & list , append , report_progress );
861
+ result = write_commit_graph (obj_dir , NULL , & list ,
862
+ append , report_progress );
861
863
862
864
string_list_clear (& list , 0 );
865
+ return result ;
863
866
}
864
867
865
- void write_commit_graph (const char * obj_dir ,
866
- struct string_list * pack_indexes ,
867
- struct string_list * commit_hex ,
868
- int append , int report_progress )
868
+ int write_commit_graph (const char * obj_dir ,
869
+ struct string_list * pack_indexes ,
870
+ struct string_list * commit_hex ,
871
+ int append , int report_progress )
869
872
{
870
873
struct packed_oid_list oids ;
871
874
struct packed_commit_list commits ;
872
875
struct hashfile * f ;
873
876
uint32_t i , count_distinct = 0 ;
874
- char * graph_name ;
877
+ char * graph_name = NULL ;
875
878
struct lock_file lk = LOCK_INIT ;
876
879
uint32_t chunk_ids [5 ];
877
880
uint64_t chunk_offsets [5 ];
@@ -883,15 +886,17 @@ void write_commit_graph(const char *obj_dir,
883
886
uint64_t progress_cnt = 0 ;
884
887
struct strbuf progress_title = STRBUF_INIT ;
885
888
unsigned long approx_nr_objects ;
889
+ int res = 0 ;
886
890
887
891
if (!commit_graph_compatible (the_repository ))
888
- return ;
892
+ return 0 ;
889
893
890
894
oids .nr = 0 ;
891
895
approx_nr_objects = approximate_object_count ();
892
896
oids .alloc = approx_nr_objects / 32 ;
893
897
oids .progress = NULL ;
894
898
oids .progress_done = 0 ;
899
+ commits .list = NULL ;
895
900
896
901
if (append ) {
897
902
prepare_commit_graph_one (the_repository , obj_dir );
@@ -932,10 +937,16 @@ void write_commit_graph(const char *obj_dir,
932
937
strbuf_setlen (& packname , dirlen );
933
938
strbuf_addstr (& packname , pack_indexes -> items [i ].string );
934
939
p = add_packed_git (packname .buf , packname .len , 1 );
935
- if (!p )
936
- die (_ ("error adding pack %s" ), packname .buf );
937
- if (open_pack_index (p ))
938
- die (_ ("error opening index for %s" ), packname .buf );
940
+ if (!p ) {
941
+ error (_ ("error adding pack %s" ), packname .buf );
942
+ res = 1 ;
943
+ goto cleanup ;
944
+ }
945
+ if (open_pack_index (p )) {
946
+ error (_ ("error opening index for %s" ), packname .buf );
947
+ res = 1 ;
948
+ goto cleanup ;
949
+ }
939
950
for_each_object_in_pack (p , add_packed_commits , & oids ,
940
951
FOR_EACH_OBJECT_PACK_ORDER );
941
952
close_pack (p );
@@ -1006,8 +1017,11 @@ void write_commit_graph(const char *obj_dir,
1006
1017
}
1007
1018
stop_progress (& progress );
1008
1019
1009
- if (count_distinct >= GRAPH_EDGE_LAST_MASK )
1010
- die (_ ("the commit graph format cannot write %d commits" ), count_distinct );
1020
+ if (count_distinct >= GRAPH_EDGE_LAST_MASK ) {
1021
+ error (_ ("the commit graph format cannot write %d commits" ), count_distinct );
1022
+ res = 1 ;
1023
+ goto cleanup ;
1024
+ }
1011
1025
1012
1026
commits .nr = 0 ;
1013
1027
commits .alloc = count_distinct ;
@@ -1039,16 +1053,21 @@ void write_commit_graph(const char *obj_dir,
1039
1053
num_chunks = num_extra_edges ? 4 : 3 ;
1040
1054
stop_progress (& progress );
1041
1055
1042
- if (commits .nr >= GRAPH_EDGE_LAST_MASK )
1043
- die (_ ("too many commits to write graph" ));
1056
+ if (commits .nr >= GRAPH_EDGE_LAST_MASK ) {
1057
+ error (_ ("too many commits to write graph" ));
1058
+ res = 1 ;
1059
+ goto cleanup ;
1060
+ }
1044
1061
1045
1062
compute_generation_numbers (& commits , report_progress );
1046
1063
1047
1064
graph_name = get_commit_graph_filename (obj_dir );
1048
1065
if (safe_create_leading_directories (graph_name )) {
1049
1066
UNLEAK (graph_name );
1050
- die_errno (_ ("unable to create leading directories of %s" ),
1051
- graph_name );
1067
+ error (_ ("unable to create leading directories of %s" ),
1068
+ graph_name );
1069
+ res = errno ;
1070
+ goto cleanup ;
1052
1071
}
1053
1072
1054
1073
hold_lock_file_for_update (& lk , graph_name , LOCK_DIE_ON_ERROR );
@@ -1107,9 +1126,12 @@ void write_commit_graph(const char *obj_dir,
1107
1126
finalize_hashfile (f , NULL , CSUM_HASH_IN_STREAM | CSUM_FSYNC );
1108
1127
commit_lock_file (& lk );
1109
1128
1129
+ cleanup :
1110
1130
free (graph_name );
1111
1131
free (commits .list );
1112
1132
free (oids .list );
1133
+
1134
+ return res ;
1113
1135
}
1114
1136
1115
1137
#define VERIFY_COMMIT_GRAPH_ERROR_HASH 2
0 commit comments