commit: prepare repo_unuse_commit_buffer to handle any repo

Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Nov 13, 2018 at 16:12 UTC 70315373ae51b45b9ca0ac43df396bb9035fe449
3 files changed +18 -3
commit.c
+4 -2
@@ -318,10 +318,12 @@ const void *repo_get_commit_buffer(struct repository *r,
318 return ret;
319 }
320
321 -void unuse_commit_buffer(const struct commit *commit, const void *buffer)
321 +void repo_unuse_commit_buffer(struct repository *r,
322 + const struct commit *commit,
323 + const void *buffer)
324 {
325 struct commit_buffer *v = buffer_slab_peek(
324 - the_repository->parsed_objects->buffer_slab, commit);
326 + r->parsed_objects->buffer_slab, commit);
327 if (!(v && v->buffer == buffer))
328 free((void *)buffer);
329 }
commit.h
+6 -1
@@ -130,7 +130,12 @@ const void *repo_get_commit_buffer(struct repository *r,
130 * from an earlier call to get_commit_buffer. The buffer may or may not be
131 * freed by this call; callers should not access the memory afterwards.
132 */
133 -void unuse_commit_buffer(const struct commit *, const void *buffer);
133 +void repo_unuse_commit_buffer(struct repository *r,
134 + const struct commit *,
135 + const void *buffer);
136 +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
137 +#define unuse_commit_buffer(c, b) repo_unuse_commit_buffer(the_repository, c, b)
138 +#endif
139
140 /*
141 * Free any cached object buffer associated with the commit.
contrib/coccinelle/the_repository.pending.cocci
+8
@@ -115,3 +115,11 @@ expression F;
115 - get_commit_buffer(
116 + repo_get_commit_buffer(the_repository,
117 E, F);
118 +
119 +@@
120 +expression E;
121 +expression F;
122 +@@
123 +- unuse_commit_buffer(
124 ++ repo_unuse_commit_buffer(the_repository,
125 + E, F);