git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org
Cc: Stefan Beller <sbeller@google.com>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 21/23] commit: prepare free_commit_buffer and release_commit_memory for any repo
Date: Fri, 14 Dec 2018 16:09:40 -0800	[thread overview]
Message-ID: <20181215000942.46033-22-sbeller@google.com> (raw)
In-Reply-To: <20181215000942.46033-1-sbeller@google.com>

Pass the object pool to free_commit_buffer and release_commit_memory,
such that we can eliminate access to 'the_repository'.

Also remove the TODO in release_commit_memory, as commit->util was
removed in 9d2c97016f (commit.h: delete 'util' field in struct commit,
2018-05-19)

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/fsck.c     | 3 ++-
 builtin/log.c      | 6 ++++--
 builtin/rev-list.c | 3 ++-
 commit.c           | 9 ++++-----
 commit.h           | 4 ++--
 object.c           | 2 +-
 6 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/builtin/fsck.c b/builtin/fsck.c
index 06eb421720..c476ac6983 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -382,7 +382,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
 	if (obj->type == OBJ_TREE)
 		free_tree_buffer((struct tree *)obj);
 	if (obj->type == OBJ_COMMIT)
-		free_commit_buffer((struct commit *)obj);
+		free_commit_buffer(the_repository->parsed_objects,
+				   (struct commit *)obj);
 	return err;
 }
 
diff --git a/builtin/log.c b/builtin/log.c
index 061d4fd864..64c2649c7c 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -395,7 +395,8 @@ static int cmd_log_walk(struct rev_info *rev)
 			 * We may show a given commit multiple times when
 			 * walking the reflogs.
 			 */
-			free_commit_buffer(commit);
+			free_commit_buffer(the_repository->parsed_objects,
+					   commit);
 			free_commit_list(commit->parents);
 			commit->parents = NULL;
 		}
@@ -1922,7 +1923,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		    open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
 			die(_("Failed to create output files"));
 		shown = log_tree_commit(&rev, commit);
-		free_commit_buffer(commit);
+		free_commit_buffer(the_repository->parsed_objects,
+				   commit);
 
 		/* We put one extra blank line between formatted
 		 * patches and this flag is used by log-tree code
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index cc1b70522f..2b301fa315 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -196,7 +196,8 @@ static void finish_commit(struct commit *commit, void *data)
 		free_commit_list(commit->parents);
 		commit->parents = NULL;
 	}
-	free_commit_buffer(commit);
+	free_commit_buffer(the_repository->parsed_objects,
+			   commit);
 }
 
 static inline void finish_object__ma(struct object *obj)
diff --git a/commit.c b/commit.c
index 7d2f3a9a93..4fe74aa4bc 100644
--- a/commit.c
+++ b/commit.c
@@ -328,10 +328,10 @@ void repo_unuse_commit_buffer(struct repository *r,
 		free((void *)buffer);
 }
 
-void free_commit_buffer(struct commit *commit)
+void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
 {
 	struct commit_buffer *v = buffer_slab_peek(
-		the_repository->parsed_objects->buffer_slab, commit);
+		pool->buffer_slab, commit);
 	if (v) {
 		FREE_AND_NULL(v->buffer);
 		v->size = 0;
@@ -354,13 +354,12 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
 	return &get_commit_tree(commit)->object.oid;
 }
 
-void release_commit_memory(struct commit *c)
+void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
 {
 	c->maybe_tree = NULL;
 	c->index = 0;
-	free_commit_buffer(c);
+	free_commit_buffer(pool, c);
 	free_commit_list(c->parents);
-	/* TODO: what about commit->util? */
 
 	c->object.parsed = 0;
 }
diff --git a/commit.h b/commit.h
index 2e6b799b26..d2779a23f6 100644
--- a/commit.h
+++ b/commit.h
@@ -140,7 +140,7 @@ void repo_unuse_commit_buffer(struct repository *r,
 /*
  * Free any cached object buffer associated with the commit.
  */
-void free_commit_buffer(struct commit *);
+void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
 
 struct tree *get_commit_tree(const struct commit *);
 struct object_id *get_commit_tree_oid(const struct commit *);
@@ -149,7 +149,7 @@ struct object_id *get_commit_tree_oid(const struct commit *);
  * Release memory related to a commit, including the parent list and
  * any cached object buffer.
  */
-void release_commit_memory(struct commit *c);
+void release_commit_memory(struct parsed_object_pool *pool, struct commit *c);
 
 /*
  * Disassociate any cached object buffer from the commit, but do not free it.
diff --git a/object.c b/object.c
index 003f870484..c4170d2d0c 100644
--- a/object.c
+++ b/object.c
@@ -540,7 +540,7 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
 		if (obj->type == OBJ_TREE)
 			free_tree_buffer((struct tree*)obj);
 		else if (obj->type == OBJ_COMMIT)
-			release_commit_memory((struct commit*)obj);
+			release_commit_memory(o, (struct commit*)obj);
 		else if (obj->type == OBJ_TAG)
 			release_tag_memory((struct tag*)obj);
 	}
-- 
2.20.0.405.gbc1bbc6f85-goog


  parent reply	other threads:[~2018-12-15  0:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-15  0:09 [PATCH 00/23] sb/more-repo-in-api Stefan Beller
2018-12-15  0:09 ` [PATCH 01/23] sha1_file: allow read_object to read objects in arbitrary repositories Stefan Beller
2018-12-15  0:09 ` [PATCH 02/23] packfile: allow has_packed_and_bad to handle " Stefan Beller
2018-12-15  0:09 ` [PATCH 03/23] object-store: allow read_object_file_extended to read from any repo Stefan Beller
2018-12-15  0:09 ` [PATCH 04/23] object-store: prepare read_object_file to deal with " Stefan Beller
2018-12-15  0:09 ` [PATCH 05/23] object-store: prepare has_{sha1, object}_file to handle " Stefan Beller
2018-12-15  0:09 ` [PATCH 06/23] object: parse_object to honor its repository argument Stefan Beller
2018-12-15  0:09 ` [PATCH 07/23] commit: allow parse_commit* to handle any repo Stefan Beller
2018-12-15  0:09 ` [PATCH 08/23] commit-reach.c: allow paint_down_to_common " Stefan Beller
2018-12-15  0:09 ` [PATCH 09/23] commit-reach.c: allow merge_bases_many " Stefan Beller
2018-12-15  0:09 ` [PATCH 10/23] commit-reach.c: allow remove_redundant " Stefan Beller
2018-12-15  0:09 ` [PATCH 11/23] commit-reach.c: allow get_merge_bases_many_0 " Stefan Beller
2018-12-15  0:09 ` [PATCH 12/23] commit-reach: prepare get_merge_bases " Stefan Beller
2018-12-15  0:09 ` [PATCH 13/23] commit-reach: prepare in_merge_bases[_many] " Stefan Beller
2018-12-15  0:09 ` [PATCH 14/23] commit: prepare get_commit_buffer " Stefan Beller
2018-12-15  0:09 ` [PATCH 15/23] commit: prepare repo_unuse_commit_buffer " Stefan Beller
2018-12-15  0:09 ` [PATCH 16/23] commit: prepare logmsg_reencode to handle arbitrary repositories Stefan Beller
2018-12-15  0:09 ` [PATCH 17/23] pretty: prepare format_commit_message " Stefan Beller
2018-12-15  0:09 ` [PATCH 18/23] submodule: use submodule repos for object lookup Stefan Beller
2018-12-15  0:09 ` [PATCH 19/23] submodule: don't add submodule as odb for push Stefan Beller
2018-12-15  0:09 ` [PATCH 20/23] commit-graph: convert remaining functions to handle any repo Stefan Beller
2018-12-15  0:09 ` Stefan Beller [this message]
2018-12-15  0:09 ` [PATCH 22/23] path.h: make REPO_GIT_PATH_FUNC repository agnostic Stefan Beller
2018-12-15  0:09 ` [PATCH 23/23] t/helper/test-repository: celebrate independence from the_repository Stefan Beller
2018-12-26 18:42 ` [PATCH 00/23] sb/more-repo-in-api Junio C Hamano
2018-12-27 14:41 ` Derrick Stolee
  -- strict thread matches above, loose matches on Subject: below --
2018-11-14  0:12 [PATCHv3 00/23] Bring more repository handles into our code base Stefan Beller
2018-11-14  0:13 ` [PATCH 21/23] commit: prepare free_commit_buffer and release_commit_memory for any repo Stefan Beller

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20181215000942.46033-22-sbeller@google.com \
    --to=sbeller@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).