diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-11-30 14:44:22 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-11-30 14:44:22 -0800 |
commit | 684d0d8dcfa2288744a553fc7294c5f9f5c12026 (patch) | |
tree | d790223199de25afa95aeb898d1b85d1e1dd3e1c /pretty.c | |
parent | 261fbda903762b9c47e4138312673ea25555d9e5 (diff) | |
parent | 9fa708dab1ccf8be69a606ca4eb58e62f3ef334a (diff) | |
download | git-684d0d8dcfa2288744a553fc7294c5f9f5c12026.tar.gz |
Merge branch 'jc/pretty-lf'
Conflicts:
pretty.c
t/t6006-rev-list-format.sh
Diffstat (limited to 'pretty.c')
-rw-r--r-- | pretty.c | 42 |
1 files changed, 40 insertions, 2 deletions
@@ -628,8 +628,8 @@ static void rewrap_message_tail(struct strbuf *sb, c->indent2 = new_indent2; } -static size_t format_commit_item(struct strbuf *sb, const char *placeholder, - void *context) +static size_t format_commit_one(struct strbuf *sb, const char *placeholder, + void *context) { struct format_commit_context *c = context; const struct commit *commit = c->commit; @@ -816,6 +816,44 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder, return 0; /* unknown placeholder */ } +static size_t format_commit_item(struct strbuf *sb, const char *placeholder, + void *context) +{ + int consumed; + size_t orig_len; + enum { + NO_MAGIC, + ADD_LF_BEFORE_NON_EMPTY, + DEL_LF_BEFORE_EMPTY, + } magic = NO_MAGIC; + + switch (placeholder[0]) { + case '-': + magic = DEL_LF_BEFORE_EMPTY; + break; + case '+': + magic = ADD_LF_BEFORE_NON_EMPTY; + break; + default: + break; + } + if (magic != NO_MAGIC) + placeholder++; + + orig_len = sb->len; + consumed = format_commit_one(sb, placeholder, context); + if (magic == NO_MAGIC) + return consumed; + + if ((orig_len == sb->len) && magic == DEL_LF_BEFORE_EMPTY) { + while (sb->len && sb->buf[sb->len - 1] == '\n') + strbuf_setlen(sb, sb->len - 1); + } else if ((orig_len != sb->len) && magic == ADD_LF_BEFORE_NON_EMPTY) { + strbuf_insert(sb, orig_len, "\n", 1); + } + return consumed + 1; +} + void format_commit_message(const struct commit *commit, const char *format, struct strbuf *sb, const struct pretty_print_context *pretty_ctx) |