commit-graph: add free_commit_graph
Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Jul 11, 2018 at 15:42 UTC
c3756d5b7fc6e163032296aa6c10fad2589273dc
3 files changed
+18
-10
builtin/commit-graph.c
+2
@@ -115,6 +115,8 @@ static int graph_read(int argc, const char **argv)
115
printf(" large_edges");
116
printf("\n");
117
118
+ free_commit_graph(graph);
119
+
120
return 0;
121
}
122
commit-graph.c
+14
-10
@@ -231,16 +231,8 @@ static int prepare_commit_graph(void)
231
232
static void close_commit_graph(void)
233
{
234
- if (!commit_graph)
235
- return;
236
-
237
- if (commit_graph->graph_fd >= 0) {
238
- munmap((void *)commit_graph->data, commit_graph->data_len);
239
- commit_graph->data = NULL;
240
- close(commit_graph->graph_fd);
241
- }
242
-
243
- FREE_AND_NULL(commit_graph);
234
+ free_commit_graph(commit_graph);
235
+ commit_graph = NULL;
236
}
237
238
static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t *pos)
@@ -1033,3 +1025,15 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
1025
1026
return verify_commit_graph_error;
1027
}
1028
+
1029
+void free_commit_graph(struct commit_graph *g)
1030
+{
1031
+ if (!g)
1032
+ return;
1033
+ if (g->graph_fd >= 0) {
1034
+ munmap((void *)g->data, g->data_len);
1035
+ g->data = NULL;
1036
+ close(g->graph_fd);
1037
+ }
1038
+ free(g);
1039
+}
commit-graph.h
+2
@@ -58,4 +58,6 @@ void write_commit_graph(const char *obj_dir,
58
59
int verify_commit_graph(struct repository *r, struct commit_graph *g);
60
61
+void free_commit_graph(struct commit_graph *);
62
+
63
#endif