@matheusbsbs / matheus-bagliano / commits / 1fe10844ca
Fork 0

commit-graph.c: extract 'refs_cb_data'

In subsequent patches, we are going to update a progress meter when 'add_ref_to_set()' is called, and need a convenient way to pass a 'struct progress *' in from the caller. Introduce 'refs_cb_data' as a catch-all for parameters that 'add_ref_to_set' may need, and wrap the existing single parameter in that struct. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed May 4, 2020 at 19:13 UTC 1fe10844cad39db18de18412c928a0e69b0067ae
1 file changed +11 -3
commit-graph.c
+11 -3
@@ -1318,13 +1318,17 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
1318 stop_progress(&progress);
1319 }
1320
1321 +struct refs_cb_data {
1322 + struct oidset *commits;
1323 +};
1324 +
1325 static int add_ref_to_set(const char *refname,
1326 const struct object_id *oid,
1327 int flags, void *cb_data)
1328 {
1325 - struct oidset *commits = (struct oidset *)cb_data;
1329 + struct refs_cb_data *data = (struct refs_cb_data *)cb_data;
1330
1327 - oidset_insert(commits, oid);
1331 + oidset_insert(data->commits, oid);
1332 return 0;
1333 }
1334
@@ -1333,9 +1337,13 @@ int write_commit_graph_reachable(struct object_directory *odb,
1337 const struct split_commit_graph_opts *split_opts)
1338 {
1339 struct oidset commits = OIDSET_INIT;
1340 + struct refs_cb_data data;
1341 int result;
1342
1338 - for_each_ref(add_ref_to_set, &commits);
1343 + memset(&data, 0, sizeof(data));
1344 + data.commits = &commits;
1345 +
1346 + for_each_ref(add_ref_to_set, &data);
1347 result = write_commit_graph(odb, NULL, &commits,
1348 flags, split_opts);
1349