Commits

Ezio Melotti committed c3e9ae0

Improve the cleanpath function.

  • Participants
  • Parent commits 375ed8b

Comments (0)

Files changed (1)

 
 from __future__ import print_function
 
+import re
 import sys
 import json
 
     cached = True
   return (filename, cached)
 
+days = 'Mon|Tue|Wed|Thu|Fri|Sat|Sun'
+path_re = re.compile(r'^(?:[ab]/)?(?:python[-23][^/]*/)?(.*?)\s*'
+                     r'(?:\s(?:%s|20[01]\d|199\d|\(\w+\s)\b.*)?(?:\.orig)?$' %
+                     days, re.I)
 def cleanpath(source, target):
-    # best-effort function to clean up the path
-    path = source
-    if not source or source == 'dev/null':
-        path = target
-    # some paths are followed by the date
-    path = path.split()[0]
-    if path.startswith(('a/', 'b/')):
-        path = path[2:]
-    if path.endswith('.orig'):
-        path = path[:-5]
-    parts = path.split('/')
-    if parts[0].startswith('Python-'):
-        parts = parts[1:]
-    path = '/'.join(parts)
+    # clean up the path by removing leading a/, b/, or python* dirs,
+    # and trailing dates, or '(working copy)', or '.orig' extensions
+    path = target
+    if not target or target == 'dev/null':
+        path = source
+    # if this fails the regex is broken
+    path = path_re.match(path).group(1)
     return path
 
 issue_files = {}    # 'number' => []