]> asedeno.scripts.mit.edu Git - git.git/blobdiff - diff.c
Merge branch 'mw/send-email'
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index 5b8afdcb05abd4f634b49adb2f521fc75e220647..cd8bc4dcc32757dfed9374fa8769599a6a7857ad 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -158,6 +158,8 @@ int git_diff_ui_config(const char *var, const char *value)
                return 0;
        }
        if (!strcmp(var, "diff.external")) {
+               if (!value)
+                       return config_error_nonbool(var);
                external_diff_cmd_cfg = xstrdup(value);
                return 0;
        }
@@ -165,8 +167,11 @@ int git_diff_ui_config(const char *var, const char *value)
                const char *ep = strrchr(var, '.');
 
                if (ep != var + 4) {
-                       if (!strcmp(ep, ".command"))
+                       if (!strcmp(ep, ".command")) {
+                               if (!value)
+                                       return config_error_nonbool(var);
                                return parse_lldiff_command(var, ep, value);
+                       }
                }
        }
 
@@ -177,6 +182,8 @@ int git_diff_basic_config(const char *var, const char *value)
 {
        if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) {
                int slot = parse_diff_color_slot(var, 11);
+               if (!value)
+                       return config_error_nonbool(var);
                color_parse(value, var, diff_colors[slot]);
                return 0;
        }
@@ -184,8 +191,11 @@ int git_diff_basic_config(const char *var, const char *value)
        if (!prefixcmp(var, "diff.")) {
                const char *ep = strrchr(var, '.');
                if (ep != var + 4) {
-                       if (!strcmp(ep, ".funcname"))
+                       if (!strcmp(ep, ".funcname")) {
+                               if (!value)
+                                       return config_error_nonbool(var);
                                return parse_funcname_pattern(var, ep, value);
+                       }
                }
        }
 
@@ -1510,17 +1520,22 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
        if (pos < 0)
                return 0;
        ce = active_cache[pos];
-       if ((lstat(name, &st) < 0) ||
-           !S_ISREG(st.st_mode) || /* careful! */
-           ce_match_stat(ce, &st, 0) ||
-           hashcmp(sha1, ce->sha1))
+
+       /*
+        * This is not the sha1 we are looking for, or
+        * unreusable because it is not a regular file.
+        */
+       if (hashcmp(sha1, ce->sha1) || !S_ISREG(ce->ce_mode))
                return 0;
-       /* we return 1 only when we can stat, it is a regular file,
-        * stat information matches, and sha1 recorded in the cache
-        * matches.  I.e. we know the file in the work tree really is
-        * the same as the <name, sha1> pair.
+
+       /*
+        * If ce matches the file in the work tree, we can reuse it.
         */
-       return 1;
+       if (ce_uptodate(ce) ||
+           (!lstat(name, &st) && !ce_match_stat(ce, &st, 0)))
+               return 1;
+
+       return 0;
 }
 
 static int populate_from_stdin(struct diff_filespec *s)