Emit a whole line in one go
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7be5761073
commit
2efcc97764
32
diff.c
32
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);
|
const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
|
||||||
static const char atat[2] = { '@', '@' };
|
static const char atat[2] = { '@', '@' };
|
||||||
const char *cp, *ep;
|
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> @@",
|
* As a hunk header must begin with "@@ -<old>, +<new> @@",
|
||||||
@ -384,17 +387,36 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
|
|||||||
ep += 2; /* skip over @@ */
|
ep += 2; /* skip over @@ */
|
||||||
|
|
||||||
/* The hunk header in fraginfo color */
|
/* 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 */
|
/* blank before the func header */
|
||||||
for (cp = ep; ep - line < len; ep++)
|
for (cp = ep; ep - line < len; ep++)
|
||||||
if (*ep != ' ' && *ep != '\t')
|
if (*ep != ' ' && *ep != '\t')
|
||||||
break;
|
break;
|
||||||
if (ep != cp)
|
if (ep != cp) {
|
||||||
emit_line(ecbdata->opt, plain, reset, cp, ep - cp);
|
strbuf_add(&msgbuf, plain, strlen(plain));
|
||||||
|
strbuf_add(&msgbuf, cp, ep - cp);
|
||||||
|
strbuf_add(&msgbuf, reset, strlen(reset));
|
||||||
|
}
|
||||||
|
|
||||||
if (ep < line + len)
|
if (ep < line + len) {
|
||||||
emit_line(ecbdata->opt, func, reset, ep, line + len - ep);
|
strbuf_add(&msgbuf, func, strlen(func));
|
||||||
|
strbuf_add(&msgbuf, ep, line + len - ep);
|
||||||
|
strbuf_add(&msgbuf, reset, strlen(reset));
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
static struct diff_tempfile *claim_diff_tempfile(void) {
|
||||||
|
Loading…
Reference in New Issue
Block a user