From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 06/19] Move tree_entry_interesting() to tree-walk.c and export it
Date: Mon, 13 Dec 2010 16:46:43 +0700 [thread overview]
Message-ID: <1292233616-27692-7-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1292233616-27692-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
tree-diff.c | 109 ---------------------------------------------------------
tree-walk.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tree-walk.h | 2 +
3 files changed, 113 insertions(+), 109 deletions(-)
diff --git a/tree-diff.c b/tree-diff.c
index 822d45e..50d7e6d 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -82,115 +82,6 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
return 0;
}
-/*
- * Is a tree entry interesting given the pathspec we have?
- *
- * Return:
- * - 2 for "yes, and all subsequent entries will be"
- * - 1 for yes
- * - zero for no
- * - negative for "no, and no subsequent entries will be either"
- */
-static int tree_entry_interesting(const struct name_entry *entry, const char *base, int baselen, const struct pathspec *ps)
-{
- int i;
- int pathlen;
- int never_interesting = -1;
-
- if (!ps || !ps->nr)
- return 1;
-
- pathlen = tree_entry_len(entry->path, entry->sha1);
-
- for (i = 0; i < ps->nr; i++) {
- const char *match = ps->raw[i];
- int matchlen = ps->items[i].len;
- int m = -1; /* signals that we haven't called strncmp() */
-
- if (baselen >= matchlen) {
- /* If it doesn't match, move along... */
- if (strncmp(base, match, matchlen))
- continue;
-
- /*
- * If the base is a subdirectory of a path which
- * was specified, all of them are interesting.
- */
- if (!matchlen ||
- base[matchlen] == '/' ||
- match[matchlen - 1] == '/')
- return 2;
-
- /* Just a random prefix match */
- continue;
- }
-
- /* Does the base match? */
- if (strncmp(base, match, baselen))
- continue;
-
- match += baselen;
- matchlen -= baselen;
-
- if (never_interesting) {
- /*
- * We have not seen any match that sorts later
- * than the current path.
- */
-
- /*
- * Does match sort strictly earlier than path
- * with their common parts?
- */
- m = strncmp(match, entry->path,
- (matchlen < pathlen) ? matchlen : pathlen);
- if (m < 0)
- continue;
-
- /*
- * If we come here even once, that means there is at
- * least one pathspec that would sort equal to or
- * later than the path we are currently looking at.
- * In other words, if we have never reached this point
- * after iterating all pathspecs, it means all
- * pathspecs are either outside of base, or inside the
- * base but sorts strictly earlier than the current
- * one. In either case, they will never match the
- * subsequent entries. In such a case, we initialized
- * the variable to -1 and that is what will be
- * returned, allowing the caller to terminate early.
- */
- never_interesting = 0;
- }
-
- if (pathlen > matchlen)
- continue;
-
- if (matchlen > pathlen) {
- if (match[pathlen] != '/')
- continue;
- if (!S_ISDIR(entry->mode))
- continue;
- }
-
- if (m == -1)
- /*
- * we cheated and did not do strncmp(), so we do
- * that here.
- */
- m = strncmp(match, entry->path, pathlen);
-
- /*
- * If common part matched earlier then it is a hit,
- * because we rejected the case where path is not a
- * leading directory and is shorter than match.
- */
- if (!m)
- return 1;
- }
- return never_interesting; /* No matches */
-}
-
/* A whole sub-tree went away or appeared */
static void show_tree(struct diff_options *opt, const char *prefix, struct tree_desc *desc, const char *base, int baselen)
{
diff --git a/tree-walk.c b/tree-walk.c
index a9bbf4e..01168ea 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -455,3 +455,114 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
free(tree);
return retval;
}
+
+/*
+ * Is a tree entry interesting given the pathspec we have?
+ *
+ * Return:
+ * - 2 for "yes, and all subsequent entries will be"
+ * - 1 for yes
+ * - zero for no
+ * - negative for "no, and no subsequent entries will be either"
+ */
+int tree_entry_interesting(const struct name_entry *entry,
+ const char *base, int baselen,
+ const struct pathspec *ps)
+{
+ int i;
+ int pathlen;
+ int never_interesting = -1;
+
+ if (!ps || !ps->nr)
+ return 1;
+
+ pathlen = tree_entry_len(entry->path, entry->sha1);
+
+ for (i = 0; i < ps->nr; i++) {
+ const char *match = ps->raw[i];
+ int matchlen = ps->items[i].len;
+ int m = -1; /* signals that we haven't called strncmp() */
+
+ if (baselen >= matchlen) {
+ /* If it doesn't match, move along... */
+ if (strncmp(base, match, matchlen))
+ continue;
+
+ /*
+ * If the base is a subdirectory of a path which
+ * was specified, all of them are interesting.
+ */
+ if (!matchlen ||
+ base[matchlen] == '/' ||
+ match[matchlen - 1] == '/')
+ return 2;
+
+ /* Just a random prefix match */
+ continue;
+ }
+
+ /* Does the base match? */
+ if (strncmp(base, match, baselen))
+ continue;
+
+ match += baselen;
+ matchlen -= baselen;
+
+ if (never_interesting) {
+ /*
+ * We have not seen any match that sorts later
+ * than the current path.
+ */
+
+ /*
+ * Does match sort strictly earlier than path
+ * with their common parts?
+ */
+ m = strncmp(match, entry->path,
+ (matchlen < pathlen) ? matchlen : pathlen);
+ if (m < 0)
+ continue;
+
+ /*
+ * If we come here even once, that means there is at
+ * least one pathspec that would sort equal to or
+ * later than the path we are currently looking at.
+ * In other words, if we have never reached this point
+ * after iterating all pathspecs, it means all
+ * pathspecs are either outside of base, or inside the
+ * base but sorts strictly earlier than the current
+ * one. In either case, they will never match the
+ * subsequent entries. In such a case, we initialized
+ * the variable to -1 and that is what will be
+ * returned, allowing the caller to terminate early.
+ */
+ never_interesting = 0;
+ }
+
+ if (pathlen > matchlen)
+ continue;
+
+ if (matchlen > pathlen) {
+ if (match[pathlen] != '/')
+ continue;
+ if (!S_ISDIR(entry->mode))
+ continue;
+ }
+
+ if (m == -1)
+ /*
+ * we cheated and did not do strncmp(), so we do
+ * that here.
+ */
+ m = strncmp(match, entry->path, pathlen);
+
+ /*
+ * If common part matched earlier then it is a hit,
+ * because we rejected the case where path is not a
+ * leading directory and is shorter than match.
+ */
+ if (!m)
+ return 1;
+ }
+ return never_interesting; /* No matches */
+}
diff --git a/tree-walk.h b/tree-walk.h
index 7e3e0b5..c12f0a2 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -60,4 +60,6 @@ static inline int traverse_path_len(const struct traverse_info *info, const stru
return info->pathlen + tree_entry_len(n->path, n->sha1);
}
+extern int tree_entry_interesting(const struct name_entry *, const char *, int, const struct pathspec *ps);
+
#endif
--
1.7.3.3.476.g10a82
next prev parent reply other threads:[~2010-12-13 9:48 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-13 9:46 [PATCH 00/19] nd/struct-pathspec (or pathspec unification [1]) Nguyễn Thái Ngọc Duy
2010-12-13 9:46 ` [PATCH 01/19] Add struct pathspec Nguyễn Thái Ngọc Duy
2010-12-13 17:31 ` Thiago Farina
2010-12-14 12:50 ` Nguyen Thai Ngoc Duy
2010-12-13 9:46 ` [PATCH 02/19] diff-no-index: use diff_tree_setup_paths() Nguyễn Thái Ngọc Duy
2010-12-13 9:46 ` [PATCH 03/19] pathspec: cache string length when initializing pathspec Nguyễn Thái Ngọc Duy
2010-12-13 9:46 ` [PATCH 04/19] Convert struct diff_options to use struct pathspec Nguyễn Thái Ngọc Duy
2010-12-13 19:00 ` Junio C Hamano
2010-12-14 5:02 ` Nguyen Thai Ngoc Duy
2010-12-13 9:46 ` [PATCH 05/19] tree_entry_interesting(): remove dependency on struct diff_options Nguyễn Thái Ngọc Duy
2010-12-13 19:11 ` Junio C Hamano
2010-12-13 9:46 ` Nguyễn Thái Ngọc Duy [this message]
2010-12-13 9:46 ` [PATCH 07/19] glossary: define pathspec Nguyễn Thái Ngọc Duy
2010-12-13 9:46 ` [PATCH 08/19] pathspec: mark wildcard pathspecs from the beginning Nguyễn Thái Ngọc Duy
2010-12-13 18:09 ` Junio C Hamano
2010-12-13 9:46 ` [PATCH 09/19] tree-diff.c: reserve space in "base" for pathname concatenation Nguyễn Thái Ngọc Duy
2010-12-13 18:10 ` Junio C Hamano
2010-12-14 5:00 ` Nguyen Thai Ngoc Duy
2010-12-14 5:32 ` Junio C Hamano
2010-12-14 7:10 ` Nguyen Thai Ngoc Duy
2010-12-14 7:32 ` Johannes Sixt
2010-12-14 7:43 ` Nguyen Thai Ngoc Duy
2010-12-14 8:21 ` Johannes Sixt
2010-12-14 13:01 ` Nguyen Thai Ngoc Duy
2010-12-14 17:11 ` Junio C Hamano
2010-12-13 9:46 ` [PATCH 10/19] tree_entry_interesting(): factor out most matching logic Nguyễn Thái Ngọc Duy
2010-12-13 18:10 ` Junio C Hamano
2010-12-13 9:46 ` [PATCH 11/19] tree_entry_interesting: support depth limit Nguyễn Thái Ngọc Duy
2010-12-13 18:10 ` Junio C Hamano
2010-12-14 14:44 ` Nguyen Thai Ngoc Duy
2010-12-13 9:46 ` [PATCH 12/19] tree_entry_interesting(): support wildcard matching Nguyễn Thái Ngọc Duy
2010-12-13 18:10 ` Junio C Hamano
2010-12-14 15:04 ` Nguyen Thai Ngoc Duy
2010-12-13 9:46 ` [PATCH 13/19] tree_entry_interesting(): optimize fnmatch when base is matched Nguyễn Thái Ngọc Duy
2010-12-13 18:10 ` Junio C Hamano
2010-12-13 9:46 ` [PATCH 14/19] Convert ce_path_match() use to match_pathspec() Nguyễn Thái Ngọc Duy
2010-12-13 19:31 ` Junio C Hamano
2010-12-14 15:14 ` Nguyen Thai Ngoc Duy
2010-12-13 9:46 ` [PATCH 15/19] pathspec: add match_pathspec_depth() Nguyễn Thái Ngọc Duy
2010-12-13 19:28 ` Junio C Hamano
2010-12-14 5:07 ` Nguyen Thai Ngoc Duy
2010-12-13 9:46 ` [PATCH 16/19] grep: convert to use struct pathspec Nguyễn Thái Ngọc Duy
2010-12-13 9:46 ` [PATCH 17/19] grep: use match_pathspec_depth() for cache/worktree grepping Nguyễn Thái Ngọc Duy
2010-12-13 9:46 ` [PATCH 18/19] grep: use preallocated buffer for grep_tree() Nguyễn Thái Ngọc Duy
2010-12-13 9:46 ` [PATCH 19/19] grep: drop pathspec_matches() in favor of tree_entry_interesting() Nguyễn Thái Ngọc 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1292233616-27692-7-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).