Thread (8 messages) flat view 8 messages, 2 authors, 2016-06-15
STALE3739d

[PATCH 2/3] ls-files: support -o --max-depth (more of a hack as fill_directory should support this)

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:47:58
Subsystem: the rest · Maintainer: Linus Torvalds

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 builtin-ls-files.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 2bb851a..e16638e 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -51,6 +51,17 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
 	if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))
 		return;
 
+	if (max_depth) {
+		int slashes = 0;
+		const char *entry = ent->name + prefix_offset;
+		while ((entry = strchr(entry, '/')) != NULL) {
+			slashes++;
+			if (slashes >= max_depth)
+				return;
+			entry++;
+		}
+	}
+
 	fputs(tag, stdout);
 	write_name_quoted(ent->name + offset, stdout, line_terminator);
 }
-- 
1.6.6.315.g1a406
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help