All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Tan <jonathantanmy@google.com>
To: git@vger.kernel.org
Cc: Jonathan Tan <jonathantanmy@google.com>
Subject: [PATCH v2 4/6] commit-graph: add free_commit_graph
Date: Mon,  9 Jul 2018 13:44:38 -0700	[thread overview]
Message-ID: <06fd347b21dbc039936dd9ab2701d16b9befbd19.1531168854.git.jonathantanmy@google.com> (raw)
In-Reply-To: <cover.1531168854.git.jonathantanmy@google.com>

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 builtin/commit-graph.c |  2 ++
 commit-graph.c         | 24 ++++++++++++++----------
 commit-graph.h         |  2 ++
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index c7d0db5ab4..0bf0c48657 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -115,6 +115,8 @@ static int graph_read(int argc, const char **argv)
 		printf(" large_edges");
 	printf("\n");
 
+	free_commit_graph(graph);
+
 	return 0;
 }
 
diff --git a/commit-graph.c b/commit-graph.c
index 5ba60f63f9..6d1bc4ff7c 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -231,16 +231,8 @@ static int prepare_commit_graph(void)
 
 static void close_commit_graph(void)
 {
-	if (!commit_graph)
-		return;
-
-	if (commit_graph->graph_fd >= 0) {
-		munmap((void *)commit_graph->data, commit_graph->data_len);
-		commit_graph->data = NULL;
-		close(commit_graph->graph_fd);
-	}
-
-	FREE_AND_NULL(commit_graph);
+	free_commit_graph(commit_graph);
+	commit_graph = NULL;
 }
 
 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)
 
 	return verify_commit_graph_error;
 }
+
+void free_commit_graph(struct commit_graph *g)
+{
+	if (!g)
+		return;
+	if (g->graph_fd >= 0) {
+		munmap((void *)g->data, g->data_len);
+		g->data = NULL;
+		close(g->graph_fd);
+	}
+	free(g);
+}
diff --git a/commit-graph.h b/commit-graph.h
index 674052bef4..94defb04a9 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -58,4 +58,6 @@ void write_commit_graph(const char *obj_dir,
 
 int verify_commit_graph(struct repository *r, struct commit_graph *g);
 
+void free_commit_graph(struct commit_graph *);
+
 #endif
-- 
2.18.0.203.gfac676dfb9-goog


  parent reply	other threads:[~2018-07-09 20:45 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-21 21:29 [PATCH 0/5] Object store refactoring: commit graph Jonathan Tan
2018-06-21 21:29 ` [PATCH 1/5] object-store: add missing include Jonathan Tan
2018-06-21 21:29 ` [PATCH 2/5] commit-graph: add missing forward declaration Jonathan Tan
2018-06-21 21:43   ` Stefan Beller
2018-06-21 22:39     ` Jonathan Tan
2018-06-22  0:17       ` Derrick Stolee
2018-06-21 21:29 ` [PATCH 3/5] commit-graph: add free_commit_graph Jonathan Tan
2018-06-21 21:29 ` [PATCH 4/5] commit-graph: store graph in struct object_store Jonathan Tan
2018-06-25 20:57   ` Junio C Hamano
2018-06-25 22:09     ` Jonathan Tan
2018-06-26 16:40       ` Junio C Hamano
2018-06-21 21:29 ` [PATCH 5/5] commit-graph: add repo arg to graph readers Jonathan Tan
2018-06-21 22:41   ` Stefan Beller
2018-06-21 23:06     ` Jonathan Tan
2018-06-22  0:33       ` Derrick Stolee
2018-06-22  1:01         ` Derrick Stolee
2018-06-22 17:21         ` Jonathan Tan
2018-07-09 20:44 ` [PATCH v2 on ds/commit-graph-fsck 0/6] Object store refactoring: commit graph Jonathan Tan
2018-07-09 20:44   ` [PATCH v2 1/6] commit-graph: refactor preparing " Jonathan Tan
2018-07-09 21:41     ` Stefan Beller
2018-07-10  0:23       ` Derrick Stolee
2018-07-09 20:44   ` [PATCH v2 2/6] object-store: add missing include Jonathan Tan
2018-07-09 20:44   ` [PATCH v2 3/6] commit-graph: add missing forward declaration Jonathan Tan
2018-07-09 20:44   ` Jonathan Tan [this message]
2018-07-09 20:44   ` [PATCH v2 5/6] commit-graph: store graph in struct object_store Jonathan Tan
2018-07-09 20:44   ` [PATCH v2 6/6] commit-graph: add repo arg to graph readers Jonathan Tan
2018-07-10  0:48     ` Derrick Stolee
2018-07-10 17:31       ` Jonathan Tan
2018-07-11 19:41         ` Derrick Stolee
2018-07-11 21:08           ` Jonathan Tan
2018-07-10 11:53     ` SZEDER Gábor
2018-07-10 13:18       ` Johannes Schindelin
2018-07-10 17:23         ` Jonathan Tan
2018-07-09 21:47   ` [PATCH v2 on ds/commit-graph-fsck 0/6] Object store refactoring: commit graph Stefan Beller
2018-07-09 22:27   ` Junio C Hamano
2018-07-10  0:30     ` Derrick Stolee
2018-07-10  0:32       ` Derrick Stolee
2018-07-11 22:42 ` [PATCH v3 " Jonathan Tan
2018-07-11 22:42   ` [PATCH v3 1/6] commit-graph: refactor preparing " Jonathan Tan
2018-07-11 22:42   ` [PATCH v3 2/6] object-store: add missing include Jonathan Tan
2018-07-11 22:42   ` [PATCH v3 3/6] commit-graph: add missing forward declaration Jonathan Tan
2018-07-11 22:42   ` [PATCH v3 4/6] commit-graph: add free_commit_graph Jonathan Tan
2018-07-11 22:42   ` [PATCH v3 5/6] commit-graph: store graph in struct object_store Jonathan Tan
2018-07-11 22:42   ` [PATCH v3 6/6] commit-graph: add repo arg to graph readers Jonathan Tan
2018-08-13  0:30     ` [PATCH] t5318: avoid unnecessary command substitutions SZEDER Gábor
2018-08-13 11:23       ` Derrick Stolee
2018-08-13 19:05       ` Junio C Hamano
2018-07-12 16:56   ` [PATCH v3 0/6] Object store refactoring: commit graph Junio C Hamano
2018-07-12 17:43   ` Derrick Stolee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=06fd347b21dbc039936dd9ab2701d16b9befbd19.1531168854.git.jonathantanmy@google.com \
    --to=jonathantanmy@google.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.