Code

git config: codestyle cleanups
[git.git] / builtin-ls-files.c
index 068f424696864f3db1c1b78ef25a92a197ff5474..34340312953867fdcb4ae62d530bdae3162744a5 100644 (file)
@@ -36,42 +36,6 @@ static const char *tag_other = "";
 static const char *tag_killed = "";
 static const char *tag_modified = "";
 
-
-/*
- * Match a pathspec against a filename. The first "skiplen" characters
- * are the common prefix
- */
-int pathspec_match(const char **spec, char *ps_matched,
-                  const char *filename, int skiplen)
-{
-       const char *m;
-
-       while ((m = *spec++) != NULL) {
-               int matchlen = strlen(m + skiplen);
-
-               if (!matchlen)
-                       goto matched;
-               if (!strncmp(m + skiplen, filename + skiplen, matchlen)) {
-                       if (m[skiplen + matchlen - 1] == '/')
-                               goto matched;
-                       switch (filename[skiplen + matchlen]) {
-                       case '/': case '\0':
-                               goto matched;
-                       }
-               }
-               if (!fnmatch(m + skiplen, filename + skiplen, 0))
-                       goto matched;
-               if (ps_matched)
-                       ps_matched++;
-               continue;
-       matched:
-               if (ps_matched)
-                       *ps_matched = 1;
-               return 1;
-       }
-       return 0;
-}
-
 static void show_dir_entry(const char *tag, struct dir_entry *ent)
 {
        int len = prefix_len;
@@ -80,7 +44,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
        if (len >= ent->len)
                die("git ls-files: internal error - directory entry not superset of prefix");
 
-       if (pathspec && !pathspec_match(pathspec, ps_matched, ent->name, len))
+       if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))
                return;
 
        fputs(tag, stdout);
@@ -91,39 +55,10 @@ static void show_other_files(struct dir_struct *dir)
 {
        int i;
 
-
-       /*
-        * Skip matching and unmerged entries for the paths,
-        * since we want just "others".
-        *
-        * (Matching entries are normally pruned during
-        * the directory tree walk, but will show up for
-        * gitlinks because we don't necessarily have
-        * dir->show_other_directories set to suppress
-        * them).
-        */
        for (i = 0; i < dir->nr; i++) {
                struct dir_entry *ent = dir->entries[i];
-               int len, pos;
-               struct cache_entry *ce;
-
-               /*
-                * Remove the '/' at the end that directory
-                * walking adds for directory entries.
-                */
-               len = ent->len;
-               if (len && ent->name[len-1] == '/')
-                       len--;
-               pos = cache_name_pos(ent->name, len);
-               if (0 <= pos)
-                       continue;       /* exact match */
-               pos = -pos - 1;
-               if (pos < active_nr) {
-                       ce = active_cache[pos];
-                       if (ce_namelen(ce) == len &&
-                           !memcmp(ce->name, ent->name, len))
-                               continue; /* Yup, this one exists unmerged */
-               }
+               if (!cache_name_is_other(ent->name, ent->len))
+                       continue;
                show_dir_entry(tag_other, ent);
        }
 }
@@ -185,7 +120,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
        if (len >= ce_namelen(ce))
                die("git ls-files: internal error - cache entry not superset of prefix");
 
-       if (pathspec && !pathspec_match(pathspec, ps_matched, ce->name, len))
+       if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched))
                return;
 
        if (tag && *tag && show_valid_bit &&
@@ -256,6 +191,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
                        int dtype = ce_to_dtype(ce);
                        if (excluded(dir, ce->name, &dtype) != dir->show_ignored)
                                continue;
+                       if (ce->ce_flags & CE_UPDATE)
+                               continue;
                        err = lstat(ce->name, &st);
                        if (show_deleted && err)
                                show_ce_entry(tag_removed, ce);
@@ -358,7 +295,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
        if (prefix) {
                static const char *(matchbuf[2]);
                matchbuf[0] = prefix;
-               matchbuf [1] = NULL;
+               matchbuf[1] = NULL;
                match = matchbuf;
        } else
                match = NULL;