Turn the flags in struct dir_struct into a single variable
[gitweb.git] / builtin-ls-files.c
index 34340312953867fdcb4ae62d530bdae3162744a5..d36f80b3de96c43cfc131f336850486c04444080 100644 (file)
@@ -174,7 +174,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
                for (i = 0; i < active_nr; i++) {
                        struct cache_entry *ce = active_cache[i];
                        int dtype = ce_to_dtype(ce);
-                       if (excluded(dir, ce->name, &dtype) != dir->show_ignored)
+                       if (excluded(dir, ce->name, &dtype) !=
+                                       !!(dir->flags & DIR_SHOW_IGNORED))
                                continue;
                        if (show_unmerged && !ce_stage(ce))
                                continue;
@@ -189,7 +190,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
                        struct stat st;
                        int err;
                        int dtype = ce_to_dtype(ce);
-                       if (excluded(dir, ce->name, &dtype) != dir->show_ignored)
+                       if (excluded(dir, ce->name, &dtype) !=
+                                       !!(dir->flags & DIR_SHOW_IGNORED))
                                continue;
                        if (ce->ce_flags & CE_UPDATE)
                                continue;
@@ -262,6 +264,21 @@ static const char *verify_pathspec(const char *prefix)
        return max ? xmemdupz(prev, max) : NULL;
 }
 
+static void strip_trailing_slash_from_submodules(void)
+{
+       const char **p;
+
+       for (p = pathspec; *p != NULL; p++) {
+               int len = strlen(*p), pos;
+
+               if (len < 1 || (*p)[len - 1] != '/')
+                       continue;
+               pos = cache_name_pos(*p, len - 1);
+               if (pos >= 0 && S_ISGITLINK(active_cache[pos]->ce_mode))
+                       *p = xstrndup(*p, len - 1);
+       }
+}
+
 /*
  * Read the tree specified with --with-tree option
  * (typically, HEAD) into stage #1 and then
@@ -417,7 +434,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
                        continue;
                }
                if (!strcmp(arg, "-i") || !strcmp(arg, "--ignored")) {
-                       dir.show_ignored = 1;
+                       dir.flags |= DIR_SHOW_IGNORED;
                        require_work_tree = 1;
                        continue;
                }
@@ -431,11 +448,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
                        continue;
                }
                if (!strcmp(arg, "--directory")) {
-                       dir.show_other_directories = 1;
+                       dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
                        continue;
                }
                if (!strcmp(arg, "--no-empty-directory")) {
-                       dir.hide_empty_directories = 1;
+                       dir.flags |= DIR_HIDE_EMPTY_DIRECTORIES;
                        continue;
                }
                if (!strcmp(arg, "-u") || !strcmp(arg, "--unmerged")) {
@@ -510,6 +527,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 
        pathspec = get_pathspec(prefix, argv + i);
 
+       /* be nice with submodule patsh ending in a slash */
+       read_cache();
+       if (pathspec)
+               strip_trailing_slash_from_submodules();
+
        /* Verify that the pathspec matches the prefix */
        if (pathspec)
                prefix = verify_pathspec(prefix);
@@ -522,7 +544,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
                ps_matched = xcalloc(1, num);
        }
 
-       if (dir.show_ignored && !exc_given) {
+       if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given) {
                fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
                        argv[0]);
                exit(1);
@@ -533,7 +555,6 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
              show_killed | show_modified))
                show_cached = 1;
 
-       read_cache();
        if (prefix)
                prune_cache(prefix);
        if (with_tree) {