Code

diff.c: emit_add_line() takes only the rest of the line
authorJunio C Hamano <gitster@pobox.com>
Tue, 15 Sep 2009 01:44:01 +0000 (18:44 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Sep 2009 09:41:02 +0000 (02:41 -0700)
As the first character on the line that is fed to this function is always
"+", it is pointless to send that along with the rest of the line.

This change will make it easier to reuse the logic when emitting the
rewrite diff, as we do not want to copy a line only to add "+"/"-"/" "
immediately before its first character when we produce rewrite diff
output.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c

diff --git a/diff.c b/diff.c
index e4aaebf0d0ada1bf78efcbba3a8dc9cb2234213b..07cf04365ca579d8488ae0263e05276d58f17832 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -424,23 +424,25 @@ static int new_blank_line_at_eof(struct emit_callback *ecbdata, const char *line
              ecbdata->blank_at_eof_in_preimage <= ecbdata->lno_in_preimage &&
              ecbdata->blank_at_eof_in_postimage <= ecbdata->lno_in_postimage))
                return 0;
-       return ws_blank_line(line + 1, len - 1, ecbdata->ws_rule);
+       return ws_blank_line(line, len, ecbdata->ws_rule);
 }
 
-static void emit_add_line(const char *reset, struct emit_callback *ecbdata, const char *line, int len)
+static void emit_add_line(const char *reset,
+                         struct emit_callback *ecbdata,
+                         const char *line, int len)
 {
        const char *ws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);
        const char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_NEW);
 
        if (!*ws)
-               emit_line(ecbdata->file, set, reset, line, len);
+               emit_line_0(ecbdata->file, set, reset, '+', line, len);
        else if (new_blank_line_at_eof(ecbdata, line, len))
                /* Blank line at EOF - paint '+' as well */
-               emit_line(ecbdata->file, ws, reset, line, len);
+               emit_line_0(ecbdata->file, ws, reset, '+', line, len);
        else {
                /* Emit just the prefix, then the rest. */
-               emit_line(ecbdata->file, set, reset, line, 1);
-               ws_check_emit(line + 1, len - 1, ecbdata->ws_rule,
+               emit_line_0(ecbdata->file, set, reset, '+', "", 0);
+               ws_check_emit(line, len, ecbdata->ws_rule,
                              ecbdata->file, set, reset, ws);
        }
 }
@@ -737,7 +739,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
                emit_line(ecbdata->file, color, reset, line, len);
        } else {
                ecbdata->lno_in_postimage++;
-               emit_add_line(reset, ecbdata, line, len);
+               emit_add_line(reset, ecbdata, line + 1, len - 1);
        }
 }