summaryrefslogtreecommitdiff
path: root/commit.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-08-27 07:56:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-08-27 17:25:28 (GMT)
commitfe6eb7f2c506190c817407accf27834005a57f2b (patch)
treefde1f530c243bfa9b71762fe29862528320f7ec4 /commit.h
parent6c4ab27f2378ce67940b4496365043119d7ffff2 (diff)
downloadgit-fe6eb7f2c506190c817407accf27834005a57f2b.zip
git-fe6eb7f2c506190c817407accf27834005a57f2b.tar.gz
git-fe6eb7f2c506190c817407accf27834005a57f2b.tar.bz2
commit: provide a function to find a header in a buffer
Usually when we parse a commit, we read it line by line and handle each individual line (e.g., parse_commit and parse_commit_header). Sometimes, however, we only care about extracting a single header. Code in this situation is stuck doing an ad-hoc parse of the commit buffer. Let's provide a reusable function to locate a header within the commit. The code is modeled after pretty.c's get_header, which is used to extract the encoding. Since some callers may not have the "struct commit" to go along with the buffer, we drop that parameter. The only thing lost is a warning for truncated commits, but that's OK. This shouldn't happen in practice, and even if it does, there's no particular reason that this function needs to complain about it. It either finds the header it was asked for, or it doesn't (and in the latter case, the caller will typically complain). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.h')
-rw-r--r--commit.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/commit.h b/commit.h
index a8cbf52..12f4fe1 100644
--- a/commit.h
+++ b/commit.h
@@ -313,6 +313,17 @@ extern struct commit_extra_header *read_commit_extra_headers(struct commit *, co
extern void free_commit_extra_headers(struct commit_extra_header *extra);
+/*
+ * Search the commit object contents given by "msg" for the header "key".
+ * Returns a pointer to the start of the header contents, or NULL. The length
+ * of the header, up to the first newline, is returned via out_len.
+ *
+ * Note that some headers (like mergetag) may be multi-line. It is the caller's
+ * responsibility to parse further in this case!
+ */
+extern const char *find_commit_header(const char *msg, const char *key,
+ size_t *out_len);
+
typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra,
void *cb_data);