summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8978d04)
raw | patch | inline | side by side (parent: 8978d04)
author | Petr Baudis <pasky@suse.cz> | |
Sun, 26 Mar 2006 14:59:52 +0000 (16:59 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 27 Mar 2006 03:08:24 +0000 (19:08 -0800) |
Without the --directory flag, git-ls-files wouldn't ever list directories,
producing no output for empty directories, which is good since they cannot
be added and they bear no content, even untracked one (if Git ever starts
tracking directories on their own, this should obviously change since the
content notion will change).
With the --directory flag however, git-ls-files would list even empty
directories. This may be good in some situations but sometimes you want to
prevent that. This patch adds a --no-empty-directory option which makes
git-ls-files omit empty directories.
Signed-off-by: Petr Baudis <pasky@suse.cz>
producing no output for empty directories, which is good since they cannot
be added and they bear no content, even untracked one (if Git ever starts
tracking directories on their own, this should obviously change since the
content notion will change).
With the --directory flag however, git-ls-files would list even empty
directories. This may be good in some situations but sometimes you want to
prevent that. This patch adds a --no-empty-directory option which makes
git-ls-files omit empty directories.
Signed-off-by: Petr Baudis <pasky@suse.cz>
Documentation/git-ls-files.txt | patch | blob | history | |
ls-files.c | patch | blob | history |
index e813f8420275f5b95810646c2a43c35f57a5ba70..980c5c9186d5093deeb8830e8770bcd9132c0820 100644 (file)
If a whole directory is classified as "other", show just its
name (with a trailing slash) and not its whole contents.
+--no-empty-directory::
+ Do not list empty directories. Has no effect without --directory.
+
-u|--unmerged::
Show unmerged files in the output (forces --stage)
diff --git a/ls-files.c b/ls-files.c
index e42119c5ee1d0ceffca3d36462fc09cd53d2eef5..83b0a3b49f55c444019eb55eb3af9c9230e85144 100644 (file)
--- a/ls-files.c
+++ b/ls-files.c
static int show_modified = 0;
static int show_killed = 0;
static int show_other_directories = 0;
+static int hide_empty_directories = 0;
static int show_valid_bit = 0;
static int line_terminator = '\n';
* Also, we ignore the name ".git" (even if it is not a directory).
* That likely will not change.
*/
-static void read_directory(const char *path, const char *base, int baselen)
+static int read_directory(const char *path, const char *base, int baselen)
{
- DIR *dir = opendir(path);
+ DIR *fdir = opendir(path);
+ int contents = 0;
- if (dir) {
+ if (fdir) {
int exclude_stk;
struct dirent *de;
char fullname[MAXPATHLEN + 1];
exclude_stk = push_exclude_per_directory(base, baselen);
- while ((de = readdir(dir)) != NULL) {
+ while ((de = readdir(fdir)) != NULL) {
int len;
if ((de->d_name[0] == '.') &&
switch (DTYPE(de)) {
struct stat st;
+ int subdir, rewind_base;
default:
continue;
case DT_UNKNOWN:
case DT_DIR:
memcpy(fullname + baselen + len, "/", 2);
len++;
+ rewind_base = nr_dir;
+ subdir = read_directory(fullname, fullname,
+ baselen + len);
if (show_other_directories &&
- !dir_exists(fullname, baselen + len))
+ (subdir || !hide_empty_directories) &&
+ !dir_exists(fullname, baselen + len)) {
+ // Rewind the read subdirectory
+ while (nr_dir > rewind_base)
+ free(dir[--nr_dir]);
break;
- read_directory(fullname, fullname,
- baselen + len);
+ }
+ contents += subdir;
continue;
case DT_REG:
case DT_LNK:
break;
}
add_name(fullname, baselen + len);
+ contents++;
}
- closedir(dir);
+ closedir(fdir);
pop_exclude_per_directory(exclude_stk);
}
+
+ return contents;
}
static int cmp_name(const void *p1, const void *p2)
show_other_directories = 1;
continue;
}
+ if (!strcmp(arg, "--no-empty-directory")) {
+ hide_empty_directories = 1;
+ continue;
+ }
if (!strcmp(arg, "-u") || !strcmp(arg, "--unmerged")) {
/* There's no point in showing unmerged unless
* you also show the stage information.