Signed-off-by: Stefan Beller <[email protected]>
---
 builtin/fast-export.c                      |  2 +-
 builtin/fmt-merge-msg.c                    |  2 +-
 builtin/log.c                              |  3 ++-
 builtin/replace.c                          |  2 +-
 commit.c                                   |  8 ++++----
 commit.h                                   |  3 ++-
 contrib/coccinelle/submodule_reading.cocci |  7 +++++++
 fsck.c                                     |  3 ++-
 merge-recursive.c                          |  3 ++-
 notes-merge.c                              |  3 ++-
 pretty.c                                   |  2 +-
 sequencer.c                                | 13 ++++++++-----
 sha1_name.c                                |  2 +-
 13 files changed, 34 insertions(+), 19 deletions(-)
 create mode 100644 contrib/coccinelle/submodule_reading.cocci

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 80853bb91a..bc04e3f0a7 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -561,7 +561,7 @@ static void handle_commit(struct commit *commit, struct 
rev_info *rev,
        rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
 
        parse_commit_or_die(commit);
-       commit_buffer = get_commit_buffer(commit, NULL);
+       commit_buffer = get_commit_buffer(the_repository, commit, NULL);
        author = strstr(commit_buffer, "\nauthor ");
        if (!author)
                die ("Could not find author in commit %s",
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index c54f045ccd..6dedb92d61 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -261,7 +261,7 @@ static void record_person_from_buf(int which, struct 
string_list *people,
 static void record_person(int which, struct string_list *people,
                          struct commit *commit)
 {
-       const char *buffer = get_commit_buffer(commit, NULL);
+       const char *buffer = get_commit_buffer(the_repository, commit, NULL);
        record_person_from_buf(which, people, buffer);
        unuse_commit_buffer(the_repository, commit, buffer);
 }
diff --git a/builtin/log.c b/builtin/log.c
index 3ccab366e7..bb9d909f59 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1022,7 +1022,8 @@ static void make_cover_letter(struct rev_info *rev, int 
use_stdout,
        log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte);
 
        for (i = 0; !need_8bit_cte && i < nr; i++) {
-               const char *buf = get_commit_buffer(list[i], NULL);
+               const char *buf = get_commit_buffer(the_repository, list[i],
+                                                   NULL);
                if (has_non_ascii(buf))
                        need_8bit_cte = 1;
                unuse_commit_buffer(the_repository, list[i], buf);
diff --git a/builtin/replace.c b/builtin/replace.c
index 1a92c0082a..46bb7cdfe8 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -401,7 +401,7 @@ static int create_graft(int argc, const char **argv, int 
force)
                die(_("Not a valid object name: '%s'"), old_ref);
        commit = lookup_commit_or_die(&old, old_ref);
 
-       buffer = get_commit_buffer(commit, &size);
+       buffer = get_commit_buffer(the_repository, commit, &size);
        strbuf_add(&buf, buffer, size);
        unuse_commit_buffer(the_repository, commit, buffer);
 
diff --git a/commit.c b/commit.c
index ac65c1dbd7..b241cc7979 100644
--- a/commit.c
+++ b/commit.c
@@ -277,7 +277,7 @@ const void *get_cached_commit_buffer(struct repository *r, 
const struct commit *
        return v->buffer;
 }
 
-const void *get_commit_buffer(const struct commit *commit, unsigned long 
*sizep)
+const void *get_commit_buffer_the_repository(const struct commit *commit, 
unsigned long *sizep)
 {
        const void *ret = get_cached_commit_buffer(the_repository, commit, 
sizep);
        if (!ret) {
@@ -617,7 +617,7 @@ define_commit_slab(author_date_slab, unsigned long);
 static void record_author_date(struct author_date_slab *author_date,
                               struct commit *commit)
 {
-       const char *buffer = get_commit_buffer(commit, NULL);
+       const char *buffer = get_commit_buffer(the_repository, commit, NULL);
        struct ident_split ident;
        const char *ident_line;
        size_t ident_len;
@@ -1163,7 +1163,7 @@ int parse_signed_commit(const struct commit *commit,
 {
 
        unsigned long size;
-       const char *buffer = get_commit_buffer(commit, &size);
+       const char *buffer = get_commit_buffer(the_repository, commit, &size);
        int in_signature, saw_signature = -1;
        const char *line, *tail;
 
@@ -1320,7 +1320,7 @@ struct commit_extra_header 
*read_commit_extra_headers(struct commit *commit,
 {
        struct commit_extra_header *extra = NULL;
        unsigned long size;
-       const char *buffer = get_commit_buffer(commit, &size);
+       const char *buffer = get_commit_buffer(the_repository, commit, &size);
        extra = read_commit_extra_header_lines(buffer, size, exclude);
        unuse_commit_buffer(the_repository, commit, buffer);
        return extra;
diff --git a/commit.h b/commit.h
index d2d5e66b53..b9eb079e21 100644
--- a/commit.h
+++ b/commit.h
@@ -88,7 +88,8 @@ const void *get_cached_commit_buffer(struct repository *r, 
const struct commit *
  * from disk. The resulting memory should not be modified, and must be given
  * to unuse_commit_buffer when the caller is done.
  */
-const void *get_commit_buffer(const struct commit *, unsigned long *size);
+#define get_commit_buffer(r, c, s) get_commit_buffer_##r(c, s)
+const void *get_commit_buffer_the_repository(const struct commit *, unsigned 
long *size);
 
 /*
  * Tell the commit subsytem that we are done with a particular commit buffer.
diff --git a/contrib/coccinelle/submodule_reading.cocci 
b/contrib/coccinelle/submodule_reading.cocci
new file mode 100644
index 0000000000..17c2e02512
--- /dev/null
+++ b/contrib/coccinelle/submodule_reading.cocci
@@ -0,0 +1,7 @@
+@@
+expression E;
+expression F;
+@@
+ get_commit_buffer(
++the_repository,
+ E, F)
diff --git a/fsck.c b/fsck.c
index 3155b77348..7788b60bf4 100644
--- a/fsck.c
+++ b/fsck.c
@@ -791,7 +791,8 @@ static int fsck_commit_buffer(struct commit *commit, const 
char *buffer,
 static int fsck_commit(struct commit *commit, const char *data,
        unsigned long size, struct fsck_options *options)
 {
-       const char *buffer = data ?  data : get_commit_buffer(commit, &size);
+       const char *buffer = data ?  data : get_commit_buffer(the_repository,
+                                                             commit, &size);
        int ret = fsck_commit_buffer(commit, buffer, size, options);
        if (!data)
                unuse_commit_buffer(the_repository, commit, buffer);
diff --git a/merge-recursive.c b/merge-recursive.c
index 6e06634993..30ddfcb94e 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -237,7 +237,8 @@ static void output_commit_title(struct merge_options *o, 
struct commit *commit)
                        strbuf_addstr(&o->obuf, _("(bad commit)\n"));
                else {
                        const char *title;
-                       const char *msg = get_commit_buffer(commit, NULL);
+                       const char *msg = get_commit_buffer(the_repository,
+                                                           commit, NULL);
                        int len = find_commit_subject(msg, &title);
                        if (len)
                                strbuf_addf(&o->obuf, "%.*s\n", len, title);
diff --git a/notes-merge.c b/notes-merge.c
index 58b518ae0a..1cb1c4f8f4 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -672,7 +672,8 @@ int notes_merge_commit(struct notes_merge_options *o,
        DIR *dir;
        struct dirent *e;
        struct strbuf path = STRBUF_INIT;
-       const char *buffer = get_commit_buffer(partial_commit, NULL);
+       const char *buffer = get_commit_buffer(the_repository, partial_commit,
+                                              NULL);
        const char *msg = strstr(buffer, "\n\n");
        int baselen;
 
diff --git a/pretty.c b/pretty.c
index 9a7f19f8c7..c5a2f0b018 100644
--- a/pretty.c
+++ b/pretty.c
@@ -602,7 +602,7 @@ const char *logmsg_reencode(const struct commit *commit,
        static const char *utf8 = "UTF-8";
        const char *use_encoding;
        char *encoding;
-       const char *msg = get_commit_buffer(commit, NULL);
+       const char *msg = get_commit_buffer(the_repository, commit, NULL);
        char *out;
 
        if (!output_encoding || !*output_encoding) {
diff --git a/sequencer.c b/sequencer.c
index 521da238b5..40ba4b6047 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -859,7 +859,7 @@ static int update_squash_messages(enum todo_command command,
                        return error(_("need a HEAD to fixup"));
                if (!(head_commit = lookup_commit_reference(the_repository, 
&head)))
                        return error(_("could not read HEAD"));
-               if (!(head_message = get_commit_buffer(head_commit, NULL)))
+               if (!(head_message = get_commit_buffer(the_repository, 
head_commit, NULL)))
                        return error(_("could not read HEAD's commit message"));
 
                find_commit_subject(head_message, &body);
@@ -883,7 +883,7 @@ static int update_squash_messages(enum todo_command command,
                unuse_commit_buffer(the_repository, head_commit, head_message);
        }
 
-       if (!(message = get_commit_buffer(commit, NULL)))
+       if (!(message = get_commit_buffer(the_repository, commit, NULL)))
                return error(_("could not read commit message of %s"),
                             oid_to_hex(&commit->object.oid));
        find_commit_subject(message, &body);
@@ -1549,7 +1549,8 @@ static int walk_revs_populate_todo(struct todo_list 
*todo_list,
 
        while ((commit = get_revision(opts->revs))) {
                struct todo_item *item = append_new_todo(todo_list);
-               const char *commit_buffer = get_commit_buffer(commit, NULL);
+               const char *commit_buffer = get_commit_buffer(the_repository,
+                                                             commit, NULL);
                const char *subject;
                int subject_len;
 
@@ -1816,7 +1817,8 @@ static int make_patch(struct commit *commit, struct 
replay_opts *opts)
 
        strbuf_addf(&buf, "%s/message", get_dir(opts));
        if (!file_exists(buf.buf)) {
-               const char *commit_buffer = get_commit_buffer(commit, NULL);
+               const char *commit_buffer = get_commit_buffer(the_repository,
+                                                             commit, NULL);
                find_commit_subject(commit_buffer, &subject);
                res |= write_message(subject, strlen(subject), buf.buf, 1);
                unuse_commit_buffer(the_repository, commit, commit_buffer);
@@ -2906,7 +2908,8 @@ int rearrange_squash(void)
                item->commit->util = item;
 
                parse_commit(the_repository, item->commit);
-               commit_buffer = get_commit_buffer(item->commit, NULL);
+               commit_buffer = get_commit_buffer(the_repository,
+                                                 item->commit, NULL);
                find_commit_subject(commit_buffer, &subject);
                format_subject(&buf, subject, " ");
                subject = subjects[i] = strbuf_detach(&buf, &subject_len);
diff --git a/sha1_name.c b/sha1_name.c
index 7675ec634f..ee889daead 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1150,7 +1150,7 @@ static int get_oid_oneline(const char *prefix, struct 
object_id *oid,
                commit = pop_most_recent_commit(&list, ONELINE_SEEN);
                if (!parse_object(the_repository, &commit->object.oid))
                        continue;
-               buf = get_commit_buffer(commit, NULL);
+               buf = get_commit_buffer(the_repository, commit, NULL);
                p = strstr(buf, "\n\n");
                matches = negative ^ (p && !regexec(&regex, p + 2, 0, NULL, 0));
                unuse_commit_buffer(the_repository, commit, buf);
-- 
2.15.1.433.g936d1b9894.dirty

Reply via email to