Skip to content

Commit 5faf357

Browse files
jonathantanmygitster
authored andcommitted
commit-graph: refactor preparing commit graph
Two functions in the code (1) check if the repository is configured for commit graphs, (2) call prepare_commit_graph(), and (3) check if the graph exists. Move (1) and (3) into prepare_commit_graph(), reducing duplication of code. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8295296 commit 5faf357

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

commit-graph.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,33 @@ static void prepare_commit_graph_one(const char *obj_dir)
200200
}
201201

202202
static int prepare_commit_graph_run_once = 0;
203-
static void prepare_commit_graph(void)
203+
204+
/*
205+
* Return 1 if commit_graph is non-NULL, and 0 otherwise.
206+
*
207+
* On the first invocation, this function attemps to load the commit
208+
* graph if the_repository is configured to have one.
209+
*/
210+
static int prepare_commit_graph(void)
204211
{
205212
struct alternate_object_database *alt;
206213
char *obj_dir;
207214

208215
if (prepare_commit_graph_run_once)
209-
return;
216+
return !!commit_graph;
210217
prepare_commit_graph_run_once = 1;
211218

219+
if (!core_commit_graph)
220+
return 0;
221+
212222
obj_dir = get_object_directory();
213223
prepare_commit_graph_one(obj_dir);
214224
prepare_alt_odb(the_repository);
215225
for (alt = the_repository->objects->alt_odb_list;
216226
!commit_graph && alt;
217227
alt = alt->next)
218228
prepare_commit_graph_one(alt->path);
229+
return !!commit_graph;
219230
}
220231

221232
static void close_commit_graph(void)
@@ -337,22 +348,17 @@ static int parse_commit_in_graph_one(struct commit_graph *g, struct commit *item
337348

338349
int parse_commit_in_graph(struct commit *item)
339350
{
340-
if (!core_commit_graph)
351+
if (!prepare_commit_graph())
341352
return 0;
342-
343-
prepare_commit_graph();
344-
if (commit_graph)
345-
return parse_commit_in_graph_one(commit_graph, item);
346-
return 0;
353+
return parse_commit_in_graph_one(commit_graph, item);
347354
}
348355

349356
void load_commit_graph_info(struct commit *item)
350357
{
351358
uint32_t pos;
352-
if (!core_commit_graph)
359+
if (!prepare_commit_graph())
353360
return;
354-
prepare_commit_graph();
355-
if (commit_graph && find_commit_in_graph(item, commit_graph, &pos))
361+
if (find_commit_in_graph(item, commit_graph, &pos))
356362
fill_commit_graph_info(item, commit_graph, pos);
357363
}
358364

0 commit comments

Comments
 (0)