From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH v5 10/12] wildmatch: adjust "**" behavior Date: Sun, 14 Oct 2012 09:35:08 +0700 Message-ID: <1350182110-25936-11-git-send-email-pclouds@gmail.com> References: <1350182110-25936-1-git-send-email-pclouds@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Junio C Hamano , =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Sun Oct 14 04:36:48 2012 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TNE4K-0005zN-NK for gcvg-git-2@plane.gmane.org; Sun, 14 Oct 2012 04:36:45 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751995Ab2JNCge convert rfc822-to-quoted-printable (ORCPT ); Sat, 13 Oct 2012 22:36:34 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:37467 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751674Ab2JNCgd (ORCPT ); Sat, 13 Oct 2012 22:36:33 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr4so3964144pbb.19 for ; Sat, 13 Oct 2012 19:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=7gB2CWMmuw5AequhCzTFugaSBohbVDvtaRw22eTEKlA=; b=A9qS31LZFqTGkxhrpck9nIfFKEtGg/B+gbIRHW1IqE+yl/Y4zlpuOdV6QQqaYU73Ww m046sHf31+B05B6X5XjkAFdvIvX51NaB8jB2ZMqdOl6cPoeaov5kgi0XqA99eiJxnUb7 Suz/DKWV3Z7R49Dx2h1DD6M3aloe5lvc59dXz+AheYLVZ95e2P/kDA0iJyHjxyNqEUYH y53y/W0/mCOG/BJi90rjw5l0AJqEUn5UrX1NoHx5hpxOHu1gkzMMb9LwKiJaAJAMDiD6 qLSsQZ690KjmEXzKqEjZJfO1vqhzvw7BQT7CFKNuQeAD9k9yczVITy+/IK5/xe0PngI+ GD1A== Received: by 10.66.85.162 with SMTP id i2mr14691300paz.72.1350182192944; Sat, 13 Oct 2012 19:36:32 -0700 (PDT) Received: from pclouds@gmail.com ([115.74.54.82]) by mx.google.com with ESMTPS id pw2sm6811966pbb.59.2012.10.13.19.36.30 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 13 Oct 2012 19:36:32 -0700 (PDT) Received: by pclouds@gmail.com (sSMTP sendmail emulation); Sun, 14 Oct 2012 09:36:18 +0700 X-Mailer: git-send-email 1.8.0.rc2.11.g2b79d01 In-Reply-To: <1350182110-25936-1-git-send-email-pclouds@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Standard wildmatch() sees consecutive asterisks as "*" that can also match slashes. But that may be hard to explain to users as "abc/**/def" can match "abcdef", "abcxyzdef", "abc/def", "abc/x/def", "abc/x/y/def"... This patch changes wildmatch so that users can do - "**/def" -> all paths ending with file/directory 'def' - "abc/**" - equivalent to "/abc/" - "abc/**/def" -> "abc/x/def", "abc/x/y/def"... - otherwise consider the pattern malformed if "**" is found Basically the magic of "**" only remains if it's wrapped around by slashes. Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- t/t3070-wildmatch.sh | 5 +++-- wildmatch.c | 13 +++++++------ wildmatch.h | 6 ++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/t/t3070-wildmatch.sh b/t/t3070-wildmatch.sh index dd95b00..15848d5 100755 --- a/t/t3070-wildmatch.sh +++ b/t/t3070-wildmatch.sh @@ -46,7 +46,7 @@ match 0 0 foobar 'foo\*bar' match 1 1 'f\oo' 'f\\oo' match 1 1 ball '*[al]?' match 0 0 ten '[ten]' -match 1 1 ten '**[!te]' +match 0 1 ten '**[!te]' match 0 0 ten '**[!ten]' match 1 1 ten 't[a-g]n' match 0 0 ten 't[!a-g]n' @@ -61,7 +61,8 @@ match 1 1 ']' ']' =20 # Extended slash-matching features match 0 0 'foo/baz/bar' 'foo*bar' -match 1 0 'foo/baz/bar' 'foo**bar' +match 0 0 'foo/baz/bar' 'foo**bar' +match 0 1 'foobazbar' 'foo**bar' match 0 0 'foo/bar' 'foo?bar' match 0 0 'foo/bar' 'foo[/]bar' match 0 0 'foo/bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r' diff --git a/wildmatch.c b/wildmatch.c index 6542524..7209f26 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -21,11 +21,6 @@ typedef unsigned char uchar; #define FALSE 0 #define TRUE 1 =20 -#define NOMATCH 1 -#define MATCH 0 -#define ABORT_ALL -1 -#define ABORT_TO_STARSTAR -2 - #define CC_EQ(class, len, litmatch) ((len) =3D=3D sizeof (litmatch)-1 = \ && *(class) =3D=3D *(litmatch) \ && strncmp((char*)class, litmatch, len) =3D=3D 0) @@ -90,8 +85,14 @@ static int dowild(const uchar *p, const uchar *text,= int force_lower_case) continue; case '*': if (*++p =3D=3D '*') { + const uchar *prev_p =3D p - 2; while (*++p =3D=3D '*') {} - special =3D TRUE; + if ((prev_p =3D=3D text || *prev_p =3D=3D '/') || + (*p =3D=3D '\0' || *p =3D=3D '/' || + (p[0] =3D=3D '\\' && p[1] =3D=3D '/'))) { + special =3D TRUE; + } else + return ABORT_MALFORMED; } else special =3D FALSE; if (*p =3D=3D '\0') { diff --git a/wildmatch.h b/wildmatch.h index e974f9a..984a38c 100644 --- a/wildmatch.h +++ b/wildmatch.h @@ -1,3 +1,9 @@ /* wildmatch.h */ =20 +#define ABORT_MALFORMED 2 +#define NOMATCH 1 +#define MATCH 0 +#define ABORT_ALL -1 +#define ABORT_TO_STARSTAR -2 + int wildmatch(const char *pattern, const char *text, int flags); --=20 1.8.0.rc2.11.g2b79d01