diff.c: emit_diff_symbol learns about DIFF_SYMBOL_SUMMARY

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Stefan Beller 2017-06-29 17:07:05 -07:00 коммит произвёл Junio C Hamano
Родитель 30b7e1e7ef
Коммит 146fdb0dfe
1 изменённых файлов: 41 добавлений и 30 удалений

71
diff.c
Просмотреть файл

@ -572,6 +572,7 @@ enum diff_symbol {
DIFF_SYMBOL_STATS_LINE,
DIFF_SYMBOL_WORD_DIFF,
DIFF_SYMBOL_STAT_SEP,
DIFF_SYMBOL_SUMMARY,
DIFF_SYMBOL_SUBMODULE_ADD,
DIFF_SYMBOL_SUBMODULE_DEL,
DIFF_SYMBOL_SUBMODULE_UNTRACKED,
@ -648,6 +649,7 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
case DIFF_SYMBOL_SUBMODULE_ERROR:
case DIFF_SYMBOL_SUBMODULE_PIPETHROUGH:
case DIFF_SYMBOL_STATS_SUMMARY_INSERTS_DELETES:
case DIFF_SYMBOL_SUMMARY:
case DIFF_SYMBOL_STATS_LINE:
case DIFF_SYMBOL_BINARY_DIFF_BODY:
case DIFF_SYMBOL_CONTEXT_FRAGINFO:
@ -4717,67 +4719,76 @@ static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt)
}
}
static void show_file_mode_name(FILE *file, const char *newdelete, struct diff_filespec *fs)
static void show_file_mode_name(struct diff_options *opt, const char *newdelete, struct diff_filespec *fs)
{
struct strbuf sb = STRBUF_INIT;
if (fs->mode)
fprintf(file, " %s mode %06o ", newdelete, fs->mode);
strbuf_addf(&sb, " %s mode %06o ", newdelete, fs->mode);
else
fprintf(file, " %s ", newdelete);
write_name_quoted(fs->path, file, '\n');
strbuf_addf(&sb, " %s ", newdelete);
quote_c_style(fs->path, &sb, NULL, 0);
strbuf_addch(&sb, '\n');
emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
sb.buf, sb.len, 0);
strbuf_release(&sb);
}
static void show_mode_change(FILE *file, struct diff_filepair *p, int show_name,
const char *line_prefix)
static void show_mode_change(struct diff_options *opt, struct diff_filepair *p,
int show_name)
{
if (p->one->mode && p->two->mode && p->one->mode != p->two->mode) {
fprintf(file, "%s mode change %06o => %06o%c", line_prefix, p->one->mode,
p->two->mode, show_name ? ' ' : '\n');
struct strbuf sb = STRBUF_INIT;
strbuf_addf(&sb, " mode change %06o => %06o",
p->one->mode, p->two->mode);
if (show_name) {
write_name_quoted(p->two->path, file, '\n');
strbuf_addch(&sb, ' ');
quote_c_style(p->two->path, &sb, NULL, 0);
}
emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
sb.buf, sb.len, 0);
strbuf_release(&sb);
}
}
static void show_rename_copy(FILE *file, const char *renamecopy, struct diff_filepair *p,
const char *line_prefix)
static void show_rename_copy(struct diff_options *opt, const char *renamecopy,
struct diff_filepair *p)
{
struct strbuf sb = STRBUF_INIT;
char *names = pprint_rename(p->one->path, p->two->path);
fprintf(file, " %s %s (%d%%)\n", renamecopy, names, similarity_index(p));
strbuf_addf(&sb, " %s %s (%d%%)\n",
renamecopy, names, similarity_index(p));
free(names);
show_mode_change(file, p, 0, line_prefix);
emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
sb.buf, sb.len, 0);
show_mode_change(opt, p, 0);
}
static void diff_summary(struct diff_options *opt, struct diff_filepair *p)
{
FILE *file = opt->file;
const char *line_prefix = diff_line_prefix(opt);
switch(p->status) {
case DIFF_STATUS_DELETED:
fputs(line_prefix, file);
show_file_mode_name(file, "delete", p->one);
show_file_mode_name(opt, "delete", p->one);
break;
case DIFF_STATUS_ADDED:
fputs(line_prefix, file);
show_file_mode_name(file, "create", p->two);
show_file_mode_name(opt, "create", p->two);
break;
case DIFF_STATUS_COPIED:
fputs(line_prefix, file);
show_rename_copy(file, "copy", p, line_prefix);
show_rename_copy(opt, "copy", p);
break;
case DIFF_STATUS_RENAMED:
fputs(line_prefix, file);
show_rename_copy(file, "rename", p, line_prefix);
show_rename_copy(opt, "rename", p);
break;
default:
if (p->score) {
fprintf(file, "%s rewrite ", line_prefix);
write_name_quoted(p->two->path, file, ' ');
fprintf(file, "(%d%%)\n", similarity_index(p));
struct strbuf sb = STRBUF_INIT;
strbuf_addstr(&sb, " rewrite ");
quote_c_style(p->two->path, &sb, NULL, 0);
strbuf_addf(&sb, " (%d%%)\n", similarity_index(p));
emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
sb.buf, sb.len, 0);
}
show_mode_change(file, p, !p->score, line_prefix);
show_mode_change(opt, p, !p->score);
break;
}
}