From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/6] Convert prefix_pathspec() to produce struct pathspec_item
Date: Wed, 12 Oct 2011 09:44:40 +1100 [thread overview]
Message-ID: <1318373083-13840-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1318373083-13840-1-git-send-email-pclouds@gmail.com>
New field plain_len is used to mark the first part of 'match' where no
magic can be applied. It's not used though. tree_entry_interesting()
should learn to utilize it.
Now we can show get_pathspec() what magic a pathspec has. Make sure
only certain magic is accepted because more will come in future and
not all of them can be converted to plain string like
PATHSPEC_FROMTOP.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
match_pathspec_depth() should also check for unsupported magic..
cache.h | 1 +
setup.c | 22 +++++++++++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/cache.h b/cache.h
index fe46f1e..17df06f 100644
--- a/cache.h
+++ b/cache.h
@@ -548,6 +548,7 @@ struct pathspec {
struct pathspec_item {
const char *match;
int len;
+ int plain_len; /* match[0..plain_len-1] does not have any kind of magic*/
unsigned magic;
} *items;
};
diff --git a/setup.c b/setup.c
index 35db910..8f1c2c0 100644
--- a/setup.c
+++ b/setup.c
@@ -126,7 +126,8 @@ static struct pathspec_magic {
* the prefix part must always match literally, and a single stupid
* string cannot express such a case.
*/
-static const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
+static const char *prefix_pathspec(struct pathspec_item *item, const char *prefix,
+ int prefixlen, const char *elt)
{
unsigned magic = 0;
const char *copyfrom = elt;
@@ -181,10 +182,17 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
copyfrom++;
}
+ memset(item, 0, sizeof(*item));
+ item->magic = magic;
+
if (magic & PATHSPEC_FROMTOP)
- return xstrdup(copyfrom);
- else
- return prefix_path(prefix, prefixlen, copyfrom);
+ item->match = xstrdup(copyfrom);
+ else {
+ item->match = prefix_path(prefix, prefixlen, copyfrom);
+ item->plain_len = prefixlen;
+ }
+ item->len = strlen(item->match);
+ return 0;
}
const char **get_pathspec(const char *prefix, const char **pathspec)
@@ -208,7 +216,11 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
dst = pathspec;
prefixlen = prefix ? strlen(prefix) : 0;
while (*src) {
- *(dst++) = prefix_pathspec(prefix, prefixlen, *src);
+ struct pathspec_item item;
+ prefix_pathspec(&item, prefix, prefixlen, *src);
+ if (item.magic & ~PATHSPEC_FROMTOP)
+ die("Unsupported magic pathspec %s", *src);
+ *(dst++) = item.match;
src++;
}
*dst = NULL;
--
1.7.3.1.256.g2539c.dirty
next prev parent reply other threads:[~2011-10-11 22:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-11 22:44 [PATCH 0/6] Negation magic pathspec Nguyễn Thái Ngọc Duy
2011-10-11 22:44 ` [PATCH 1/6] Recognize magic pathspec as filenames Nguyễn Thái Ngọc Duy
2011-10-12 20:49 ` Junio C Hamano
2011-10-13 4:23 ` Nguyen Thai Ngoc Duy
2011-10-13 6:06 ` Junio C Hamano
2011-10-11 22:44 ` [PATCH 2/6] Replace has_wildcard with PATHSPEC_NOGLOB Nguyễn Thái Ngọc Duy
2011-10-11 22:44 ` Nguyễn Thái Ngọc Duy [this message]
2011-10-11 22:44 ` [PATCH 4/6] Implement parse_pathspec() Nguyễn Thái Ngọc Duy
2011-10-11 22:44 ` [PATCH 5/6] Convert simple init_pathspec() cases to parse_pathspec() Nguyễn Thái Ngọc Duy
2011-10-13 0:29 ` Junio C Hamano
2011-10-11 22:44 ` [PATCH 6/6] Implement negative pathspec Nguyễn Thái Ngọc Duy
2011-10-11 23:17 ` [PATCH 0/6] Negation magic pathspec 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=1318373083-13840-4-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.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).