diff -ur trac_russian.orig/trac/scripts/admin.py trac_russian/trac/scripts/admin.py
--- trac_russian.orig/trac/scripts/admin.py	2005-12-14 18:59:23 +0300
+++ trac_russian/trac/scripts/admin.py	2005-12-14 19:01:51 +0300
@@ -649,20 +649,53 @@
            project_dir=os.path.basename(self.envname),
            config_path=os.path.join(self.envname, 'conf', 'trac.ini'))
 
-    _help_resync = [('resync', 'Re-synchronize trac with the repository')]
+    _help_resync = [('resync [start-rev][:end-rev]', 'Re-synchronize trac with the repository')]
 
     ## Resync
     def do_resync(self, line):
+        arg = self.arg_tokenize(line)
+        if len(arg) > 0 and arg[0] != '':
+            sep = arg[0].find(':')
+            if sep == 0:                # only the 'end-rev' given
+                start = 0               # forces a resync from the start
+                end = int(arg[0][1:])
+            elif sep > 0:               # both 'start-rev' and 'end-rev' given
+                start = int(arg[0][:sep])
+                end = int(arg[0][sep+1:])
+            else:                       # only the 'start-rev' given
+                start = int(arg[0])
+                end = -1
+        else:                           # no revs given
+            start = 0
+            end = -1        
         print 'Resyncing repository history...'
         cnx = self.db_open()
         cursor = cnx.cursor()
-        cursor.execute("DELETE FROM revision")
-        cursor.execute("DELETE FROM node_change")
+        if start > 0 and end > 0:
+            print '  from revision %d to revision %d' % (start, end)
+            cursor.execute("DELETE FROM revision where rev >= %d and rev <= %d" % (start, end))
+            cursor.execute("DELETE FROM node_change where rev >= %d and rev <= %d" % (start, end))
+        elif start > 0:
+            print '  from revision %d to the youngest revision' % start
+            cursor.execute("DELETE FROM revision where rev >= %d" % start)
+            cursor.execute("DELETE FROM node_change where rev >= %d" % start)
+        elif end > 0:
+            print '  from the first revision to revision %d' % end
+            cursor.execute("DELETE FROM revision where rev <= %d" % end)
+            cursor.execute("DELETE FROM node_change where rev <= %d" % end)
+        else:
+            print '  all revisions'
+            cursor.execute("DELETE FROM revision")
+            cursor.execute("DELETE FROM node_change")
         repos = self.__env.get_repository()
         cursor.execute("DELETE FROM system WHERE name='repository_dir'")
         cursor.execute("INSERT INTO system (name,value) "
                        "VALUES ('repository_dir',%s)", (repos.name,))
-        repos.sync()
+        if start <= 0:
+            start = None
+        if end <= 0:
+            end = None
+        repos.sync(start, end)
         print 'Done.'
 
     ## Wiki
diff -ur trac_russian.orig/trac/versioncontrol/cache.py trac_russian/trac/versioncontrol/cache.py
--- trac_russian.orig/trac/versioncontrol/cache.py	2005-12-14 19:00:15 +0300
+++ trac_russian/trac/versioncontrol/cache.py	2005-12-14 19:02:39 +0300
@@ -44,7 +44,7 @@
         return CachedChangeset(self.repos.normalize_rev(rev), self.db,
                                self.authz)
 
-    def sync(self):
+    def sync(self, first = None, last = None):
         self.log.debug("Checking whether sync with repository is needed")
         cursor = self.db.cursor()
 
@@ -61,25 +61,34 @@
                               "a 'trac-admin resync' operation is needed.")
 
         youngest_stored = self.repos.get_youngest_rev_in_cache(self.db)
-
-        if youngest_stored != str(self.repos.youngest_rev):
+        if youngest_stored != str(self.repos.youngest_rev) or first or last:
             authz = self.repos.authz
             self.repos.authz = Authorizer() # remove permission checking
 
             kindmap = dict(zip(_kindmap.values(), _kindmap.keys()))
             actionmap = dict(zip(_actionmap.values(), _actionmap.keys()))
-            self.log.info("Syncing with repository (%s to %s)"
-                          % (youngest_stored, self.repos.youngest_rev))
-            if youngest_stored:
-                current_rev = self.repos.next_rev(youngest_stored)
+            
+            if first == None and not youngest_stored:
+                first = self.repos.oldest_rev
+            elif first == None or self.rev_older_than(youngest_stored, first):
+                first = self.repos.next_rev(youngest_stored)
+            else:
+                first = self.normalize_rev(first)
+            
+            if last == None:
+                last = self.repos.youngest_rev
             else:
-                current_rev = self.repos.oldest_rev
-            while current_rev is not None:
+                last = self.normalize_rev(last)
+            
+            self.log.info("Syncing with repository (%s to %s)" % (first, last))
+            
+            current_rev = first
+            while current_rev is not None and not self.repos.rev_older_than(last, current_rev):
                 changeset = self.repos.get_changeset(current_rev)
-                cursor.execute("INSERT INTO revision (rev,time,author,message) "
-                               "VALUES (%s,%s,%s,%s)", (str(current_rev),
-                               changeset.date, changeset.author,
-                               changeset.message))
+                cursor.execute("INSERT INTO revision (rev, time, "
+                               "author, message) VALUES (%s,%s,%s,%s)",
+                               (str(current_rev), changeset.date,
+                                changeset.author, changeset.message))
                 for path,kind,action,base_path,base_rev in changeset.get_changes():
                     self.log.debug("Caching node change in [%s]: %s"
                                    % (current_rev, (path, kind, action,

