[Python-checkins] r85303 - in tracker/instances/python-dev: lib/identify_patch.py scripts/addpatchsets

martin.v.loewis python-checkins at python.org
Thu Oct 7 21:42:30 CEST 2010


Author: martin.v.loewis
Date: Thu Oct  7 21:42:30 2010
New Revision: 85303

Log:
Record all file paths, to identify patches applying
to subdirectories.


Modified:
   tracker/instances/python-dev/lib/identify_patch.py
   tracker/instances/python-dev/scripts/addpatchsets

Modified: tracker/instances/python-dev/lib/identify_patch.py
==============================================================================
--- tracker/instances/python-dev/lib/identify_patch.py	(original)
+++ tracker/instances/python-dev/lib/identify_patch.py	Thu Oct  7 21:42:30 2010
@@ -21,6 +21,26 @@
     # may need to cache more revisions
     return fill_revs(db, lookfor=rev)
 
+def addfiles(cursor, files):
+    """Add all files to fileprefix that aren't there, in all
+    prefix/suffix combinations."""
+    to_add = []
+    for f in files:
+        cursor.execute("select count(*) from fileprefix "
+                       "where prefix='' and suffix=%s",
+                       (f,))
+        if cursor.fetchone()[0] > 0:
+            continue
+        parts = f.split('/')
+        for i in range(len(parts)):
+            prefix = '/'.join(parts[:i])
+            if i:
+                prefix += '/'
+            suffix = '/'.join(parts[i:])
+            to_add.append((prefix, suffix))
+    cursor.executemany("insert into fileprefix(prefix, suffix) "
+                       "values(%s, %s)", to_add)
+
 def fill_revs(db, lookfor=None):
     """Initialize/update svnbranch table. If lookfor is given,
     return its branch, or None if that cannot be determined."""
@@ -44,6 +64,7 @@
         # svn log failed
         return None
     xml = ElementTree.fromstring(data)
+    files = set()
     for entry in xml.findall('logentry'):
         rev = int(entry.get('revision'))
         paths = [p.text for p in entry.findall('paths/path')]
@@ -67,10 +88,15 @@
                 # inconsistent commit
                 break
         else:
+            if branch in ('/trunk', '/branches/py3k'):
+                # Add all files that ever existed on the main trunks
+                for p in paths:
+                    files.add(p[len(ppath)+1:])
             c.execute('insert into svnbranch(rev, branch) values(%s, %s)',
                       (rev, branch))
             if lookfor == rev:
                 result = branch
+    addfiles(c, files)
     db.commit()
     return result
 
@@ -78,9 +104,12 @@
 if __name__=='__main__':
     # manual setup:
     # create table svnbranch(rev integer primary key, branch text);
+    # create table fileprefix(prefix text, suffix text);
+    # create index fileprefix_suffix on fileprefix(suffix);
     # then run this once in the instance directory
     sys.path.append('/home/roundup/lib/python2.5/site-packages')
     import roundup.instance
     tracker = roundup.instance.open('.')
     db = tracker.open('admin')
+    #db.cursor.execute('delete from svnbranch')
     fill_revs(db)

Modified: tracker/instances/python-dev/scripts/addpatchsets
==============================================================================
--- tracker/instances/python-dev/scripts/addpatchsets	(original)
+++ tracker/instances/python-dev/scripts/addpatchsets	Thu Oct  7 21:42:30 2010
@@ -48,9 +48,28 @@
     return base
 
 def find_bases(data, rev):
+    c = connection.cursor()
     startrev = rev
     to_match = []
-    for filename, data in engine.SplitPatch(data):
+    split = engine.SplitPatch(data)
+    # Check whether a prefix needs to be added to each file path
+    prefixes = None
+    for filename, data in split:
+        c.execute('select prefix from fileprefix where suffix=%s', (filename,))
+        res = c.fetchall()
+        if not res:
+            # prefix not known to Python at all - not a Python patch
+            return None, None
+        res = set(p[0] for p in res)
+        if prefixes is None:
+            prefixes = res
+        else:
+            prefixes = prefixes.intersection(res)
+        if not prefixes:
+            # no common prefix can be found
+            return None, None
+    # parse each file patch to chunks
+    for filename, data in split:
         lines = data.splitlines(True)
         chunks = patching.ParsePatchToChunks(lines)
         if not chunks:
@@ -78,16 +97,24 @@
         if verbose:
             print "Trying ", branch, rev
 
-        bases = []
-        for filename, data, chunks in to_match:
-            res = try_match(filename, chunks, branch, rev)
-            if not res:
-                break
-            bases.append((filename, data, chunks, res))
-        else:
-            if verbose:
-                print "Found match", branch, rev
-            return branch, bases
+        # if some file may occur with multiple prefixes,
+        # try them all - except that the intersection of all
+        # possible prefixes was taken above, so this should
+        # typically only use one round, and typically use ''
+        # as the prefix
+        for prefix in prefixes:
+            bases = []
+            for filename, data, chunks in to_match:
+                res = try_match(prefix+filename, chunks, branch, rev)
+                if not res:
+                    # try next prefix if any,
+                    # else go to previous revision
+                    break
+                bases.append((prefix+filename, data, chunks, res))
+            else:
+                if verbose:
+                    print "Found match", branch+prefix, rev
+                return branch, bases
         rev -= 1
 
 c = connection.cursor()


More information about the Python-checkins mailing list