[PATCH v2 5/5] fn_out_diff_words_aux: Handle common diff line more carefully

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

 



Before feeding minus and plus lines into xdi_diff, we replace non word
characters with '\n'. So we need recover the replaced character (always
the last character) in the callback fn_out_diff_words_aux.

Therefore, a common diff line beginning with ' ' is not always a real
common line. And we should check the last characters of the common diff
line. If they are different, we should output the first len-1 characters
as the common part and then the last characters in minus and plus
separately.

Signed-off-by: Ping Yin <pkufranky@xxxxxxxxx>
---
 diff.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/diff.c b/diff.c
index 50d7fa7..72fe804 100644
--- a/diff.c
+++ b/diff.c
@@ -414,7 +414,7 @@ static void print_word(FILE *file, struct diff_words_buffer *buffer, int len, in
 static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
 {
 	struct diff_words_data *diff_words;
-	char cm;
+	char cm, cp;
 	struct diff_words_buffer *dm, *dp;
 	FILE *df;
 
@@ -440,10 +440,18 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
 			break;
 		case ' ':
 			cm = dm->text.ptr[dm->current + len - 1];
-			print_word(df, dp, len, DIFF_PLAIN, 1);
-			dm->current += len;
-			if (cm == '\n')
-				dm->suppressed_newline = 1;
+			cp = dp->text.ptr[dp->current + len - 1];
+			if (cm == cp) {
+				print_word(df, dp, len, DIFF_PLAIN, 1);
+				dm->current += len;
+			}
+			else {
+				len--;
+				print_word(df, dp, len, DIFF_PLAIN, 1);
+				dm->current += len;
+				print_word(df, dm, 1, DIFF_FILE_OLD, 1);
+				print_word(df, dp, 1, DIFF_FILE_NEW, 1);
+			}
 			break;
 	}
 }
-- 
1.5.5.1.121.g26b3

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

  Powered by Linux