Rev 2478: Change calls to try/mkdir('.')/except FileExists to ensure_base() in http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/single_connect_for_push_75721

John Arbash Meinel john at arbash-meinel.com
Wed May 2 15:54:38 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/single_connect_for_push_75721

------------------------------------------------------------
revno: 2478
revision-id: john at arbash-meinel.com-20070502145420-k2vebnl0rd45q8kk
parent: john at arbash-meinel.com-20070502143655-id25373m3lgue8ke
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: single_connect_for_push_75721
timestamp: Wed 2007-05-02 09:54:20 -0500
message:
  Change calls to try/mkdir('.')/except FileExists to ensure_base()
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2007-04-24 19:43:09 +0000
+++ b/bzrlib/branch.py	2007-05-02 14:54:20 +0000
@@ -783,10 +783,7 @@
         :return: The tree of the created checkout
         """
         t = transport.get_transport(to_location)
-        try:
-            t.mkdir('.')
-        except errors.FileExists:
-            pass
+        t.ensure_base()
         if lightweight:
             format = self._get_checkout_format()
             checkout = format.initialize_on_transport(t)

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-05-01 22:41:41 +0000
+++ b/bzrlib/builtins.py	2007-05-02 14:54:20 +0000
@@ -771,8 +771,8 @@
                 # Now we only need to create child directories
                 while needed:
                     cur_transport = needed.pop()
-                    cur_transport.mkdir('.')
-            
+                    cur_transport.ensure_base()
+
             # Now the target directory exists, but doesn't have a .bzr
             # directory. So we need to create it, along with any work to create
             # all of the dependent branches, etc.
@@ -1283,11 +1283,8 @@
         # believe that we want to create a bunch of
         # locations if the user supplies an extended path
         # TODO: create-prefix
-        try:
-            to_transport.mkdir('.')
-        except errors.FileExists:
-            pass
-                    
+        to_transport.ensure_base()
+
         try:
             existing_bzrdir = bzrdir.BzrDir.open(location)
         except errors.NotBranchError:
@@ -1348,10 +1345,7 @@
             location = '.'
 
         to_transport = transport.get_transport(location)
-        try:
-            to_transport.mkdir('.')
-        except errors.FileExists:
-            pass
+        to_transport.ensure_base()
 
         newdir = format.initialize_on_transport(to_transport)
         repo = newdir.create_repository(shared=True)

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2007-05-01 22:41:41 +0000
+++ b/bzrlib/bzrdir.py	2007-05-02 14:54:20 +0000
@@ -170,7 +170,7 @@
         :param force_new_repo: Do not use a shared repository for the target 
                                even if one is available.
         """
-        self._make_tail_on_transport(transport)
+        transport.ensure_base()
         result = self._format.initialize_on_transport(transport)
         try:
             local_repo = self.find_repository()
@@ -210,24 +210,8 @@
     # TODO: This should be given a Transport, and should chdir up; otherwise
     # this will open a new connection.
     def _make_tail(self, url):
-        head, tail = urlutils.split(url)
-        if tail and tail != '.':
-            t = get_transport(head)
-            try:
-                t.mkdir(tail)
-            except errors.FileExists:
-                pass
-
-    def _make_tail_on_transport(self, transport):
-        """Create the final directory in transport if it doesn't exist.
-
-        We use "Easier to ask for Permission". And just create it, and ignore
-        if the directory already exists.
-        """
-        try:
-            transport.mkdir('.')
-        except errors.FileExists:
-            pass
+        t = get_transport(url)
+        t.ensure_base()
 
     # TODO: Should take a Transport
     @classmethod
@@ -243,13 +227,8 @@
         if cls is not BzrDir:
             raise AssertionError("BzrDir.create always creates the default"
                 " format, not one of %r" % cls)
-        head, tail = urlutils.split(base)
-        if tail and tail != '.':
-            t = get_transport(head)
-            try:
-                t.mkdir(tail)
-            except errors.FileExists:
-                pass
+        t = get_transport(base)
+        t.ensure_base()
         if format is None:
             format = BzrDirFormat.get_default_format()
         return format.initialize(safe_unicode(base))
@@ -783,7 +762,7 @@
             itself to download less data.
         """
         target_transport = get_transport(url)
-        self._make_tail_on_transport(target_transport)
+        target_transport.ensure_base()
         cloning_format = self.cloning_metadir()
         result = cloning_format.initialize_on_transport(target_transport)
         try:

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-04-26 09:07:38 +0000
+++ b/bzrlib/tests/__init__.py	2007-05-02 14:54:20 +0000
@@ -1805,10 +1805,7 @@
             segments = maybe_a_url.rsplit('/', 1)
             t = get_transport(maybe_a_url)
             if len(segments) > 1 and segments[-1] not in ('', '.'):
-                try:
-                    t.mkdir('.')
-                except errors.FileExists:
-                    pass
+                t.ensure_base()
             if format is None:
                 format = 'default'
             if isinstance(format, basestring):

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2007-04-25 06:50:22 +0000
+++ b/bzrlib/workingtree.py	2007-05-02 14:54:20 +0000
@@ -932,20 +932,14 @@
             transport = self.branch.bzrdir.root_transport
             for name in segments:
                 transport = transport.clone(name)
-                try:
-                    transport.mkdir('.')
-                except errors.FileExists:
-                    pass
+                transport.ensure_base()
             return transport
             
         sub_path = self.id2path(file_id)
         branch_transport = mkdirs(sub_path)
         if format is None:
             format = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
-        try:
-            branch_transport.mkdir('.')
-        except errors.FileExists:
-            pass
+        branch_transport.ensure_base()
         branch_bzrdir = format.initialize_on_transport(branch_transport)
         try:
             repo = branch_bzrdir.find_repository()



More information about the bazaar-commits mailing list