git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Lodato <lodatom@gmail.com>
To: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
	"René Scharfe" <rene.scharfe@lsrfire.ath.cx>,
	"Bert Wesarg" <bert.wesarg@googlemail.com>
Cc: Mark Lodato <lodatom@gmail.com>
Subject: [PATCH 5/4] move sane_truncate_line to utf8_truncate_line
Date: Tue, 27 Mar 2012 01:31:25 -0400	[thread overview]
Message-ID: <1332826286-13490-1-git-send-email-lodatom@gmail.com> (raw)
In-Reply-To: <1332729705-9283-1-git-send-email-lodatom@gmail.com>

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---

As promised, here are the additional patches to move the function name to the
same line as the hunk header.

 diff.c |   14 ++------------
 utf8.c |   13 +++++++++++++
 utf8.h |    2 ++
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/diff.c b/diff.c
index 377ec1e..74c77bc 100644
--- a/diff.c
+++ b/diff.c
@@ -1015,20 +1015,10 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
 
 static unsigned long sane_truncate_line(struct emit_callback *ecb, char *line, unsigned long len)
 {
-	const char *cp;
-	unsigned long allot;
-	size_t l = len;
-
 	if (ecb->truncate)
 		return ecb->truncate(line, len);
-	cp = line;
-	allot = l;
-	while (0 < l) {
-		(void) utf8_width(&cp, &l);
-		if (!cp)
-			break; /* truncated in the middle? */
-	}
-	return allot - l;
+	else
+		return utf8_truncate_line(line, len);
 }
 
 static void find_lno(const char *line, struct emit_callback *ecbdata)
diff --git a/utf8.c b/utf8.c
index 8acbc66..d70ee9b 100644
--- a/utf8.c
+++ b/utf8.c
@@ -482,3 +482,16 @@ char *reencode_string(const char *in, const char *out_encoding, const char *in_e
 	return out;
 }
 #endif
+
+unsigned long utf8_truncate_line(const char *line, unsigned long len)
+{
+	const char *cp = line;
+	unsigned long allot = len;
+	size_t l = len;
+	while (0 < l) {
+		(void) utf8_width(&cp, &l);
+		if (!cp)
+			break; /* truncated in the middle? */
+	}
+	return allot - l;
+}
diff --git a/utf8.h b/utf8.h
index 81f2c82..929e2df 100644
--- a/utf8.h
+++ b/utf8.h
@@ -19,4 +19,6 @@ char *reencode_string(const char *in, const char *out_encoding, const char *in_e
 #define reencode_string(a,b,c) NULL
 #endif
 
+unsigned long utf8_truncate_line(const char *line, unsigned long len);
+
 #endif
-- 
1.7.9.4

  parent reply	other threads:[~2012-03-27  5:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-26  2:41 [PATCH 0/4] grep: add more information to hunk separators Mark Lodato
2012-03-26  2:41 ` [PATCH 1/4] grep doc: add --break / --heading / -W to synopsis Mark Lodato
2012-03-26  2:41 ` [PATCH 2/4] add tests for grep --heading with context Mark Lodato
2012-03-26  2:41 ` [PATCH 3/4] grep: move code to print hunk markers after heading Mark Lodato
2012-03-26  2:41 ` [PATCH 4/4] grep: add --hunk-heading option Mark Lodato
2012-03-26  5:14 ` [PATCH 0/4] grep: add more information to hunk separators Junio C Hamano
2012-03-26 16:16   ` René Scharfe
2012-03-26 18:05     ` Junio C Hamano
2012-03-26 18:48   ` Bert Wesarg
2012-03-26 16:16 ` René Scharfe
2012-03-26 18:01   ` Junio C Hamano
2012-03-26 21:12     ` René Scharfe
2012-03-26 21:19       ` Junio C Hamano
2012-03-27  5:31 ` Mark Lodato [this message]
2012-03-27  5:31 ` [PATCH 6/4] add grep.hunkHeadingFunction option Mark Lodato

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=1332826286-13490-1-git-send-email-lodatom@gmail.com \
    --to=lodatom@gmail.com \
    --cc=bert.wesarg@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=rene.scharfe@lsrfire.ath.cx \
    /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).