From: Eric Sunshine Date: Wed, 26 Mar 2014 19:50:08 GMT Subject: Re: [PATCH v2 08/17] ls-files: support --max-depth Message-ID: In-Reply-To: <1395841697-11742-9-git-send-email-pclouds@gmail.com> On Wed, Mar 26, 2014 at 9:48 AM, Nguyễn Thái Ngọc Duy wrote: > Signed-off-by: Nguyễn Thái Ngọc Duy > --- > Documentation/git-ls-files.txt | 7 +++++++ > builtin/ls-files.c | 7 +++++++ > 2 files changed, 14 insertions(+) > > diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt > index cd52461..3c022eb 100644 > --- a/Documentation/git-ls-files.txt > +++ b/Documentation/git-ls-files.txt > @@ -162,6 +162,13 @@ a space) at the start of each line: > for option syntax.`--column` and `--no-column` without options > are equivalent to 'always' and 'never' respectively. > > +--max-depth :: Other options in this file are documented as: --max-depth=:: > + For each given on command line, descend at most > + levels of directories. A negative value means no limit. > + This option is ignored if contains active wildcards. > + In other words if "a*" matches a directory named "a*", > + "*" is matched literally so --max-depth is still effective. Would it be worthwhile to mention the default? > + > \--:: > Do not interpret any more arguments as options. > > diff --git a/builtin/ls-files.c b/builtin/ls-files.c > index 335d3b0..8eef423 100644 > --- a/builtin/ls-files.c > +++ b/builtin/ls-files.c > @@ -503,6 +503,7 @@ static int option_parse_exclude_standard(const struct option *opt, > int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) > { > int require_work_tree = 0, show_tag = 0, i; > + int max_depth = -1; > const char *max_prefix; > struct dir_struct dir; > struct exclude_list *el; > @@ -560,6 +561,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) > N_("pretend that paths removed since 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 levels"), PARSE_OPT_NONEG, > + NULL, 1 }, > OPT__ABBREV(&abbrev), > OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")), > OPT_END() > @@ -624,8 +628,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.1.345.ga1a145c