Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
diff.c: emit_diff_symbol learns DIFF_SYMBOL_REWRITE_DIFF
author
Stefan Beller
<sbeller@google.com>
Fri, 30 Jun 2017 00:06:59 +0000
(17:06 -0700)
committer
Junio C Hamano
<gitster@pobox.com>
Fri, 30 Jun 2017 20:13:02 +0000
(13:13 -0700)
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
4acaaa7
)
diff --git
a/diff.c
b/diff.c
index 1d0f8b509ff400f28bd7717a98415b477835c942..5c428e02b6a3fc49475a0ac05cad634708276059 100644
(file)
--- a/
diff.c
+++ b/
diff.c
@@
-561,6
+561,7
@@
static void emit_line(struct diff_options *o, const char *set, const char *reset
}
enum diff_symbol {
}
enum diff_symbol {
+ DIFF_SYMBOL_REWRITE_DIFF,
DIFF_SYMBOL_BINARY_FILES,
DIFF_SYMBOL_HEADER,
DIFF_SYMBOL_FILEPAIR_PLUS,
DIFF_SYMBOL_BINARY_FILES,
DIFF_SYMBOL_HEADER,
DIFF_SYMBOL_FILEPAIR_PLUS,
@@
-615,7
+616,7
@@
static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
const char *line, int len, unsigned flags)
{
static const char *nneof = " No newline at end of file\n";
const char *line, int len, unsigned flags)
{
static const char *nneof = " No newline at end of file\n";
- const char *context, *reset, *set, *meta;
+ const char *context, *reset, *set, *meta
, *fraginfo
;
switch (s) {
case DIFF_SYMBOL_NO_LF_EOF:
context = diff_get_color_opt(o, DIFF_CONTEXT);
switch (s) {
case DIFF_SYMBOL_NO_LF_EOF:
context = diff_get_color_opt(o, DIFF_CONTEXT);
@@
-695,6
+696,11
@@
static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
case DIFF_SYMBOL_HEADER:
fprintf(o->file, "%s", line);
break;
case DIFF_SYMBOL_HEADER:
fprintf(o->file, "%s", line);
break;
+ case DIFF_SYMBOL_REWRITE_DIFF:
+ fraginfo = diff_get_color(o->use_color, DIFF_FRAGINFO);
+ reset = diff_get_color_opt(o, DIFF_RESET);
+ emit_line(o, fraginfo, reset, line, len);
+ break;
default:
die("BUG: unknown diff symbol");
}
default:
die("BUG: unknown diff symbol");
}
@@
-817,17
+823,17
@@
static void remove_tempfile(void)
}
}
}
}
-static void
print_line_count(FILE *file
, int count)
+static void
add_line_count(struct strbuf *out
, int count)
{
switch (count) {
case 0:
{
switch (count) {
case 0:
-
fprintf(file
, "0,0");
+
strbuf_addstr(out
, "0,0");
break;
case 1:
break;
case 1:
-
fprintf(file
, "1");
+
strbuf_addstr(out
, "1");
break;
default:
break;
default:
-
fprintf(file
, "1,%d", count);
+
strbuf_addf(out
, "1,%d", count);
break;
}
}
break;
}
}
@@
-866,14
+872,12
@@
static void emit_rewrite_diff(const char *name_a,
struct diff_options *o)
{
int lc_a, lc_b;
struct diff_options *o)
{
int lc_a, lc_b;
- const char *fraginfo = diff_get_color(o->use_color, DIFF_FRAGINFO);
- const char *reset = diff_get_color(o->use_color, DIFF_RESET);
static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;
const char *a_prefix, *b_prefix;
char *data_one, *data_two;
size_t size_one, size_two;
struct emit_callback ecbdata;
static struct strbuf a_name = STRBUF_INIT, b_name = STRBUF_INIT;
const char *a_prefix, *b_prefix;
char *data_one, *data_two;
size_t size_one, size_two;
struct emit_callback ecbdata;
-
const char *line_prefix = diff_line_prefix(o)
;
+
struct strbuf out = STRBUF_INIT
;
if (diff_mnemonic_prefix && DIFF_OPT_TST(o, REVERSE_DIFF)) {
a_prefix = o->b_prefix;
if (diff_mnemonic_prefix && DIFF_OPT_TST(o, REVERSE_DIFF)) {
a_prefix = o->b_prefix;
@@
-917,14
+921,17
@@
static void emit_rewrite_diff(const char *name_a,
emit_diff_symbol(o, DIFF_SYMBOL_FILEPAIR_PLUS,
b_name.buf, b_name.len, 0);
emit_diff_symbol(o, DIFF_SYMBOL_FILEPAIR_PLUS,
b_name.buf, b_name.len, 0);
-
fprintf(o->file, "%s%s@@ -", line_prefix, fraginfo
);
+
strbuf_addstr(&out, "@@ -"
);
if (!o->irreversible_delete)
if (!o->irreversible_delete)
-
print_line_count(o->file
, lc_a);
+
add_line_count(&out
, lc_a);
else
else
- fprintf(o->file, "?,?");
- fprintf(o->file, " +");
- print_line_count(o->file, lc_b);
- fprintf(o->file, " @@%s\n", reset);
+ strbuf_addstr(&out, "?,?");
+ strbuf_addstr(&out, " +");
+ add_line_count(&out, lc_b);
+ strbuf_addstr(&out, " @@\n");
+ emit_diff_symbol(o, DIFF_SYMBOL_REWRITE_DIFF, out.buf, out.len, 0);
+ strbuf_release(&out);
+
if (lc_a && !o->irreversible_delete)
emit_rewrite_lines(&ecbdata, '-', data_one, size_one);
if (lc_b)
if (lc_a && !o->irreversible_delete)
emit_rewrite_lines(&ecbdata, '-', data_one, size_one);
if (lc_b)