[patch] add 'init --format' option

Martin Pool mbp at sourcefrog.net
Thu Mar 9 03:40:08 GMT 2006


This lets you create new self-contained branches of a specified format.

-- 
Martin
-------------- next part --------------
=== added file 'b/bzrlib/tests/blackbox/test_init.py'
--- /dev/null	
+++ b/bzrlib/tests/blackbox/test_init.py	
@@ -0,0 +1,32 @@
+# Copyright (C) 2006 by Canonical Ltd
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+"""Test "bzr init"""
+
+
+from bzrlib.tests.blackbox import ExternalBase
+
+
+class TestInit(ExternalBase):
+
+    def test_init_with_format(self):
+        """Verify bzr init --format constructs something plausible"""
+        t = self.get_transport()
+        self.runbzr('init --format metadir')
+        self.assertIsDirectory('.bzr', t)
+        self.assertIsDirectory('.bzr/checkout', t)
+        self.assertIsDirectory('.bzr/checkout/lock', t)

=== modified file 'a/NEWS'
--- a/NEWS	
+++ b/NEWS	
@@ -55,6 +55,10 @@
     * New 'reconcile' command will check branch consistency and repair indexes
       that can become out of sync in pre 0.8 formats. (Robert Collins,
       Aaron Bentley)
+
+    * New 'bzr init --format' and 'bzr upgrade --format' option to control 
+      what storage format is created or produced.  (Robert Collins, 
+      Martin Pool)
 
   INTERNALS:
   

=== modified file 'a/bzrlib/builtins.py'
--- a/bzrlib/builtins.py	
+++ b/bzrlib/builtins.py	
@@ -68,6 +68,19 @@
         except errors.PathNotChild:
             raise FileInWrongBranch(tree.branch, filename)
     return tree, new_list
+
+
+def get_format_type(typestring):
+    """Parse and return a format specifier."""
+    if typestring == "metadir":
+        return bzrdir.BzrDirMetaFormat1()
+    if typestring == "knit":
+        format = bzrdir.BzrDirMetaFormat1()
+        format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
+        return format
+    msg = "No known bzr-dir format %s. Supported types are: metadir\n" %\
+        (typestring)
+    raise BzrCommandError(msg)
 
 
 # TODO: Make sure no commands unconditionally use the working directory as a
@@ -862,7 +875,14 @@
         bzr commit -m 'imported project'
     """
     takes_args = ['location?']
-    def run(self, location=None):
+    takes_options = [
+                     Option('format', 
+                            help='Create a specific format rather than the'
+                                 ' current default format. Currently this '
+                                 ' option only accepts =metadir',
+                            type=get_format_type),
+                     ]
+    def run(self, location=None, format=None):
         from bzrlib.branch import Branch
         if location is None:
             location = u'.'
@@ -874,7 +894,16 @@
             # locations if the user supplies an extended path
             if not os.path.exists(location):
                 os.mkdir(location)
-        bzrdir.BzrDir.create_standalone_workingtree(location)
+        if format is None:
+            # create default
+            bzrdir.BzrDir.create_standalone_workingtree(location)
+        else:
+            new_dir = format.initialize(location)
+            new_dir.create_repository()
+            new_dir.create_branch()
+            # TODO: ask the bzrdir format for the right classs
+            import bzrlib.workingtree
+            bzrlib.workingtree.WorkingTreeFormat3().initialize(new_dir)
 
 
 class cmd_diff(Command):
@@ -1518,19 +1547,6 @@
 
         if c.needs_write:
             c.write()
-
-
-def get_format_type(typestring):
-    """Parse and return a format specifier."""
-    if typestring == "metadir":
-        return bzrdir.BzrDirMetaFormat1()
-    if typestring == "knit":
-        format = bzrdir.BzrDirMetaFormat1()
-        format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
-        return format
-    msg = "No known bzr-dir format %s. Supported types are: metadir\n" %\
-        (typestring)
-    raise BzrCommandError(msg)
 
 
 class cmd_upgrade(Command):

=== modified file 'a/bzrlib/tests/blackbox/__init__.py'
--- a/bzrlib/tests/blackbox/__init__.py	
+++ b/bzrlib/tests/blackbox/__init__.py	
@@ -48,6 +48,7 @@
                      'bzrlib.tests.blackbox.test_find_merge_base',
                      'bzrlib.tests.blackbox.test_help',
                      'bzrlib.tests.blackbox.test_info',
+                     'bzrlib.tests.blackbox.test_init',
                      'bzrlib.tests.blackbox.test_log',
                      'bzrlib.tests.blackbox.test_logformats',
                      'bzrlib.tests.blackbox.test_missing',



More information about the bazaar mailing list