diff.c: use diff_line_prefix() where applicable
Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f192223447
commit
30997bb8f1
115
diff.c
115
diff.c
@ -402,12 +402,7 @@ static void emit_line_0(struct diff_options *o, const char *set, const char *res
|
|||||||
int nofirst;
|
int nofirst;
|
||||||
FILE *file = o->file;
|
FILE *file = o->file;
|
||||||
|
|
||||||
if (o->output_prefix) {
|
fputs(diff_line_prefix(o), file);
|
||||||
struct strbuf *msg = NULL;
|
|
||||||
msg = o->output_prefix(o, o->output_prefix_data);
|
|
||||||
assert(msg);
|
|
||||||
fwrite(msg->buf, msg->len, 1, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
has_trailing_newline = (first == '\n');
|
has_trailing_newline = (first == '\n');
|
||||||
@ -625,13 +620,7 @@ static void emit_rewrite_diff(const char *name_a,
|
|||||||
char *data_one, *data_two;
|
char *data_one, *data_two;
|
||||||
size_t size_one, size_two;
|
size_t size_one, size_two;
|
||||||
struct emit_callback ecbdata;
|
struct emit_callback ecbdata;
|
||||||
char *line_prefix = "";
|
const char *line_prefix = diff_line_prefix(o);
|
||||||
struct strbuf *msgbuf;
|
|
||||||
|
|
||||||
if (o && o->output_prefix) {
|
|
||||||
msgbuf = o->output_prefix(o, o->output_prefix_data);
|
|
||||||
line_prefix = msgbuf->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (diff_mnemonic_prefix && DIFF_OPT_TST(o, REVERSE_DIFF)) {
|
if (diff_mnemonic_prefix && DIFF_OPT_TST(o, REVERSE_DIFF)) {
|
||||||
a_prefix = o->b_prefix;
|
a_prefix = o->b_prefix;
|
||||||
@ -827,18 +816,14 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
|
|||||||
int minus_first, minus_len, plus_first, plus_len;
|
int minus_first, minus_len, plus_first, plus_len;
|
||||||
const char *minus_begin, *minus_end, *plus_begin, *plus_end;
|
const char *minus_begin, *minus_end, *plus_begin, *plus_end;
|
||||||
struct diff_options *opt = diff_words->opt;
|
struct diff_options *opt = diff_words->opt;
|
||||||
struct strbuf *msgbuf;
|
const char *line_prefix;
|
||||||
char *line_prefix = "";
|
|
||||||
|
|
||||||
if (line[0] != '@' || parse_hunk_header(line, len,
|
if (line[0] != '@' || parse_hunk_header(line, len,
|
||||||
&minus_first, &minus_len, &plus_first, &plus_len))
|
&minus_first, &minus_len, &plus_first, &plus_len))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(opt);
|
assert(opt);
|
||||||
if (opt->output_prefix) {
|
line_prefix = diff_line_prefix(opt);
|
||||||
msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
|
|
||||||
line_prefix = msgbuf->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* POSIX requires that first be decremented by one if len == 0... */
|
/* POSIX requires that first be decremented by one if len == 0... */
|
||||||
if (minus_len) {
|
if (minus_len) {
|
||||||
@ -962,14 +947,10 @@ static void diff_words_show(struct diff_words_data *diff_words)
|
|||||||
struct diff_words_style *style = diff_words->style;
|
struct diff_words_style *style = diff_words->style;
|
||||||
|
|
||||||
struct diff_options *opt = diff_words->opt;
|
struct diff_options *opt = diff_words->opt;
|
||||||
struct strbuf *msgbuf;
|
const char *line_prefix;
|
||||||
char *line_prefix = "";
|
|
||||||
|
|
||||||
assert(opt);
|
assert(opt);
|
||||||
if (opt->output_prefix) {
|
line_prefix = diff_line_prefix(opt);
|
||||||
msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
|
|
||||||
line_prefix = msgbuf->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* special case: only removal */
|
/* special case: only removal */
|
||||||
if (!diff_words->plus.text.size) {
|
if (!diff_words->plus.text.size) {
|
||||||
@ -1155,13 +1136,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
|
|||||||
const char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);
|
const char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);
|
||||||
const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
|
const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
|
||||||
struct diff_options *o = ecbdata->opt;
|
struct diff_options *o = ecbdata->opt;
|
||||||
char *line_prefix = "";
|
const char *line_prefix = diff_line_prefix(o);
|
||||||
struct strbuf *msgbuf;
|
|
||||||
|
|
||||||
if (o && o->output_prefix) {
|
|
||||||
msgbuf = o->output_prefix(o, o->output_prefix_data);
|
|
||||||
line_prefix = msgbuf->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecbdata->header) {
|
if (ecbdata->header) {
|
||||||
fprintf(ecbdata->opt->file, "%s", ecbdata->header->buf);
|
fprintf(ecbdata->opt->file, "%s", ecbdata->header->buf);
|
||||||
@ -1485,16 +1460,11 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
|
|||||||
const char *reset, *add_c, *del_c;
|
const char *reset, *add_c, *del_c;
|
||||||
const char *line_prefix = "";
|
const char *line_prefix = "";
|
||||||
int extra_shown = 0;
|
int extra_shown = 0;
|
||||||
struct strbuf *msg = NULL;
|
|
||||||
|
|
||||||
if (data->nr == 0)
|
if (data->nr == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (options->output_prefix) {
|
line_prefix = diff_line_prefix(options);
|
||||||
msg = options->output_prefix(options, options->output_prefix_data);
|
|
||||||
line_prefix = msg->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
count = options->stat_count ? options->stat_count : data->nr;
|
count = options->stat_count ? options->stat_count : data->nr;
|
||||||
|
|
||||||
reset = diff_get_color_opt(options, DIFF_RESET);
|
reset = diff_get_color_opt(options, DIFF_RESET);
|
||||||
@ -1746,12 +1716,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
|
|||||||
dels += deleted;
|
dels += deleted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options->output_prefix) {
|
fprintf(options->file, "%s", diff_line_prefix(options));
|
||||||
struct strbuf *msg = NULL;
|
|
||||||
msg = options->output_prefix(options,
|
|
||||||
options->output_prefix_data);
|
|
||||||
fprintf(options->file, "%s", msg->buf);
|
|
||||||
}
|
|
||||||
print_stat_summary(options->file, total_files, adds, dels);
|
print_stat_summary(options->file, total_files, adds, dels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1765,12 +1730,7 @@ static void show_numstat(struct diffstat_t *data, struct diff_options *options)
|
|||||||
for (i = 0; i < data->nr; i++) {
|
for (i = 0; i < data->nr; i++) {
|
||||||
struct diffstat_file *file = data->files[i];
|
struct diffstat_file *file = data->files[i];
|
||||||
|
|
||||||
if (options->output_prefix) {
|
fprintf(options->file, "%s", diff_line_prefix(options));
|
||||||
struct strbuf *msg = NULL;
|
|
||||||
msg = options->output_prefix(options,
|
|
||||||
options->output_prefix_data);
|
|
||||||
fprintf(options->file, "%s", msg->buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file->is_binary)
|
if (file->is_binary)
|
||||||
fprintf(options->file, "-\t-\t");
|
fprintf(options->file, "-\t-\t");
|
||||||
@ -1812,13 +1772,7 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
|
|||||||
{
|
{
|
||||||
unsigned long this_dir = 0;
|
unsigned long this_dir = 0;
|
||||||
unsigned int sources = 0;
|
unsigned int sources = 0;
|
||||||
const char *line_prefix = "";
|
const char *line_prefix = diff_line_prefix(opt);
|
||||||
struct strbuf *msg = NULL;
|
|
||||||
|
|
||||||
if (opt->output_prefix) {
|
|
||||||
msg = opt->output_prefix(opt, opt->output_prefix_data);
|
|
||||||
line_prefix = msg->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (dir->nr) {
|
while (dir->nr) {
|
||||||
struct dirstat_file *f = dir->files;
|
struct dirstat_file *f = dir->files;
|
||||||
@ -2068,15 +2022,10 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
|
|||||||
const char *reset = diff_get_color(data->o->use_color, DIFF_RESET);
|
const char *reset = diff_get_color(data->o->use_color, DIFF_RESET);
|
||||||
const char *set = diff_get_color(data->o->use_color, DIFF_FILE_NEW);
|
const char *set = diff_get_color(data->o->use_color, DIFF_FILE_NEW);
|
||||||
char *err;
|
char *err;
|
||||||
char *line_prefix = "";
|
const char *line_prefix;
|
||||||
struct strbuf *msgbuf;
|
|
||||||
|
|
||||||
assert(data->o);
|
assert(data->o);
|
||||||
if (data->o->output_prefix) {
|
line_prefix = diff_line_prefix(data->o);
|
||||||
msgbuf = data->o->output_prefix(data->o,
|
|
||||||
data->o->output_prefix_data);
|
|
||||||
line_prefix = msgbuf->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line[0] == '+') {
|
if (line[0] == '+') {
|
||||||
unsigned bad;
|
unsigned bad;
|
||||||
@ -2263,13 +2212,7 @@ static void builtin_diff(const char *name_a,
|
|||||||
struct userdiff_driver *textconv_one = NULL;
|
struct userdiff_driver *textconv_one = NULL;
|
||||||
struct userdiff_driver *textconv_two = NULL;
|
struct userdiff_driver *textconv_two = NULL;
|
||||||
struct strbuf header = STRBUF_INIT;
|
struct strbuf header = STRBUF_INIT;
|
||||||
struct strbuf *msgbuf;
|
const char *line_prefix = diff_line_prefix(o);
|
||||||
char *line_prefix = "";
|
|
||||||
|
|
||||||
if (o->output_prefix) {
|
|
||||||
msgbuf = o->output_prefix(o, o->output_prefix_data);
|
|
||||||
line_prefix = msgbuf->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DIFF_OPT_TST(o, SUBMODULE_LOG) &&
|
if (DIFF_OPT_TST(o, SUBMODULE_LOG) &&
|
||||||
(!one->mode || S_ISGITLINK(one->mode)) &&
|
(!one->mode || S_ISGITLINK(one->mode)) &&
|
||||||
@ -2968,14 +2911,9 @@ static void fill_metainfo(struct strbuf *msg,
|
|||||||
{
|
{
|
||||||
const char *set = diff_get_color(use_color, DIFF_METAINFO);
|
const char *set = diff_get_color(use_color, DIFF_METAINFO);
|
||||||
const char *reset = diff_get_color(use_color, DIFF_RESET);
|
const char *reset = diff_get_color(use_color, DIFF_RESET);
|
||||||
struct strbuf *msgbuf;
|
const char *line_prefix = diff_line_prefix(o);
|
||||||
char *line_prefix = "";
|
|
||||||
|
|
||||||
*must_show_header = 1;
|
*must_show_header = 1;
|
||||||
if (o->output_prefix) {
|
|
||||||
msgbuf = o->output_prefix(o, o->output_prefix_data);
|
|
||||||
line_prefix = msgbuf->buf;
|
|
||||||
}
|
|
||||||
strbuf_init(msg, PATH_MAX * 2 + 300);
|
strbuf_init(msg, PATH_MAX * 2 + 300);
|
||||||
switch (p->status) {
|
switch (p->status) {
|
||||||
case DIFF_STATUS_COPIED:
|
case DIFF_STATUS_COPIED:
|
||||||
@ -3910,12 +3848,8 @@ static void diff_flush_raw(struct diff_filepair *p, struct diff_options *opt)
|
|||||||
{
|
{
|
||||||
int line_termination = opt->line_termination;
|
int line_termination = opt->line_termination;
|
||||||
int inter_name_termination = line_termination ? '\t' : '\0';
|
int inter_name_termination = line_termination ? '\t' : '\0';
|
||||||
if (opt->output_prefix) {
|
|
||||||
struct strbuf *msg = NULL;
|
|
||||||
msg = opt->output_prefix(opt, opt->output_prefix_data);
|
|
||||||
fprintf(opt->file, "%s", msg->buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fprintf(opt->file, "%s", diff_line_prefix(opt));
|
||||||
if (!(opt->output_format & DIFF_FORMAT_NAME_STATUS)) {
|
if (!(opt->output_format & DIFF_FORMAT_NAME_STATUS)) {
|
||||||
fprintf(opt->file, ":%06o %06o %s ", p->one->mode, p->two->mode,
|
fprintf(opt->file, ":%06o %06o %s ", p->one->mode, p->two->mode,
|
||||||
diff_unique_abbrev(p->one->sha1, opt->abbrev));
|
diff_unique_abbrev(p->one->sha1, opt->abbrev));
|
||||||
@ -4185,12 +4119,7 @@ static void show_rename_copy(FILE *file, const char *renamecopy, struct diff_fil
|
|||||||
static void diff_summary(struct diff_options *opt, struct diff_filepair *p)
|
static void diff_summary(struct diff_options *opt, struct diff_filepair *p)
|
||||||
{
|
{
|
||||||
FILE *file = opt->file;
|
FILE *file = opt->file;
|
||||||
char *line_prefix = "";
|
const char *line_prefix = diff_line_prefix(opt);
|
||||||
|
|
||||||
if (opt->output_prefix) {
|
|
||||||
struct strbuf *buf = opt->output_prefix(opt, opt->output_prefix_data);
|
|
||||||
line_prefix = buf->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(p->status) {
|
switch(p->status) {
|
||||||
case DIFF_STATUS_DELETED:
|
case DIFF_STATUS_DELETED:
|
||||||
@ -4491,13 +4420,9 @@ void diff_flush(struct diff_options *options)
|
|||||||
|
|
||||||
if (output_format & DIFF_FORMAT_PATCH) {
|
if (output_format & DIFF_FORMAT_PATCH) {
|
||||||
if (separator) {
|
if (separator) {
|
||||||
if (options->output_prefix) {
|
fprintf(options->file, "%s%c",
|
||||||
struct strbuf *msg = NULL;
|
diff_line_prefix(options),
|
||||||
msg = options->output_prefix(options,
|
options->line_termination);
|
||||||
options->output_prefix_data);
|
|
||||||
fwrite(msg->buf, msg->len, 1, options->file);
|
|
||||||
}
|
|
||||||
putc(options->line_termination, options->file);
|
|
||||||
if (options->stat_sep) {
|
if (options->stat_sep) {
|
||||||
/* attach patch instead of inline */
|
/* attach patch instead of inline */
|
||||||
fputs(options->stat_sep, options->file);
|
fputs(options->stat_sep, options->file);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user