From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Ramsay Jones" <ramsay@ramsay1.demon.co.uk>
Subject: [PATCH 4/5] Integrate wildmatch to git
Date: Wed, 26 Sep 2012 18:25:40 +0700 [thread overview]
Message-ID: <1348658741-8146-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1348658741-8146-1-git-send-email-pclouds@gmail.com>
This makes wildmatch.c part of libgit.a and builds test-wildmatch; the
dependency on libpopt in the original has been replaced with the use
of our parse-options. Global variables in test-wildmatch are marked
static to avoid sparse warnings.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
.gitignore | 1 +
Makefile | 3 ++
t/t3070-wildmatch.sh | 27 ++++++++++++++++
test-wildmatch.c | 88 ++++++++++++++++++++++------------------------------
wildmatch.c | 26 +++++-----------
5 files changed, 75 insertions(+), 70 deletions(-)
create mode 100755 t/t3070-wildmatch.sh
diff --git a/.gitignore b/.gitignore
index 68fe464..54b1b3b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -196,6 +196,7 @@
/test-sigchain
/test-subprocess
/test-svn-fe
+/test-wildmatch
/common-cmds.h
*.tar.gz
*.dsc
diff --git a/Makefile b/Makefile
index 26b697d..d6235e6 100644
--- a/Makefile
+++ b/Makefile
@@ -504,6 +504,7 @@ TEST_PROGRAMS_NEED_X += test-sha1
TEST_PROGRAMS_NEED_X += test-sigchain
TEST_PROGRAMS_NEED_X += test-subprocess
TEST_PROGRAMS_NEED_X += test-svn-fe
+TEST_PROGRAMS_NEED_X += test-wildmatch
TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
@@ -676,6 +677,7 @@ LIB_H += userdiff.h
LIB_H += utf8.h
LIB_H += varint.h
LIB_H += walker.h
+LIB_H += wildmatch.h
LIB_H += wt-status.h
LIB_H += xdiff-interface.h
LIB_H += xdiff/xdiff.h
@@ -807,6 +809,7 @@ LIB_OBJS += utf8.o
LIB_OBJS += varint.o
LIB_OBJS += version.o
LIB_OBJS += walker.o
+LIB_OBJS += wildmatch.o
LIB_OBJS += wrapper.o
LIB_OBJS += write_or_die.o
LIB_OBJS += ws.o
diff --git a/t/t3070-wildmatch.sh b/t/t3070-wildmatch.sh
new file mode 100755
index 0000000..c4da26c
--- /dev/null
+++ b/t/t3070-wildmatch.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+test_description='wildmatch tests'
+
+. ./test-lib.sh
+
+test_wildmatch() {
+ test_expect_success "wildmatch $*" "
+ test-wildmatch $* ../t3070/wildtest.txt >actual &&
+ echo 'No wildmatch errors found.' >expected &&
+ test_cmp expected actual
+ "
+}
+
+test_wildmatch -x1
+test_wildmatch -x1 -e1
+test_wildmatch -x1 -else
+test_wildmatch -x2
+test_wildmatch -x2 -ese
+test_wildmatch -x3
+test_wildmatch -x3 -e1
+test_wildmatch -x4
+test_wildmatch -x4 -e2e
+test_wildmatch -x5
+test_wildmatch -x5 -es
+
+test_done
diff --git a/test-wildmatch.c b/test-wildmatch.c
index 88585c2..bb726c8 100644
--- a/test-wildmatch.c
+++ b/test-wildmatch.c
@@ -19,34 +19,38 @@
/*#define COMPARE_WITH_FNMATCH*/
-#define WILD_TEST_ITERATIONS
-#include "lib/wildmatch.c"
+#include "cache.h"
+#include "parse-options.h"
+#include "wildmatch.h"
-#include <popt.h>
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 1024
+#endif
+#ifdef NO_STRLCPY
+#include "compat/strlcpy.c"
+#define strlcpy gitstrlcpy
+#endif
#ifdef COMPARE_WITH_FNMATCH
#include <fnmatch.h>
-int fnmatch_errors = 0;
+static int fnmatch_errors = 0;
#endif
-int wildmatch_errors = 0;
-char number_separator = ',';
+static int wildmatch_errors = 0;
typedef char bool;
-int output_iterations = 0;
-int explode_mod = 0;
-int empties_mod = 0;
-int empty_at_start = 0;
-int empty_at_end = 0;
-
-static struct poptOption long_options[] = {
- /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
- {"iterations", 'i', POPT_ARG_NONE, &output_iterations, 0, 0, 0},
- {"empties", 'e', POPT_ARG_STRING, 0, 'e', 0, 0},
- {"explode", 'x', POPT_ARG_INT, &explode_mod, 0, 0, 0},
- {0,0,0,0, 0, 0, 0}
+static int explode_mod = 0;
+static int empties_mod = 0;
+static int empty_at_start = 0;
+static int empty_at_end = 0;
+static char *empties;
+
+static struct option options[] = {
+ OPT_STRING('e', "empties", &empties, "", ""),
+ OPT_INTEGER('x', "explode", &explode_mod, ""),
+ OPT_END(),
};
/* match just at the start of string (anchored tests) */
@@ -100,51 +104,33 @@ run_test(int line, bool matches,
fnmatch_errors++;
}
#endif
- if (output_iterations) {
- printf("%d: \"%s\" iterations = %d\n", line, pattern,
- wildmatch_iteration_count);
- }
}
int
main(int argc, char **argv)
{
char buf[2048], *s, *string[2], *end[2];
- const char *arg;
FILE *fp;
- int opt, line, i, flag[2];
- poptContext pc = poptGetContext("wildtest", argc, (const char**)argv,
- long_options, 0);
-
- while ((opt = poptGetNextOpt(pc)) != -1) {
- switch (opt) {
- case 'e':
- arg = poptGetOptArg(pc);
- empties_mod = atoi(arg);
- if (strchr(arg, 's'))
- empty_at_start = 1;
- if (strchr(arg, 'e'))
- empty_at_end = 1;
- if (!explode_mod)
- explode_mod = 1024;
- break;
- default:
- fprintf(stderr, "%s: %s\n",
- poptBadOption(pc, POPT_BADOPTION_NOALIAS),
- poptStrerror(opt));
- exit(1);
- }
+ int line, i, flag[2];
+ const char *help[] = { NULL };
+
+ argc = parse_options(argc, (const char **)argv, "", options, help, 0);
+ if (argc != 1)
+ die("redundant options");
+ if (empties) {
+ const char *arg = empties;
+ empties_mod = atoi(arg);
+ if (strchr(empties, 's'))
+ empty_at_start = 1;
+ if (strchr(arg, 'e'))
+ empty_at_end = 1;
+ if (!explode_mod)
+ explode_mod = 1024;
}
if (explode_mod && !empties_mod)
empties_mod = 1024;
- argv = (char**)poptGetArgs(pc);
- if (!argv || argv[1]) {
- fprintf(stderr, "Usage: wildtest [OPTIONS] TESTFILE\n");
- exit(1);
- }
-
if ((fp = fopen(*argv, "r")) == NULL) {
fprintf(stderr, "Unable to open %s\n", *argv);
exit(1);
diff --git a/wildmatch.c b/wildmatch.c
index c7f7f9f..f153f8a 100644
--- a/wildmatch.c
+++ b/wildmatch.c
@@ -9,7 +9,13 @@
** work differently than '*', and to fix the character-class code.
*/
-#include "rsync.h"
+#include <stddef.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "wildmatch.h"
+
+typedef unsigned char uchar;
/* What character marks an inverted character class? */
#define NEGATE_CLASS '!'
@@ -53,10 +59,6 @@
#define ISUPPER(c) (ISASCII(c) && isupper(c))
#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
-#ifdef WILD_TEST_ITERATIONS
-int wildmatch_iteration_count;
-#endif
-
/* Match pattern "p" against the a virtually-joined string consisting
* of "text" and any strings in array "a". */
static int dowild(const uchar *p, const uchar *text,
@@ -64,10 +66,6 @@ static int dowild(const uchar *p, const uchar *text,
{
uchar p_ch;
-#ifdef WILD_TEST_ITERATIONS
- wildmatch_iteration_count++;
-#endif
-
for ( ; (p_ch = *p) != '\0'; text++, p++) {
int matched, special;
uchar t_ch, prev_ch;
@@ -289,9 +287,6 @@ static const uchar *trailing_N_elements(const uchar*const **a_ptr, int count)
int wildmatch(const char *pattern, const char *text)
{
static const uchar *nomore[1]; /* A NULL pointer. */
-#ifdef WILD_TEST_ITERATIONS
- wildmatch_iteration_count = 0;
-#endif
return dowild((const uchar*)pattern, (const uchar*)text, nomore, 0) == TRUE;
}
@@ -300,9 +295,6 @@ int iwildmatch(const char *pattern, const char *text)
{
static const uchar *nomore[1]; /* A NULL pointer. */
int ret;
-#ifdef WILD_TEST_ITERATIONS
- wildmatch_iteration_count = 0;
-#endif
ret = dowild((const uchar*)pattern, (const uchar*)text, nomore, 1) == TRUE;
return ret;
}
@@ -319,10 +311,6 @@ int wildmatch_array(const char *pattern, const char*const *texts, int where)
const uchar *text;
int matched;
-#ifdef WILD_TEST_ITERATIONS
- wildmatch_iteration_count = 0;
-#endif
-
if (where > 0)
text = trailing_N_elements(&a, where);
else
--
1.7.12.1.406.g6ab07c4
next prev parent reply other threads:[~2012-09-26 11:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-26 11:25 [PATCH 0/5] wildmatch series update Nguyễn Thái Ngọc Duy
2012-09-26 11:25 ` [PATCH 1/5] Import wildmatch from rsync Nguyễn Thái Ngọc Duy
2012-10-02 14:07 ` Ævar Arnfjörð Bjarmason
[not found] ` <CAHSx_SsnSAV7SVLRnAFvS7AmdRgPkPX3NEM+6HTjfW5r8hXeig@mail.gmail.com>
2012-10-02 18:26 ` Junio C Hamano
2012-09-26 11:25 ` [PATCH 2/5] compat/wildmatch: remove static variable force_lower_case Nguyễn Thái Ngọc Duy
2012-09-26 11:25 ` [PATCH 3/5] compat/wildmatch: fix case-insensitive matching Nguyễn Thái Ngọc Duy
2012-09-26 11:25 ` Nguyễn Thái Ngọc Duy [this message]
2012-09-26 11:25 ` [PATCH 5/5] Support "**" in .gitignore and .gitattributes patterns using wildmatch() Nguyễn Thái Ngọc Duy
2012-09-27 18:08 ` [PATCH 0/5] wildmatch series update Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2012-09-15 12:01 [PATCH 0/5] Support matching "**" in .gitattributes and .gitignore Nguyễn Thái Ngọc Duy
2012-09-15 12:02 ` [PATCH 4/5] Integrate wildmatch to git Nguyễn Thái Ngọc 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=1348658741-8146-5-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ramsay@ramsay1.demon.co.uk \
/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).