Subject: [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 <[email-masked]>
Date: Fri, 8 Jan 2010 00:07:55 +0700

Signed-off-by: Nguyễn Thái Ngọc Duy <[email-masked]>
---
 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