summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2007-03-28 17:52:09 -0400
committerJunio C Hamano <junkio@cox.net>2007-03-28 15:06:18 -0700
commitd0e50cb4cb8e0cc8b445a9749547019efaa5703e (patch)
tree142558d300e99c0123792f53f08ac88d514489cf /commit.c
parent75c962c99a9115d489549ad9b8419d3e37e85f02 (diff)
downloadgit-d0e50cb4cb8e0cc8b445a9749547019efaa5703e.tar.gz
commit: fix pretty-printing of messages with "\nencoding "
The function replace_encoding_header is given the whole commit buffer, including the commit message. When looking for the encoding header, if none was found in the header, it would locate any line in the commit message matching "\nencoding " and remove it. Instead, we now make sure to search only to the end of the header. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/commit.c b/commit.c
index 3e8c87294b..1fe23b6e3a 100644
--- a/commit.c
+++ b/commit.c
@@ -644,6 +644,7 @@ static char *get_header(const struct commit *commit, const char *key)
static char *replace_encoding_header(char *buf, char *encoding)
{
char *encoding_header = strstr(buf, "\nencoding ");
+ char *header_end = strstr(buf, "\n\n");
char *end_of_encoding_header;
int encoding_header_pos;
int encoding_header_len;
@@ -651,8 +652,10 @@ static char *replace_encoding_header(char *buf, char *encoding)
int need_len;
int buflen = strlen(buf) + 1;
- if (!encoding_header)
- return buf; /* should not happen but be defensive */
+ if (!header_end)
+ header_end = buf + buflen;
+ if (!encoding_header || encoding_header >= header_end)
+ return buf;
encoding_header++;
end_of_encoding_header = strchr(encoding_header, '\n');
if (!end_of_encoding_header)