From: Jonathan Tan <jonathantanmy@google.com>
To: git@vger.kernel.org
Cc: Jonathan Tan <jonathantanmy@google.com>,
jrnieder@gmail.com, sbeller@google.com,
computersforpeace@gmail.com, Johannes.Schindelin@gmx.de
Subject: [PATCH v2] sequencer: require trailing NL in footers
Date: Tue, 25 Apr 2017 16:57:41 -0700 [thread overview]
Message-ID: <20170425235741.32546-1-jonathantanmy@google.com> (raw)
In-Reply-To: <20170425190651.8910-1-jonathantanmy@google.com>
In commit 967dfd4 ("sequencer: use trailer's trailer layout",
2016-11-29), sequencer was taught to use the same mechanism as
interpret-trailers to determine the nature of the trailer of a commit
message (referred to as the "footer" in sequencer.c). However, the
requirement that a footer end in a newline character was inadvertently
removed. Restore that requirement.
While writing this commit, I noticed that if the "ignore_footer"
parameter in "has_conforming_footer" is greater than the distance
between the trailer start and sb->len, "has_conforming_footer" will
return an unexpected result. This does not occur in practice, because
"ignore_footer" is either zero or the return value of an invocation to
"ignore_non_trailer", which only skips empty lines and comment lines.
This commit contains a comment explaining this in the function's
documentation.
Reported-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
jrnieder pointed out the existence of commit-tree to me, which I have
used to write the test below.
Changes from v1:
- added test
- used one of sbeller's documentation suggestions
sequencer.c | 11 +++++++++++
t/t3511-cherry-pick-x.sh | 14 ++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/sequencer.c b/sequencer.c
index 77afecaeb..500a76260 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -151,6 +151,12 @@ static const char *get_todo_path(const struct replay_opts *opts)
* Returns 1 for conforming footer
* Returns 2 when sob exists within conforming footer
* Returns 3 when sob exists within conforming footer as last entry
+ *
+ * A footer that does not end in a newline is considered non-conforming.
+ *
+ * ignore_footer, if not zero, should be the return value of an invocation to
+ * ignore_non_trailer(). See the documentation of that function for more
+ * information.
*/
static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
int ignore_footer)
@@ -159,6 +165,11 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
int i;
int found_sob = 0, found_sob_last = 0;
+ if (sb->len <= ignore_footer)
+ return 0;
+ if (sb->buf[sb->len - ignore_footer - 1] != '\n')
+ return 0;
+
trailer_info_get(&info, sb->buf);
if (info.trailer_start == info.trailer_end)
diff --git a/t/t3511-cherry-pick-x.sh b/t/t3511-cherry-pick-x.sh
index bf0a5c988..6f518020b 100755
--- a/t/t3511-cherry-pick-x.sh
+++ b/t/t3511-cherry-pick-x.sh
@@ -208,6 +208,20 @@ test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists fo
test_cmp expect actual
'
+test_expect_success 'cherry-pick -x handles commits with no NL at end of message' '
+ pristine_detach initial &&
+ sha1=$(printf "title\n\nSigned-off-by: a" | git commit-tree -p initial mesg-with-footer^{tree}) &&
+ git cherry-pick -x $sha1 &&
+ cat <<-EOF >expect &&
+ title
+
+ Signed-off-by: a
+ (cherry picked from commit $sha1)
+ EOF
+ git log -1 --pretty=format:%B >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
pristine_detach initial &&
sha1=$(git rev-parse mesg-with-cherry-footer^0) &&
--
2.13.0.rc0.306.g87b477812d-goog
next prev parent reply other threads:[~2017-04-25 23:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-21 22:01 [GIT 2.12.2 REGRESSION] git cherry-pick -x Brian Norris
2017-04-21 22:10 ` Stefan Beller
2017-04-21 22:13 ` Jeff King
2017-04-25 19:06 ` [PATCH] sequencer: require trailing NL in footers Jonathan Tan
2017-04-25 21:04 ` Stefan Beller
2017-04-25 21:51 ` Jonathan Tan
2017-04-25 21:56 ` Stefan Beller
2017-04-25 22:05 ` Johannes Schindelin
2017-04-25 23:39 ` Jonathan Nieder
2017-04-25 22:30 ` Brian Norris
2017-04-26 20:31 ` Brian Norris
2017-04-25 21:56 ` Johannes Schindelin
2017-04-25 23:34 ` Jonathan Nieder
2017-04-25 23:57 ` Jonathan Tan [this message]
2017-04-26 0:07 ` [PATCH v2] " Jonathan Nieder
2017-04-26 2:08 ` Junio C Hamano
2017-04-26 9:09 ` Johannes Schindelin
2017-04-26 20:50 ` [PATCH v3] sequencer: add newline before adding footers Jonathan Tan
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=20170425235741.32546-1-jonathantanmy@google.com \
--to=jonathantanmy@google.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=computersforpeace@gmail.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=sbeller@google.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.
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).