summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2013-10-27 01:34:02 +0000
committerJunio C Hamano <gitster@pobox.com>2013-10-30 11:32:10 -0700
commit517fcac36fdc59cd9fa1e67212cd9b49d5fda475 (patch)
tree4cc4e48b586c489ab3910a4e4e2bd4ae7a565a38 /sequencer.c
parent0d6cf2471f426dd2b742e2285aad78381738be96 (diff)
downloadgit-jt/commit-fixes-footer.tar.gz
commit: Add -f, --fixes <commit> option to add Fixes: linejt/commit-fixes-footer
Linux Kernel Summit 2013 decided on a commit message convention to identify commits containing bugs fixed by a commit: a "Fixes:" line, included in the standard commit footer (along with "Signed-off-by:" if present), containing an abbreviated commit hash (at least 12 characters to keep it valid for a long time) and the subject of the commit (for human readers). This helps people (or automated tools) determine how far to backport a commit. Add a command line option for git commit to automatically construct the "Fixes:" line for a commit. This avoids the need to manually construct that line by copy-pasting the commit hash and subject. Also works with --amend to modify an existing commit's message. To add a Fixes line to an earlier commit in a series, use rebase -i and add the following line after the existing commit: x git commit --amend --no-edit --fixes $commit_containing_bug Generalize append_signoff to support appending arbitrary extra lines to a commit in the signoff block; this avoids duplicating the logic to find or construct that block. Signed-off-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/sequencer.c b/sequencer.c
index 06e52b4c83..f4cf0e1240 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1135,26 +1135,33 @@ int sequencer_pick_revisions(struct replay_opts *opts)
return pick_commits(todo_list, opts);
}
-void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
+void append_signoff_extra(struct strbuf *msgbuf, int ignore_footer,
+ unsigned flag, struct strbuf *extrabuf)
{
unsigned no_dup_sob = flag & APPEND_SIGNOFF_DEDUP;
+ unsigned append_sob = !(flag & APPEND_EXTRA_ONLY);
struct strbuf sob = STRBUF_INIT;
int has_footer;
- strbuf_addstr(&sob, sign_off_header);
- strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"),
- getenv("GIT_COMMITTER_EMAIL")));
- strbuf_addch(&sob, '\n');
+ if (append_sob) {
+ strbuf_addstr(&sob, sign_off_header);
+ strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"),
+ getenv("GIT_COMMITTER_EMAIL")));
+ strbuf_addch(&sob, '\n');
+ }
/*
* If the whole message buffer is equal to the sob, pretend that we
* found a conforming footer with a matching sob
*/
- if (msgbuf->len - ignore_footer == sob.len &&
+ if (append_sob &&
+ msgbuf->len - ignore_footer == sob.len &&
!strncmp(msgbuf->buf, sob.buf, sob.len))
has_footer = 3;
else
- has_footer = has_conforming_footer(msgbuf, &sob, ignore_footer);
+ has_footer = has_conforming_footer(msgbuf,
+ append_sob ? &sob : NULL,
+ ignore_footer);
if (!has_footer) {
const char *append_newlines = NULL;
@@ -1193,9 +1200,17 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
append_newlines, strlen(append_newlines));
}
- if (has_footer != 3 && (!no_dup_sob || has_footer != 2))
+ if (append_sob && has_footer != 3 && (!no_dup_sob || has_footer != 2))
strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0,
sob.buf, sob.len);
+ if (extrabuf)
+ strbuf_insert(msgbuf, msgbuf->len - ignore_footer,
+ extrabuf->buf, extrabuf->len);
strbuf_release(&sob);
}
+
+void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
+{
+ append_signoff_extra(msgbuf, ignore_footer, flag, NULL);
+}