Full rework of quote_c_style and write_name_quoted.
* quote_c_style works on a strbuf instead of a wild buffer. * quote_c_style is now clever enough to not add double quotes if not needed. * write_name_quoted inherits those advantages, but also take a different set of arguments. Now instead of asking for quotes or not, you pass a "terminator". If it's \0 then we assume you don't want to escape, else C escaping is performed. In any case, the terminator is also appended to the stream. It also no longer takes the prefix/prefix_len arguments, as it's seldomly used, and makes some optimizations harder. * write_name_quotedpfx is created to work like write_name_quoted and take the prefix/prefix_len arguments. Thanks to those API changes, diff.c has somehow lost weight, thanks to the removal of functions that were wrappers around the old write_name_quoted trying to give it a semantics like the new one, but performing a lot of allocations for this goal. Now we always write directly to the stream, no intermediate allocation is performed. As a side effect of the refactor in builtin-apply.c, the length of the bar graphs in diffstats are not affected anymore by the fact that the path was clipped. Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
committed by
Junio C Hamano
parent
7fb1011e61
commit
663af3422a
@ -650,10 +650,7 @@ static void dump_quoted_path(const char *prefix, const char *path,
|
||||
const char *c_meta, const char *c_reset)
|
||||
{
|
||||
printf("%s%s", c_meta, prefix);
|
||||
if (quote_c_style(path, NULL, NULL, 0))
|
||||
quote_c_style(path, NULL, stdout, 0);
|
||||
else
|
||||
printf("%s", path);
|
||||
quote_c_style(path, NULL, stdout, 0);
|
||||
printf("%s\n", c_reset);
|
||||
}
|
||||
|
||||
@ -900,16 +897,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
|
||||
putchar(inter_name_termination);
|
||||
}
|
||||
|
||||
if (line_termination) {
|
||||
if (quote_c_style(p->path, NULL, NULL, 0))
|
||||
quote_c_style(p->path, NULL, stdout, 0);
|
||||
else
|
||||
printf("%s", p->path);
|
||||
putchar(line_termination);
|
||||
}
|
||||
else {
|
||||
printf("%s%c", p->path, line_termination);
|
||||
}
|
||||
write_name_quoted(p->path, stdout, line_termination);
|
||||
}
|
||||
|
||||
void show_combined_diff(struct combine_diff_path *p,
|
||||
|
||||
Reference in New Issue
Block a user