Prechádzať zdrojové kódy

Support zero-matching for multi-asterisk patterns.

Jelmer Vernooij 7 rokov pred
rodič
commit
b30038c5f8
2 zmenil súbory, kde vykonal 8 pridanie a 7 odobranie
  1. 5 5
      dulwich/ignore.py
  2. 3 2
      dulwich/tests/test_ignore.py

+ 5 - 5
dulwich/ignore.py

@@ -51,14 +51,14 @@ def translate(pat):
     i, n = 0, len(pat)
 
     while i < n:
+        if pat[i:i+3] == b'/**':
+            res = res + '(\\/.*)?'
+            i = i+3
+            continue
         c = pat[i]
         i = i+1
         if c == '*':
-            if i < n and pat[i:i+1] == '*':
-                res = res + '.*?'
-                i = i+1
-            else:
-                res = res + '[^\/]+'
+            res = res + '[^\/]+'
         elif c == '?':
             res = res + '.'
         elif c == '[':

+ 3 - 2
dulwich/tests/test_ignore.py

@@ -61,9 +61,10 @@ TRANSLATE_TESTS = [
     ("/foo.c", 'foo\\.c\\Z(?ms)'),
     ("foo.c", '(.*\\/)?foo\\.c\\Z(?ms)'),
     ("foo.[ch]", '(.*\\/)?foo\\.[ch]\\Z(?ms)'),
-    ("foo/**", 'foo\\/.*?\\Z(?ms)'),
-    ("foo/**/blie.c", 'foo\\/.*?\\/blie\\.c\\Z(?ms)'),
+    ("foo/**", 'foo(\\/.*)?\\Z(?ms)'),
+    ("foo/**/blie.c", 'foo(\\/.*)?\\/blie\\.c\\Z(?ms)'),
     ("**/bla.c", '(.*\\/)?bla\\.c\\Z(?ms)'),
+    ("foo/**/bar", 'foo(\\/.*)?\\/bar\\Z(?ms)'),
 ]