diff --color-words: bit of clean-up
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index b7ecfe3b179cc68d18b34e675b3c0e67c13ba95d..8c66e4a0d4e5ab1729f400f7e95c4970952ec202 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -541,14 +541,18 @@ struct emit_callback {
        FILE *file;
 };
 
+/* In "color-words" mode, show word-diff of words accumulated in the buffer */
+static void diff_words_flush(struct emit_callback *ecbdata)
+{
+       if (ecbdata->diff_words->minus.text.size ||
+           ecbdata->diff_words->plus.text.size)
+               diff_words_show(ecbdata->diff_words);
+}
+
 static void free_diff_words_data(struct emit_callback *ecbdata)
 {
        if (ecbdata->diff_words) {
-               /* flush buffers */
-               if (ecbdata->diff_words->minus.text.size ||
-                               ecbdata->diff_words->plus.text.size)
-                       diff_words_show(ecbdata->diff_words);
-
+               diff_words_flush(ecbdata);
                free (ecbdata->diff_words->minus.text.ptr);
                free (ecbdata->diff_words->minus.orig);
                free (ecbdata->diff_words->plus.text.ptr);
@@ -656,12 +660,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
        for (i = 0; i < len && line[i] == '@'; i++)
                ;
        if (2 <= i && i < len && line[i] == ' ') {
-               /* flush --color-words even for --unified=0 */
-               if (ecbdata->diff_words &&
-                   (ecbdata->diff_words->minus.text.size ||
-                    ecbdata->diff_words->plus.text.size))
-                       diff_words_show(ecbdata->diff_words);
-
+               if (ecbdata->diff_words)
+                       diff_words_flush(ecbdata);
                ecbdata->nparents = i - 1;
                len = sane_truncate_line(ecbdata, line, len);
                emit_line(ecbdata->file,
@@ -691,9 +691,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
                                          &ecbdata->diff_words->plus);
                        return;
                }
-               if (ecbdata->diff_words->minus.text.size ||
-                   ecbdata->diff_words->plus.text.size)
-                       diff_words_show(ecbdata->diff_words);
+               diff_words_flush(ecbdata);
                line++;
                len--;
                emit_line(ecbdata->file, plain, reset, line, len);