Sfoglia il codice sorgente

Put flags at begining of expression, to make Python3.7 happy.

Jelmer Vernooij 7 anni fa
parent
commit
ca3cc8a58b
2 ha cambiato i file con 15 aggiunte e 15 eliminazioni
  1. 5 5
      dulwich/ignore.py
  2. 10 10
      dulwich/tests/test_ignore.py

+ 5 - 5
dulwich/ignore.py

@@ -34,16 +34,16 @@ def translate(pat):
     to cope with features in Git ignore patterns.
     """
 
-    res = b''
+    res = b'(?ms)'
 
     if b'/' not in pat:
         # If there's no slash, this is a filename-based match
-        res = b'(.*\/)?'
+        res = res + b'(.*\/)?'
 
     if pat.startswith(b'**/'):
         # Leading **/
         pat = pat[2:]
-        res = b'(.*\/)?'
+        res = res + b'(.*\/)?'
 
     if pat.startswith(b'/'):
         pat = pat[1:]
@@ -81,7 +81,7 @@ def translate(pat):
                 res = res + b'[' + stuff + b']'
         else:
             res = res + re.escape(c)
-    return res + b'\Z(?ms)'
+    return res + b'\Z'
 
 
 def read_ignore_patterns(f):
@@ -98,7 +98,7 @@ def read_ignore_patterns(f):
         if not l:
             continue
 
-        if l[0:1] == b'#':
+        if l.startswith(b'#'):
             # Comment
             continue
 

+ 10 - 10
dulwich/tests/test_ignore.py

@@ -56,16 +56,16 @@ NEGATIVE_MATCH_TESTS = [
 
 
 TRANSLATE_TESTS = [
-    (b"*.c", b'(.*\\/)?[^\\/]+\\.c\\Z(?ms)'),
-    (b"foo.c", b'(.*\\/)?foo\\.c\\Z(?ms)'),
-    (b"/*.c", b'[^\\/]+\\.c\\Z(?ms)'),
-    (b"/foo.c", b'foo\\.c\\Z(?ms)'),
-    (b"foo.c", b'(.*\\/)?foo\\.c\\Z(?ms)'),
-    (b"foo.[ch]", b'(.*\\/)?foo\\.[ch]\\Z(?ms)'),
-    (b"foo/**", b'foo(\\/.*)?\\Z(?ms)'),
-    (b"foo/**/blie.c", b'foo(\\/.*)?\\/blie\\.c\\Z(?ms)'),
-    (b"**/bla.c", b'(.*\\/)?bla\\.c\\Z(?ms)'),
-    (b"foo/**/bar", b'foo(\\/.*)?\\/bar\\Z(?ms)'),
+    (b"*.c", b'(?ms)(.*\\/)?[^\\/]+\\.c\\Z'),
+    (b"foo.c", b'(?ms)(.*\\/)?foo\\.c\\Z'),
+    (b"/*.c", b'(?ms)[^\\/]+\\.c\\Z'),
+    (b"/foo.c", b'(?ms)foo\\.c\\Z'),
+    (b"foo.c", b'(?ms)(.*\\/)?foo\\.c\\Z'),
+    (b"foo.[ch]", b'(?ms)(.*\\/)?foo\\.[ch]\\Z'),
+    (b"foo/**", b'(?ms)foo(\\/.*)?\\Z'),
+    (b"foo/**/blie.c", b'(?ms)foo(\\/.*)?\\/blie\\.c\\Z'),
+    (b"**/bla.c", b'(?ms)(.*\\/)?bla\\.c\\Z'),
+    (b"foo/**/bar", b'(?ms)foo(\\/.*)?\\/bar\\Z'),
 ]