Merge branch 'jk/diff-color-moved-fix'
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index 3c6a3e0faa58f810ce2fe8b27f62581c175edf64..c4a669ffa8690f7640294f717e817352265a8bf6 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -358,6 +358,9 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (git_color_config(var, value, cb) < 0)
+               return -1;
+
        return git_diff_basic_config(var, value, cb);
 }
 
@@ -709,23 +712,30 @@ static int next_byte(const char **cp, const char **endp,
 {
        int retval;
 
-       if (*cp > *endp)
+       if (*cp >= *endp)
                return -1;
 
-       if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_CHANGE)) {
-               while (*cp < *endp && isspace(**cp))
-                       (*cp)++;
-               /*
-                * After skipping a couple of whitespaces, we still have to
-                * account for one space.
-                */
-               return (int)' ';
-       }
+       if (isspace(**cp)) {
+               if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_CHANGE)) {
+                       while (*cp < *endp && isspace(**cp))
+                               (*cp)++;
+                       /*
+                        * After skipping a couple of whitespaces,
+                        * we still have to account for one space.
+                        */
+                       return (int)' ';
+               }
 
-       if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
-               while (*cp < *endp && isspace(**cp))
-                       (*cp)++;
-               /* return the first non-ws character via the usual below */
+               if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
+                       while (*cp < *endp && isspace(**cp))
+                               (*cp)++;
+                       /*
+                        * return the first non-ws character via the usual
+                        * below, unless we ate all of the bytes
+                        */
+                       if (*cp >= *endp)
+                               return -1;
+               }
        }
 
        retval = (unsigned char)(**cp);
@@ -745,9 +755,9 @@ static int moved_entry_cmp(const struct diff_options *diffopt,
                return a->es->len != b->es->len  || memcmp(ap, bp, a->es->len);
 
        if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_AT_EOL)) {
-               while (ae > ap && isspace(*ae))
+               while (ae > ap && isspace(ae[-1]))
                        ae--;
-               while (be > bp && isspace(*be))
+               while (be > bp && isspace(be[-1]))
                        be--;
        }
 
@@ -770,9 +780,9 @@ static unsigned get_string_hash(struct emitted_diff_symbol *es, struct diff_opti
                int c;
 
                strbuf_reset(&sb);
-               while (ae > ap && isspace(*ae))
+               while (ae > ap && isspace(ae[-1]))
                        ae--;
-               while ((c = next_byte(&ap, &ae, o)) > 0)
+               while ((c = next_byte(&ap, &ae, o)) >= 0)
                        strbuf_addch(&sb, c);
 
                return memhash(sb.buf, sb.len);
@@ -1541,7 +1551,7 @@ static void emit_rewrite_diff(const char *name_a,
 
 struct diff_words_buffer {
        mmfile_t text;
-       long alloc;
+       unsigned long alloc;
        struct diff_words_orig {
                const char *begin, *end;
        } *orig;
@@ -5272,6 +5282,7 @@ static void show_mode_change(struct diff_options *opt, struct diff_filepair *p,
                        strbuf_addch(&sb, ' ');
                        quote_c_style(p->two->path, &sb, NULL, 0);
                }
+               strbuf_addch(&sb, '\n');
                emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
                                 sb.buf, sb.len, 0);
                strbuf_release(&sb);