All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brandon Casey <drafnel@gmail.com>
To: gitster@pobox.com
Cc: pclouds@gmail.com, git@vger.kernel.org,
	Brandon Casey <drafnel@gmail.com>,
	Brandon Casey <bcasey@nvidia.com>
Subject: [PATCH v2 10/10] Unify appending signoff in format-patch, commit and sequencer
Date: Mon, 21 Jan 2013 00:40:27 -0800	[thread overview]
Message-ID: <1358757627-16682-11-git-send-email-drafnel@gmail.com> (raw)
In-Reply-To: <1358757627-16682-1-git-send-email-drafnel@gmail.com>

There are two implementations of append_signoff in log-tree.c and
sequencer.c, which do more or less the same thing.  Unify on top of the
sequencer.c implementation.

Add a test in t4014 to demonstrate support for non-s-o-b elements in the
commit footer provided by sequence.c:append_sob.  Mark tests fixed as
appropriate.

[Commit message mostly stolen from Nguyễn Thái Ngọc Duy's original
 unification patch]

Signed-off-by: Brandon Casey <bcasey@nvidia.com>
---
 log-tree.c              | 88 +------------------------------------------------
 t/t4014-format-patch.sh | 31 ++++++++++++++---
 2 files changed, 27 insertions(+), 92 deletions(-)

diff --git a/log-tree.c b/log-tree.c
index 83f33f4..299dad3 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -9,6 +9,7 @@
 #include "string-list.h"
 #include "color.h"
 #include "gpg-interface.h"
+#include "sequencer.h"
 
 struct decoration name_decoration = { "object names" };
 
@@ -206,93 +207,6 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
 	putchar(')');
 }
 
-/*
- * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
- * Signed-off-by: and Acked-by: lines.
- */
-static int detect_any_signoff(char *letter, int size)
-{
-	char *cp;
-	int seen_colon = 0;
-	int seen_at = 0;
-	int seen_name = 0;
-	int seen_head = 0;
-
-	cp = letter + size;
-	while (letter <= --cp && *cp == '\n')
-		continue;
-
-	while (letter <= cp) {
-		char ch = *cp--;
-		if (ch == '\n')
-			break;
-
-		if (!seen_at) {
-			if (ch == '@')
-				seen_at = 1;
-			continue;
-		}
-		if (!seen_colon) {
-			if (ch == '@')
-				return 0;
-			else if (ch == ':')
-				seen_colon = 1;
-			else
-				seen_name = 1;
-			continue;
-		}
-		if (('A' <= ch && ch <= 'Z') ||
-		    ('a' <= ch && ch <= 'z') ||
-		    ch == '-') {
-			seen_head = 1;
-			continue;
-		}
-		/* no empty last line doesn't match */
-		return 0;
-	}
-	return seen_head && seen_name;
-}
-
-static void append_signoff(struct strbuf *sb, int ignore_footer, int no_dup_sob)
-{
-	static const char signed_off_by[] = "Signed-off-by: ";
-	char *signoff = xstrdup(fmt_name(getenv("GIT_COMMITTER_NAME"),
-					       getenv("GIT_COMMITTER_EMAIL")));
-	size_t signoff_len = strlen(signoff);
-	int has_signoff = 0;
-	char *cp;
-
-	cp = sb->buf;
-
-	/* First see if we already have the sign-off by the signer */
-	while ((cp = strstr(cp, signed_off_by))) {
-
-		has_signoff = 1;
-
-		cp += strlen(signed_off_by);
-		if (cp + signoff_len >= sb->buf + sb->len)
-			break;
-		if (strncmp(cp, signoff, signoff_len))
-			continue;
-		if (!isspace(cp[signoff_len]))
-			continue;
-		/* we already have him */
-		free(signoff);
-		return;
-	}
-
-	if (!has_signoff)
-		has_signoff = detect_any_signoff(sb->buf, sb->len);
-
-	if (!has_signoff)
-		strbuf_addch(sb, '\n');
-
-	strbuf_addstr(sb, signed_off_by);
-	strbuf_add(sb, signoff, signoff_len);
-	strbuf_addch(sb, '\n');
-	free(signoff);
-}
-
 static unsigned int digits_in_number(unsigned int number)
 {
 	unsigned int i = 10, result = 1;
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 3868cef..d0ec097 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1104,7 +1104,28 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'signoff: some random signoff-alike' '
+test_expect_success 'signoff: misc conforming footer elements' '
+	append_signoff <<\EOF >actual &&
+subject
+
+body
+
+Signed-off-by: my@house
+(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
+Tested-by: Some One <someone@example.com>
+Bug: 1234
+EOF
+	cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: my@house
+15:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+	test_cmp expected actual
+'
+
+test_expect_success 'signoff: some random signoff-alike' '
 	append_signoff <<\EOF >actual &&
 subject
 
@@ -1120,7 +1141,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'signoff: not really a signoff' '
+test_expect_success 'signoff: not really a signoff' '
 	append_signoff <<\EOF >actual &&
 subject
 
@@ -1136,7 +1157,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'signoff: not really a signoff (2)' '
+test_expect_success 'signoff: not really a signoff (2)' '
 	append_signoff <<\EOF >actual &&
 subject
 
@@ -1153,7 +1174,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'signoff: valid S-o-b paragraph in the middle' '
+test_expect_success 'signoff: valid S-o-b paragraph in the middle' '
 	append_signoff <<\EOF >actual &&
 subject
 
@@ -1221,7 +1242,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'signoff: detect garbage in non-conforming footer' '
+test_expect_success 'signoff: detect garbage in non-conforming footer' '
 	append_signoff <<\EOF >actual &&
 subject
 
-- 
1.8.1.1.252.gdb33759

      parent reply	other threads:[~2013-01-21  8:41 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-21  8:40 [PATCH v2 00/10] unify appending of sob Brandon Casey
2013-01-21  8:40 ` [PATCH v2 01/10] sequencer.c: remove broken support for rfc2822 continuation in footer Brandon Casey
2013-01-22  7:54   ` Jonathan Nieder
2013-01-22  9:35     ` Brandon Casey
2013-01-22  9:47       ` Jonathan Nieder
2013-01-22  9:49         ` Jonathan Nieder
2013-01-22 11:08           ` Brandon Casey
2013-01-22 10:12       ` Jonathan Nieder
2013-01-22 10:21         ` Jonathan Nieder
2013-01-21  8:40 ` [PATCH v2 02/10] t/test-lib-functions.sh: allow to specify the tag name to test_commit Brandon Casey
2013-01-22  8:02   ` Jonathan Nieder
2013-01-22  9:43     ` Brandon Casey
2013-01-21  8:40 ` [PATCH v2 03/10] t/t3511: add some tests of 'cherry-pick -s' functionality Brandon Casey
2013-01-22  8:17   ` Jonathan Nieder
2013-01-27 23:33     ` Brandon Casey
2013-01-27 23:40       ` Jonathan Nieder
2013-01-21  8:40 ` [PATCH v2 04/10] sequencer.c: recognize "(cherry picked from ..." as part of s-o-b footer Brandon Casey
2013-01-22  8:27   ` Jonathan Nieder
2013-01-28  1:24   ` Jonathan Nieder
2013-01-21  8:40 ` [PATCH v2 05/10] sequencer.c: always separate "(cherry picked from" from commit body Brandon Casey
2013-01-22  8:32   ` Jonathan Nieder
2013-01-21  8:40 ` [PATCH v2 06/10] sequencer.c: teach append_signoff how to detect duplicate s-o-b Brandon Casey
2013-01-22  8:38   ` Jonathan Nieder
2013-01-28  0:36     ` Brandon Casey
2013-01-28  2:06       ` Junio C Hamano
2013-02-09 23:06         ` Junio C Hamano
2013-02-09 23:49           ` Brandon Casey
2013-01-21  8:40 ` [PATCH v2 07/10] sequencer.c: teach append_signoff to avoid adding a duplicate newline Brandon Casey
2013-01-21  8:40 ` [PATCH v2 08/10] t4014: more tests about appending s-o-b lines Brandon Casey
2013-01-21  8:40 ` [PATCH v2 09/10] format-patch: update append_signoff prototype Brandon Casey
2013-01-21  8:40 ` Brandon Casey [this message]

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

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

  git send-email \
    --in-reply-to=1358757627-16682-11-git-send-email-drafnel@gmail.com \
    --to=drafnel@gmail.com \
    --cc=bcasey@nvidia.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.