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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]