git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Brandon Casey <drafnel@gmail.com>
To: pclouds@gmail.com
Cc: git@vger.kernel.org, Brandon Casey <drafnel@gmail.com>,
	Brandon Casey <bcasey@nvidia.com>
Subject: [PATCH 6/5] sequencer.c: refrain from adding duplicate s-o-b lines
Date: Thu, 15 Nov 2012 15:24:35 -0800	[thread overview]
Message-ID: <1353021875-7552-1-git-send-email-drafnel@gmail.com> (raw)
In-Reply-To: <1352943474-15573-5-git-send-email-drafnel@gmail.com>

Detect whether the s-o-b already exists in the commit footer and refrain
from adding a duplicate.

Update t3511 to test new behavior.

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
---


Hi Duy,

How about this patch on top of my series as a base for your patch to
unify the code paths that append signoff in format-patch, commit, and
sequencer?

-Brandon


 sequencer.c              | 28 ++++++++++++++++++----------
 t/t3511-cherry-pick-x.sh | 20 ++++++++++++++++++--
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 7ad1163..546dacb 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -42,13 +42,15 @@ static int is_cherry_pick_from_line(const char *buf, int len)
 		!prefixcmp(buf, cherry_picked_prefix);
 }
 
-static int ends_rfc2822_footer(struct strbuf *sb, int ignore_footer)
+static int ends_rfc2822_footer(struct strbuf *sb, struct strbuf *sob,
+	int ignore_footer)
 {
 	int hit = 0;
 	int i, k;
 	int len = sb->len - ignore_footer;
 	int last_was_rfc2822 = 0;
 	const char *buf = sb->buf;
+	int found_sob = 0;
 
 	for (i = len - 1; i > 0; i--) {
 		if (hit && buf[i] == '\n')
@@ -66,12 +68,15 @@ static int ends_rfc2822_footer(struct strbuf *sb, int ignore_footer)
 
 		if (last_was_rfc2822 && (buf[i] == ' ' || buf[i] == '\t'))
 			continue;
+		if ((last_was_rfc2822 = is_rfc2822_line(buf+i, k-i)) &&
+			sob && !found_sob &&
+			!strncasecmp(buf+i, sob->buf, sob->len))
+			found_sob = 1;
 
-		if (!((last_was_rfc2822 = is_rfc2822_line(buf+i, k-i)) ||
-			is_cherry_pick_from_line(buf+i, k-i)))
+		if (!(last_was_rfc2822 || is_cherry_pick_from_line(buf+i, k-i)))
 			return 0;
 	}
-	return 1;
+	return 1 + found_sob;
 }
 
 static void remove_sequencer_state(void)
@@ -547,7 +552,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
 		}
 
 		if (opts->record_origin) {
-			if (!ends_rfc2822_footer(&msgbuf, 0))
+			if (!ends_rfc2822_footer(&msgbuf, NULL, 0))
 				strbuf_addch(&msgbuf, '\n');
 			strbuf_addstr(&msgbuf, cherry_picked_prefix);
 			strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
@@ -1077,6 +1082,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
 void append_signoff(struct strbuf *msgbuf, int ignore_footer)
 {
 	struct strbuf sob = STRBUF_INIT;
+	int has_footer = 0;
 	int i;
 
 	strbuf_addstr(&sob, sign_off_header);
@@ -1085,10 +1091,12 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer)
 	strbuf_addch(&sob, '\n');
 	for (i = msgbuf->len - 1 - ignore_footer; i > 0 && msgbuf->buf[i - 1] != '\n'; i--)
 		; /* do nothing */
-	if (prefixcmp(msgbuf->buf + i, sob.buf)) {
-		if (!i || !ends_rfc2822_footer(msgbuf, ignore_footer))
-			strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, "\n", 1);
-		strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, sob.buf, sob.len);
-	}
+	if (!i || !(has_footer =
+		ends_rfc2822_footer(msgbuf, &sob, ignore_footer)))
+			strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0,
+				"\n", 1);
+	if (has_footer != 2)
+		strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, sob.buf,
+			sob.len);
 	strbuf_release(&sob);
 }
diff --git a/t/t3511-cherry-pick-x.sh b/t/t3511-cherry-pick-x.sh
index af7a87c..a15b199 100755
--- a/t/t3511-cherry-pick-x.sh
+++ b/t/t3511-cherry-pick-x.sh
@@ -11,9 +11,10 @@ pristine_detach () {
 	git clean -d -f -f -q -x
 }
 
-non_rfc2822_mesg='base with footer
+non_rfc2822_mesg="base with footer
 
-Commit message body is here.'
+Commit message body is here.
+Not an s-o-b Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
 
 rfc2822_mesg="$non_rfc2822_mesg
 
@@ -25,6 +26,9 @@ rfc2822_cherry_mesg="$rfc2822_mesg
 (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
 Tested-by: C.U. Thor <cuthor@example.com>"
 
+rfc2822_cherry_sob_mesg="$rfc2822_cherry_mesg
+Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+Signed-off-by: C.U. Thor <cuthor@example.com>"
 
 test_expect_success setup '
 	git config advice.detachedhead false &&
@@ -36,6 +40,8 @@ test_expect_success setup '
 	test_commit "$rfc2822_mesg" foo b rfc2822-base &&
 	git reset --hard initial &&
 	test_commit "$rfc2822_cherry_mesg" foo b rfc2822-cherry-base &&
+	git reset --hard initial &&
+	test_commit "$rfc2822_cherry_sob_mesg" foo b rfc2822-cherry-sob-base &&
 	pristine_detach initial &&
 	test_commit conflicting unrelated
 '
@@ -151,4 +157,14 @@ test_expect_success 'cherry-pick treats -x -s "(cherry picked from..." line as p
 	test_cmp expect actual
 '
 
+test_expect_success 'cherry-pick -s detects committer s-o-b already exists' '
+	pristine_detach initial &&
+	git cherry-pick -s rfc2822-cherry-sob-base &&
+	cat <<-EOF >expect &&
+		$rfc2822_cherry_sob_mesg
+	EOF
+	git log -1 --pretty=format:%B >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
1.8.0

  reply	other threads:[~2012-11-15 23:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-15  1:37 [PATCH 1/5] t/test-lib-functions.sh: allow to specify the tag name to test_commit Brandon Casey
2012-11-15  1:37 ` [PATCH 2/5] t/t3511: demonstrate breakage in cherry-pick -s Brandon Casey
2012-11-16  1:58   ` Junio C Hamano
2012-11-16  2:40     ` Brandon Casey
2012-11-15  1:37 ` [PATCH 3/5] sequencer.c: handle rfc2822 continuation lines correctly Brandon Casey
2012-11-15  1:37 ` [PATCH 4/5] sequencer.c: recognize "(cherry picked from ..." as part of s-o-b footer Brandon Casey
2012-11-15 17:55   ` [PATCH v2 " Brandon Casey
2012-11-15  1:37 ` [PATCH/RFC 5/5] sequencer.c: always separate "(cherry picked from" from commit body Brandon Casey
2012-11-15 23:24   ` Brandon Casey [this message]
2012-11-16  2:03     ` [PATCH 6/5] sequencer.c: refrain from adding duplicate s-o-b lines Junio C Hamano
2012-11-16 23:55       ` Brandon Casey
2012-11-15  3:20 ` [PATCH 1/5] t/test-lib-functions.sh: allow to specify the tag name to test_commit Matt Kraai
2012-11-15  5:43   ` Brandon Casey
2012-11-15  5:49   ` [PATCH 1/5 v2] " Brandon Casey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1353021875-7552-1-git-send-email-drafnel@gmail.com \
    --to=drafnel@gmail.com \
    --cc=bcasey@nvidia.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).