Edgewall Software

Ticket #1271: trac-0.9stable-r2652.resync-ranges.patch

File trac-0.9stable-r2652.resync-ranges.patch, 5.8 KB (added by vyt@…, 6 years ago)

Patch against 0.9 stable

  • trac/scripts/admin.py

    diff -ur trac_russian.orig/trac/scripts/admin.py trac_russian/trac/scripts/admin.py
    old new  
    649649           project_dir=os.path.basename(self.envname), 
    650650           config_path=os.path.join(self.envname, 'conf', 'trac.ini')) 
    651651 
    652     _help_resync = [('resync', 'Re-synchronize trac with the repository')] 
     652    _help_resync = [('resync [start-rev][:end-rev]', 'Re-synchronize trac with the repository')] 
    653653 
    654654    ## Resync 
    655655    def do_resync(self, line): 
     656        arg = self.arg_tokenize(line) 
     657        if len(arg) > 0 and arg[0] != '': 
     658            sep = arg[0].find(':') 
     659            if sep == 0:                # only the 'end-rev' given 
     660                start = 0               # forces a resync from the start 
     661                end = int(arg[0][1:]) 
     662            elif sep > 0:               # both 'start-rev' and 'end-rev' given 
     663                start = int(arg[0][:sep]) 
     664                end = int(arg[0][sep+1:]) 
     665            else:                       # only the 'start-rev' given 
     666                start = int(arg[0]) 
     667                end = -1 
     668        else:                           # no revs given 
     669            start = 0 
     670            end = -1         
    656671        print 'Resyncing repository history...' 
    657672        cnx = self.db_open() 
    658673        cursor = cnx.cursor() 
    659         cursor.execute("DELETE FROM revision") 
    660         cursor.execute("DELETE FROM node_change") 
     674        if start > 0 and end > 0: 
     675            print '  from revision %d to revision %d' % (start, end) 
     676            cursor.execute("DELETE FROM revision where rev >= %d and rev <= %d" % (start, end)) 
     677            cursor.execute("DELETE FROM node_change where rev >= %d and rev <= %d" % (start, end)) 
     678        elif start > 0: 
     679            print '  from revision %d to the youngest revision' % start 
     680            cursor.execute("DELETE FROM revision where rev >= %d" % start) 
     681            cursor.execute("DELETE FROM node_change where rev >= %d" % start) 
     682        elif end > 0: 
     683            print '  from the first revision to revision %d' % end 
     684            cursor.execute("DELETE FROM revision where rev <= %d" % end) 
     685            cursor.execute("DELETE FROM node_change where rev <= %d" % end) 
     686        else: 
     687            print '  all revisions' 
     688            cursor.execute("DELETE FROM revision") 
     689            cursor.execute("DELETE FROM node_change") 
    661690        repos = self.__env.get_repository() 
    662691        cursor.execute("DELETE FROM system WHERE name='repository_dir'") 
    663692        cursor.execute("INSERT INTO system (name,value) " 
    664693                       "VALUES ('repository_dir',%s)", (repos.name,)) 
    665         repos.sync() 
     694        if start <= 0: 
     695            start = None 
     696        if end <= 0: 
     697            end = None 
     698        repos.sync(start, end) 
    666699        print 'Done.' 
    667700 
    668701    ## Wiki 
  • trac/versioncontrol/cache.py

    diff -ur trac_russian.orig/trac/versioncontrol/cache.py trac_russian/trac/versioncontrol/cache.py
    old new  
    4444        return CachedChangeset(self.repos.normalize_rev(rev), self.db, 
    4545                               self.authz) 
    4646 
    47     def sync(self): 
     47    def sync(self, first = None, last = None): 
    4848        self.log.debug("Checking whether sync with repository is needed") 
    4949        cursor = self.db.cursor() 
    5050 
     
    6161                              "a 'trac-admin resync' operation is needed.") 
    6262 
    6363        youngest_stored = self.repos.get_youngest_rev_in_cache(self.db) 
    64  
    65         if youngest_stored != str(self.repos.youngest_rev): 
     64        if youngest_stored != str(self.repos.youngest_rev) or first or last: 
    6665            authz = self.repos.authz 
    6766            self.repos.authz = Authorizer() # remove permission checking 
    6867 
    6968            kindmap = dict(zip(_kindmap.values(), _kindmap.keys())) 
    7069            actionmap = dict(zip(_actionmap.values(), _actionmap.keys())) 
    71             self.log.info("Syncing with repository (%s to %s)" 
    72                           % (youngest_stored, self.repos.youngest_rev)) 
    73             if youngest_stored: 
    74                 current_rev = self.repos.next_rev(youngest_stored) 
     70             
     71            if first == None and not youngest_stored: 
     72                first = self.repos.oldest_rev 
     73            elif first == None or self.rev_older_than(youngest_stored, first): 
     74                first = self.repos.next_rev(youngest_stored) 
     75            else: 
     76                first = self.normalize_rev(first) 
     77             
     78            if last == None: 
     79                last = self.repos.youngest_rev 
    7580            else: 
    76                 current_rev = self.repos.oldest_rev 
    77             while current_rev is not None: 
     81                last = self.normalize_rev(last) 
     82             
     83            self.log.info("Syncing with repository (%s to %s)" % (first, last)) 
     84             
     85            current_rev = first 
     86            while current_rev is not None and not self.repos.rev_older_than(last, current_rev): 
    7887                changeset = self.repos.get_changeset(current_rev) 
    79                 cursor.execute("INSERT INTO revision (rev,time,author,message) " 
    80                                "VALUES (%s,%s,%s,%s)", (str(current_rev), 
    81                                changeset.date, changeset.author, 
    82                                changeset.message)) 
     88                cursor.execute("INSERT INTO revision (rev, time, " 
     89                               "author, message) VALUES (%s,%s,%s,%s)", 
     90                               (str(current_rev), changeset.date, 
     91                                changeset.author, changeset.message)) 
    8392                for path,kind,action,base_path,base_rev in changeset.get_changes(): 
    8493                    self.log.debug("Caching node change in [%s]: %s" 
    8594                                   % (current_rev, (path, kind, action,