* [PATCH 4/6 rebase-version] Emit a whole line once a time.
2010-05-25 9:02 ` [PATCH 3/6 rebase-version] diff.c: Output the text graph padding before each diff line Bo Yang
@ 2010-05-25 9:02 ` Bo Yang
0 siblings, 0 replies; 2+ messages in thread
From: Bo Yang @ 2010-05-25 9:02 UTC (permalink / raw)
To: git; +Cc: gitster, trast, peff
Use a strbuf to compose the whole line, and then
call emit_line to output it once. This make output_prefix
callback works well.
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 b99a56c..067260b 100644
--- a/diff.c
+++ b/diff.c
@@ -370,6 +370,18 @@ 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;
+
+ /*
+ * trailing \r\n
+ */
+ int i = 1;
+ for (; i < 3; i++) {
+ if (line[len - i] == '\r' || line[len - i] == '\n') {
+ len --;
+ }
+ }
/*
* As a hunk header must begin with "@@ -<old>, +<new> @@",
@@ -384,17 +396,29 @@ 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));
/* 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.6.0.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 4/6 rebase-version] Emit a whole line once a time.
@ 2010-05-25 10:44 Bo Yang
0 siblings, 0 replies; 2+ messages in thread
From: Bo Yang @ 2010-05-25 10:44 UTC (permalink / raw)
To: git; +Cc: gitster, trast, peff, Bo Yang
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 b99a56c..067260b 100644
--- a/diff.c
+++ b/diff.c
@@ -370,6 +370,18 @@ 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;
+
+ /*
+ * trailing \r\n
+ */
+ int i = 1;
+ for (; i < 3; i++) {
+ if (line[len - i] == '\r' || line[len - i] == '\n') {
+ len --;
+ }
+ }
/*
* As a hunk header must begin with "@@ -<old>, +<new> @@",
@@ -384,17 +396,29 @@ 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));
/* 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.6.0.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-05-25 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-25 10:44 [PATCH 4/6 rebase-version] Emit a whole line once a time Bo Yang
-- strict thread matches above, loose matches on Subject: below --
2010-05-25 9:02 [PATCH 0/6 rebase-version] Make git log --graph looks better with -p and other diff options Bo Yang
2010-05-25 9:02 ` [PATCH 1/6 rebase-version] Add a prefix output callback to diff output Bo Yang
2010-05-25 9:02 ` [PATCH 2/6 rebase-version] Output the graph columns at the end of the commit message Bo Yang
2010-05-25 9:02 ` [PATCH 3/6 rebase-version] diff.c: Output the text graph padding before each diff line Bo Yang
2010-05-25 9:02 ` [PATCH 4/6 rebase-version] Emit a whole line once a time Bo Yang
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).