git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH v2 3/4] builtin/commit.c: extract ignore_non_trailer() helper function
Date: Tue, 28 Oct 2014 14:36:51 -0700	[thread overview]
Message-ID: <1414532212-9016-4-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1414532212-9016-1-git-send-email-gitster@pobox.com>

Extract a helper function from prepare_to_commit() to determine
where to place a new Signed-off-by: line, which is essentially the
true "end" of the log message, ignoring the trailing "Conflicts:"
line and everything below it.

The detection _should_ make sure the "Conflicts:" line it finds is
truly the conflict hint block by checking everything that follows is
a HT indented pathname to avoid false positive, but this logic will
be revamped in a later patch to ignore comments and blanks anyway,
so it is left as-is in this step.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/commit.c | 59 +++++++++++++++++++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 26 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index fedb45a..cd455aa 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -593,6 +593,37 @@ static char *cut_ident_timestamp_part(char *string)
 	return ket;
 }
 
+/*
+ * Inspect sb and determine the true "end" of the log message, in
+ * order to find where to put a new Signed-off-by: line.  Ignored are
+ * trailing "Conflict:" block.
+ *
+ * Returns the number of bytes from the tail to ignore, to be fed as
+ * the second parameter to append_signoff().
+ */
+static int ignore_non_trailer(struct strbuf *sb)
+{
+	int ignore_footer = 0;
+	int i, eol, previous = 0;
+	const char *nl;
+
+	for (i = 0; i < sb->len; i++) {
+		nl = memchr(sb->buf + i, '\n', sb->len - i);
+		if (nl)
+			eol = nl - sb->buf;
+		else
+			eol = sb->len;
+		if (!prefixcmp(sb->buf + previous, "\nConflicts:\n")) {
+			ignore_footer = sb->len - previous;
+			break;
+		}
+		while (i < eol)
+			i++;
+		previous = eol;
+	}
+	return ignore_footer;
+}
+
 static int prepare_to_commit(const char *index_file, const char *prefix,
 			     struct commit *current_head,
 			     struct wt_status *s,
@@ -718,32 +749,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	if (clean_message_contents)
 		stripspace(&sb, 0);
 
-	if (signoff) {
-		/*
-		 * See if we have a Conflicts: block at the end. If yes, count
-		 * its size, so we can ignore it.
-		 */
-		int ignore_footer = 0;
-		int i, eol, previous = 0;
-		const char *nl;
-
-		for (i = 0; i < sb.len; i++) {
-			nl = memchr(sb.buf + i, '\n', sb.len - i);
-			if (nl)
-				eol = nl - sb.buf;
-			else
-				eol = sb.len;
-			if (!prefixcmp(sb.buf + previous, "\nConflicts:\n")) {
-				ignore_footer = sb.len - previous;
-				break;
-			}
-			while (i < eol)
-				i++;
-			previous = eol;
-		}
-
-		append_signoff(&sb, ignore_footer, 0);
-	}
+	if (signoff)
+		append_signoff(&sb, ignore_non_trailer(&sb), 0);
 
 	if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
 		die_errno(_("could not write commit template"));
-- 
2.1.2-620-g33c52cb

  parent reply	other threads:[~2014-10-28 21:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24 18:27 [PATCH] builtin/merge.c: drop a parameter that is never used Junio C Hamano
2014-10-24 19:37 ` Jonathan Nieder
2014-10-24 21:22 ` [PATCH] merge & sequencer: unify codepaths that write "Conflicts:" hint Junio C Hamano
2014-10-24 21:24   ` [PATCH] merge & sequencer: turn "Conflicts:" hint into a comment Junio C Hamano
2014-10-26 18:59     ` Jeff King
2014-10-27 17:32       ` Junio C Hamano
2014-10-27 20:59         ` Junio C Hamano
2014-10-28 22:21           ` Jeff King
2014-10-28  6:51         ` Christian Couder
2014-10-27 21:14       ` Jonathan Nieder
2014-10-28 22:22         ` Jeff King
2014-10-28 21:36 ` [PATCH v2 0/4] Turning Conflicts: hint into comment Junio C Hamano
2014-10-28 21:36   ` [PATCH v2 1/4] builtin/merge.c: drop a parameter that is never used Junio C Hamano
2014-10-28 21:36   ` [PATCH v2 2/4] merge & sequencer: unify codepaths that write "Conflicts:" hint Junio C Hamano
2014-10-28 21:36   ` Junio C Hamano [this message]
2014-10-28 21:36   ` [PATCH v2 4/4] merge & sequencer: turn "Conflicts:" hint into a comment 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=1414532212-9016-4-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /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).