All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Elijah Newren <newren@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/8] tree_entry_interesting(): remove dependency on struct diff_options
Date: Thu,  9 Sep 2010 01:50:18 +1000	[thread overview]
Message-ID: <1283961023-4491-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1283961023-4491-1-git-send-email-pclouds@gmail.com>

This function can be potentially used in more places than just
tree-diff.c. "struct diff_options" does not make much sense outside
diff_tree_sha1().

Moreover people seem to be agree that diff machinery should learn
proper pathspecs too (i.e. globbing, negative pathspecs...), not just
treating pathspecs as tree prefix.

So tree_entry_interesting() now uses struct tree_pathspec_list, which
can be easily extended later on.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 tree-diff.c |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/tree-diff.c b/tree-diff.c
index 270dea0..b0aa3a0 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -91,25 +91,20 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
  *  - zero for no
  *  - negative for "no, and no subsequent entries will be either"
  */
-static int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)
+static int tree_entry_interesting(const struct name_entry *entry, const char *base, int baselen, const struct tree_pathspec_list *ps)
 {
-	const char *path;
-	const unsigned char *sha1;
-	unsigned mode;
 	int i;
 	int pathlen;
 	int never_interesting = -1;
 
-	if (!opt->pathspec.nr)
+	if (!ps->nr)
 		return 1;
 
-	sha1 = tree_entry_extract(desc, &path, &mode);
-
-	pathlen = tree_entry_len(path, sha1);
+	pathlen = tree_entry_len(entry->path, entry->sha1);
 
-	for (i = 0; i < opt->pathspec.nr; i++) {
-		const char *match = opt->pathspec.paths[i];
-		int matchlen = opt->pathspec.info[i].pathlen;
+	for (i = 0; i < ps->nr; i++) {
+		const char *match = ps->info[i].path;
+		int matchlen = ps->info[i].pathlen;
 		int m = -1; /* signals that we haven't called strncmp() */
 
 		if (baselen >= matchlen) {
@@ -147,7 +142,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
 			 * Does match sort strictly earlier than path
 			 * with their common parts?
 			 */
-			m = strncmp(match, path,
+			m = strncmp(match, entry->path,
 				    (matchlen < pathlen) ? matchlen : pathlen);
 			if (m < 0)
 				continue;
@@ -174,7 +169,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
 		if (matchlen > pathlen) {
 			if (match[pathlen] != '/')
 				continue;
-			if (!S_ISDIR(mode))
+			if (!S_ISDIR(entry->mode))
 				continue;
 		}
 
@@ -183,7 +178,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
 			 * we cheated and did not do strncmp(), so we do
 			 * that here.
 			 */
-			m = strncmp(match, path, pathlen);
+			m = strncmp(match, entry->path, pathlen);
 
 		/*
 		 * If common part matched earlier then it is a hit,
@@ -206,8 +201,7 @@ static void show_tree(struct diff_options *opt, const char *prefix, struct tree_
 		if (all_interesting)
 			show = 1;
 		else {
-			show = tree_entry_interesting(desc, base, baselen,
-						      opt);
+			show = tree_entry_interesting(&desc->entry, base, baselen, &opt->pathspec);
 			if (show == 2)
 				all_interesting = 1;
 		}
@@ -266,7 +260,7 @@ static void skip_uninteresting(struct tree_desc *t, const char *base, int basele
 		if (all_interesting)
 			show = 1;
 		else {
-			show = tree_entry_interesting(t, base, baselen, opt);
+			show = tree_entry_interesting(&t->entry, base, baselen, &opt->pathspec);
 			if (show == 2)
 				all_interesting = 1;
 		}
-- 
1.7.1.rc1.70.g13aff

  parent reply	other threads:[~2010-09-09  3:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-08 15:50 [PATCH 0/8] en/object-list-with-pathspec v4 Nguyễn Thái Ngọc Duy
2010-09-08 15:50 ` [PATCH 1/8] diff-no-index: use diff_tree_setup_paths() Nguyễn Thái Ngọc Duy
2010-09-08 15:50 ` [PATCH 2/8] Introduce struct tree_pathspec_list Nguyễn Thái Ngọc Duy
2010-09-08 15:50 ` Nguyễn Thái Ngọc Duy [this message]
2010-09-14 15:59   ` [PATCH 3/8] tree_entry_interesting(): remove dependency on struct diff_options Junio C Hamano
2010-09-14 22:33     ` Nguyen Thai Ngoc Duy
2010-09-14 23:20       ` Junio C Hamano
2010-09-08 15:50 ` [PATCH 4/8] tree-walk: move tree_entry_interesting() from tree-diff.c Nguyễn Thái Ngọc Duy
2010-09-08 15:50 ` [PATCH 5/8] Add testcases showing how pathspecs are ignored with rev-list --objects Nguyễn Thái Ngọc Duy
2010-09-14 16:02   ` Junio C Hamano
2010-09-08 15:50 ` [PATCH 6/8] Make rev-list --objects work together with pathspecs Nguyễn Thái Ngọc Duy
2010-09-08 15:50 ` [PATCH 7/8] setup_tree_pathspec(): interpret '^' as negative pathspec Nguyễn Thái Ngọc Duy
2010-09-11 17:29   ` Elijah Newren
2010-09-13  1:39     ` Nguyen Thai Ngoc Duy
2010-09-14 16:06   ` Junio C Hamano
2010-09-14 22:41     ` Nguyen Thai Ngoc Duy
2010-09-08 15:50 ` [PATCH 8/8] tree_entry_interesting(): support " Nguyễn Thái Ngọc Duy
2010-09-11 17:33   ` Elijah Newren
2010-09-14 16:18   ` Junio C Hamano
2010-09-14 22:46     ` Nguyen Thai Ngoc Duy
2010-09-11 17:19 ` [PATCH 0/8] en/object-list-with-pathspec v4 Elijah Newren

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=1283961023-4491-4-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.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.
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.