Edgewall Software

Ticket #6654: 6654-padded-revs-r9212.patch

File 6654-padded-revs-r9212.patch, 13.2 KB (added by rblank, 2 years ago)

Updated patch, added a missing conversion to int.

  • trac/db_default.py

    diff --git a/trac/db_default.py b/trac/db_default.py
    a b  
    1717from trac.db import Table, Column, Index 
    1818 
    1919# Database version identifier. Used for automatic upgrades. 
    20 db_version = 25 
     20db_version = 26 
    2121 
    2222def __mkreports(reports): 
    2323    """Utility function used to create report data in same syntax as the 
  • new file trac/upgrades/db26.py

    diff --git a/trac/upgrades/db26.py b/trac/upgrades/db26.py
    new file mode 100644
    - +  
     1 
     2def do_upgrade(env, ver, cursor): 
     3    """Zero-pad Subversion revision numbers in the cache.""" 
     4    cursor.execute(""" 
     5        SELECT id, value FROM repository WHERE name='repository_dir' 
     6        """) 
     7    for id in [id for id, dir in cursor if dir.startswith('svn:')]: 
     8        cursor.execute("SELECT DISTINCT rev FROM revision WHERE repos=%s", 
     9                       (id,)) 
     10        for rev in set(row[0] for row in cursor): 
     11            cursor.execute(""" 
     12                UPDATE revision SET rev=%s WHERE repos=%s AND rev=%s 
     13                """, ('%010d' % int(rev), id, rev)) 
     14         
     15        cursor.execute("SELECT DISTINCT rev FROM node_change WHERE repos=%s", 
     16                       (id,)) 
     17        for rev in set(row[0] for row in cursor): 
     18            cursor.execute(""" 
     19                UPDATE node_change SET rev=%s WHERE repos=%s AND rev=%s 
     20                """, ('%010d' % int(rev), id, rev)) 
  • trac/versioncontrol/cache.py

    diff --git a/trac/versioncontrol/cache.py b/trac/versioncontrol/cache.py
    a b  
    8383 
    8484    def sync_changeset(self, rev): 
    8585        cset = self.repos.get_changeset(rev) 
     86        srev = '%010d' % cset.rev 
    8687        old_cset = [None] 
    8788 
    8889        @with_transaction(self.env) 
     
    9192            cursor.execute(""" 
    9293                SELECT time,author,message FROM revision 
    9394                WHERE repos=%s AND rev=%s 
    94                 """, (self.id, str(cset.rev))) 
     95                """, (self.id, srev)) 
    9596            for time, author, message in cursor: 
    9697                old_cset[0] = Changeset(self.repos, cset.rev, message, author, 
    9798                                        from_utimestamp(time)) 
     
    99100                UPDATE revision SET time=%s, author=%s, message=%s 
    100101                WHERE repos=%s AND rev=%s 
    101102                """, (to_utimestamp(cset.date), cset.author, cset.message, 
    102                       self.id, str(cset.rev))) 
     103                      self.id, srev)) 
    103104        return old_cset[0] 
    104105         
    105106    def _metadata(self, db): 
     
    205206 
    206207            if next_youngest is None: # nothing to cache yet 
    207208                return 
     209            srev = '%010d' % next_youngest 
    208210 
    209211            # 0. first check if there's no (obvious) resync in progress 
    210212            cursor.execute(""" 
    211213               SELECT rev FROM revision WHERE repos=%s AND rev=%s 
    212                """, (self.id, str(next_youngest))) 
     214               """, (self.id, srev)) 
    213215            for rev, in cursor: 
    214216                # already there, but in progress, so keep ''previous'' 
    215217                # notion of 'youngest' 
     
    223225            actionmap = dict(zip(_actionmap.values(), _actionmap.keys())) 
    224226 
    225227            while next_youngest is not None: 
     228                srev = '%010d' % next_youngest 
    226229                 
    227230                # 1.1 Attempt to resync the 'revision' table 
    228231                self.log.info("Trying to sync revision [%s]", 
     
    233236                        INSERT INTO revision 
    234237                            (repos,rev,time,author,message) 
    235238                        VALUES (%s,%s,%s,%s,%s) 
    236                         """, (self.id, str(next_youngest), 
    237                               to_utimestamp(cset.date), 
     239                        """, (self.id, srev, to_utimestamp(cset.date), 
    238240                              cset.author, cset.message)) 
    239241                except Exception, e: # *another* 1.1. resync attempt won  
    240242                    self.log.warning('Revision %s already cached: %r', 
     
    251253                for path, kind, action, bpath, brev in cset.get_changes(): 
    252254                    self.log.debug("Caching node change in [%s]: %r", 
    253255                                   next_youngest, 
    254                                    (path,kind,action,bpath,brev)) 
     256                                   (path, kind, action, bpath, brev)) 
    255257                    kind = kindmap[kind] 
    256258                    action = actionmap[action] 
    257259                    cursor.execute(""" 
     
    259261                            (repos,rev,path,node_type, 
    260262                             change_type,base_path,base_rev) 
    261263                        VALUES (%s,%s,%s,%s,%s,%s,%s) 
    262                         """, (self.id, str(next_youngest), 
    263                               path, kind, action, bpath, brev)) 
     264                        """, (self.id, srev, path, kind, action, bpath, brev)) 
    264265 
    265266                # 1.3. iterate (1.1 should always succeed now) 
    266267                youngest = next_youngest 
     
    286287        revisions. 
    287288        """ 
    288289        last = self.normalize_rev(last) 
    289         node = self.get_node(path, last)    # Check node existence and perms 
     290        slast = '%010d' % last 
     291        node = self.get_node(path, last)    # Check node existence 
    290292        db = self.env.get_db_cnx() 
    291293        cursor = db.cursor() 
    292         rev_as_int = db.cast('rev', 'int') 
    293294        if first is None: 
    294295            cursor.execute("SELECT rev FROM node_change " 
    295                            "WHERE repos=%%s AND %s<=%%s " 
    296                            "  AND path=%%s " 
     296                           "WHERE repos=%s AND rev<=%s " 
     297                           "  AND path=%s " 
    297298                           "  AND change_type IN ('A', 'C', 'M') " 
    298                            "ORDER BY %s DESC " 
    299                            "LIMIT 1" % ((rev_as_int,) * 2), 
    300                            (self.id, last, path)) 
     299                           "ORDER BY rev DESC LIMIT 1", 
     300                           (self.id, slast, path)) 
    301301            first = 0 
    302302            for row in cursor: 
    303303                first = int(row[0]) 
     304        sfirst = '%010d' % first 
    304305        cursor.execute("SELECT DISTINCT rev FROM node_change " 
    305                        "WHERE repos=%%s AND %s>=%%s AND %s<=%%s " 
    306                        " AND (path=%%s OR path %s)" %  
    307                        (rev_as_int, rev_as_int, db.like()), 
    308                        (self.id, first, last, path, 
     306                       "WHERE repos=%%s AND rev>=%%s AND rev<=%%s " 
     307                       " AND (path=%%s OR path %s)" % db.like(), 
     308                       (self.id, sfirst, slast, path, 
    309309                        db.like_escape(path + '/') + '%')) 
    310310        return [int(row[0]) for row in cursor] 
    311311 
     
    331331            return self.repos.next_rev(self.normalize_rev(rev), path) 
    332332 
    333333    def _next_prev_rev(self, direction, rev, path=''): 
     334        srev = '%010d' % rev 
    334335        db = self.env.get_db_cnx() 
    335336        # the changeset revs are sequence of ints: 
    336337        sql = "SELECT rev FROM node_change WHERE repos=%s AND " + \ 
    337               db.cast('rev', 'int') + direction + "%s" 
    338         args = [self.id, rev] 
     338              "rev" + direction + "%s" 
     339        args = [self.id, srev] 
    339340 
    340341        if path: 
    341342            path = path.lstrip('/') 
     
    349350            for i in range(1, len(components) + 1): 
    350351                args.append('/'.join(components[:i])) 
    351352 
    352         sql += " ORDER BY " + db.cast('rev', 'int') + \ 
    353                 (direction == '<' and " DESC" or "") + " LIMIT 1" 
     353        sql += " ORDER BY rev" + (direction == '<' and " DESC" or "") \ 
     354               + " LIMIT 1" 
    354355         
    355356        cursor = db.cursor() 
    356357        cursor.execute(sql, args) 
    357358        for rev, in cursor: 
    358             return rev 
     359            return int(rev) 
    359360 
    360361    def rev_older_than(self, rev1, rev2): 
    361362        return self.repos.rev_older_than(self.normalize_rev(rev1), 
     
    396397        cursor = db.cursor() 
    397398        cursor.execute("SELECT time,author,message FROM revision " 
    398399                       "WHERE repos=%s AND rev=%s", 
    399                        (repos.id, str(rev))) 
     400                       (repos.id, '%010d' % rev)) 
    400401        row = cursor.fetchone() 
    401402        if row: 
    402403            _date, author, message = row 
     
    411412        cursor = db.cursor() 
    412413        cursor.execute("SELECT path,node_type,change_type,base_path,base_rev " 
    413414                       "FROM node_change WHERE repos=%s AND rev=%s " 
    414                        "ORDER BY path", (self.repos.id, str(self.rev))) 
     415                       "ORDER BY path", (self.repos.id, '%010d' % self.rev)) 
    415416        for path, kind, change, base_path, base_rev in cursor: 
    416417            kind = _kindmap[kind] 
    417418            change = _actionmap[change] 
  • trac/versioncontrol/tests/cache.py

    diff --git a/trac/versioncontrol/tests/cache.py b/trac/versioncontrol/tests/cache.py
    a b  
    7171                    """, [(rev[0],) + change for change in changes]) 
    7272        cursor.execute(""" 
    7373            UPDATE repository SET value=%s WHERE id=1 AND name='youngest_rev' 
    74             """, (args[-1][0][0],)) 
     74            """, (str(int(args[-1][0][0])),)) 
    7575 
    7676    # Tests 
    7777 
     
    102102 
    103103        cursor = self.db.cursor() 
    104104        cursor.execute("SELECT rev,time,author,message FROM revision") 
    105         self.assertEquals(('0', to_utimestamp(t1), '', ''), cursor.fetchone()) 
    106         self.assertEquals(('1', to_utimestamp(t2), 'joe', 'Import'), 
     105        self.assertEquals(('0000000000', to_utimestamp(t1), '', ''), 
     106                          cursor.fetchone()) 
     107        self.assertEquals(('0000000001', to_utimestamp(t2), 'joe', 'Import'), 
    107108                          cursor.fetchone()) 
    108109        self.assertEquals(None, cursor.fetchone()) 
    109110        cursor.execute(""" 
    110111            SELECT rev,path,node_type,change_type,base_path,base_rev 
    111112            FROM node_change 
    112113            """) 
    113         self.assertEquals(('1', 'trunk', 'D', 'A', None, None), 
     114        self.assertEquals(('0000000001', 'trunk', 'D', 'A', None, None), 
    114115                          cursor.fetchone()) 
    115         self.assertEquals(('1', 'trunk/README', 'F', 'A', None, None), 
     116        self.assertEquals(('0000000001', 'trunk/README', 'F', 'A', None, None), 
    116117                          cursor.fetchone()) 
    117118        self.assertEquals(None, cursor.fetchone()) 
    118119 
     
    121122        t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc) 
    122123        t3 = datetime(2003, 1, 1, 1, 1, 1, 0, utc) 
    123124        self.preset_cache( 
    124             (('0', to_utimestamp(t1), '', ''), []), 
    125             (('1', to_utimestamp(t2), 'joe', 'Import'), 
     125            (('0000000000', to_utimestamp(t1), '', ''), []), 
     126            (('0000000001', to_utimestamp(t2), 'joe', 'Import'), 
    126127             [('trunk', 'D', 'A', None, None), 
    127128              ('trunk/README', 'F', 'A', None, None)]), 
    128129            ) 
     
    141142 
    142143        cursor = self.db.cursor() 
    143144        cursor.execute(""" 
    144             SELECT time,author,message FROM revision WHERE rev='2' 
     145            SELECT time,author,message FROM revision WHERE rev='0000000002' 
    145146            """) 
    146147        self.assertEquals((to_utimestamp(t3), 'joe', 'Update'), 
    147148                          cursor.fetchone()) 
    148149        self.assertEquals(None, cursor.fetchone()) 
    149150        cursor.execute(""" 
    150151            SELECT path,node_type,change_type,base_path,base_rev 
    151             FROM node_change WHERE rev='2' 
     152            FROM node_change WHERE rev='0000000002' 
    152153            """) 
    153154        self.assertEquals(('trunk/README', 'F', 'E', 'trunk/README', '1'), 
    154155                          cursor.fetchone()) 
     
    194195            SELECT rev,path,node_type,change_type,base_path,base_rev 
    195196            FROM node_change ORDER BY rev 
    196197            """) 
    197         self.assertEquals(('1', 'trunk', 'D', 'A', None, None), 
     198        self.assertEquals(('0000000001', 'trunk', 'D', 'A', None, None), 
    198199                          cursor.fetchone()) 
    199         self.assertEquals(('1', 'trunk/README', 'F', 'A', None, None), 
     200        self.assertEquals(('0000000001', 'trunk/README', 'F', 'A', None, None), 
    200201                          cursor.fetchone()) 
    201         self.assertEquals(('2', 'trunk/README', 'F', 'E', 'trunk/README', '1'), 
     202        self.assertEquals(('0000000002', 'trunk/README', 'F', 'E', 'trunk/README', 
     203                           '1'), 
    202204                          cursor.fetchone()) 
    203205        self.assertEquals(None, cursor.fetchone()) 
    204206 
     
    206208        t1 = datetime(2001, 1, 1, 1, 1, 1, 0, utc) 
    207209        t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc) 
    208210        self.preset_cache( 
    209             (('0', to_utimestamp(t1), '', ''), []), 
    210             (('1', to_utimestamp(t2), 'joe', 'Import'), 
     211            (('0000000000', to_utimestamp(t1), '', ''), []), 
     212            (('0000000001', to_utimestamp(t2), 'joe', 'Import'), 
    211213             [('trunk', 'D', 'A', None, None), 
    212214              ('trunk/README', 'F', 'A', None, None)]), 
    213215            ) 
     
    236238        t1 = datetime(2001, 1, 1, 1, 1, 1, 0, utc) 
    237239        t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc) 
    238240        self.preset_cache( 
    239             (('0', to_utimestamp(t1), '', ''), []), 
    240             (('1', to_utimestamp(t2), 'joe', 'Import'), 
     241            (('0000000000', to_utimestamp(t1), '', ''), []), 
     242            (('0000000001', to_utimestamp(t2), 'joe', 'Import'), 
    241243             [('trunk', 'D', 'A', None, None), 
    242244              ('trunk/RDME', 'F', 'A', None, None)]), 
    243245            )