From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 1/3] ls-files: support --max-depth
Date: Fri, 8 Jan 2010 00:07:54 +0700 [thread overview]
Message-ID: <1262884076-12293-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1262884076-12293-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin-ls-files.c | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 7382157..2bb851a 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -30,6 +30,7 @@ static int error_unmatch;
static char *ps_matched;
static const char *with_tree;
static int exc_given;
+static int max_depth = 0;
static const char *tag_cached = "";
static const char *tag_unmerged = "";
@@ -232,6 +233,30 @@ static void prune_cache(const char *prefix)
active_nr = last;
}
+/*
+ * It is assumed that prune_cache() as been called before this
+ */
+static void prune_cache_by_depth(const char *prefix, int max_depth)
+{
+ int i = active_nr-1;
+
+ while (i >= 0) {
+ int slashes = 0;
+ const char *entry = active_cache[i]->name + prefix_len;
+ while ((entry = strchr(entry, '/')) != NULL) {
+ slashes++;
+ if (slashes >= max_depth) {
+ memmove(active_cache + i, active_cache + i + 1,
+ (active_nr - i - 1) * sizeof(struct cache_entry *));
+ active_nr--;
+ break;
+ }
+ entry++;
+ }
+ i--;
+ }
+}
+
static const char *verify_pathspec(const char *prefix)
{
const char **p, *n, *prev;
@@ -476,6 +501,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
"if any <file> is not in the index, treat this as an error"),
OPT_STRING(0, "with-tree", &with_tree, "tree-ish",
"pretend that paths removed since <tree-ish> are still present"),
+ OPT_INTEGER(0, "max-depth", &max_depth, "max recursive depth"),
OPT__ABBREV(&abbrev),
OPT_END()
};
@@ -541,6 +567,10 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
if (prefix)
prune_cache(prefix);
+
+ if (max_depth)
+ prune_cache_by_depth(prefix, max_depth);
+
if (with_tree) {
/*
* Basic sanity check; show-stages and show-unmerged
--
1.6.6.315.g1a406
next prev parent reply other threads:[~2010-01-07 17:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-07 17:07 [PATCH 0/3] Bringing git-ls-files to porcelain level Nguyễn Thái Ngọc Duy
2010-01-07 17:07 ` Nguyễn Thái Ngọc Duy [this message]
2010-01-07 17:07 ` [PATCH 2/3] ls-files: support -o --max-depth (more of a hack as fill_directory should support this) Nguyễn Thái Ngọc Duy
2010-01-07 18:01 ` Junio C Hamano
2010-01-07 17:07 ` [PATCH 3/3] Add "ls", which is basically ls-files with user-friendly settings Nguyễn Thái Ngọc Duy
2010-01-07 18:01 ` Junio C Hamano
2010-01-07 18:09 ` Nguyen Thai Ngoc Duy
2010-01-08 14:16 ` Nguyen Thai Ngoc Duy
2010-01-07 18:12 ` Matthieu Moy
2010-01-07 17:40 ` [PATCH 0/3] Bringing git-ls-files to porcelain level Matthieu Moy
2010-01-07 17:47 ` Nguyen Thai Ngoc Duy
2010-11-01 10:30 ` Kan-Ru Chen
2010-11-01 11:20 ` Nguyen Thai Ngoc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1262884076-12293-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.