Re: [PATCH v10 12/12] trailer: add blank line before the trailers if needed

2014-04-08 Thread Christian Couder
On Mon, Apr 7, 2014 at 11:38 PM, Junio C Hamano gits...@pobox.com wrote:

 Hmph, this is more fixing a mistake made earlier in the series at
 the end than adding a new feature or something.  Can you start from
 a version that does not have the mistake from the beginning?

Ok, I will squash this patch in other previous patches.

Thanks,
Christian.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 12/12] trailer: add blank line before the trailers if needed

2014-04-07 Thread Christian Couder
Signed-off-by: Christian Couder chrisc...@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 aut...@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 aut...@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 aut...@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;
 
 

Re: [PATCH v10 12/12] trailer: add blank line before the trailers if needed

2014-04-07 Thread Junio C Hamano
Christian Couder chrisc...@tuxfamily.org writes:

 Signed-off-by: Christian Couder chrisc...@tuxfamily.org
 ---

Hmph, this is more fixing a mistake made earlier in the series at
the end than adding a new feature or something.  Can you start from
a version that does not have the mistake from the beginning?
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html