git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 4/5] Integrate wildmatch to git

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 17, 2012, 17:20 UTC
Message-ID
<7vtxuwva67.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120917124020.GA21798@lanh>
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
Show 7 quoted lines
> On Sun, Sep 16, 2012 at 10:54:57PM -0700, Junio C Hamano wrote:
>> Yeah, popt.h it is.  It is a bit distasteful that we have a build
>> dependency only to build test-* helper on something that we do not
>> even have runtime dependency on.
>
> Perhaps this squash-in? It kills libpopt and removes the "#include
> "wildmatch.c"". Now we really do test what libgit.a carries.
Sounds fine to me.  Thanks; will take a look.
Show 192 quoted lines
>
> -- 8< --
> diff --git a/Makefile b/Makefile
> index 745e88c..093ab9c 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2589,9 +2589,6 @@ test-svn-fe$X: vcs-svn/lib.a
>  test-%$X: test-%.o GIT-LDFLAGS $(GITLIBS)
>  	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
>  
> -test-wildmatch$X: test-wildmatch.o GIT-LDFLAGS
> -	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) -lpopt
> -
>  check-sha1:: test-sha1$X
>  	./test-sha1.sh
>  
> diff --git a/test-wildmatch.c b/test-wildmatch.c
> index 828188a..b94921b 100644
> --- a/test-wildmatch.c
> +++ b/test-wildmatch.c
> @@ -19,17 +19,18 @@
>  
>  /*#define COMPARE_WITH_FNMATCH*/
>  
> -#define WILD_TEST_ITERATIONS
> -#include "wildmatch.c"
> +#include "cache.h"
> +#include "parse-options.h"
> +#include "wildmatch.h"
>  
> +#ifndef MAXPATHLEN
>  #define MAXPATHLEN 1024
> +#endif
>  #ifdef NO_STRLCPY
>  #include "compat/strlcpy.c"
>  #define strlcpy gitstrlcpy
>  #endif
>  
> -#include <popt.h>
> -
>  #ifdef COMPARE_WITH_FNMATCH
>  #include <fnmatch.h>
>  
> @@ -41,18 +42,16 @@ char number_separator = ',';
>  
>  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;
> +char *empties;
>  
> -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 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) */
> @@ -106,51 +105,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 625cb0c..f153f8a 100644
> --- a/wildmatch.c
> +++ b/wildmatch.c
> @@ -59,10 +59,6 @@ typedef unsigned char uchar;
>  #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,
> @@ -70,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;
> @@ -295,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;
>  }
>  
> @@ -306,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;
>  }
> @@ -325,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
> -- 8< --
Previous: Nguyen Thai Ngoc DuyNext: Nguyễn Thái Ngọc Duy
Message 32 of 34 in “Support matching "**" in .gitattributes and .gitignore”
  1. 0/5 Support matching "**" in .gitattributes and .gitignoreNguyễn Thái Ngọc Duy, Sep 15, 2012
  2. 1/5 Import wildmatch from rsyncNguyễn Thái Ngọc Duy, Sep 15, 2012
  3. Junio C HamanoSep 16, 2012
  4. 2/5 compat/wildmatch: remove static variable force_lower_caseNguyễn Thái Ngọc Duy, Sep 15, 2012
  5. 3/5 compat/wildmatch: fix case-insensitive matchingNguyễn Thái Ngọc Duy, Sep 15, 2012
  6. 4/5 Integrate wildmatch to gitNguyễn Thái Ngọc Duy, Sep 15, 2012
  7. 5/5 Support "**" in .gitignore and .gitattributes patterns using wildmatch()Nguyễn Thái Ngọc Duy, Sep 15, 2012
  8. How to create the " [PATCH 0/5]" first email?Philip Oakley, Sep 15, 2012
  9. Junio C HamanoSep 15, 2012
  10. Philip OakleySep 17, 2012
  11. Junio C HamanoSep 17, 2012
  12. Jeff KingSep 18, 2012
  13. Junio C HamanoSep 18, 2012
  14. Jeff KingSep 18, 2012
  15. Junio C HamanoSep 18, 2012
  16. Jeff KingSep 18, 2012
  17. Junio C HamanoSep 18, 2012
  18. Philip OakleySep 18, 2012
  19. Jeff KingSep 18, 2012
  20. Jeff KingSep 18, 2012
  21. Wesley J. LandakerSep 18, 2012
  22. Jan EngelhardtSep 23, 2012
  23. 0/5 Support matching "**" in .gitattributes and .gitignoreNguyễn Thái Ngọc Duy, Sep 16, 2012
  24. 1/5 Import wildmatch from rsyncNguyễn Thái Ngọc Duy, Sep 16, 2012
  25. 2/5 compat/wildmatch: remove static variable force_lower_caseNguyễn Thái Ngọc Duy, Sep 16, 2012
  26. 3/5 compat/wildmatch: fix case-insensitive matchingNguyễn Thái Ngọc Duy, Sep 16, 2012
  27. 4/5 Integrate wildmatch to gitNguyễn Thái Ngọc Duy, Sep 16, 2012
  28. Junio C HamanoSep 17, 2012
  29. Junio C HamanoSep 17, 2012
  30. Nguyen Thai Ngoc DuySep 17, 2012
  31. Nguyen Thai Ngoc DuySep 17, 2012
  32. Junio C HamanoSep 17, 2012
  33. 5/5 Support "**" in .gitignore and .gitattributes patterns using wildmatch()Nguyễn Thái Ngọc Duy, Sep 16, 2012
  34. 6/5 side-step a make rule that builds t3070-wildmatchJohannes Sixt, Sep 25, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.