Skip to content

Commit 146fdb0

Browse files
stefanbellergitster
authored andcommitted
diff.c: emit_diff_symbol learns about DIFF_SYMBOL_SUMMARY
Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30b7e1e commit 146fdb0

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

diff.c

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ enum diff_symbol {
572572
DIFF_SYMBOL_STATS_LINE,
573573
DIFF_SYMBOL_WORD_DIFF,
574574
DIFF_SYMBOL_STAT_SEP,
575+
DIFF_SYMBOL_SUMMARY,
575576
DIFF_SYMBOL_SUBMODULE_ADD,
576577
DIFF_SYMBOL_SUBMODULE_DEL,
577578
DIFF_SYMBOL_SUBMODULE_UNTRACKED,
@@ -648,6 +649,7 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
648649
case DIFF_SYMBOL_SUBMODULE_ERROR:
649650
case DIFF_SYMBOL_SUBMODULE_PIPETHROUGH:
650651
case DIFF_SYMBOL_STATS_SUMMARY_INSERTS_DELETES:
652+
case DIFF_SYMBOL_SUMMARY:
651653
case DIFF_SYMBOL_STATS_LINE:
652654
case DIFF_SYMBOL_BINARY_DIFF_BODY:
653655
case DIFF_SYMBOL_CONTEXT_FRAGINFO:
@@ -4717,67 +4719,76 @@ static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt)
47174719
}
47184720
}
47194721

4720-
static void show_file_mode_name(FILE *file, const char *newdelete, struct diff_filespec *fs)
4722+
static void show_file_mode_name(struct diff_options *opt, const char *newdelete, struct diff_filespec *fs)
47214723
{
4724+
struct strbuf sb = STRBUF_INIT;
47224725
if (fs->mode)
4723-
fprintf(file, " %s mode %06o ", newdelete, fs->mode);
4726+
strbuf_addf(&sb, " %s mode %06o ", newdelete, fs->mode);
47244727
else
4725-
fprintf(file, " %s ", newdelete);
4726-
write_name_quoted(fs->path, file, '\n');
4727-
}
4728+
strbuf_addf(&sb, " %s ", newdelete);
47284729

4730+
quote_c_style(fs->path, &sb, NULL, 0);
4731+
strbuf_addch(&sb, '\n');
4732+
emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
4733+
sb.buf, sb.len, 0);
4734+
strbuf_release(&sb);
4735+
}
47294736

4730-
static void show_mode_change(FILE *file, struct diff_filepair *p, int show_name,
4731-
const char *line_prefix)
4737+
static void show_mode_change(struct diff_options *opt, struct diff_filepair *p,
4738+
int show_name)
47324739
{
47334740
if (p->one->mode && p->two->mode && p->one->mode != p->two->mode) {
4734-
fprintf(file, "%s mode change %06o => %06o%c", line_prefix, p->one->mode,
4735-
p->two->mode, show_name ? ' ' : '\n');
4741+
struct strbuf sb = STRBUF_INIT;
4742+
strbuf_addf(&sb, " mode change %06o => %06o",
4743+
p->one->mode, p->two->mode);
47364744
if (show_name) {
4737-
write_name_quoted(p->two->path, file, '\n');
4745+
strbuf_addch(&sb, ' ');
4746+
quote_c_style(p->two->path, &sb, NULL, 0);
47384747
}
4748+
emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
4749+
sb.buf, sb.len, 0);
4750+
strbuf_release(&sb);
47394751
}
47404752
}
47414753

4742-
static void show_rename_copy(FILE *file, const char *renamecopy, struct diff_filepair *p,
4743-
const char *line_prefix)
4754+
static void show_rename_copy(struct diff_options *opt, const char *renamecopy,
4755+
struct diff_filepair *p)
47444756
{
4757+
struct strbuf sb = STRBUF_INIT;
47454758
char *names = pprint_rename(p->one->path, p->two->path);
4746-
4747-
fprintf(file, " %s %s (%d%%)\n", renamecopy, names, similarity_index(p));
4759+
strbuf_addf(&sb, " %s %s (%d%%)\n",
4760+
renamecopy, names, similarity_index(p));
47484761
free(names);
4749-
show_mode_change(file, p, 0, line_prefix);
4762+
emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
4763+
sb.buf, sb.len, 0);
4764+
show_mode_change(opt, p, 0);
47504765
}
47514766

47524767
static void diff_summary(struct diff_options *opt, struct diff_filepair *p)
47534768
{
4754-
FILE *file = opt->file;
4755-
const char *line_prefix = diff_line_prefix(opt);
4756-
47574769
switch(p->status) {
47584770
case DIFF_STATUS_DELETED:
4759-
fputs(line_prefix, file);
4760-
show_file_mode_name(file, "delete", p->one);
4771+
show_file_mode_name(opt, "delete", p->one);
47614772
break;
47624773
case DIFF_STATUS_ADDED:
4763-
fputs(line_prefix, file);
4764-
show_file_mode_name(file, "create", p->two);
4774+
show_file_mode_name(opt, "create", p->two);
47654775
break;
47664776
case DIFF_STATUS_COPIED:
4767-
fputs(line_prefix, file);
4768-
show_rename_copy(file, "copy", p, line_prefix);
4777+
show_rename_copy(opt, "copy", p);
47694778
break;
47704779
case DIFF_STATUS_RENAMED:
4771-
fputs(line_prefix, file);
4772-
show_rename_copy(file, "rename", p, line_prefix);
4780+
show_rename_copy(opt, "rename", p);
47734781
break;
47744782
default:
47754783
if (p->score) {
4776-
fprintf(file, "%s rewrite ", line_prefix);
4777-
write_name_quoted(p->two->path, file, ' ');
4778-
fprintf(file, "(%d%%)\n", similarity_index(p));
4784+
struct strbuf sb = STRBUF_INIT;
4785+
strbuf_addstr(&sb, " rewrite ");
4786+
quote_c_style(p->two->path, &sb, NULL, 0);
4787+
strbuf_addf(&sb, " (%d%%)\n", similarity_index(p));
4788+
emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
4789+
sb.buf, sb.len, 0);
47794790
}
4780-
show_mode_change(file, p, !p->score, line_prefix);
4791+
show_mode_change(opt, p, !p->score);
47814792
break;
47824793
}
47834794
}

0 commit comments

Comments
 (0)