OSDN Git Service

cat-file doc: document that -e will return some output
[git-core/git.git] / diff.c
diff --git a/diff.c b/diff.c
index 4da0714..1898dd3 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);
 }
 
@@ -704,81 +707,14 @@ struct moved_entry {
        struct moved_entry *next_line;
 };
 
-static int next_byte(const char **cp, const char **endp,
-                    const struct diff_options *diffopt)
-{
-       int retval;
-
-       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 (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
-               while (*cp < *endp && isspace(**cp))
-                       (*cp)++;
-               /* return the first non-ws character via the usual below */
-       }
-
-       retval = (unsigned char)(**cp);
-       (*cp)++;
-       return retval;
-}
-
 static int moved_entry_cmp(const struct diff_options *diffopt,
                           const struct moved_entry *a,
                           const struct moved_entry *b,
                           const void *keydata)
 {
-       const char *ap = a->es->line, *ae = a->es->line + a->es->len;
-       const char *bp = b->es->line, *be = b->es->line + b->es->len;
-
-       if (!(diffopt->xdl_opts & XDF_WHITESPACE_FLAGS))
-               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))
-                       ae--;
-               while (be > bp && isspace(*be))
-                       be--;
-       }
-
-       while (1) {
-               int ca, cb;
-               ca = next_byte(&ap, &ae, diffopt);
-               cb = next_byte(&bp, &be, diffopt);
-               if (ca != cb)
-                       return 1;
-               if (ca < 0)
-                       return 0;
-       }
-}
-
-static unsigned get_string_hash(struct emitted_diff_symbol *es, struct diff_options *o)
-{
-       if (o->xdl_opts & XDF_WHITESPACE_FLAGS) {
-               static struct strbuf sb = STRBUF_INIT;
-               const char *ap = es->line, *ae = es->line + es->len;
-               int c;
-
-               strbuf_reset(&sb);
-               while (ae > ap && isspace(*ae))
-                       ae--;
-               while ((c = next_byte(&ap, &ae, o)) > 0)
-                       strbuf_addch(&sb, c);
-
-               return memhash(sb.buf, sb.len);
-       } else {
-               return memhash(es->line, es->len);
-       }
+       return !xdiff_compare_lines(a->es->line, a->es->len,
+                                   b->es->line, b->es->len,
+                                   diffopt->xdl_opts);
 }
 
 static struct moved_entry *prepare_entry(struct diff_options *o,
@@ -787,7 +723,7 @@ static struct moved_entry *prepare_entry(struct diff_options *o,
        struct moved_entry *ret = xmalloc(sizeof(*ret));
        struct emitted_diff_symbol *l = &o->emitted_symbols->buf[line_no];
 
-       ret->ent.hash = get_string_hash(l, o);
+       ret->ent.hash = xdiff_hash_string(l->line, l->len, o->xdl_opts);
        ret->es = l;
        ret->next_line = NULL;
 
@@ -3609,14 +3545,12 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
                int fd;
 
                if (lstat(s->path, &st) < 0) {
-                       if (errno == ENOENT) {
-                       err_empty:
-                               err = -1;
-                       empty:
-                               s->data = (char *)"";
-                               s->size = 0;
-                               return err;
-                       }
+               err_empty:
+                       err = -1;
+               empty:
+                       s->data = (char *)"";
+                       s->size = 0;
+                       return err;
                }
                s->size = xsize_t(st.st_size);
                if (!s->size)
@@ -5272,6 +5206,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);