{"thread":{"id":"11402","subject":"[PATCH] combine-diff: use diff_opts->a_prefix","startedAt":"2007-12-25T13:46:13Z","lastAt":"2007-12-27T01:19:27Z","messageCount":3,"participants":["Salikh Zakirov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"64094","messageId":"477109A5.9040000@gmail.com","threadId":"11402","inReplyTo":null,"subject":"[PATCH] combine-diff: use diff_opts->a_prefix","fromName":"Salikh Zakirov","fromEmail":"salikh@gmail.com","sentAt":"2007-12-25T13:46:13Z","receivedAt":"2007-12-25T13:46:13Z","isPatch":true,"sender":{"key":"salikh@gmail.com","avatar":"https://gravatar.com/avatar/952c102bb1dcf721dab8de4f5a11d276756a65d301d021f755e265cc3251efae?d=mp&s=160"},"body":"\nThe introduction of configurable dir prefix for diff headers in commit\neab9a40b 'Teach diff machinery to display other prefixes than \"a/\" and \"b/\"'\nmissed combined diff generation.\n\nSigned-off-by: Salikh Zakirov <salikh@gmail.com>\n---\n\nI realize that this fix is ugly, so I am all ears for a suggestion\nof a better fix.\n\n combine-diff.c |   19 +++++++++++--------\n 1 files changed, 11 insertions(+), 8 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex e22db89..5c3b42d 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -646,10 +646,11 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,\n \tsline->p_lno[i] = sline->p_lno[j];\n }\n \n-static void dump_quoted_path(const char *prefix, const char *path,\n-\t\t\t     const char *c_meta, const char *c_reset)\n+static void dump_quoted_path(const char *prefix, const char *prefix2,\n+                             const char *path, const char *c_meta,\n+\t\t\t     const char *c_reset)\n {\n-\tprintf(\"%s%s\", c_meta, prefix);\n+\tprintf(\"%s%s%s\", c_meta, prefix, prefix2);\n \tquote_c_style(path, NULL, stdout, 0);\n \tprintf(\"%s\\n\", c_reset);\n }\n@@ -792,7 +793,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \n \t\tif (rev->loginfo && !rev->no_commit_id)\n \t\t\tshow_log(rev, opt->msg_sep);\n-\t\tdump_quoted_path(dense ? \"diff --cc \" : \"diff --combined \",\n+\t\tdump_quoted_path(dense ? \"diff --cc \" : \"diff --combined \", \"\",\n \t\t\t\t elem->path, c_meta, c_reset);\n \t\tprintf(\"%sindex \", c_meta);\n \t\tfor (i = 0; i < num_parent; i++) {\n@@ -829,13 +830,15 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\t\tprintf(\"%s\\n\", c_reset);\n \t\t}\n \t\tif (added)\n-\t\t\tdump_quoted_path(\"--- /dev/\", \"null\", c_meta, c_reset);\n+\t\t\tdump_quoted_path(\"--- /dev/\", \"\", \"null\", c_meta, c_reset);\n \t\telse\n-\t\t\tdump_quoted_path(\"--- a/\", elem->path, c_meta, c_reset);\n+\t\t\tdump_quoted_path(\"--- \", opt->a_prefix, elem->path,\n+\t\t\t                 c_meta, c_reset);\n \t\tif (deleted)\n-\t\t\tdump_quoted_path(\"+++ /dev/\", \"null\", c_meta, c_reset);\n+\t\t\tdump_quoted_path(\"+++ /dev/\", \"\", \"null\", c_meta, c_reset);\n \t\telse\n-\t\t\tdump_quoted_path(\"+++ b/\", elem->path, c_meta, c_reset);\n+\t\t\tdump_quoted_path(\"+++ \", opt->b_prefix, elem->path,\n+\t\t\t                 c_meta, c_reset);\n \t\tdump_sline(sline, cnt, num_parent, DIFF_OPT_TST(opt, COLOR_DIFF));\n \t}\n \tfree(result);\n-- \n1.5.3.7.1315.g1b8e7\n"},{"id":"64113","messageId":"7vodcdkl82.fsf@gitster.siamese.dyndns.org","threadId":"11402","inReplyTo":"477109A5.9040000@gmail.com","subject":"Re: [PATCH] combine-diff: use diff_opts->a_prefix","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-27T00:57:49Z","receivedAt":"2007-12-27T00:57:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Salikh Zakirov <salikh@gmail.com> writes:\n\n> The introduction of configurable dir prefix for diff headers in commit\n> eab9a40b 'Teach diff machinery to display other prefixes than \"a/\" and \"b/\"'\n> missed combined diff generation.\n>\n> Signed-off-by: Salikh Zakirov <salikh@gmail.com>\n> ---\n>\n> I realize that this fix is ugly, so I am all ears for a suggestion\n> of a better fix.\n\nIt is not so ugly, but I think the original code is broken wrt\nits calling of quote_c_style().  It will output \"a/\" literally\nand then would spit out the path with quoting.  IOW, you would\nget something like:\n\n\t--- a/\"foo\\tbar\"\n        +++ b/\"foo\\tbar\"\n\nwhen it should show:\n\n\t--- \"a/foo\\tbar\"\n        +++ \"b/foo\\tbar\"\n\nIncidentally, I just noticed that diff.c::emit_rewrite_diff()\nhas the same bug.\n\nHere is a fix to combine-diff.c\n\n-- >8 -- \n[PATCH] combine-diff: Fix path quoting\n\nEarlier when showing combined diff, the filenames on the ---/+++\nheader lines were quoted incorrectly.  a/ (or b/) prefix was\noutput literally and then the path was output, with c-quoting.\n\nThis fixes the quoting logic, and while at it, adjusts the code\nto use the customizable prefix (a_prefix and b_prefix)\nintroduced recently.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n combine-diff.c |   41 +++++++++++++++++++++++++++++++----------\n 1 files changed, 31 insertions(+), 10 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex e22db89..7d71033 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -646,12 +646,28 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,\n \tsline->p_lno[i] = sline->p_lno[j];\n }\n \n-static void dump_quoted_path(const char *prefix, const char *path,\n+static void dump_quoted_path(const char *head,\n+\t\t\t     const char *prefix,\n+\t\t\t     const char *path,\n \t\t\t     const char *c_meta, const char *c_reset)\n {\n-\tprintf(\"%s%s\", c_meta, prefix);\n-\tquote_c_style(path, NULL, stdout, 0);\n-\tprintf(\"%s\\n\", c_reset);\n+\tstatic struct strbuf buf = STRBUF_INIT;\n+\n+\tstrbuf_reset(&buf);\n+\tstrbuf_addstr(&buf, c_meta);\n+\tstrbuf_addstr(&buf, head);\n+\tif (quote_c_style(prefix, NULL, NULL, 0) ||\n+\t    quote_c_style(path, NULL, NULL, 0)) {\n+\t\tstrbuf_addch(&buf, '\"');\n+\t\tquote_c_style(prefix, &buf, NULL, 1);\n+\t\tquote_c_style(path, &buf, NULL, 1);\n+\t\tstrbuf_addch(&buf, '\"');\n+\t} else {\n+\t\tstrbuf_addstr(&buf, prefix);\n+\t\tstrbuf_addstr(&buf, path);\n+\t}\n+\tstrbuf_addstr(&buf, c_reset);\n+\tputs(buf.buf);\n }\n \n static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n@@ -793,7 +809,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\tif (rev->loginfo && !rev->no_commit_id)\n \t\t\tshow_log(rev, opt->msg_sep);\n \t\tdump_quoted_path(dense ? \"diff --cc \" : \"diff --combined \",\n-\t\t\t\t elem->path, c_meta, c_reset);\n+\t\t\t\t \"\", elem->path, c_meta, c_reset);\n \t\tprintf(\"%sindex \", c_meta);\n \t\tfor (i = 0; i < num_parent; i++) {\n \t\t\tabb = find_unique_abbrev(elem->parent[i].sha1,\n@@ -829,14 +845,19 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\t\tprintf(\"%s\\n\", c_reset);\n \t\t}\n \t\tif (added)\n-\t\t\tdump_quoted_path(\"--- /dev/\", \"null\", c_meta, c_reset);\n+\t\t\tdump_quoted_path(\"--- \", \"\", \"/dev/null\",\n+\t\t\t\t\t c_meta, c_reset);\n \t\telse\n-\t\t\tdump_quoted_path(\"--- a/\", elem->path, c_meta, c_reset);\n+\t\t\tdump_quoted_path(\"--- \", opt->a_prefix, elem->path,\n+\t\t\t\t\t c_meta, c_reset);\n \t\tif (deleted)\n-\t\t\tdump_quoted_path(\"+++ /dev/\", \"null\", c_meta, c_reset);\n+\t\t\tdump_quoted_path(\"+++ \", \"\", \"/dev/null\",\n+\t\t\t\t\t c_meta, c_reset);\n \t\telse\n-\t\t\tdump_quoted_path(\"+++ b/\", elem->path, c_meta, c_reset);\n-\t\tdump_sline(sline, cnt, num_parent, DIFF_OPT_TST(opt, COLOR_DIFF));\n+\t\t\tdump_quoted_path(\"+++ \", opt->b_prefix, elem->path,\n+\t\t\t\t\t c_meta, c_reset);\n+\t\tdump_sline(sline, cnt, num_parent,\n+\t\t\t   DIFF_OPT_TST(opt, COLOR_DIFF));\n \t}\n \tfree(result);\n \n-- \n1.5.4.rc1.23.g3a969\n"},{"id":"64114","messageId":"7vir2lkk80.fsf_-_@gitster.siamese.dyndns.org","threadId":"11402","inReplyTo":"7vodcdkl82.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] Fix rewrite_diff() name quoting.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-27T01:19:27Z","receivedAt":"2007-12-27T01:19:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This moves the logic to quote two paths (prefix + path) in\nC-style introduced in the previous commit from the\ndump_quoted_path() in combine-diff.c to quote.c, and uses it to\nfix rewrite_diff() that never C-quoted the pathnames correctly.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n combine-diff.c |   11 +----------\n diff.c         |   12 +++++++++---\n quote.c        |   16 ++++++++++++++++\n quote.h        |    1 +\n 4 files changed, 27 insertions(+), 13 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 7d71033..0e19cba 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -656,16 +656,7 @@ static void dump_quoted_path(const char *head,\n \tstrbuf_reset(&buf);\n \tstrbuf_addstr(&buf, c_meta);\n \tstrbuf_addstr(&buf, head);\n-\tif (quote_c_style(prefix, NULL, NULL, 0) ||\n-\t    quote_c_style(path, NULL, NULL, 0)) {\n-\t\tstrbuf_addch(&buf, '\"');\n-\t\tquote_c_style(prefix, &buf, NULL, 1);\n-\t\tquote_c_style(path, &buf, NULL, 1);\n-\t\tstrbuf_addch(&buf, '\"');\n-\t} else {\n-\t\tstrbuf_addstr(&buf, prefix);\n-\t\tstrbuf_addstr(&buf, path);\n-\t}\n+\tquote_two_c_style(&buf, prefix, path, 0);\n \tstrbuf_addstr(&buf, c_reset);\n \tputs(buf.buf);\n }\ndiff --git a/diff.c b/diff.c\nindex 61fd492..5bdc111 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -300,19 +300,25 @@ static void emit_rewrite_diff(const char *name_a,\n \tconst char *old = diff_get_color(color_diff, DIFF_FILE_OLD);\n \tconst char *new = diff_get_color(color_diff, DIFF_FILE_NEW);\n \tconst char *reset = diff_get_color(color_diff, DIFF_RESET);\n+\tstatic struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;\n \n \tname_a += (*name_a == '/');\n \tname_b += (*name_b == '/');\n \tname_a_tab = strchr(name_a, ' ') ? \"\\t\" : \"\";\n \tname_b_tab = strchr(name_b, ' ') ? \"\\t\" : \"\";\n \n+\tstrbuf_reset(&a_name);\n+\tstrbuf_reset(&b_name);\n+\tquote_two_c_style(&a_name, o->a_prefix, name_a, 0);\n+\tquote_two_c_style(&b_name, o->b_prefix, name_b, 0);\n+\n \tdiff_populate_filespec(one, 0);\n \tdiff_populate_filespec(two, 0);\n \tlc_a = count_lines(one->data, one->size);\n \tlc_b = count_lines(two->data, two->size);\n-\tprintf(\"%s--- %s%s%s%s\\n%s+++ %s%s%s%s\\n%s@@ -\",\n-\t       metainfo, o->a_prefix, name_a, name_a_tab, reset,\n-\t       metainfo, o->b_prefix, name_b, name_b_tab, reset, fraginfo);\n+\tprintf(\"%s--- %s%s%s\\n%s+++ %s%s%s\\n%s@@ -\",\n+\t       metainfo, a_name.buf, name_a_tab, reset,\n+\t       metainfo, b_name.buf, name_b_tab, reset, fraginfo);\n \tprint_line_count(lc_a);\n \tprintf(\" +\");\n \tprint_line_count(lc_b);\ndiff --git a/quote.c b/quote.c\nindex 6986b44..d061626 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -213,6 +213,22 @@ size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, int nodq)\n \treturn quote_c_style_counted(name, -1, sb, fp, nodq);\n }\n \n+void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path, int nodq)\n+{\n+\tif (quote_c_style(prefix, NULL, NULL, 0) ||\n+\t    quote_c_style(path, NULL, NULL, 0)) {\n+\t\tif (!nodq)\n+\t\t\tstrbuf_addch(sb, '\"');\n+\t\tquote_c_style(prefix, sb, NULL, 1);\n+\t\tquote_c_style(path, sb, NULL, 1);\n+\t\tif (!nodq)\n+\t\t\tstrbuf_addch(sb, '\"');\n+\t} else {\n+\t\tstrbuf_addstr(sb, prefix);\n+\t\tstrbuf_addstr(sb, path);\n+\t}\n+}\n+\n void write_name_quoted(const char *name, FILE *fp, int terminator)\n {\n \tif (terminator) {\ndiff --git a/quote.h b/quote.h\nindex ab7596f..4da110e 100644\n--- a/quote.h\n+++ b/quote.h\n@@ -41,6 +41,7 @@ extern char *sq_dequote(char *);\n \n extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);\n extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);\n+extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);\n \n extern void write_name_quoted(const char *name, FILE *, int terminator);\n extern void write_name_quotedpfx(const char *pfx, size_t pfxlen,\n-- \n1.5.4.rc1.23.g3a969\n"}]}