From: Ping Yin Date: Sun, 04 May 2008 04:20:14 GMT Subject: [PATCH v3 5/6] fn_out_diff_words_aux: Handle common diff line more carefully Message-ID: <1209874815-14411-6-git-send-email-pkufranky@gmail.com> In-Reply-To: <1209874815-14411-5-git-send-email-pkufranky@gmail.com> 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 --- diff.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diff --git a/diff.c b/diff.c index eb7c086..08048e4 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 lastchar_minus; + char lastchar_minus, lastchar_plus; struct diff_words_buffer *dwb_minus, *dwb_plus; FILE *outfile; @@ -440,10 +440,18 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len) break; case ' ': lastchar_minus = dwb_minus->text.ptr[dwb_minus->current + len - 1]; - print_word(outfile, dwb_plus, len, DIFF_PLAIN, 1); - dwb_minus->current += len; - if (lastchar_minus == '\n') - dwb_minus->suppressed_newline = 1; + lastchar_plus = dwb_plus->text.ptr[dwb_plus->current + len - 1]; + if (lastchar_minus == lastchar_plus) { + print_word(outfile, dwb_plus, len, DIFF_PLAIN, 1); + dwb_minus->current += len; + } + else { + len--; + print_word(outfile, dwb_plus, len, DIFF_PLAIN, 1); + dwb_minus->current += len; + print_word(outfile, dwb_minus, 1, DIFF_FILE_OLD, 1); + print_word(outfile, dwb_plus, 1, DIFF_FILE_NEW, 1); + } break; } } -- 1.5.5.1.121.g26b3