From: Clemens Buchacher <drizzd@aon.at>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
johannes@familieschneider.info, Clemens Buchacher <drizzd@aon.at>
Subject: [PATCH 3/3] implement pattern matching in ce_path_match
Date: Wed, 14 Jan 2009 15:54:36 +0100 [thread overview]
Message-ID: <1231944876-29930-4-git-send-email-drizzd@aon.at> (raw)
In-Reply-To: <1231944876-29930-3-git-send-email-drizzd@aon.at>
For tracked files, matching globbing pattern in "git add" was broken
by 1e5f764c (builtin-add.c: optimize -A option and "git add ."), which
uses ce_path_match instead of match_pathspec for tracked files.
But ce_path_match does not implement pattern matching.
With this patch ce_path_match uses match_pathspec in order to perform
pattern matching.
This also implies pattern matching for many other git commands, such
as add -u, blame, log, etc. For "git log --follow", we have to
disallow globbing pattern, because they potentially match more than
one file.
Reported-by: Johannes Schneider <johannes@familieschneider.info>
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
builtin-log.c | 13 ++++++++++++-
read-cache.c | 23 +----------------------
t/t2200-add-update.sh | 10 ++++++++++
3 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index c7aa48e..16e9207 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -25,6 +25,17 @@ static int default_show_root = 1;
static const char *fmt_patch_subject_prefix = "PATCH";
static const char *fmt_pretty;
+static int has_special(const char *p)
+{
+ int x;
+
+ while ((x = *p++) != '\0')
+ if (isspecial(x))
+ return 1;
+
+ return 0;
+}
+
static void cmd_log_init(int argc, const char **argv, const char *prefix,
struct rev_info *rev)
{
@@ -49,7 +60,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
rev->always_show_header = 0;
if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
rev->always_show_header = 0;
- if (rev->diffopt.nr_paths != 1)
+ if (rev->diffopt.nr_paths != 1 || has_special(rev->diffopt.paths[0]))
usage("git logs can only follow renames on one pathname at a time");
}
for (i = 1; i < argc; i++) {
diff --git a/read-cache.c b/read-cache.c
index b1475ff..8a5f306 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -640,28 +640,7 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)
int ce_path_match(const struct cache_entry *ce, const char **pathspec)
{
- const char *match, *name;
- int len;
-
- if (!pathspec)
- return 1;
-
- len = ce_namelen(ce);
- name = ce->name;
- while ((match = *pathspec++) != NULL) {
- int matchlen = strlen(match);
- if (matchlen > len)
- continue;
- if (memcmp(name, match, matchlen))
- continue;
- if (matchlen && name[matchlen-1] == '/')
- return 1;
- if (name[matchlen] == '/' || !name[matchlen])
- return 1;
- if (!matchlen)
- return 1;
- }
- return 0;
+ return match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL);
}
/*
diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index cd9231c..6d99461 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -128,4 +128,14 @@ test_expect_success 'add -n -u should not add but just report' '
'
+test_expect_success 'wildcard update' '
+
+ : >a.x &&
+ git add "*.x" &&
+ echo asdf >a.x &&
+ git add -u "*.x" &&
+ test -z "`git ls-files -m a.x`"
+
+'
+
test_done
--
1.6.1
next prev parent reply other threads:[~2009-01-14 14:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-14 14:54 [PATCH 0/3] fix "git add" pattern matching Clemens Buchacher
2009-01-14 14:54 ` [PATCH 1/3] clean up pathspec matching Clemens Buchacher
2009-01-14 14:54 ` [PATCH 2/3] remove pathspec_match, use match_pathspec instead Clemens Buchacher
2009-01-14 14:54 ` Clemens Buchacher [this message]
2009-01-14 15:25 ` [PATCH 3/3] implement pattern matching in ce_path_match Clemens Buchacher
2009-01-14 15:44 ` Johannes Schindelin
2009-01-14 15:55 ` Sverre Rabbelier
2009-01-14 16:18 ` Samuel Tardieu
2009-01-14 16:53 ` Jeff King
2009-01-14 18:39 ` Junio C Hamano
2009-01-14 19:23 ` Clemens Buchacher
2009-01-14 22:27 ` Junio C Hamano
2009-01-15 8:20 ` Clemens Buchacher
2009-01-16 2:51 ` Junio C Hamano
2009-01-14 15:40 ` [PATCH 2/3] remove pathspec_match, use match_pathspec instead Johannes Schindelin
2009-01-14 16:09 ` Clemens Buchacher
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=1231944876-29930-4-git-send-email-drizzd@aon.at \
--to=drizzd@aon.at \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes@familieschneider.info \
/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).