{"thread":{"id":"23899","subject":"Re: [PATCH 4/6 rebase-version] Emit a whole line once a time.","startedAt":"2010-05-25T10:44:20Z","lastAt":"2010-05-25T10:44:20Z","messageCount":1,"participants":["Bo Yang"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"142277","messageId":"1274784260-13991-1-git-send-email-struggleyb.nku@gmail.com","threadId":"23899","inReplyTo":null,"subject":"Re: [PATCH 4/6 rebase-version] Emit a whole line once a time.","fromName":"Bo Yang","fromEmail":"struggleyb.nku@gmail.com","sentAt":"2010-05-25T10:44:20Z","receivedAt":"2010-05-25T10:44:20Z","isPatch":true,"sender":{"key":"struggleyb.nku@gmail.com","avatar":"https://avatars.githubusercontent.com/u/233030?v=4"},"body":"Since the graph prefix will be printed when calling\nemit_line, so the functions should be used to emit a\ncomplete line out once a time. No one should call\nemit_line to just output some strings instead of a\ncomplete line.\nUse a strbuf to compose the whole line, and then\ncall emit_line to output it once.\n\nSigned-off-by: Bo Yang <struggleyb.nku@gmail.com>\n---\n diff.c |   34 +++++++++++++++++++++++++++++-----\n 1 files changed, 29 insertions(+), 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex b99a56c..067260b 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -370,6 +370,18 @@ static void emit_hunk_header(struct emit_callback *ecbdata,\n \tconst char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);\n \tstatic const char atat[2] = { '@', '@' };\n \tconst char *cp, *ep;\n+\tstruct strbuf msgbuf = STRBUF_INIT;\n+\tint org_len = len;\n+\n+\t/*\n+\t * trailing \\r\\n\n+\t */\n+\tint i = 1;\n+\tfor (; i < 3; i++) {\n+\t\tif (line[len - i] == '\\r' || line[len - i] == '\\n') {\n+\t\t\tlen --;\n+\t\t}\n+\t}\n \n \t/*\n \t * As a hunk header must begin with \"@@ -<old>, +<new> @@\",\n@@ -384,17 +396,29 @@ static void emit_hunk_header(struct emit_callback *ecbdata,\n \tep += 2; /* skip over @@ */\n \n \t/* The hunk header in fraginfo color */\n-\temit_line(ecbdata->opt, frag, reset, line, ep - line);\n+\tstrbuf_add(&msgbuf, frag, strlen(frag));\n+\tstrbuf_add(&msgbuf, line, ep - line);\n+\tstrbuf_add(&msgbuf, reset, strlen(reset));\n \n \t/* blank before the func header */\n \tfor (cp = ep; ep - line < len; ep++)\n \t\tif (*ep != ' ' && *ep != '\\t')\n \t\t\tbreak;\n-\tif (ep != cp)\n-\t\temit_line(ecbdata->opt, plain, reset, cp, ep - cp);\n+\tif (ep != cp) {\n+\t\tstrbuf_add(&msgbuf, plain, strlen(plain));\n+\t\tstrbuf_add(&msgbuf, cp, ep - cp);\n+\t\tstrbuf_add(&msgbuf, reset, strlen(reset));\n+\t}\n+\n+\tif (ep < line + len) {\n+\t\tstrbuf_add(&msgbuf, func, strlen(func));\n+\t\tstrbuf_add(&msgbuf, ep, line + len - ep);\n+\t\tstrbuf_add(&msgbuf, reset, strlen(reset));\n+\t}\n \n-\tif (ep < line + len)\n-\t\temit_line(ecbdata->opt, func, reset, ep, line + len - ep);\n+\tstrbuf_add(&msgbuf, line + len, org_len - len);\n+\temit_line(ecbdata->opt, \"\", \"\", msgbuf.buf, msgbuf.len);\n+\tstrbuf_release(&msgbuf);\n }\n \n static struct diff_tempfile *claim_diff_tempfile(void) {\n-- \n1.6.0.4\n"}]}