diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_MARKER
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index 77ef56a6e443537d84f2122f7b3a5ae8177b995a..75b996c4cf17d712d7430c24869208263d05f064 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -560,6 +560,31 @@ static void emit_line(struct diff_options *o, const char *set, const char *reset
        emit_line_0(o, set, reset, line[0], line+1, len-1);
 }
 
+enum diff_symbol {
+       DIFF_SYMBOL_CONTEXT_MARKER,
+       DIFF_SYMBOL_SEPARATOR
+};
+
+static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
+                            const char *line, int len)
+{
+       const char *context, *reset;
+       switch (s) {
+       case DIFF_SYMBOL_CONTEXT_MARKER:
+               context = diff_get_color_opt(o, DIFF_CONTEXT);
+               reset = diff_get_color_opt(o, DIFF_RESET);
+               emit_line(o, context, reset, line, len);
+               break;
+       case DIFF_SYMBOL_SEPARATOR:
+               fprintf(o->file, "%s%c",
+                       diff_line_prefix(o),
+                       o->line_termination);
+               break;
+       default:
+               die("BUG: unknown diff symbol");
+       }
+}
+
 static int new_blank_line_at_eof(struct emit_callback *ecbdata, const char *line, int len)
 {
        if (!((ecbdata->ws_rule & WS_BLANK_AT_EOF) &&
@@ -644,7 +669,8 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
        if (len < 10 ||
            memcmp(line, atat, 2) ||
            !(ep = memmem(line + 2, len - 2, atat, 2))) {
-               emit_line(ecbdata->opt, context, reset, line, len);
+               emit_diff_symbol(ecbdata->opt,
+                                DIFF_SYMBOL_CONTEXT_MARKER, line, len);
                return;
        }
        ep += 2; /* skip over @@ */
@@ -4828,9 +4854,7 @@ void diff_flush(struct diff_options *options)
 
        if (output_format & DIFF_FORMAT_PATCH) {
                if (separator) {
-                       fprintf(options->file, "%s%c",
-                               diff_line_prefix(options),
-                               options->line_termination);
+                       emit_diff_symbol(options, DIFF_SYMBOL_SEPARATOR, NULL, 0);
                        if (options->stat_sep) {
                                /* attach patch instead of inline */
                                fputs(options->stat_sep, options->file);