git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 2/6] ls-files -i: micro-optimize path_excluded()
Date: Tue,  5 Jun 2012 22:45:15 -0700	[thread overview]
Message-ID: <1338961519-30970-3-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1338961519-30970-1-git-send-email-gitster@pobox.com>

As we know a caller that does not recurse is calling us in the index
order, we can remember the last directory we found to be excluded
and see if the path we are looking at is still inside it, in which
case we can just answer that it is excluded.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 dir.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/dir.c b/dir.c
index c3f0884..839bc9f 100644
--- a/dir.c
+++ b/dir.c
@@ -592,11 +592,25 @@ void path_exclude_check_clear(struct path_exclude_check *check)
 	strbuf_release(&check->path);
 }
 
+/*
+ * Is the ce->name excluded?  This is for a caller like show_files() that
+ * do not honor directory hierarchy and iterate through paths that are
+ * possibly in an ignored directory.
+ *
+ * A path to a directory known to be excluded is left in check->path to
+ * optimize for repeated checks for files in the same excluded directory.
+ */
 int path_excluded(struct path_exclude_check *check, struct cache_entry *ce)
 {
 	int i, dtype;
 	struct strbuf *path = &check->path;
 
+	if (path->len &&
+	    path->len <= ce_namelen(ce) &&
+	    !memcmp(ce->name, path->buf, path->len) &&
+	    (!ce->name[path->len] || ce->name[path->len] == '/'))
+		return 1;
+
 	strbuf_setlen(path, 0);
 	for (i = 0; ce->name[i]; i++) {
 		int ch = ce->name[i];
@@ -608,6 +622,10 @@ int path_excluded(struct path_exclude_check *check, struct cache_entry *ce)
 		}
 		strbuf_addch(path, ch);
 	}
+
+	/* An entry in the index; cannot be a directory with subentries */
+	strbuf_setlen(path, 0);
+
 	dtype = ce_to_dtype(ce);
 	return excluded(check->dir, ce->name, &dtype);
 }
-- 
1.7.11.rc1.37.g09843ac

  parent reply	other threads:[~2012-06-06  5:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06  5:45 [PATCH 0/6] "ls-files -i" not honoring directory wide ignore Junio C Hamano
2012-06-06  5:45 ` [PATCH 1/6] ls-files -i: pay attention to exclusion of leading paths Junio C Hamano
2012-06-06  5:45 ` Junio C Hamano [this message]
2012-06-06  5:45 ` [PATCH 3/6] path_excluded(): update API to less cache-entry centric Junio C Hamano
2012-06-06  5:45 ` [PATCH 4/6] builtin/add.c: use path_excluded() Junio C Hamano
2012-06-06  5:45 ` [PATCH 5/6] unpack-trees.c: use path_excluded() in check_ok_to_remove() Junio C Hamano
2012-06-06  5:45 ` [PATCH 6/6] dir.c: make excluded() file scope static Junio C Hamano

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=1338961519-30970-3-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).