[PATCH 2/3] diff: move the handling of the hunk header after the changed lines

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

 



In preparation for a special case handling of colored word diff without
context.

Signed-off-by: Markus Heidelberg <markus.heidelberg@xxxxxx>
---
 diff.c |   41 +++++++++++++++++++++--------------------
 1 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/diff.c b/diff.c
index b0c7e61..067e5a0 100644
--- a/diff.c
+++ b/diff.c
@@ -771,17 +771,6 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 		len = 1;
 	}
 
-	if (line[0] == '@') {
-		len = sane_truncate_line(ecbdata, line, len);
-		find_lno(line, ecbdata);
-		emit_line(ecbdata->file,
-			  diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO),
-			  reset, line, len);
-		if (line[len-1] != '\n')
-			putc('\n', ecbdata->file);
-		return;
-	}
-
 	if (len < 1) {
 		emit_line(ecbdata->file, reset, reset, line, len);
 		return;
@@ -796,17 +785,18 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 			diff_words_append(line, len,
 					  &ecbdata->diff_words->plus);
 			return;
+		} else if (line[0] == ' ') {
+			if (ecbdata->diff_words->minus.text.size ||
+			    ecbdata->diff_words->plus.text.size)
+				diff_words_show(ecbdata->diff_words);
+			line++;
+			len--;
+			emit_line(ecbdata->file, plain, reset, line, len);
+			return;
 		}
-		if (ecbdata->diff_words->minus.text.size ||
-		    ecbdata->diff_words->plus.text.size)
-			diff_words_show(ecbdata->diff_words);
-		line++;
-		len--;
-		emit_line(ecbdata->file, plain, reset, line, len);
-		return;
 	}
 
-	if (line[0] != '+') {
+	if (line[0] == ' ' || line[0] == '-') {
 		const char *color =
 			diff_get_color(ecbdata->color_diff,
 				       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);
@@ -814,10 +804,21 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 		if (line[0] == ' ')
 			ecbdata->lno_in_postimage++;
 		emit_line(ecbdata->file, color, reset, line, len);
-	} else {
+		return;
+	} else if (line[0] == '+') {
 		ecbdata->lno_in_postimage++;
 		emit_add_line(reset, ecbdata, line + 1, len - 1);
+		return;
 	}
+
+	/* line[0] == '@' */
+	len = sane_truncate_line(ecbdata, line, len);
+	find_lno(line, ecbdata);
+	emit_line(ecbdata->file,
+		  diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO),
+		  reset, line, len);
+	if (line[len-1] != '\n')
+		putc('\n', ecbdata->file);
 }
 
 static char *pprint_rename(const char *a, const char *b)
-- 
1.6.5.2.86.g61663

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[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]