Rev 2522: merge init --create-prefix in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jun 12 03:17:44 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2522
revision-id: pqm at pqm.ubuntu.com-20070612021742-uetsy3g747iq3xkk
parent: pqm at pqm.ubuntu.com-20070612000924-if8v5wnnp3nwmghg
parent: mbp at sourcefrog.net-20070612014420-kie1j69sqjn8cig0
committer: Canonical.com Patch Queue Manager<pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2007-06-12 03:17:42 +0100
message:
  merge init --create-prefix
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_init.py test_init.py-20060309032856-a292116204d86eb7
    ------------------------------------------------------------
    revno: 2521.1.1
    merged: mbp at sourcefrog.net-20070612014420-kie1j69sqjn8cig0
    parent: pqm at pqm.ubuntu.com-20070612000924-if8v5wnnp3nwmghg
    parent: d.m.watkins at warwick.ac.uk-20070603214150-uqxz0emixszcj6cz
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: 56322
    timestamp: Tue 2007-06-12 11:44:20 +1000
    message:
      merge init --create-prefix
    ------------------------------------------------------------
    revno: 2504.1.4
    merged: d.m.watkins at warwick.ac.uk-20070603214150-uqxz0emixszcj6cz
    parent: d.m.watkins at warwick.ac.uk-20070603214016-y449vw1v37bv6oxt
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: 56322
    timestamp: Sun 2007-06-03 22:41:50 +0100
    message:
      Removed TODO relating to create-prefix.
    ------------------------------------------------------------
    revno: 2504.1.3
    merged: d.m.watkins at warwick.ac.uk-20070603214016-y449vw1v37bv6oxt
    parent: d.m.watkins at warwick.ac.uk-20070603213950-3e81fuyuxpb9abcc
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: 56322
    timestamp: Sun 2007-06-03 22:40:16 +0100
    message:
      Implemented --create-prefix for 'init'.
    ------------------------------------------------------------
    revno: 2504.1.2
    merged: d.m.watkins at warwick.ac.uk-20070603213950-3e81fuyuxpb9abcc
    parent: d.m.watkins at warwick.ac.uk-20070603204524-no0cjahivzp0txv4
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: 56322
    timestamp: Sun 2007-06-03 22:39:50 +0100
    message:
      Created tests for adding --create-prefix to 'init'.
    ------------------------------------------------------------
    revno: 2504.1.1
    merged: d.m.watkins at warwick.ac.uk-20070603204524-no0cjahivzp0txv4
    parent: pqm at pqm.ubuntu.com-20070602184854-kwqaduxs0b19r76n
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: 56322
    timestamp: Sun 2007-06-03 21:45:24 +0100
    message:
      Abstracted create_prefix code from the class 'cmd_push' to the function '_create_prefix' (both in builtins.py).
=== modified file 'NEWS'
--- a/NEWS	2007-06-12 00:09:24 +0000
+++ b/NEWS	2007-06-12 01:44:20 +0000
@@ -54,6 +54,9 @@
       66 seconds to 32 seconds. For a small tree of 600 files, commit of a
       small change is 33% faster. (Ian Clatworthy)
 
+    * New --create-prefix option to bzr init, like for push.  (Daniel Watkins,
+      #56322)
+
   BUGFIXES:
 
     * ``bzr push`` should only connect to the remote location one time.

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-06-08 13:43:40 +0000
+++ b/bzrlib/builtins.py	2007-06-12 01:44:20 +0000
@@ -755,27 +755,7 @@
                         " leading parent directories."
                         % location)
 
-                cur_transport = to_transport
-                needed = [cur_transport]
-                # Recurse upwards until we can create a directory successfully
-                while True:
-                    new_transport = cur_transport.clone('..')
-                    if new_transport.base == cur_transport.base:
-                        raise errors.BzrCommandError("Failed to create path"
-                                                     " prefix for %s."
-                                                     % location)
-                    try:
-                        new_transport.mkdir('.')
-                    except errors.NoSuchFile:
-                        needed.append(new_transport)
-                        cur_transport = new_transport
-                    else:
-                        break
-
-                # Now we only need to create child directories
-                while needed:
-                    cur_transport = needed.pop()
-                    cur_transport.ensure_base()
+                _create_prefix(to_transport)
 
             # Now the target directory exists, but doesn't have a .bzr
             # directory. So we need to create it, along with any work to create
@@ -1270,6 +1250,9 @@
     _see_also = ['init-repo', 'branch', 'checkout']
     takes_args = ['location?']
     takes_options = [
+        Option('create-prefix',
+               help='Create the path leading up to the branch '
+                    'if it does not already exist'),
          RegistryOption('format',
                 help='Specify a format for this branch. '
                 'See "help formats".',
@@ -1282,7 +1265,8 @@
                 help='Never change revnos or the existing log.'
                 '  Append revisions to it only.')
          ]
-    def run(self, location=None, format=None, append_revisions_only=False):
+    def run(self, location=None, format=None, append_revisions_only=False,
+            create_prefix=False):
         if format is None:
             format = bzrdir.format_registry.make_bzrdir('default')
         if location is None:
@@ -1295,8 +1279,16 @@
         # Just using os.mkdir, since I don't
         # believe that we want to create a bunch of
         # locations if the user supplies an extended path
-        # TODO: create-prefix
-        to_transport.ensure_base()
+        try:
+            to_transport.ensure_base()
+        except errors.NoSuchFile:
+            if not create_prefix:
+                raise errors.BzrCommandError("Parent directory of %s"
+                    " does not exist."
+                    "\nYou may supply --create-prefix to create all"
+                    " leading parent directories."
+                    % location)
+            _create_prefix(to_transport)
 
         try:
             existing_bzrdir = bzrdir.BzrDir.open(location)
@@ -3774,6 +3766,28 @@
     return conflicts
 
 
+def _create_prefix(cur_transport):
+    needed = [cur_transport]
+    # Recurse upwards until we can create a directory successfully
+    while True:
+        new_transport = cur_transport.clone('..')
+        if new_transport.base == cur_transport.base:
+            raise errors.BzrCommandError("Failed to create path"
+                                         " prefix for %s."
+                                         % location)
+        try:
+            new_transport.mkdir('.')
+        except errors.NoSuchFile:
+            needed.append(new_transport)
+            cur_transport = new_transport
+        else:
+            break
+
+    # Now we only need to create child directories
+    while needed:
+        cur_transport = needed.pop()
+        cur_transport.ensure_base()
+
 # Compatibility
 merge = _merge_helper
 

=== modified file 'bzrlib/tests/blackbox/test_init.py'
--- a/bzrlib/tests/blackbox/test_init.py	2007-03-14 05:08:55 +0000
+++ b/bzrlib/tests/blackbox/test_init.py	2007-06-03 21:39:50 +0000
@@ -73,11 +73,10 @@
         self.assertEqual('', err)
         WorkingTree.open('subdir1')
         
+        self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
+                            'init', 'subdir2/nothere')
         out, err = self.run_bzr('init', 'subdir2/nothere', retcode=3)
         self.assertEqual('', out)
-        self.assertContainsRe(err,
-            r'^bzr: ERROR: No such file: .*'
-            '\[Err(no|or) 2\]')
         
         os.mkdir('subdir2')
         out, err = self.run_bzr('init', 'subdir2')
@@ -120,6 +119,24 @@
         # try to init unicode dir
         self.run_bzr('init', u'mu-\xb5')
 
+    def create_simple_tree(self):
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/a'])
+        tree.add(['a'], ['a-id'])
+        tree.commit('one', rev_id='r1')
+        return tree
+
+    def test_init_create_prefix(self):
+        """'bzr init --create-prefix; will create leading directories."""
+        tree = self.create_simple_tree()
+
+        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
+                            'init', '../new/tree',
+                            working_dir='tree')
+        self.run_bzr('init', '../new/tree', '--create-prefix',
+                        working_dir='tree')
+        self.failUnlessExists('new/tree/.bzr')
+
 
 class TestSFTPInit(TestCaseWithSFTPServer):
 




More information about the bazaar-commits mailing list