851
return 0;
852
}
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
{
857
struct string_list list = STRING_LIST_INIT_DUP;
858
+ int result;
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);
863
864
string_list_clear(&list, 0);
865
+ return result;
866
}
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)
872
{
873
struct packed_oid_list oids;
874
struct packed_commit_list commits;
875
struct hashfile *f;
876
uint32_t i, count_distinct = 0;
874
- char *graph_name;
877
+ char *graph_name = NULL;
878
struct lock_file lk = LOCK_INIT;
879
uint32_t chunk_ids[5];
880
uint64_t chunk_offsets[5];
886
uint64_t progress_cnt = 0;
887
struct strbuf progress_title = STRBUF_INIT;
888
unsigned long approx_nr_objects;
889
+ int res = 0;
890
891
if (!commit_graph_compatible(the_repository))
888
- return;
892
+ return 0;
893
894
oids.nr = 0;
895
approx_nr_objects = approximate_object_count();
896
oids.alloc = approx_nr_objects / 32;
897
oids.progress = NULL;
898
oids.progress_done = 0;
899
+ commits.list = NULL;
900
901
if (append) {
902
prepare_commit_graph_one(the_repository, obj_dir);
937
strbuf_setlen(&packname, dirlen);
938
strbuf_addstr(&packname, pack_indexes->items[i].string);
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
+ }
950
for_each_object_in_pack(p, add_packed_commits, &oids,
951
FOR_EACH_OBJECT_PACK_ORDER);
952
close_pack(p);
1017
}
1018
stop_progress(&progress);
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
+ }
1025
1026
commits.nr = 0;
1027
commits.alloc = count_distinct;
1053
num_chunks = num_extra_edges ? 4 : 3;
1054
stop_progress(&progress);
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
+ }
1061
1062
compute_generation_numbers(&commits, report_progress);
1063
1064
graph_name = get_commit_graph_filename(obj_dir);
1065
if (safe_create_leading_directories(graph_name)) {
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 = -1;
1070
+ goto cleanup;
1071
}
1072
1073
hold_lock_file_for_update(&lk, graph_name, LOCK_DIE_ON_ERROR);
1126
finalize_hashfile(f, NULL, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
1127
commit_lock_file(&lk);
1128
1129
+cleanup:
1130
free(graph_name);
1131
free(commits.list);
1132
free(oids.list);
1133
+
1134
+ return res;
1135
}
1136
1137
#define VERIFY_COMMIT_GRAPH_ERROR_HASH 2