@@ -851,27 +851,30 @@ static int add_ref_to_list(const char *refname,
851851 return 0 ;
852852}
853853
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 )
856856{
857857 struct string_list list = STRING_LIST_INIT_DUP ;
858+ int result ;
858859
859860 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 );
861863
862864 string_list_clear (& list , 0 );
865+ return result ;
863866}
864867
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 )
869872{
870873 struct packed_oid_list oids ;
871874 struct packed_commit_list commits ;
872875 struct hashfile * f ;
873876 uint32_t i , count_distinct = 0 ;
874- char * graph_name ;
877+ char * graph_name = NULL ;
875878 struct lock_file lk = LOCK_INIT ;
876879 uint32_t chunk_ids [5 ];
877880 uint64_t chunk_offsets [5 ];
@@ -883,15 +886,17 @@ void write_commit_graph(const char *obj_dir,
883886 uint64_t progress_cnt = 0 ;
884887 struct strbuf progress_title = STRBUF_INIT ;
885888 unsigned long approx_nr_objects ;
889+ int res = 0 ;
886890
887891 if (!commit_graph_compatible (the_repository ))
888- return ;
892+ return 0 ;
889893
890894 oids .nr = 0 ;
891895 approx_nr_objects = approximate_object_count ();
892896 oids .alloc = approx_nr_objects / 32 ;
893897 oids .progress = NULL ;
894898 oids .progress_done = 0 ;
899+ commits .list = NULL ;
895900
896901 if (append ) {
897902 prepare_commit_graph_one (the_repository , obj_dir );
@@ -932,10 +937,16 @@ void write_commit_graph(const char *obj_dir,
932937 strbuf_setlen (& packname , dirlen );
933938 strbuf_addstr (& packname , pack_indexes -> items [i ].string );
934939 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+ }
939950 for_each_object_in_pack (p , add_packed_commits , & oids ,
940951 FOR_EACH_OBJECT_PACK_ORDER );
941952 close_pack (p );
@@ -1006,8 +1017,11 @@ void write_commit_graph(const char *obj_dir,
10061017 }
10071018 stop_progress (& progress );
10081019
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+ }
10111025
10121026 commits .nr = 0 ;
10131027 commits .alloc = count_distinct ;
@@ -1039,16 +1053,21 @@ void write_commit_graph(const char *obj_dir,
10391053 num_chunks = num_extra_edges ? 4 : 3 ;
10401054 stop_progress (& progress );
10411055
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+ }
10441061
10451062 compute_generation_numbers (& commits , report_progress );
10461063
10471064 graph_name = get_commit_graph_filename (obj_dir );
10481065 if (safe_create_leading_directories (graph_name )) {
10491066 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 = -1 ;
1070+ goto cleanup ;
10521071 }
10531072
10541073 hold_lock_file_for_update (& lk , graph_name , LOCK_DIE_ON_ERROR );
@@ -1107,9 +1126,12 @@ void write_commit_graph(const char *obj_dir,
11071126 finalize_hashfile (f , NULL , CSUM_HASH_IN_STREAM | CSUM_FSYNC );
11081127 commit_lock_file (& lk );
11091128
1129+ cleanup :
11101130 free (graph_name );
11111131 free (commits .list );
11121132 free (oids .list );
1133+
1134+ return res ;
11131135}
11141136
11151137#define VERIFY_COMMIT_GRAPH_ERROR_HASH 2
0 commit comments