[showing-off RFC/PATCH 26/26] diff.c: have a "machine parseable" move coloring

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ævar asked for it, this is how you would do it.
(plus documentation, tests, CLI knobs, options)

Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
---
 diff.c | 15 +++++++++++----
 diff.h |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/diff.c b/diff.c
index 7756f7610c..61caa057ff 100644
--- a/diff.c
+++ b/diff.c
@@ -997,6 +997,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
 	static const char *nneof = " No newline at end of file\n";
 	const char *context, *reset, *set, *meta, *fraginfo;
 	struct strbuf sb = STRBUF_INIT;
+	int sign;
 
 	enum diff_symbol s = eds->s;
 	const char *line = eds->line;
@@ -1058,8 +1059,11 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
 		default:
 			set = diff_get_color_opt(o, DIFF_FILE_NEW);
 		}
+		sign = '+';
+		if (flags & DIFF_SYMBOL_MOVED_LINE && o->machine_readable_moves)
+			sign = '*';
 		reset = diff_get_color_opt(o, DIFF_RESET);
-		emit_line_ws_markup(o, set, reset, line, len, '+',
+		emit_line_ws_markup(o, set, reset, line, len, sign,
 				    flags & DIFF_SYMBOL_CONTENT_WS_MASK,
 				    flags & DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF);
 		break;
@@ -1086,8 +1090,11 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
 		default:
 			set = diff_get_color_opt(o, DIFF_FILE_OLD);
 		}
+		sign = '-';
+		if (flags & DIFF_SYMBOL_MOVED_LINE && o->machine_readable_moves)
+			sign = '_';
 		reset = diff_get_color_opt(o, DIFF_RESET);
-		emit_line_ws_markup(o, set, reset, line, len, '-',
+		emit_line_ws_markup(o, set, reset, line, len, sign,
 				    flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
 		break;
 	case DIFF_SYMBOL_WORDS_PORCELAIN:
@@ -5475,7 +5482,7 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o)
 	static struct emitted_diff_symbols esm = EMITTED_DIFF_SYMBOLS_INIT;
 	struct diff_queue_struct *q = &diff_queued_diff;
 
-	if (o->color_moved)
+	if (o->color_moved || o->machine_readable_moves)
 		o->emitted_symbols = &esm;
 
 	for (i = 0; i < q->nr; i++) {
@@ -5485,7 +5492,7 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o)
 	}
 
 	if (o->emitted_symbols) {
-		if (o->color_moved) {
+		if (o->color_moved || o->machine_readable_moves) {
 			struct hashmap add_lines, del_lines;
 			unsigned ignore_ws = DIFF_XDL_TST(o, IGNORE_WHITESPACE);
 
diff --git a/diff.h b/diff.h
index 98abd75521..b6c4d7ab0f 100644
--- a/diff.h
+++ b/diff.h
@@ -194,6 +194,8 @@ struct diff_options {
 		COLOR_MOVED_ZEBRA = 2,
 		COLOR_MOVED_ZEBRA_DIM = 3,
 	} color_moved;
+
+	int machine_readable_moves;
 };
 
 void diff_emit_submodule_del(struct diff_options *o, const char *line);
-- 
2.12.2.575.gb14f27f917




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux