From: Junio C Hamano <gitster@pobox.com>
To: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Cc: git@vger.kernel.org, Michael J Gruber <git@drmicha.warpmail.net>
Subject: Re: [PATCH] pathspec: rename per-item field has_wildcard to use_wildcard
Date: Wed, 06 Apr 2011 12:52:10 -0700 [thread overview]
Message-ID: <7vsjtvi2dx.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7vfwpvjobl.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Wed, 06 Apr 2011 10:13:02 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> I am actually tempted to add Michael's hack to get_pathspec() only to
> support the "from the top" (and error out with any other magic---as the
> approach without a proper restructuring will not work with anything but
> that particular magic), to get the "add -u" topic going, and let you (or
> other people who are interested in the pathspec rationalization) later fix
> it up just a small part of existing issues.
Just a heads-up; it would look like this (no docs, tests, nor "add -u"
message updates yet). The entries other than "top" should not be in the
final version but I just wanted to make sure that the extensibility would
look sane.
setup.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 99 insertions(+), 2 deletions(-)
diff --git a/setup.c b/setup.c
index 03cd84f..704a930 100644
--- a/setup.c
+++ b/setup.c
@@ -126,6 +126,104 @@ void verify_non_filename(const char *prefix, const char *arg)
"Use '--' to separate filenames from revisions", arg);
}
+/*
+ * Magic pathspec
+ *
+ * NEEDSWORK: These need to be moved to dir.h or even to a new
+ * pathspec.h when we restructure get_pathspec() users to use the
+ * "struct pathspec" interface.
+ */
+#define PATHSPEC_FROMTOP (1<<0)
+#define PATHSPEC_NOGLOB (1<<1)
+#define PATHSPEC_ICASE (1<<2)
+#define PATHSPEC_RECURSIVE (1<<3)
+#define PATHSPEC_REGEXP (1<<4)
+
+struct pathspec_magic {
+ unsigned bit;
+ char mnemonic; /* cannot be ':'! */
+ const char *name;
+} pathspec_magic[] = {
+ { PATHSPEC_FROMTOP, '/', "top" },
+ { PATHSPEC_NOGLOB, '!', "noglob" },
+ { PATHSPEC_ICASE, '\0', "icase" },
+ { PATHSPEC_RECURSIVE, '*', "recursive" },
+ { PATHSPEC_REGEXP, '\0', "regexp" },
+};
+
+/*
+ * Take an element of a pathspec and check for magic signatures.
+ * Append the result to the prefix.
+ *
+ * For now, we only parse the syntax and throw out anything other than
+ * "top" magic.
+ *
+ * NEEDSWORK: This needs to be rewritten when we start migrating
+ * get_pathspec() users to use the "struct pathspec" interface. For
+ * example, a pathspec element may be marked as case-insensitive, but
+ * the prefix part must always match literally, and a single stupid
+ * string cannot express such a case.
+ */
+const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
+{
+ unsigned magic = 0;
+ const char *copyfrom = elt;
+ int i;
+
+ if (elt[0] != ':') {
+ ; /* nothing to do */
+ } else if (elt[1] == '(') {
+ /* longhand */
+ const char *nextat;
+ for (copyfrom = elt + 2;
+ *copyfrom && *copyfrom != ')';
+ copyfrom = nextat) {
+ size_t len = strcspn(copyfrom, ",)");
+ if (copyfrom[len] == ')')
+ nextat = copyfrom + len;
+ else
+ nextat = copyfrom + len + 1;
+ if (!len)
+ continue;
+ for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)
+ if (strlen(pathspec_magic[i].name) == len &&
+ !strncmp(pathspec_magic[i].name, copyfrom, len)) {
+ magic |= pathspec_magic[i].bit;
+ break;
+ }
+ if (ARRAY_SIZE(pathspec_magic) <= i)
+ die("Invalid pathspec magic '%.*s' in '%s'",
+ (int) len, copyfrom, elt);
+ }
+ if (*copyfrom == ')')
+ copyfrom++;
+ } else {
+ /* shorthand */
+ for (copyfrom = elt + 1;
+ *copyfrom && *copyfrom != ':';
+ copyfrom++) {
+ char ch = *copyfrom;
+ for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)
+ if (pathspec_magic[i].mnemonic == ch) {
+ magic |= pathspec_magic[i].bit;
+ break;
+ }
+ if (ARRAY_SIZE(pathspec_magic) <= i)
+ break;
+ }
+ if (*copyfrom == ':')
+ copyfrom++;
+ }
+
+ if (magic & ~(PATHSPEC_FROMTOP))
+ die("Unsupported pathspec magic in '%s'", elt);
+
+ if (magic & PATHSPEC_FROMTOP)
+ return xstrdup(copyfrom);
+ else
+ return prefix_path(prefix, prefixlen, copyfrom);
+}
+
const char **get_pathspec(const char *prefix, const char **pathspec)
{
const char *entry = *pathspec;
@@ -147,8 +245,7 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
dst = pathspec;
prefixlen = prefix ? strlen(prefix) : 0;
while (*src) {
- const char *p = prefix_path(prefix, prefixlen, *src);
- *(dst++) = p;
+ *(dst++) = prefix_pathspec(prefix, prefixlen, *src);
src++;
}
*dst = NULL;
next prev parent reply other threads:[~2011-04-06 19:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-05 22:10 [PATCH] pathspec: rename per-item field has_wildcard to use_wildcard Junio C Hamano
2011-04-06 15:54 ` Nguyen Thai Ngoc Duy
2011-04-06 17:13 ` Junio C Hamano
2011-04-06 19:52 ` Junio C Hamano [this message]
2011-04-07 11:09 ` Michael J Gruber
2011-04-07 13:00 ` Nguyen Thai Ngoc Duy
2011-04-07 19:44 ` Junio C Hamano
2011-04-07 19:47 ` Junio C Hamano
2011-04-08 8:29 ` Michael J Gruber
2011-04-08 19:40 ` Junio C Hamano
2011-04-07 12:51 ` 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
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=7vsjtvi2dx.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=pclouds@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.
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).