diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-06-06 11:36:10 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-06-06 11:36:10 -0700 |
commit | 1e2600dd6a2acf8d2e9c0923184ca2335b861138 (patch) | |
tree | 3cf920ef1d92e62eae2b5f7cac17f2045c63fd6c /builtin | |
parent | 075652953772dbabd01d471a4c73200b0ab5d8a6 (diff) | |
parent | 84c9dc2c5a2d34351a06554af32501d4f99990e9 (diff) | |
download | git-1e2600dd6a2acf8d2e9c0923184ca2335b861138.tar.gz |
Merge branch 'nd/status-auto-comment-char'
* nd/status-auto-comment-char:
commit: allow core.commentChar=auto for character auto selection
config: be strict on core.commentChar
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/commit.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index d28505a857..99c2044635 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -620,6 +620,36 @@ static int author_date_is_interesting(void) return author_message || force_date; } +static void adjust_comment_line_char(const struct strbuf *sb) +{ + char candidates[] = "#;@!$%^&|:"; + char *candidate; + const char *p; + + comment_line_char = candidates[0]; + if (!memchr(sb->buf, comment_line_char, sb->len)) + return; + + p = sb->buf; + candidate = strchr(candidates, *p); + if (candidate) + *candidate = ' '; + for (p = sb->buf; *p; p++) { + if ((p[0] == '\n' || p[0] == '\r') && p[1]) { + candidate = strchr(candidates, p[1]); + if (candidate) + *candidate = ' '; + } + } + + for (p = candidates; *p == ' '; p++) + ; + if (!*p) + die(_("unable to select a comment character that is not used\n" + "in the current commit message")); + comment_line_char = *p; +} + static int prepare_to_commit(const char *index_file, const char *prefix, struct commit *current_head, struct wt_status *s, @@ -773,6 +803,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len) die_errno(_("could not write commit template")); + if (auto_comment_line_char) + adjust_comment_line_char(&sb); strbuf_release(&sb); /* This checks if committer ident is explicitly given */ |