git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Max Bernstein via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Max Bernstein <donotemailthisaddress@bernsteinbear.com>,
	Max Bernstein <max@bernsteinbear.com>
Subject: [PATCH v2] trailer: allow spaces in tokens
Date: Thu, 18 Aug 2022 07:54:03 +0000	[thread overview]
Message-ID: <pull.1309.v2.git.git.1660809243298.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1309.git.git.1660806376021.gitgitgadget@gmail.com>

From: Max Bernstein <max@bernsteinbear.com>

The docs (for example, https://git-scm.com/docs/git-interpret-trailers)
say that whitespace should be allowed inside tokens:

> There can also be whitespaces inside the token and the value.

The code since e4319562bc2834096fade432fd90c985b96476db does not allow
that, so re-enable and add a test.

Signed-off-by: Max Bernstein <max@bernsteinbear.com>
---
    trailer: allow spaces in tokens
    
    Changed since v1:
    
     * "Fixed" a format-patch test. I'm not sure if the new output is what
       everyone might expect for this particular case.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1309%2Ftekknolagi%2Fmaint-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1309/tekknolagi/maint-v2
Pull-Request: https://github.com/git/git/pull/1309

Range-diff vs v1:

 1:  404a6d1b193 ! 1:  4d490851ac2 trailer: allow spaces in tokens
     @@ Commit message
      
          Signed-off-by: Max Bernstein <max@bernsteinbear.com>
      
     + ## t/t4014-format-patch.sh ##
     +@@ t/t4014-format-patch.sh: test_expect_success 'signoff: not really a signoff' '
     + 	4:Subject: [PATCH] subject
     + 	8:
     + 	9:I want to mention about Signed-off-by: here.
     +-	10:
     +-	11:Signed-off-by: C O Mitter <committer@example.com>
     ++	10:Signed-off-by: C O Mitter <committer@example.com>
     + 	EOF
     + 	test_cmp expect actual
     + '
     +
       ## t/t7513-interpret-trailers.sh ##
      @@ t/t7513-interpret-trailers.sh: test_expect_success 'only-trailers omits non-trailer in middle of block' '
       	test_cmp expected actual


 t/t4014-format-patch.sh       |  3 +--
 t/t7513-interpret-trailers.sh | 40 +++++++++++++++++++++++++++++++++++
 trailer.c                     |  7 +-----
 3 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index fbec8ad2ef7..db95cb6ee66 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1544,8 +1544,7 @@ test_expect_success 'signoff: not really a signoff' '
 	4:Subject: [PATCH] subject
 	8:
 	9:I want to mention about Signed-off-by: here.
-	10:
-	11:Signed-off-by: C O Mitter <committer@example.com>
+	10:Signed-off-by: C O Mitter <committer@example.com>
 	EOF
 	test_cmp expect actual
 '
diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
index 97f10905d23..47bf83003ef 100755
--- a/t/t7513-interpret-trailers.sh
+++ b/t/t7513-interpret-trailers.sh
@@ -1481,6 +1481,46 @@ test_expect_success 'only-trailers omits non-trailer in middle of block' '
 	test_cmp expected actual
 '
 
+test_expect_success 'supports spaces inside token' '
+	git config --unset trailer.sign.command &&
+	cat >expected <<-\EOF &&
+		Signed-off-by: nobody <nobody@nowhere>
+		some other trailer: a value
+		Signed-off-by: somebody <somebody@somewhere>
+	EOF
+	echo "wrote to expected" 1>&2 &&
+	git interpret-trailers --only-trailers >actual <<-\EOF &&
+		subject
+
+		it is important that the trailers below are signed-off-by
+		so that they meet the "25% trailers Git knows about" heuristic
+
+		Signed-off-by: nobody <nobody@nowhere>
+		some other trailer: a value
+		Signed-off-by: somebody <somebody@somewhere>
+	EOF
+	test_cmp expected actual
+'
+
+test_expect_success 'does not support space at beginning of token' '
+	cat >expected <<-\EOF &&
+		Signed-off-by: nobody <nobody@nowhere> not a trailer: thing
+		Signed-off-by: somebody <somebody@somewhere>
+	EOF
+	echo "wrote to expected" 1>&2 &&
+	git interpret-trailers --only-trailers --unfold >actual <<-\EOF &&
+		subject
+
+		it is important that the trailers below are signed-off-by
+		so that they meet the "25% trailers Git knows about" heuristic
+
+		Signed-off-by: nobody <nobody@nowhere>
+		 not a trailer: thing
+		Signed-off-by: somebody <somebody@somewhere>
+	EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'only input' '
 	git config trailer.sign.command "echo config-value" &&
 	cat >expected <<-\EOF &&
diff --git a/trailer.c b/trailer.c
index d419c20735e..d02a9154512 100644
--- a/trailer.c
+++ b/trailer.c
@@ -618,17 +618,12 @@ static int token_matches_item(const char *tok, struct arg_item *item, size_t tok
  */
 static ssize_t find_separator(const char *line, const char *separators)
 {
-	int whitespace_found = 0;
 	const char *c;
 	for (c = line; *c; c++) {
 		if (strchr(separators, *c))
 			return c - line;
-		if (!whitespace_found && (isalnum(*c) || *c == '-'))
+		if (isalnum(*c) || *c == '-' || (c != line && (*c == ' ' || *c == '\t')))
 			continue;
-		if (c != line && (*c == ' ' || *c == '\t')) {
-			whitespace_found = 1;
-			continue;
-		}
 		break;
 	}
 	return -1;

base-commit: ad60dddad72dfb8367bd695028b5b8dc6c33661b
-- 
gitgitgadget

  reply	other threads:[~2022-08-18  7:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18  7:06 [PATCH] trailer: allow spaces in tokens Max Bernstein via GitGitGadget
2022-08-18  7:54 ` Max Bernstein via GitGitGadget [this message]
2022-08-18 16:54   ` [PATCH v2] " Junio C Hamano
2022-08-18 17:56     ` Jonathan Tan
2022-08-18 19:03     ` Maxwell Bernstein
2022-08-18 20:46       ` Christian Couder
2022-08-18 21:31         ` Junio C Hamano
2022-08-19  4:33           ` Junio C Hamano
2022-08-19 10:29             ` Christian Couder
2022-08-22 13:58               ` Johannes Schindelin
2022-08-23 14:06               ` [PATCH] Documentation: clarify whitespace rules for trailers Christian Couder
2022-08-24 18:13                 ` Junio C Hamano
2022-08-25 11:59                   ` Christian Couder
2022-08-25 16:20                     ` Junio C Hamano
2022-08-30 10:50                     ` [PATCH v2] " Christian Couder
2022-08-30 17:20                       ` Junio C Hamano
2022-08-18 16:48 ` [PATCH] trailer: allow spaces in tokens Junio C Hamano
2022-08-18 17:52   ` Jonathan Tan
2022-08-18 17:58     ` Junio C Hamano

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=pull.1309.v2.git.git.1660809243298.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=donotemailthisaddress@bernsteinbear.com \
    --cc=git@vger.kernel.org \
    --cc=max@bernsteinbear.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 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 NNTP newsgroup(s).