From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Johan Herland <johan@herland.net>,
Josh Triplett <josh@joshtriplett.org>,
Thomas Rast <tr@thomasrast.ch>,
Michael Haggerty <mhagger@alum.mit.edu>,
Dan Carpenter <dan.carpenter@oracle.com>,
Greg Kroah-Hartman <greg@kroah.com>, Jeff King <peff@peff.net>,
Eric Sunshine <sunshine@sunshineco.com>,
Ramsay Jones <ramsay@ramsay1.demon.co.uk>,
Jonathan Nieder <jrnieder@gmail.com>
Subject: [PATCH v10 12/12] trailer: add blank line before the trailers if needed
Date: Sun, 06 Apr 2014 19:02:03 +0200 [thread overview]
Message-ID: <20140406170204.15116.15100.chriscool@tuxfamily.org> (raw)
In-Reply-To: <20140406163214.15116.91484.chriscool@tuxfamily.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
t/t7513-interpret-trailers.sh | 12 +++++++++++-
trailer.c | 26 ++++++++++++++++++--------
2 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
index 262f7bf..44a7131 100755
--- a/t/t7513-interpret-trailers.sh
+++ b/t/t7513-interpret-trailers.sh
@@ -34,6 +34,7 @@ test_expect_success 'setup' '
test_expect_success 'without config' '
sed -e "s/ Z\$/ /" >expected <<-\EOF &&
+
ack: Peff
Reviewed-by: Z
Acked-by: Johan
@@ -44,6 +45,7 @@ test_expect_success 'without config' '
test_expect_success '--trim-empty without config' '
cat >expected <<-\EOF &&
+
ack: Peff
Acked-by: Johan
EOF
@@ -55,6 +57,7 @@ test_expect_success '--trim-empty without config' '
test_expect_success 'with config setup' '
git config trailer.ack.key "Acked-by: " &&
cat >expected <<-\EOF &&
+
Acked-by: Peff
EOF
git interpret-trailers --trim-empty "ack = Peff" >actual &&
@@ -68,6 +71,7 @@ test_expect_success 'with config setup' '
test_expect_success 'with config setup and = sign' '
git config trailer.ack.key "Acked-by= " &&
cat >expected <<-\EOF &&
+
Acked-by= Peff
EOF
git interpret-trailers --trim-empty "ack = Peff" >actual &&
@@ -81,6 +85,7 @@ test_expect_success 'with config setup and = sign' '
test_expect_success 'with config setup and # sign' '
git config trailer.bug.key "Bug #" &&
cat >expected <<-\EOF &&
+
Bug #42
EOF
git interpret-trailers --trim-empty "bug = 42" >actual &&
@@ -88,8 +93,10 @@ test_expect_success 'with config setup and # sign' '
'
test_expect_success 'with commit basic message' '
+ cat basic_message >expected &&
+ echo >>expected &&
git interpret-trailers <basic_message >actual &&
- test_cmp basic_message actual
+ test_cmp expected actual
'
test_expect_success 'with commit complex message' '
@@ -436,6 +443,7 @@ test_expect_success 'with failing command using $ARG' '
test_expect_success 'with empty tokens' '
cat >expected <<-EOF &&
+
Signed-off-by: A U Thor <author@example.com>
EOF
git interpret-trailers ":" ":test" >actual <<-EOF &&
@@ -446,6 +454,7 @@ test_expect_success 'with empty tokens' '
test_expect_success 'with command but no key' '
git config --unset trailer.sign.key &&
cat >expected <<-EOF &&
+
sign: A U Thor <author@example.com>
EOF
git interpret-trailers >actual <<-EOF &&
@@ -456,6 +465,7 @@ test_expect_success 'with command but no key' '
test_expect_success 'with no command and no key' '
git config --unset trailer.review.key &&
cat >expected <<-EOF &&
+
review: Junio
sign: A U Thor <author@example.com>
EOF
diff --git a/trailer.c b/trailer.c
index 09db2c2..639f657 100644
--- a/trailer.c
+++ b/trailer.c
@@ -618,12 +618,14 @@ static struct strbuf **read_stdin(void)
}
/*
- * Return the the (0 based) index of the first trailer line
+ * Return the (0 based) index of the first trailer line
* or the line count if there are no trailers.
+ * The has_blank_line parameter tells if there is a blank
+ * line before the trailers.
*/
-static int find_trailer_start(struct strbuf **lines)
+static int find_trailer_start(struct strbuf **lines, int *has_blank_line)
{
- int start, empty = 1, count = 0;
+ int start, only_spaces = 1, count = 0;
/* Get the line count */
while (lines[count])
@@ -635,32 +637,40 @@ static int find_trailer_start(struct strbuf **lines)
*/
for (start = count - 1; start >= 0; start--) {
if (contains_only_spaces(lines[start]->buf)) {
- if (empty)
+ if (only_spaces)
continue;
+ *has_blank_line = 1;
return start + 1;
}
if (strchr(lines[start]->buf, ':')) {
- if (empty)
- empty = 0;
+ if (only_spaces)
+ only_spaces = 0;
continue;
}
+ *has_blank_line = start == count - 1 ?
+ 0 : contains_only_spaces(lines[start + 1]->buf);
return count;
}
- return empty ? count : start + 1;
+ *has_blank_line = only_spaces ? count > 0 : 0;
+ return only_spaces ? count : start + 1;
}
static void process_stdin(struct trailer_item **in_tok_first,
struct trailer_item **in_tok_last)
{
struct strbuf **lines = read_stdin();
- int start = find_trailer_start(lines);
+ int has_blank_line;
+ int start = find_trailer_start(lines, &has_blank_line);
int i;
/* Print non trailer lines as is */
for (i = 0; lines[i] && i < start; i++)
printf("%s", lines[i]->buf);
+ if (!has_blank_line)
+ printf("\n");
+
/* Parse trailer lines */
for (i = start; lines[i]; i++) {
struct trailer_item *new = create_trailer_item(lines[i]->buf);
--
1.9.0.163.g8ca203c
next prev parent reply other threads:[~2014-04-07 18:44 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-06 17:01 [PATCH v10 00/12] Add interpret-trailers builtin Christian Couder
2014-04-06 17:01 ` [PATCH v10 01/12] trailer: add data structures and basic functions Christian Couder
2014-04-06 17:01 ` [PATCH v10 02/12] trailer: process trailers from stdin and arguments Christian Couder
2014-04-06 17:01 ` [PATCH v10 03/12] trailer: read and process config information Christian Couder
2014-04-06 17:01 ` [PATCH v10 04/12] trailer: process command line trailer arguments Christian Couder
2014-04-06 17:01 ` [PATCH v10 05/12] trailer: parse trailers from stdin Christian Couder
2014-04-06 17:01 ` [PATCH v10 06/12] trailer: put all the processing together and print Christian Couder
2014-04-06 17:01 ` [PATCH v10 07/12] trailer: add interpret-trailers command Christian Couder
2014-04-06 17:01 ` [PATCH v10 08/12] trailer: add tests for "git interpret-trailers" Christian Couder
2014-04-06 17:02 ` [PATCH v10 09/12] trailer: execute command from 'trailer.<name>.command' Christian Couder
2014-04-06 17:02 ` [PATCH v10 10/12] trailer: add tests for commands in config file Christian Couder
2014-04-06 17:02 ` [PATCH v10 11/12] Documentation: add documentation for 'git interpret-trailers' Christian Couder
2014-04-08 7:30 ` Michael Haggerty
2014-04-08 11:35 ` Christian Couder
2014-04-08 15:25 ` Michael Haggerty
2014-04-25 21:07 ` Christian Couder
2014-04-28 10:16 ` Michael Haggerty
2014-05-25 8:37 ` Christian Couder
2014-05-27 8:21 ` Michael Haggerty
2014-05-27 9:17 ` Johan Herland
2014-05-27 19:18 ` Junio C Hamano
2014-04-08 16:52 ` Junio C Hamano
2014-04-08 21:26 ` Junio C Hamano
2014-04-25 19:56 ` Christian Couder
2014-04-28 16:37 ` Junio C Hamano
2014-04-29 11:05 ` Jeremy Morton
2014-04-29 11:47 ` Christian Couder
2014-04-29 13:25 ` Jeremy Morton
2014-05-01 18:54 ` Christian Couder
2014-04-29 13:25 ` Jeremy Morton
2014-04-06 17:02 ` Christian Couder [this message]
2014-04-07 21:38 ` [PATCH v10 12/12] trailer: add blank line before the trailers if needed Junio C Hamano
2014-04-08 12:48 ` Christian Couder
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=20140406170204.15116.15100.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=dan.carpenter@oracle.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=greg@kroah.com \
--cc=johan@herland.net \
--cc=josh@joshtriplett.org \
--cc=jrnieder@gmail.com \
--cc=mhagger@alum.mit.edu \
--cc=peff@peff.net \
--cc=ramsay@ramsay1.demon.co.uk \
--cc=sunshine@sunshineco.com \
--cc=tr@thomasrast.ch \
/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).