]> git.ipfire.org Git - thirdparty/git.git/blobdiff - diff-lib.c
War on whitespace
[thirdparty/git.git] / diff-lib.c
index c6d127346ab38b3b73285f61d2dc6874ab1dc7ac..7fb19c7b87fc39cc4515628e8623ccb92fbaa60e 100644 (file)
@@ -142,18 +142,34 @@ static int queue_diff(struct diff_options *o,
        }
 }
 
+/*
+ * Does the path name a blob in the working tree, or a directory
+ * in the working tree?
+ */
 static int is_in_index(const char *path)
 {
-       int len = strlen(path);
-       int pos = cache_name_pos(path, len);
-       char c;
-
-       if (pos < 0)
-               return 0;
-       if (strncmp(active_cache[pos]->name, path, len))
-               return 0;
-       c = active_cache[pos]->name[len];
-       return c == '\0' || c == '/';
+       int len, pos;
+       struct cache_entry *ce;
+
+       len = strlen(path);
+       while (path[len-1] == '/')
+               len--;
+       if (!len)
+               return 1; /* "." */
+       pos = cache_name_pos(path, len);
+       if (0 <= pos)
+               return 1;
+       pos = -1 - pos;
+       while (pos < active_nr) {
+               ce = active_cache[pos++];
+               if (ce_namelen(ce) <= len ||
+                   strncmp(ce->name, path, len) ||
+                   (ce->name[len] > '/'))
+                       break; /* path cannot be a prefix */
+               if (ce->name[len] == '/')
+                       return 1;
+       }
+       return 0;
 }
 
 static int handle_diff_files_args(struct rev_info *revs,
@@ -648,7 +664,7 @@ int run_diff_index(struct rev_info *revs, int cached)
        const char *tree_name;
        int match_missing = 0;
 
-       /* 
+       /*
         * Backward compatibility wart - "diff-index -m" does
         * not mean "do not ignore merges", but totally different.
         */