Edgewall Software

Ticket #1271: resync_on_ranges--1333.diff

File resync_on_ranges--1333.diff, 4.5 KB (added by cboos@…, 4 years ago)

patch that implements the proposed feature

  • scripts/trac-admin

     
    583583        print 'Congratulations!' 
    584584        print 
    585585         
    586     _help_resync = [('resync', 'Re-synchronize trac with the repository')] 
     586    _help_resync = [('resync [start-rev][:end-rev]', 'Re-synchronize trac with the repository')] 
    587587     
    588588    ## Resync 
    589589    def do_resync(self, line): 
     590        arg = self.arg_tokenize(line) 
     591        if len(arg) > 0 and arg[0] != '': 
     592            sep = arg[0].find(':') 
     593            if sep == 0:                # only the 'end-rev' given 
     594                start = 0               # forces a resync from the start 
     595                end = int(arg[0][1:]) 
     596            elif sep > 0:               # both 'start-rev' and 'end-rev' given 
     597                start = int(arg[0][:sep]) 
     598                end = int(arg[0][sep+1:]) 
     599            else:                       # only the 'start-rev' given 
     600                start = int(arg[0]) 
     601                end = -1 
     602        else:                           # no revs given 
     603            start = 0 
     604            end = -1 
    590605        from svn import util, repos, core 
    591606        core.apr_initialize() 
    592607        pool = core.svn_pool_create(None) 
     
    603618         
    604619        cnx = self.__env.get_db_cnx() 
    605620        print 'resyncing...' 
    606         self.db_execsql("DELETE FROM revision") 
    607         self.db_execsql("DELETE FROM node_change") 
    608         sync.sync(cnx, rep, fs_ptr, pool) 
     621        if start > 0 and end > 0: 
     622            print '  from revision %d to revision %d' % (start, end) 
     623            self.db_execsql("DELETE FROM revision where rev >= %d and rev <= %d" % (start, end)) 
     624            self.db_execsql("DELETE FROM node_change where rev >= %d and rev <= %d" % (start, end)) 
     625        elif start > 0: 
     626            print '  from revision %d to the youngest revision' % start 
     627            self.db_execsql("DELETE FROM revision where rev >= %d" % start) 
     628            self.db_execsql("DELETE FROM node_change where rev >= %d" % start) 
     629        elif end > 0: 
     630            print '  from the first revision to revision %d' % end 
     631            self.db_execsql("DELETE FROM revision where rev <= %d" % end) 
     632            self.db_execsql("DELETE FROM node_change where rev <= %d" % end) 
     633        else: 
     634            print '  all revisions' 
     635            self.db_execsql("DELETE FROM revision") 
     636            self.db_execsql("DELETE FROM node_change") 
     637        sync.sync(cnx, rep, fs_ptr, pool, start, end) 
    609638        print 'done.' 
    610639         
    611640    ## Wiki 
  • trac/sync.py

     
    2121 
    2222from svn import fs, util, delta, repos, core 
    2323 
     24import posixpath 
    2425 
    25 def sync(db, repos, fs_ptr, pool): 
     26 
     27def sync(db, repos, fs_ptr, pool, start=-1, end=-1): 
    2628    """ 
    2729    Update the revision and node_change tables to be in sync with 
    2830    the repository. 
     31    start -- start from this changeset (-1 means the youngest stored) 
     32    end   -- end at this changeset (-1 means the youngest rev in the repository) 
    2933    """ 
    3034 
    3135    if util.SVN_VER_MAJOR < 1: 
     
    3741    cursor.execute("SELECT COALESCE(max(rev),0) FROM revision") 
    3842    youngest_stored =  int(cursor.fetchone()[0]) 
    3943    max_rev = fs.youngest_rev(fs_ptr, pool) 
    40     num = max_rev - youngest_stored 
    41     offset = youngest_stored + 1 
     44    if end < 0 or end > max_rev: 
     45        end = max_rev 
     46    # Note: after that point, start is readjusted to be one changeset _before_ the real start 
     47    if start < 0 or start > youngest_stored: 
     48        start = youngest_stored 
     49    else: 
     50        start -= 1 
     51    num = end - start 
     52    offset = start + 1 
    4253     
    4354    subpool = core.svn_pool_create(pool) 
    4455    for rev in range(num): 
     
    7788    ||     ||  'M'   || modified path                                 || 
    7889    ||     ||  'C'   || original rev, original path // copied path    || 
    7990    ||     ||  'R'   || original rev, original path // renamed path   || 
     91    ||     ||  'm'   || original rev, original path // modified path  || 
    8092    ||     ||  'd'   || original rev, original path // deleted path   || 
    8193 
    8294    The 'ADM' operations are direct operations. 
    83     The 'CR' operation can be direct operations. 
    84     The 'CRdm' may happen after a 'CR' operation on a parent path. 
     95    The 'CR' operations can be direct operations. 
     96    The 'CRdm' operations may happen after a 'CR' operation on a parent path. 
    8597    """ 
    8698 
    8799    class ChangeEditor(delta.Editor):