git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 08/21] ls-files: support --max-depth

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 25, 2015, 12:37 UTC
Message-ID
<1422189476-7518-9-git-send-email-pclouds@gmail.com>
In-Reply-To
<1422189476-7518-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 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 99328b9..3d921eb 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -160,6 +160,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=<depth>::
+	For each <pathspec> given on command line, descend at most <depth>
+	levels of directories. A negative value means no limit (default).
+	This option is ignored if <pathspec> contains active wildcards.
+	In other words if "a*" matches a directory named "a*",
+	"*" is matched literally so --max-depth is still effective.
+
 \--::
 	Do not interpret any more arguments as options.
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 44e5628..09a6b8d 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 <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()
@@ -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);
-- 
2.2.0.84.ge9c7a8a
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 9 of 30 in “nd/list-files updates”
  1. 00/21 nd/list-files updatesNguyễn Thái Ngọc Duy, Jan 25, 2015
  2. 01/21 ls_colors.c: add $LS_COLORS parsing codeNguyễn Thái Ngọc Duy, Jan 25, 2015
  3. 02/21 ls_colors.c: parse color.ls.* from config fileNguyễn Thái Ngọc Duy, Jan 25, 2015
  4. 03/21 ls_colors.c: add a function to color a file nameNguyễn Thái Ngọc Duy, Jan 25, 2015
  5. 04/21 ls_colors.c: highlight submodules like directoriesNguyễn Thái Ngọc Duy, Jan 25, 2015
  6. 05/21 ls-files: buffer full item in strbuf before printingNguyễn Thái Ngọc Duy, Jan 25, 2015
  7. 06/21 ls-files: add --color to highlight file namesNguyễn Thái Ngọc Duy, Jan 25, 2015
  8. 07/21 ls-files: add --columnNguyễn Thái Ngọc Duy, Jan 25, 2015
  9. 08/21 ls-files: support --max-depthNguyễn Thái Ngọc Duy, Jan 25, 2015
  10. 09/21 list-files: a user friendly version of ls-files and moreNguyễn Thái Ngọc Duy, Jan 25, 2015
  11. Junio C HamanoJan 27, 2015
  12. 10/21 list-files: make alias 'ls' default to 'list-files'Nguyễn Thái Ngọc Duy, Jan 25, 2015
  13. 11/21 list-files: -u does not imply showing stagesNguyễn Thái Ngọc Duy, Jan 25, 2015
  14. 12/21 list-files: add -R/--recursive short for --max-depth=-1Nguyễn Thái Ngọc Duy, Jan 25, 2015
  15. 13/21 list-files: add -1 short for --no-columnNguyễn Thái Ngọc Duy, Jan 25, 2015
  16. 14/21 list-files: add -t backNguyễn Thái Ngọc Duy, Jan 25, 2015
  17. 15/21 list-files: sort output and remove duplicatesNguyễn Thái Ngọc Duy, Jan 25, 2015
  18. 16/21 list-files: do not show duplicate cached entriesNguyễn Thái Ngọc Duy, Jan 25, 2015
  19. 17/21 list-files: show directories as well as filesNguyễn Thái Ngọc Duy, Jan 25, 2015
  20. Eric SunshineJan 25, 2015
  21. Junio C HamanoJan 27, 2015
  22. 18/21 list-files: add -F/--classifyNguyễn Thái Ngọc Duy, Jan 25, 2015
  23. 19/21 list-files -F: show submodules with the new indicator '&'Nguyễn Thái Ngọc Duy, Jan 25, 2015
  24. 20/21 list-files: -M aka diff-cachedNguyễn Thái Ngọc Duy, Jan 25, 2015
  25. 21/21 t3080: tests for git-list-filesNguyễn Thái Ngọc Duy, Jan 25, 2015
  26. Eric SunshineJan 25, 2015
  27. Michael BlumeJan 28, 2015
  28. Duy NguyenJan 28, 2015
  29. Michael BlumeJan 28, 2015
  30. Junio C HamanoJan 28, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.