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 7/8] setup_tree_pathspec(): interpret '^' as negative pathspec
Date: Thu, 9 Sep 2010 01:50:22 +1000 [thread overview]
Message-ID: <1283961023-4491-8-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1283961023-4491-1-git-send-email-pclouds@gmail.com>
This patch does preparation work for tree exclusion in
tree_entry_interesting(). '^' has similar meaning to '!' in
gitexcludes. '!' is not used because bash does not like arguments with
a leading '!'.
Eventually, "git diff -- foo ^foo/bar" should show differences in foo,
except foo/bar. If "git diff -- ^foo" is given, then it implies
everything except foo, which could surprise users that
"bar" in "git diff -- bar ^foo" has no effect at all.
NOTE: pathspec in diff machinery is also used by ce_path_match() and
read_index_preload(), which currently do not understand '^' at all.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
tree-walk.c | 28 ++++++++++++++++++++++++++++
tree-walk.h | 3 +++
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/tree-walk.c b/tree-walk.c
index e7041d7..a2f4a00 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -479,7 +479,35 @@ int setup_tree_pathspec(const char **paths, struct tree_pathspec_list *ps)
for (i=0; i < ps->nr; i++) {
struct tree_pathspec *exc = ps->info+i;
exc->path = ps->paths[i];
+ if (*exc->path == '^') {
+ exc->path++;
+ exc->to_exclude = 1;
+ }
exc->pathlen = strlen(exc->path);
+ if (exc->to_exclude) {
+ int j, found = 0;
+
+ for (j = i-1; j >= 0; j--) {
+ int len = strlen(ps->info[j].path);
+ if (len < exc->pathlen &&
+ !strncmp(ps->info[j].path, exc->path, len) &&
+ exc->path[len] == '/') {
+ ps->info[j].has_sub_pathspec = 1;
+ found = 1;
+ }
+ }
+
+ /*
+ * If a negative pathspec has nothing to
+ * negate from, include everything so it can
+ * negate from that. This way is not
+ * perfect. You may be surprised to find out
+ * "^Documentation t" does not take "t" into
+ * account at all
+ */
+ if (!found)
+ ps->include_by_default = 1;
+ }
}
return 0;
}
diff --git a/tree-walk.h b/tree-walk.h
index bb55656..6be1e6c 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -16,9 +16,12 @@ struct tree_desc {
struct tree_pathspec_list {
const char **paths;
int nr;
+ int include_by_default:1;
struct tree_pathspec {
const char *path;
int pathlen;
+ int to_exclude:1;
+ int has_sub_pathspec:1;
} *info;
};
--
1.7.1.rc1.70.g13aff
next prev parent reply other threads:[~2010-09-09 3:23 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 ` [PATCH 3/8] tree_entry_interesting(): remove dependency on struct diff_options Nguyễn Thái Ngọc Duy
2010-09-14 15:59 ` 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 ` Nguyễn Thái Ngọc Duy [this message]
2010-09-11 17:29 ` [PATCH 7/8] setup_tree_pathspec(): interpret '^' as negative pathspec 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-8-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 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).