Here's version 2 of the unify-appending-of-sob series.  Hopefully this
addresses the comments made on the first series:

   http://thread.gmane.org/gmane.comp.version-control.git/210390

The main difference is that the detection of the "(cherry picked from ...)"
line has been relaxed, and the modifications to log-tree.c have been dropped.

Here's the inter-diff of this series against the original series, both built
on top of 2d242fb3fc19fc9ba046accdd9210be8b9913f64 (the actual series in the
following emails is of course built on top of master).

diff --git a/revision.h b/revision.h
index 435a60b..d20defa 100644
--- a/revision.h
+++ b/revision.h
@@ -137,7 +137,7 @@ struct rev_info {
        int             numbered_files;
        char            *message_id;
        struct string_list *ref_message_ids;
-       int              add_signoff;
+       int             add_signoff;
        const char      *extra_headers;
        const char      *log_reencode;
        const char      *subject_prefix;
diff --git a/sequencer.c b/sequencer.c
index eb93dd6..54b3cb9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -36,13 +36,18 @@ static int is_rfc2822_line(const char *buf, int len)
        return 1;
 }
 
-static int is_cherry_pick_from_line(const char *buf, int len)
+static int is_cherry_picked_from_line(const char *buf, int len)
 {
-       return (strlen(cherry_picked_prefix) + 41) <= len &&
-               !prefixcmp(buf, cherry_picked_prefix);
+       /*
+        * We only care that it looks roughly like (cherry picked from ...)
+        */
+       return !prefixcmp(buf, cherry_picked_prefix) &&
+               (buf[len - 1] == ')' ||
+                (buf[len - 1] == '\n' && buf[len - 2] == ')'));
 }
 
-/* Returns 0 for non-conforming footer
+/*
+ * Returns 0 for non-conforming footer
  * Returns 1 for conforming footer
  * Returns 2 when sob exists within conforming footer
  * Returns 3 when sob exists within conforming footer as last entry
@@ -51,7 +56,7 @@ static int has_conforming_footer(struct strbuf *sb, struct 
strbuf *sob,
        int ignore_footer)
 {
        int hit = 0;
-       int i, k = 0;
+       int i, k;
        int len = sb->len - ignore_footer;
        const char *buf = sb->buf;
        int found_sob = 0;
@@ -76,12 +81,13 @@ static int has_conforming_footer(struct strbuf *sb, struct 
strbuf *sob,
                        ; /* do nothing */
                k++;
 
-               found_rfc2822 = is_rfc2822_line(buf+i, k-i);
+               found_rfc2822 = is_rfc2822_line(buf + i, k - i);
                if (found_rfc2822 && sob &&
-                       !strncasecmp(buf+i, sob->buf, sob->len))
+                       !strncmp(buf + i, sob->buf, sob->len))
                        found_sob = k;
 
-               if (!(found_rfc2822 || is_cherry_pick_from_line(buf+i, k-i)))
+               if (!(found_rfc2822 ||
+                       is_cherry_picked_from_line(buf + i, k - i)))
                        return 0;
        }
        if (found_sob == i)
@@ -1103,11 +1109,20 @@ void append_signoff(struct strbuf *msgbuf, int 
ignore_footer, int no_dup_sob)
        strbuf_addch(&sob, '\n');
        for (i = msgbuf->len - 1 - ignore_footer; i > 0 && msgbuf->buf[i - 1] 
!= '\n'; i--)
                ; /* do nothing */
-       if (msgbuf->buf[i] != '\n' && (!i || !(has_footer =
-               has_conforming_footer(msgbuf, &sob, ignore_footer))))
-               strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, "\n", 1);
+
+       if (msgbuf->buf[i] != '\n') {
+               if (i)
+                       has_footer = has_conforming_footer(msgbuf, &sob,
+                                       ignore_footer);
+
+               if (!has_footer)
+                       strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0,
+                                       "\n", 1);
+       }
+
        if (has_footer != 3 && (!no_dup_sob || has_footer != 2))
                strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0,
                                sob.buf, sob.len);
+
        strbuf_release(&sob);
 }
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index c53dc4b..6d00e43 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1211,16 +1211,17 @@ subject
 
 body
 
+Reviewed-id: Noone
 Tested-by: my@house
 Change-id: Ideadbeef
 Signed-off-by: C O Mitter <commit...@example.com>
-BUG: 1234
+Bug: 1234
 EOF
        cat >expected <<\EOF &&
 4:Subject: [PATCH] subject
 8:
 10:
-13:Signed-off-by: C O Mitter <commit...@example.com>
+14:Signed-off-by: C O Mitter <commit...@example.com>
 EOF
        test_cmp expected actual
 '

Brandon Casey (8):
  sequencer.c: remove broken support for rfc2822 continuation in footer
  t/test-lib-functions.sh: allow to specify the tag name to test_commit
  t/t3511: add some tests of 'cherry-pick -s' functionality
  sequencer.c: recognize "(cherry picked from ..." as part of s-o-b
    footer
  sequencer.c: always separate "(cherry picked from" from commit body
  sequencer.c: teach append_signoff how to detect duplicate s-o-b
  sequencer.c: teach append_signoff to avoid adding a duplicate newline
  Unify appending signoff in format-patch, commit and sequencer

Nguyễn Thái Ngọc Duy (2):
  t4014: more tests about appending s-o-b lines
  format-patch: update append_signoff prototype

 builtin/commit.c         |   2 +-
 builtin/log.c            |  13 +--
 log-tree.c               |  92 ++---------------
 revision.h               |   2 +-
 sequencer.c              | 146 +++++++++++++++++---------
 sequencer.h              |   2 +-
 t/t3511-cherry-pick-x.sh | 219 +++++++++++++++++++++++++++++++++++++++
 t/t4014-format-patch.sh  | 263 +++++++++++++++++++++++++++++++++++++++++++++++
 t/test-lib-functions.sh  |   9 +-
 9 files changed, 595 insertions(+), 153 deletions(-)
 create mode 100755 t/t3511-cherry-pick-x.sh

-- 
1.8.1.1.252.gdb33759
--
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

Reply via email to