From: Bo Yang <struggleyb.nku@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com
Subject: Re: [PATCH v4 4/6] Emit a whole line in one go
Date: Sat, 29 May 2010 23:32:05 +0800 [thread overview]
Message-ID: <1275147126-16784-1-git-send-email-struggleyb.nku@gmail.com> (raw)
Since the graph prefix will be printed when calling
emit_line, so the functions should be used to emit a
complete line out once a time. No one should call
emit_line to just output some strings instead of a
complete line.
Use a strbuf to compose the whole line, and then
call emit_line to output it once.
Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
---
diff.c | 34 +++++++++++++++++++++++++++++-----
1 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/diff.c b/diff.c
index 7f2538d..8b738f0 100644
--- a/diff.c
+++ b/diff.c
@@ -370,6 +370,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
static const char atat[2] = { '@', '@' };
const char *cp, *ep;
+ struct strbuf msgbuf = STRBUF_INIT;
+ int org_len = len;
+ int i = 1;
/*
* As a hunk header must begin with "@@ -<old>, +<new> @@",
@@ -384,17 +387,38 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
ep += 2; /* skip over @@ */
/* The hunk header in fraginfo color */
- emit_line(ecbdata->opt, frag, reset, line, ep - line);
+ strbuf_add(&msgbuf, frag, strlen(frag));
+ strbuf_add(&msgbuf, line, ep - line);
+ strbuf_add(&msgbuf, reset, strlen(reset));
+
+ /*
+ * trailing \r\n
+ */
+ for (; i < 3; i++) {
+ if (line[len - i] == '\r' || line[len - i] == '\n') {
+ len --;
+ }
+ }
/* blank before the func header */
for (cp = ep; ep - line < len; ep++)
if (*ep != ' ' && *ep != '\t')
break;
- if (ep != cp)
- emit_line(ecbdata->opt, plain, reset, cp, ep - cp);
+ if (ep != cp) {
+ strbuf_add(&msgbuf, plain, strlen(plain));
+ strbuf_add(&msgbuf, cp, ep - cp);
+ strbuf_add(&msgbuf, reset, strlen(reset));
+ }
+
+ if (ep < line + len) {
+ strbuf_add(&msgbuf, func, strlen(func));
+ strbuf_add(&msgbuf, ep, line + len - ep);
+ strbuf_add(&msgbuf, reset, strlen(reset));
+ }
- if (ep < line + len)
- emit_line(ecbdata->opt, func, reset, ep, line + len - ep);
+ strbuf_add(&msgbuf, line + len, org_len - len);
+ emit_line(ecbdata->opt, "", "", msgbuf.buf, msgbuf.len);
+ strbuf_release(&msgbuf);
}
static struct diff_tempfile *claim_diff_tempfile(void) {
--
1.7.0.2.273.gc2413.dirty
next reply other threads:[~2010-05-29 15:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-29 15:32 Bo Yang [this message]
2010-05-29 15:32 ` [PATCH v4 6/6] Make --color-words work well with --graph Bo Yang
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=1275147126-16784-1-git-send-email-struggleyb.nku@gmail.com \
--to=struggleyb.nku@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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.
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).