Rev 336: More consistent use of progress bars. in http://people.samba.org/bzr/jelmer/bzr-svn/bzr.dev

Jelmer Vernooij jelmer at samba.org
Sat Dec 30 17:44:49 GMT 2006


------------------------------------------------------------
revno: 336
revision-id: jelmer at samba.org-20061230174309-9614ukw3mkm0tebf
parent: jelmer at samba.org-20061230173356-d81shupvjqeb1g4j
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Sat 2006-12-30 18:43:09 +0100
message:
  More consistent use of progress bars.
  Remove unused arguments of RevisionBuildEditor.
modified:
  convert.py                     svn2bzr.py-20051018015439-cb4563bff29e632d
  fetch.py                       fetch.py-20060625004942-x2lfaib8ra707a8p-1
  fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
  format.py                      format.py-20060406233823-b6fa009fe35dfde7
  logwalker.py                   logwalker.py-20060621215743-c13fhfnyzh1xzwh2-1
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
=== modified file 'convert.py'
--- a/convert.py	2006-12-27 18:06:57 +0000
+++ b/convert.py	2006-12-30 17:43:09 +0000
@@ -30,8 +30,10 @@
 from bzrlib.branch import Branch
 from bzrlib.errors import BzrError, NotBranchError
 import bzrlib.osutils as osutils
+from bzrlib.progress import DummyProgress
 from bzrlib.repository import Repository
 from bzrlib.trace import info, mutter
+from bzrlib.ui import ui_factory
 
 from format import SvnRemoteAccess, SvnFormat
 from repository import SvnRepository
@@ -52,17 +54,19 @@
 
 
 def convert_repository(url, output_dir, scheme, create_shared_repo=True, working_trees=False):
-    tmp_repos = None
 
     if os.path.isfile(url):
         tmp_repos = tempfile.mkdtemp(prefix='bzr-svn-dump-')
         mutter('loading dumpfile %r to %r' % (url, tmp_repos))
-
         load_dumpfile(url, tmp_repos)
-            
         url = tmp_repos
+    else:
+        tmp_repos = None
 
     try:
+        source_repos = SvnRepository.open(url)
+        source_repos.set_branching_scheme(scheme)
+
         if create_shared_repo:
             try:
                 target_repos = Repository.open(output_dir)
@@ -74,34 +78,33 @@
                     BzrDir.create_repository(output_dir, shared=True)
                 target_repos = Repository.open(output_dir)
             target_repos.set_make_working_trees(working_trees)
-
-        source_repos = SvnRepository.open(url)
-
-        source_repos.set_branching_scheme(scheme)
+            # FIXME: Copy all revisions first, even the ones that aren't ancestors
+            # of currently existing branches? 
+            # source_repos.copy_content_into(target_repos)
 
         branches = list(source_repos.find_branches())
-
         mutter('branches: %r' % list(branches))
-                
         existing_branches = filter(lambda (bp, revnum, exists): exists, 
                                    branches)
-        info('Importing %d branches' % len(existing_branches))
-
-        for (branch, revnum, exists) in existing_branches:
-            source_branch = Branch.open("%s/%s" % (url, branch))
-
-            target_dir = os.path.join(output_dir, branch)
-            try:
-                target_branch = Branch.open(target_dir)
-                target_branch.pull(source_branch)
-            except NotBranchError:
-                os.makedirs(target_dir)
-                source_branch.bzrdir.sprout(target_dir, source_branch.last_revision())
-            
-            info('Converted %s:%d' % (branch, revnum))
-
+        pb = ui_factory.nested_progress_bar()
+                       
+        try:
+            i = 0
+            for (branch, revnum, exists) in existing_branches:
+                pb.update("%s:%d" % (branch, revnum), i, len(existing_branches))
+                source_branch = Branch.open("%s/%s" % (url, branch))
+
+                target_dir = os.path.join(output_dir, branch)
+                try:
+                    target_branch = Branch.open(target_dir)
+                    target_branch.pull(source_branch)
+                except NotBranchError:
+                    os.makedirs(target_dir)
+                    source_branch.bzrdir.sprout(target_dir, 
+                                                source_branch.last_revision())
+                i+=1
+        finally:
+            pb.finished()
     finally:
         if tmp_repos:
             osutils.rmtree(tmp_repos)
-
-

=== modified file 'fetch.py'
--- a/fetch.py	2006-12-30 01:18:10 +0000
+++ b/fetch.py	2006-12-30 17:43:09 +0000
@@ -18,10 +18,10 @@
 from bzrlib.decorators import needs_write_lock
 from bzrlib.inventory import Inventory, ROOT_ID
 import bzrlib.osutils as osutils
-from bzrlib.progress import ProgressBar
 from bzrlib.revision import Revision
 from bzrlib.repository import InterRepository
 from bzrlib.trace import mutter
+from bzrlib.ui import ui_factory
 
 from copy import copy
 from cStringIO import StringIO
@@ -43,25 +43,20 @@
     return s.hexdigest()
 
 class RevisionBuildEditor(svn.delta.Editor):
-    def __init__(self, source, target, branch_path, revnum, prev_inventory, revid, svn_revprops, id_map, parent_branch):
+    def __init__(self, source, target, branch_path, prev_inventory, revid, svn_revprops, id_map):
         self.branch_path = branch_path
         self.old_inventory = prev_inventory
         self.inventory = copy(prev_inventory)
         self.revid = revid
-        self.revnum = revnum
         self.id_map = id_map
-        self.parent_branch = parent_branch
         self.source = source
         self.target = target
         self.transact = target.get_transaction()
         self.weave_store = target.weave_store
-    
         self.dir_baserev = {}
-
         self._parent_ids = None
         self._revprops = {}
         self._svn_revprops = svn_revprops
-
         self.pool = Pool()
 
     def _get_revision(self, revid):
@@ -99,7 +94,6 @@
     def _get_existing_id(self, parent_id, path):
         if self.id_map.has_key(path):
             return self.id_map[path]
-
         return self._get_old_id(parent_id, path)
 
     def _get_old_id(self, parent_id, old_path):
@@ -286,7 +280,7 @@
     """The format to test with."""
 
     @needs_write_lock
-    def copy_content(self, revision_id=None, basis=None, pb=ProgressBar()):
+    def copy_content(self, revision_id=None, basis=None):
         """See InterRepository.copy_content."""
         # Dictionary with paths as keys, revnums as values
 
@@ -321,23 +315,16 @@
 
         parents[prev_revid] = None
 
-        num = 0
         needed.reverse()
         prev_revid = None
         transport = self.source.transport
+        pb = ui_factory.nested_progress_bar()
+        num = 0
         for (branch, revnum, revid) in needed:
-            if pb is not None:
-                pb.update('copying revision', num+1, len(needed)+1)
-            num += 1
+            pb.update('copying revision', num, len(needed))
 
             parent_revid = parents[revid]
 
-            if parent_revid is not None:
-                (parent_branch, parent_revnum) = self.source.parse_revision_id(parent_revid)
-            else:
-                parent_revnum = 0
-                parent_branch = None
-
             if parent_revid is None:
                 parent_inv = Inventory(ROOT_ID)
             elif prev_revid != parent_revid:
@@ -350,14 +337,14 @@
                                         revnum, branch, changes)
 
             editor = RevisionBuildEditor(self.source, self.target, branch, 
-                                         revnum, parent_inv, revid, 
+                                         parent_inv, revid, 
                                      self.source._log.get_revision_info(revnum),
-                                     id_map, parent_branch)
+                                     id_map)
 
             pool = Pool()
             edit, edit_baton = svn.delta.make_editor(editor, pool)
 
-            if parent_branch is None:
+            if parent_revid is None:
                 transport.reparent("%s/%s" % (repos_root, branch))
                 reporter, reporter_baton = transport.do_update(
                                revnum, "", True, edit, edit_baton, pool)
@@ -366,6 +353,7 @@
                 svn.ra.reporter2_invoke_set_path(reporter, reporter_baton, 
                     "", revnum, True, None, pool)
             else:
+                (parent_branch, parent_revnum) = self.source.parse_revision_id(parent_revid)
                 transport.reparent("%s/%s" % (repos_root, parent_branch))
 
                 if parent_branch != branch:
@@ -387,18 +375,16 @@
 
             prev_inv = editor.inventory
             prev_revid = revid
-
             pool.destroy()
-
-        if pb is not None:
-            pb.clear()
+            num += 1
 
         self.source.transport.reparent(repos_root)
+        pb.finished()
 
     @needs_write_lock
-    def fetch(self, revision_id=None, pb=ProgressBar()):
+    def fetch(self, revision_id=None, pb=None):
         """Fetch revisions. """
-        self.copy_content(revision_id=revision_id, pb=pb)
+        self.copy_content(revision_id=revision_id)
 
     @staticmethod
     def is_compatible(source, target):

=== modified file 'fileids.py'
--- a/fileids.py	2006-12-30 02:14:58 +0000
+++ b/fileids.py	2006-12-30 17:43:09 +0000
@@ -17,9 +17,9 @@
 from bzrlib.errors import RevisionNotPresent, NotBranchError
 from bzrlib.inventory import ROOT_ID
 from bzrlib.knit import KnitVersionedFile
-from bzrlib.progress import ProgressBar
 from bzrlib.trace import mutter
 from bzrlib.transport import get_transport
+from bzrlib.ui import ui_factory
 import bzrlib.urlutils as urlutils
 from warnings import warn
 
@@ -141,7 +141,7 @@
         return self._apply_changes(lambda x: generate_file_id(revid, x), 
                                    changes, get_children)
 
-    def get_map(self, uuid, revnum, branch, pb=None):
+    def get_map(self, uuid, revnum, branch):
         """Make sure the map is up to date until revnum."""
         # First, find the last cached map
         todo = []
@@ -163,14 +163,14 @@
         if len(map.keys()) == 0:
             map = {"": (ROOT_ID, None)} # No history -> empty map
         todo.reverse()
+        
+        pb = ui_factory.nested_progress_bar()
 
-        i = 0
+        i = 1
         for (revid, global_changes) in todo:
             changes = get_local_changes(global_changes, self.repos.scheme,
                                         uuid, self.repos._log.find_children)
-            mutter('generating file id map for %r' % revid)
-            if pb is not None:
-                pb.update('generating file id map', i, len(todo))
+            pb.update('generating file id map', i, len(todo))
 
             def find_children(path, revid):
                 (_, bp, revnum) = parse_svn_revision_id(revid)
@@ -197,11 +197,9 @@
                     map[parent] = map[parent][0], revid
                     
             next_parent_revs = [revid]
-            i = i + 1
-
-        if pb is not None:
-            pb.clear()
-
+            i += 1
+
+        pb.finished()
         self.save(revid, parent_revs, map)
         return map
 

=== modified file 'format.py'
--- a/format.py	2006-12-19 23:50:15 +0000
+++ b/format.py	2006-12-30 17:43:09 +0000
@@ -17,7 +17,7 @@
 from bzrlib.bzrdir import BzrDirFormat, BzrDir
 from bzrlib.errors import NotBranchError, NotLocalUrl, NoRepositoryPresent
 from bzrlib.lockable_files import TransportLock
-from bzrlib.progress import ProgressBar
+from bzrlib.ui import ui_factory
 from bzrlib.transport.local import LocalTransport
 import bzrlib.urlutils as urlutils
 
@@ -74,8 +74,7 @@
         else:
             try:
                 result_repo = result.find_repository()
-                result_repo.fetch(repo, revision_id=revision_id, 
-                                  pb=ProgressBar())
+                result_repo.fetch(repo, revision_id=revision_id)
             except NoRepositoryPresent:
                 result_repo = repo.clone(result, revision_id, basis)
 

=== modified file 'logwalker.py'
--- a/logwalker.py	2006-12-28 04:46:50 +0000
+++ b/logwalker.py	2006-12-30 17:43:09 +0000
@@ -15,8 +15,9 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 from bzrlib.errors import NoSuchRevision, BzrError, NotBranchError
-from bzrlib.progress import ProgressBar, DummyProgress
+from bzrlib.progress import DummyProgress
 from bzrlib.trace import mutter
+from bzrlib.ui import ui_factory
 
 import os
 
@@ -91,13 +92,16 @@
         if self.saved_revnum is None:
             self.saved_revnum = 0
 
-    def fetch_revisions(self, to_revnum, pb=None):
+    def fetch_revisions(self, to_revnum):
         """Fetch information about all revisions in the remote repository
         until to_revnum.
 
         :param to_revnum: End of range to fetch information for
-        :param pb: Optional progress bar to use
         """
+        to_revnum = max(self.last_revnum, to_revnum)
+
+        pb = ui_factory.nested_progress_bar()
+
         def rcvr(orig_paths, rev, author, date, message, pool):
             pb.update('fetching svn revision info', rev, to_revnum)
             paths = {}
@@ -118,14 +122,8 @@
             self.db.execute("replace into revision (revno, author, date, message) values (?,?,?,?)", (rev, author, date, message))
 
             self.saved_revnum = rev
-
-        to_revnum = max(self.last_revnum, to_revnum)
-
-        # Don't bother for only a few revisions
-        if abs(self.saved_revnum-to_revnum) < 10:
-            pb = DummyProgress()
-        else:
-            pb = ProgressBar()
+            if self.saved_revnum % 1000 == 0:
+                self.db.commit()
 
         pool = Pool()
         try:
@@ -133,7 +131,7 @@
                 self.transport.get_log("/", self.saved_revnum, to_revnum, 
                                0, True, True, rcvr, pool)
             finally:
-                pb.clear()
+                pb.finished()
         except SubversionException, (_, num):
             if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION:
                 raise NoSuchRevision(branch=self, 
@@ -203,7 +201,7 @@
             paths[p] = (act, cf, cr)
         return paths
 
-    def get_revision_info(self, revnum, pb=None):
+    def get_revision_info(self, revnum):
         """Obtain basic information for a specific revision.
 
         :param revnum: Revision number.
@@ -211,7 +209,7 @@
         """
         assert revnum >= 1
         if revnum > self.saved_revnum:
-            self.fetch_revisions(revnum, pb)
+            self.fetch_revisions(revnum)
         (author, message, date) = self.db.execute("select author, message, date from revision where revno="+ str(revnum)).fetchone()
         if author is None:
             author = None

=== modified file 'repository.py'
--- a/repository.py	2006-12-29 21:15:51 +0000
+++ b/repository.py	2006-12-30 17:43:09 +0000
@@ -24,7 +24,6 @@
 from bzrlib.inventory import Inventory, ROOT_ID
 from bzrlib.lockable_files import LockableFiles, TransportLock
 import bzrlib.osutils as osutils
-from bzrlib.progress import ProgressBar
 from bzrlib.repository import Repository, RepositoryFormat
 from bzrlib.revision import Revision, NULL_REVISION
 from bzrlib.transport import Transport
@@ -252,8 +251,8 @@
         assert revision_id != None
         return self.revision_tree(revision_id).inventory
 
-    def get_fileid_map(self, revnum, path, pb=None):
-        return self.fileid_map.get_map(self.uuid, revnum, path, pb)
+    def get_fileid_map(self, revnum, path):
+        return self.fileid_map.get_map(self.uuid, revnum, path)
 
     def transform_fileid_map(self, uuid, revnum, branch, changes):
         return self.fileid_map.apply_changes(uuid, revnum, branch, changes)




More information about the bazaar-commits mailing list