@matheusbsbs / matheus-bagliano / commits / 9bab081dfa
Fork 0

commit-graph: unify the signatures of all write_graph_chunk_*() functions

Update the write_graph_chunk_*() helper functions to have the same signature: - Return an int error code from all these functions. write_graph_chunk_base() already has an int error code, now the others will have one, too, but since they don't indicate any error, they will always return 0. - Drop the hash size parameter of write_graph_chunk_oids() and write_graph_chunk_data(); its value can be read directly from 'the_hash_algo' inside these functions as well. This opens up the possibility for further cleanups and foolproofing in the following two patches. Helped-by: René Scharfe <l.s.r@web.de> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Jul 1, 2020 at 13:27 UTC 9bab081dfab8ebb4fcdf0d7e8a692626aeb29358
1 file changed +26 -16
commit-graph.c
+26 -16
@@ -891,8 +891,8 @@ struct write_commit_graph_context {
891 const struct bloom_filter_settings *bloom_settings;
892 };
893
894 -static void write_graph_chunk_fanout(struct hashfile *f,
895 - struct write_commit_graph_context *ctx)
894 +static int write_graph_chunk_fanout(struct hashfile *f,
895 + struct write_commit_graph_context *ctx)
896 {
897 int i, count = 0;
898 struct commit **list = ctx->commits.list;
@@ -913,17 +913,21 @@ static void write_graph_chunk_fanout(struct hashfile *f,
913
914 hashwrite_be32(f, count);
915 }
916 +
917 + return 0;
918 }
919
918 -static void write_graph_chunk_oids(struct hashfile *f, int hash_len,
919 - struct write_commit_graph_context *ctx)
920 +static int write_graph_chunk_oids(struct hashfile *f,
921 + struct write_commit_graph_context *ctx)
922 {
923 struct commit **list = ctx->commits.list;
924 int count;
925 for (count = 0; count < ctx->commits.nr; count++, list++) {
926 display_progress(ctx->progress, ++ctx->progress_cnt);
925 - hashwrite(f, (*list)->object.oid.hash, (int)hash_len);
927 + hashwrite(f, (*list)->object.oid.hash, the_hash_algo->rawsz);
928 }
929 +
930 + return 0;
931 }
932
933 static const unsigned char *commit_to_sha1(size_t index, void *table)
@@ -932,8 +936,8 @@ static const unsigned char *commit_to_sha1(size_t index, void *table)
936 return commits[index]->object.oid.hash;
937 }
938
935 -static void write_graph_chunk_data(struct hashfile *f, int hash_len,
936 - struct write_commit_graph_context *ctx)
939 +static int write_graph_chunk_data(struct hashfile *f,
940 + struct write_commit_graph_context *ctx)
941 {
942 struct commit **list = ctx->commits.list;
943 struct commit **last = ctx->commits.list + ctx->commits.nr;
@@ -950,7 +954,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
954 die(_("unable to parse commit %s"),
955 oid_to_hex(&(*list)->object.oid));
956 tree = get_commit_tree_oid(*list);
953 - hashwrite(f, tree->hash, hash_len);
957 + hashwrite(f, tree->hash, the_hash_algo->rawsz);
958
959 parent = (*list)->parents;
960
@@ -1030,10 +1034,12 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
1034
1035 list++;
1036 }
1037 +
1038 + return 0;
1039 }
1040
1035 -static void write_graph_chunk_extra_edges(struct hashfile *f,
1036 - struct write_commit_graph_context *ctx)
1041 +static int write_graph_chunk_extra_edges(struct hashfile *f,
1042 + struct write_commit_graph_context *ctx)
1043 {
1044 struct commit **list = ctx->commits.list;
1045 struct commit **last = ctx->commits.list + ctx->commits.nr;
@@ -1082,10 +1088,12 @@ static void write_graph_chunk_extra_edges(struct hashfile *f,
1088
1089 list++;
1090 }
1091 +
1092 + return 0;
1093 }
1094
1087 -static void write_graph_chunk_bloom_indexes(struct hashfile *f,
1088 - struct write_commit_graph_context *ctx)
1095 +static int write_graph_chunk_bloom_indexes(struct hashfile *f,
1096 + struct write_commit_graph_context *ctx)
1097 {
1098 struct commit **list = ctx->commits.list;
1099 struct commit **last = ctx->commits.list + ctx->commits.nr;
@@ -1108,6 +1116,7 @@ static void write_graph_chunk_bloom_indexes(struct hashfile *f,
1116 }
1117
1118 stop_progress(&progress);
1119 + return 0;
1120 }
1121
1122 static void trace2_bloom_filter_settings(struct write_commit_graph_context *ctx)
@@ -1125,8 +1134,8 @@ static void trace2_bloom_filter_settings(struct write_commit_graph_context *ctx)
1134 jw_release(&jw);
1135 }
1136
1128 -static void write_graph_chunk_bloom_data(struct hashfile *f,
1129 - struct write_commit_graph_context *ctx)
1137 +static int write_graph_chunk_bloom_data(struct hashfile *f,
1138 + struct write_commit_graph_context *ctx)
1139 {
1140 struct commit **list = ctx->commits.list;
1141 struct commit **last = ctx->commits.list + ctx->commits.nr;
@@ -1155,6 +1164,7 @@ static void write_graph_chunk_bloom_data(struct hashfile *f,
1164 }
1165
1166 stop_progress(&progress);
1167 + return 0;
1168 }
1169
1170 static int oid_compare(const void *_a, const void *_b)
@@ -1671,8 +1681,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1681 num_chunks * ctx->commits.nr);
1682 }
1683 write_graph_chunk_fanout(f, ctx);
1674 - write_graph_chunk_oids(f, hashsz, ctx);
1675 - write_graph_chunk_data(f, hashsz, ctx);
1684 + write_graph_chunk_oids(f, ctx);
1685 + write_graph_chunk_data(f, ctx);
1686 if (ctx->num_extra_edges)
1687 write_graph_chunk_extra_edges(f, ctx);
1688 if (ctx->changed_paths) {