summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 462a15b)
raw | patch | inline | side by side (parent: 462a15b)
author | Junio C Hamano <gitster@pobox.com> | |
Thu, 27 Dec 2007 01:13:36 +0000 (17:13 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 27 Dec 2007 01:13:36 +0000 (17:13 -0800) |
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>
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>
combine-diff.c | patch | blob | history | |
diff.c | patch | blob | history | |
quote.c | patch | blob | history | |
quote.h | patch | blob | history |
diff --git a/combine-diff.c b/combine-diff.c
index 7d710334ffa9ce4fa82145f4b1745d048635c475..0e19cbaacc1099fd69f7f2d9b4a17c94a327baa9 100644 (file)
--- a/combine-diff.c
+++ b/combine-diff.c
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);
}
index 61fd49236ad505abb6a62b8b014efd6a9ddbff6b..5bdc111378d61e5bdb13d1908217ab44bfc7967d 100644 (file)
--- a/diff.c
+++ b/diff.c
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);
index 6986b4420f66e1f01cd4517d35ce9adc300eaa8b..d061626c34f1e62c538db6e931c29751be4fdbcf 100644 (file)
--- a/quote.c
+++ b/quote.c
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) {
index ab7596f57b7f23899ef1bbb8d0c7ba6ec5baf12f..4da110ec01331f346705199dde709436622967cb 100644 (file)
--- a/quote.h
+++ b/quote.h
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,