aboutsummaryrefslogtreecommitdiff
path: root/builtin/blame.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-06-10 17:44:13 -0400
committerJunio C Hamano <gitster@pobox.com>2014-06-13 12:09:38 -0700
commit8597ea3afea067b39ba7d4adae7ec6c1ee0e7c91 (patch)
tree01419168b4f08949baeabe5b8650066e6a92732c /builtin/blame.c
parentc1b3c71f4b4571abb2b2a457122fd100dc9f7eb0 (diff)
downloadgit-8597ea3afea067b39ba7d4adae7ec6c1ee0e7c91.tar.gz
git-8597ea3afea067b39ba7d4adae7ec6c1ee0e7c91.tar.xz
commit: record buffer length in cache
Most callsites which use the commit buffer try to use the cached version attached to the commit, rather than re-reading from disk. Unfortunately, that interface provides only a pointer to the NUL-terminated buffer, with no indication of the original length. For the most part, this doesn't matter. People do not put NULs in their commit messages, and the log code is happy to treat it all as a NUL-terminated string. However, some code paths do care. For example, when checking signatures, we want to be very careful that we verify all the bytes to avoid malicious trickery. This patch just adds an optional "size" out-pointer to get_commit_buffer and friends. The existing callers all pass NULL (there did not seem to be any obvious sites where we could avoid an immediate strlen() call, though perhaps with some further refactoring we could). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/blame.c')
-rw-r--r--builtin/blame.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/builtin/blame.c b/builtin/blame.c
index 857d98a32..b84e375b5 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1999,6 +1999,18 @@ static void append_merge_parents(struct commit_list **tail)
}
/*
+ * This isn't as simple as passing sb->buf and sb->len, because we
+ * want to transfer ownership of the buffer to the commit (so we
+ * must use detach).
+ */
+static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
+{
+ size_t len;
+ void *buf = strbuf_detach(sb, &len);
+ set_commit_buffer(c, buf, len);
+}
+
+/*
* Prepare a dummy commit that represents the work tree (or staged) item.
* Note that annotating work tree item never works in the reverse.
*/
@@ -2046,7 +2058,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
ident, ident, path,
(!contents_from ? path :
(!strcmp(contents_from, "-") ? "standard input" : contents_from)));
- set_commit_buffer(commit, strbuf_detach(&msg, NULL));
+ set_commit_buffer_from_strbuf(commit, &msg);
if (!contents_from || strcmp("-", contents_from)) {
struct stat st;