[PATCH 7/8] ls-files: support --max-depth
From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 23:00:23
Subsystem:
the rest · Maintainer:
Linus Torvalds
The use case in mind is --max-depth=0 to stop recursion. With this we can do git config --global alias.ls 'ls-files --column --color --max-depth=0' and have "git ls" with an output very similar to GNU ls. Another interesting one is git config --global alias.lso 'ls-files --column --color --max-depth=0 -o --exclude-standard' Signed-off-by: Nguyễn Thái Ngọc Duy <redacted> --- builtin/ls-files.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index a43abdb..2c51b0a 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c@@ -478,6 +478,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) { int require_work_tree = 0, show_tag = 0, i; unsigned int colopts = 0; + int max_depth = -1; const char *max_prefix; struct dir_struct dir; struct exclude_list *el;
@@ -535,6 +536,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) N_("pretend that paths removed since <tree-ish> are still present")), OPT__COLOR(&use_color, N_("show color")), OPT_COLUMN(0, "column", &colopts, N_("show files in columns")), + { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"), + N_("descend at most <depth> levels"), PARSE_OPT_NONEG, + NULL, 1 }, OPT__ABBREV(&abbrev), OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")), OPT_END()
@@ -591,8 +595,11 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD | + (max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0) | PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP, prefix, argv); + pathspec.max_depth = max_depth; + pathspec.recursive = 1; /* Find common prefix for all pathspec's */ max_prefix = common_prefix(&pathspec);
--
1.9.0.40.gaa8c3ea