diff options
author | Junio C Hamano <gitster@pobox.com> | 2007-12-26 17:13:36 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-12-26 17:13:36 -0800 |
commit | d56250911f4ec074048f4edb34551eaf384172cc (patch) | |
tree | 8978a2314f00add8f84a9164ba69da2fb70c9aeb | |
parent | 462a15bc82e6adbcb8db5fcc4791ec70a026aa4b (diff) | |
download | git-d56250911f4ec074048f4edb34551eaf384172cc.tar.gz |
Fix rewrite_diff() name quoting.
This moves the logic to quote two paths (prefix + path) in
C-style introduced in the previous commit from the
dump_quoted_path() in combine-diff.c to quote.c, and uses it to
fix rewrite_diff() that never C-quoted the pathnames correctly.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | combine-diff.c | 11 | ||||
-rw-r--r-- | diff.c | 12 | ||||
-rw-r--r-- | quote.c | 16 | ||||
-rw-r--r-- | quote.h | 1 |
4 files changed, 27 insertions, 13 deletions
diff --git a/combine-diff.c b/combine-diff.c index 7d710334ff..0e19cbaacc 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -656,16 +656,7 @@ static void dump_quoted_path(const char *head, strbuf_reset(&buf); strbuf_addstr(&buf, c_meta); strbuf_addstr(&buf, head); - if (quote_c_style(prefix, NULL, NULL, 0) || - quote_c_style(path, NULL, NULL, 0)) { - strbuf_addch(&buf, '"'); - quote_c_style(prefix, &buf, NULL, 1); - quote_c_style(path, &buf, NULL, 1); - strbuf_addch(&buf, '"'); - } else { - strbuf_addstr(&buf, prefix); - strbuf_addstr(&buf, path); - } + quote_two_c_style(&buf, prefix, path, 0); strbuf_addstr(&buf, c_reset); puts(buf.buf); } @@ -300,19 +300,25 @@ static void emit_rewrite_diff(const char *name_a, const char *old = diff_get_color(color_diff, DIFF_FILE_OLD); const char *new = diff_get_color(color_diff, DIFF_FILE_NEW); const char *reset = diff_get_color(color_diff, DIFF_RESET); + static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT; name_a += (*name_a == '/'); name_b += (*name_b == '/'); name_a_tab = strchr(name_a, ' ') ? "\t" : ""; name_b_tab = strchr(name_b, ' ') ? "\t" : ""; + strbuf_reset(&a_name); + strbuf_reset(&b_name); + quote_two_c_style(&a_name, o->a_prefix, name_a, 0); + quote_two_c_style(&b_name, o->b_prefix, name_b, 0); + diff_populate_filespec(one, 0); diff_populate_filespec(two, 0); lc_a = count_lines(one->data, one->size); lc_b = count_lines(two->data, two->size); - printf("%s--- %s%s%s%s\n%s+++ %s%s%s%s\n%s@@ -", - metainfo, o->a_prefix, name_a, name_a_tab, reset, - metainfo, o->b_prefix, name_b, name_b_tab, reset, fraginfo); + printf("%s--- %s%s%s\n%s+++ %s%s%s\n%s@@ -", + metainfo, a_name.buf, name_a_tab, reset, + metainfo, b_name.buf, name_b_tab, reset, fraginfo); print_line_count(lc_a); printf(" +"); print_line_count(lc_b); @@ -213,6 +213,22 @@ size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, int nodq) return quote_c_style_counted(name, -1, sb, fp, nodq); } +void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path, int nodq) +{ + if (quote_c_style(prefix, NULL, NULL, 0) || + quote_c_style(path, NULL, NULL, 0)) { + if (!nodq) + strbuf_addch(sb, '"'); + quote_c_style(prefix, sb, NULL, 1); + quote_c_style(path, sb, NULL, 1); + if (!nodq) + strbuf_addch(sb, '"'); + } else { + strbuf_addstr(sb, prefix); + strbuf_addstr(sb, path); + } +} + void write_name_quoted(const char *name, FILE *fp, int terminator) { if (terminator) { @@ -41,6 +41,7 @@ extern char *sq_dequote(char *); extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp); extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq); +extern void quote_two_c_style(struct strbuf *, const char *, const char *, int); extern void write_name_quoted(const char *name, FILE *, int terminator); extern void write_name_quotedpfx(const char *pfx, size_t pfxlen, |