diff mbox series

[14/19] commit: prepare repo_unuse_commit_buffer to handle arbitrary repositories

Message ID 20181011211754.31369-15-sbeller@google.com (mailing list archive)
State New, archived
Headers show
Series Bring more repository handles into our code base | expand

Commit Message

Stefan Beller Oct. 11, 2018, 9:17 p.m. UTC
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 commit.c                                | 6 ++++--
 commit.h                                | 7 ++++++-
 contrib/coccinelle/the_repository.cocci | 8 ++++++++
 3 files changed, 18 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/commit.c b/commit.c
index eca9a475c7..526b33758d 100644
--- a/commit.c
+++ b/commit.c
@@ -318,10 +318,12 @@  const void *repo_get_commit_buffer(struct repository *r,
 	return ret;
 }
 
-void unuse_commit_buffer(const struct commit *commit, const void *buffer)
+void repo_unuse_commit_buffer(struct repository *r,
+			      const struct commit *commit,
+			      const void *buffer)
 {
 	struct commit_buffer *v = buffer_slab_peek(
-		the_repository->parsed_objects->buffer_slab, commit);
+		r->parsed_objects->buffer_slab, commit);
 	if (!(v && v->buffer == buffer))
 		free((void *)buffer);
 }
diff --git a/commit.h b/commit.h
index fead381651..0976bf2562 100644
--- a/commit.h
+++ b/commit.h
@@ -130,7 +130,12 @@  const void *repo_get_commit_buffer(struct repository *r,
  * from an earlier call to get_commit_buffer.  The buffer may or may not be
  * freed by this call; callers should not access the memory afterwards.
  */
-void unuse_commit_buffer(const struct commit *, const void *buffer);
+void repo_unuse_commit_buffer(struct repository *r,
+			      const struct commit *,
+			      const void *buffer);
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#define unuse_commit_buffer(c, b) repo_unuse_commit_buffer(the_repository, c, b)
+#endif
 
 /*
  * Free any cached object buffer associated with the commit.
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
index ec579682f6..8c07185195 100644
--- a/contrib/coccinelle/the_repository.cocci
+++ b/contrib/coccinelle/the_repository.cocci
@@ -69,6 +69,14 @@  expression F;
 + repo_get_commit_buffer(the_repository,
   E, F);
 
+@@
+expression E;
+expression F;
+@@
+- unuse_commit_buffer(
++ repo_unuse_commit_buffer(the_repository,
+  E, F);
+
 @@
 expression E;
 expression F;