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>
Junio C Hamano committed
Dec 26, 2007 at 17:13 UTC
d56250911f4ec074048f4edb34551eaf384172cc
4 files changed
+27
-13
combine-diff.c
+1
-10
@@ -656,16 +656,7 @@ static void dump_quoted_path(const char *head,
656
strbuf_reset(&buf);
657
strbuf_addstr(&buf, c_meta);
658
strbuf_addstr(&buf, head);
659
- if (quote_c_style(prefix, NULL, NULL, 0) ||
660
- quote_c_style(path, NULL, NULL, 0)) {
661
- strbuf_addch(&buf, '"');
662
- quote_c_style(prefix, &buf, NULL, 1);
663
- quote_c_style(path, &buf, NULL, 1);
664
- strbuf_addch(&buf, '"');
665
- } else {
666
- strbuf_addstr(&buf, prefix);
667
- strbuf_addstr(&buf, path);
668
- }
659
+ quote_two_c_style(&buf, prefix, path, 0);
660
strbuf_addstr(&buf, c_reset);
661
puts(buf.buf);
662
}
diff.c
+9
-3
@@ -300,19 +300,25 @@ static void emit_rewrite_diff(const char *name_a,
300
const char *old = diff_get_color(color_diff, DIFF_FILE_OLD);
301
const char *new = diff_get_color(color_diff, DIFF_FILE_NEW);
302
const char *reset = diff_get_color(color_diff, DIFF_RESET);
303
+ static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;
304
305
name_a += (*name_a == '/');
306
name_b += (*name_b == '/');
307
name_a_tab = strchr(name_a, ' ') ? "\t" : "";
308
name_b_tab = strchr(name_b, ' ') ? "\t" : "";
309
310
+ strbuf_reset(&a_name);
311
+ strbuf_reset(&b_name);
312
+ quote_two_c_style(&a_name, o->a_prefix, name_a, 0);
313
+ quote_two_c_style(&b_name, o->b_prefix, name_b, 0);
314
+
315
diff_populate_filespec(one, 0);
316
diff_populate_filespec(two, 0);
317
lc_a = count_lines(one->data, one->size);
318
lc_b = count_lines(two->data, two->size);
313
- printf("%s--- %s%s%s%s\n%s+++ %s%s%s%s\n%s@@ -",
314
- metainfo, o->a_prefix, name_a, name_a_tab, reset,
315
- metainfo, o->b_prefix, name_b, name_b_tab, reset, fraginfo);
319
+ printf("%s--- %s%s%s\n%s+++ %s%s%s\n%s@@ -",
320
+ metainfo, a_name.buf, name_a_tab, reset,
321
+ metainfo, b_name.buf, name_b_tab, reset, fraginfo);
322
print_line_count(lc_a);
323
printf(" +");
324
print_line_count(lc_b);
quote.c
+16
@@ -213,6 +213,22 @@ size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, int nodq)
213
return quote_c_style_counted(name, -1, sb, fp, nodq);
214
}
215
216
+void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path, int nodq)
217
+{
218
+ if (quote_c_style(prefix, NULL, NULL, 0) ||
219
+ quote_c_style(path, NULL, NULL, 0)) {
220
+ if (!nodq)
221
+ strbuf_addch(sb, '"');
222
+ quote_c_style(prefix, sb, NULL, 1);
223
+ quote_c_style(path, sb, NULL, 1);
224
+ if (!nodq)
225
+ strbuf_addch(sb, '"');
226
+ } else {
227
+ strbuf_addstr(sb, prefix);
228
+ strbuf_addstr(sb, path);
229
+ }
230
+}
231
+
232
void write_name_quoted(const char *name, FILE *fp, int terminator)
233
{
234
if (terminator) {
quote.h
+1
@@ -41,6 +41,7 @@ extern char *sq_dequote(char *);
41
42
extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);
43
extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);
44
+extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);
45
46
extern void write_name_quoted(const char *name, FILE *, int terminator);
47
extern void write_name_quotedpfx(const char *pfx, size_t pfxlen,