diff options
author | Junio C Hamano <junkio@cox.net> | 2006-03-26 23:44:14 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-03-26 23:44:14 -0800 |
commit | d93067d9c7fb210766c7282d662289f54d53f93a (patch) | |
tree | a463ad3ce94a987ec3d00e10eaa98ede1fe0495d /ls-files.c | |
parent | f4e96f97e85c145616bc2e23e9441bc0daa2906e (diff) | |
parent | b0a3de42316a4e8f1d561cbe12b7bb282631a0d6 (diff) | |
download | git-d93067d9c7fb210766c7282d662289f54d53f93a.tar.gz |
Merge branch 'master' into next
* master:
Optionally do not list empty directories in git-ls-files --others
Document git-rebase behavior on conflicts.
Fix error handling for nonexistent names
Diffstat (limited to 'ls-files.c')
-rw-r--r-- | ls-files.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/ls-files.c b/ls-files.c index 3a17e5d8e0..4a4af1ca3b 100644 --- a/ls-files.c +++ b/ls-files.c @@ -21,6 +21,7 @@ static int show_unmerged = 0; 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'; @@ -259,11 +260,12 @@ static int dir_exists(const char *dirname, int len) * 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]; @@ -271,7 +273,7 @@ static void read_directory(const char *path, const char *base, int baselen) 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] == '.') && @@ -289,6 +291,7 @@ static void read_directory(const char *path, const char *base, int baselen) switch (DTYPE(de)) { struct stat st; + int subdir, rewind_base; default: continue; case DT_UNKNOWN: @@ -302,22 +305,32 @@ static void read_directory(const char *path, const char *base, int baselen) 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) @@ -699,6 +712,10 @@ int main(int argc, const char **argv) 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. |