Rev 5704: (jelmer) Move weave-era branch formats to bzrlib.branch_weave. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Mar 7 17:52:24 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5704 [merge]
revision-id: pqm at pqm.ubuntu.com-20110307175219-4wuflxgl4hfzivom
parent: pqm at pqm.ubuntu.com-20110307164922-h4ny7ro3g0k9bi9e
parent: jelmer at samba.org-20110307162825-z03uki5mp6sh22gb
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-03-07 17:52:19 +0000
message:
(jelmer) Move weave-era branch formats to bzrlib.branch_weave.
(Jelmer Vernooij)
added:
bzrlib/branch_weave.py branch_weave.py-20110303112759-greg4a9dt5pent0m-1
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2011-03-03 06:02:49 +0000
+++ b/bzrlib/branch.py 2011-03-07 16:28:25 +0000
@@ -25,7 +25,6 @@
bzrdir,
cache_utf8,
config as _mod_config,
- controldir,
debug,
errors,
fetch,
@@ -50,7 +49,14 @@
)
""")
-from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
+from bzrlib import (
+ controldir,
+ )
+from bzrlib.decorators import (
+ needs_read_lock,
+ needs_write_lock,
+ only_raises,
+ )
from bzrlib.hooks import HookPoint, Hooks
from bzrlib.inter import InterObject
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
@@ -805,7 +811,7 @@
def _unstack(self):
"""Change a branch to be unstacked, copying data as needed.
-
+
Don't call this directly, use set_stacked_on_url(None).
"""
pb = ui.ui_factory.nested_progress_bar()
@@ -1650,47 +1656,29 @@
hook(params)
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
- repository=None, lock_type='metadir',
- set_format=True):
+ repository=None):
"""Initialize a branch in a bzrdir, with specified files
:param a_bzrdir: The bzrdir to initialize the branch in
:param utf8_files: The files to create as a list of
(filename, content) tuples
:param name: Name of colocated branch to create, if any
- :param set_format: If True, set the format with
- self.get_format_string. (BzrBranch4 has its format set
- elsewhere)
:return: a branch in this format
"""
mutter('creating branch %r in %s', self, a_bzrdir.user_url)
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
- lock_map = {
- 'metadir': ('lock', lockdir.LockDir),
- 'branch4': ('branch-lock', lockable_files.TransportLock),
- }
- lock_name, lock_class = lock_map[lock_type]
control_files = lockable_files.LockableFiles(branch_transport,
- lock_name, lock_class)
+ 'lock', lockdir.LockDir)
control_files.create_lock()
+ control_files.lock_write()
try:
- control_files.lock_write()
- except errors.LockContention:
- if lock_type != 'branch4':
- raise
- lock_taken = False
- else:
- lock_taken = True
- if set_format:
utf8_files += [('format', self.get_format_string())]
- try:
for (filename, content) in utf8_files:
branch_transport.put_bytes(
filename, content,
mode=a_bzrdir._get_file_mode())
finally:
- if lock_taken:
- control_files.unlock()
+ control_files.unlock()
branch = self.open(a_bzrdir, name, _found=True,
found_repository=repository)
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
@@ -2025,58 +2013,6 @@
self.revision_id)
-class BzrBranchFormat4(BranchFormat):
- """Bzr branch format 4.
-
- This format has:
- - a revision-history file.
- - a branch-lock lock file [ to be shared with the bzrdir ]
- """
-
- def get_format_description(self):
- """See BranchFormat.get_format_description()."""
- return "Branch format 4"
-
- def initialize(self, a_bzrdir, name=None, repository=None):
- """Create a branch of this format in a_bzrdir."""
- if repository is not None:
- raise NotImplementedError(
- "initialize(repository=<not None>) on %r" % (self,))
- utf8_files = [('revision-history', ''),
- ('branch-name', ''),
- ]
- return self._initialize_helper(a_bzrdir, utf8_files, name=name,
- lock_type='branch4', set_format=False)
-
- def __init__(self):
- super(BzrBranchFormat4, self).__init__()
- self._matchingbzrdir = bzrdir.BzrDirFormat6()
-
- def network_name(self):
- """The network name for this format is the control dirs disk label."""
- return self._matchingbzrdir.get_format_string()
-
- def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
- found_repository=None):
- """See BranchFormat.open()."""
- if not _found:
- # we are being called directly and must probe.
- raise NotImplementedError
- if found_repository is None:
- found_repository = a_bzrdir.open_repository()
- return BzrBranchPreSplitOut(_format=self,
- _control_files=a_bzrdir._control_files,
- a_bzrdir=a_bzrdir,
- name=name,
- _repository=found_repository)
-
- def __str__(self):
- return "Bazaar-NG branch format 4"
-
- def supports_leaving_lock(self):
- return False
-
-
class BranchFormatMetadir(BranchFormat):
"""Common logic for meta-dir based branch formats."""
@@ -2403,7 +2339,6 @@
# formats which have no format string are not discoverable
# and not independently creatable, so are not registered.
-__format4 = BzrBranchFormat4()
__format5 = BzrBranchFormat5()
__format6 = BzrBranchFormat6()
__format7 = BzrBranchFormat7()
@@ -2414,8 +2349,10 @@
format_registry.register(__format7)
format_registry.register(__format8)
format_registry.set_default(__format7)
-format_registry.register_extra(__format4)
-network_format_registry.register(__format4.network_name(), __format4)
+format_registry.register_extra_lazy("bzrlib.branch_weave",
+ "BzrBranchFormat4")
+network_format_registry.register_lazy("Bazaar-NG branch, format 6\n",
+ "bzrlib.branch_weave", "BzrBranchFormat4")
class BranchWriteLockResult(LogicalLockResult):
@@ -2726,19 +2663,6 @@
mode=self.bzrdir._get_file_mode())
-class BzrBranchPreSplitOut(BzrBranch):
-
- def _get_checkout_format(self):
- """Return the most suitable metadir for a checkout of this branch.
- Weaves are used if this branch's repository uses weaves.
- """
- from bzrlib.repofmt.weaverepo import RepositoryFormat7
- from bzrlib.bzrdir import BzrDirMetaFormat1
- format = BzrDirMetaFormat1()
- format.repository_format = RepositoryFormat7()
- return format
-
-
class BzrBranch5(BzrBranch):
"""A format 5 branch. This supports new features over plain branches.
=== added file 'bzrlib/branch_weave.py'
--- a/bzrlib/branch_weave.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/branch_weave.py 2011-03-03 17:01:05 +0000
@@ -0,0 +1,126 @@
+# Copyright (C) 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Weave-era branch implementations."""
+
+from bzrlib import (
+ errors,
+ lockable_files,
+ )
+
+from bzrlib.trace import mutter
+
+from bzrlib.branch import (
+ BranchFormat,
+ BzrBranch,
+ )
+
+
+class PreSplitOutBzrBranch(BzrBranch):
+
+ def _get_checkout_format(self):
+ """Return the most suitable metadir for a checkout of this branch.
+ """
+ from bzrlib.repofmt.weaverepo import RepositoryFormat7
+ from bzrlib.bzrdir import BzrDirMetaFormat1
+ format = BzrDirMetaFormat1()
+ format.repository_format = RepositoryFormat7()
+ return format
+
+
+class BzrBranchFormat4(BranchFormat):
+ """Bzr branch format 4.
+
+ This format has:
+ - a revision-history file.
+ - a branch-lock lock file [ to be shared with the bzrdir ]
+ """
+
+ def get_format_description(self):
+ """See BranchFormat.get_format_description()."""
+ return "Branch format 4"
+
+ def _initialize_helper(self, a_bzrdir, utf8_files, name=None):
+ """Initialize a branch in a bzrdir, with specified files
+
+ :param a_bzrdir: The bzrdir to initialize the branch in
+ :param utf8_files: The files to create as a list of
+ (filename, content) tuples
+ :param name: Name of colocated branch to create, if any
+ :return: a branch in this format
+ """
+ mutter('creating branch %r in %s', self, a_bzrdir.user_url)
+ branch_transport = a_bzrdir.get_branch_transport(self, name=name)
+ control_files = lockable_files.LockableFiles(branch_transport,
+ 'branch-lock', lockable_files.TransportLock)
+ control_files.create_lock()
+ try:
+ control_files.lock_write()
+ except errors.LockContention:
+ lock_taken = False
+ else:
+ lock_taken = True
+ try:
+ for (filename, content) in utf8_files:
+ branch_transport.put_bytes(
+ filename, content,
+ mode=a_bzrdir._get_file_mode())
+ finally:
+ if lock_taken:
+ control_files.unlock()
+ branch = self.open(a_bzrdir, name, _found=True,
+ found_repository=None)
+ self._run_post_branch_init_hooks(a_bzrdir, name, branch)
+ return branch
+
+ def initialize(self, a_bzrdir, name=None, repository=None):
+ """Create a branch of this format in a_bzrdir."""
+ if repository is not None:
+ raise NotImplementedError(
+ "initialize(repository=<not None>) on %r" % (self,))
+ utf8_files = [('revision-history', ''),
+ ('branch-name', ''),
+ ]
+ return self._initialize_helper(a_bzrdir, utf8_files, name=name)
+
+ def __init__(self):
+ super(BzrBranchFormat4, self).__init__()
+ from bzrlib.bzrdir import BzrDirFormat6
+ self._matchingbzrdir = BzrDirFormat6()
+
+ def network_name(self):
+ """The network name for this format is the control dirs disk label."""
+ return self._matchingbzrdir.get_format_string()
+
+ def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
+ found_repository=None):
+ """See BranchFormat.open()."""
+ if not _found:
+ # we are being called directly and must probe.
+ raise NotImplementedError
+ if found_repository is None:
+ found_repository = a_bzrdir.open_repository()
+ return PreSplitOutBzrBranch(_format=self,
+ _control_files=a_bzrdir._control_files,
+ a_bzrdir=a_bzrdir,
+ name=name,
+ _repository=found_repository)
+
+ def __str__(self):
+ return "Bazaar-NG branch format 4"
+
+ def supports_leaving_lock(self):
+ return False
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2011-03-03 11:32:03 +0000
+++ b/bzrlib/bzrdir.py 2011-03-07 17:52:19 +0000
@@ -1137,7 +1137,7 @@
def open_branch(self, name=None, unsupported=False,
ignore_fallbacks=False):
"""See BzrDir.open_branch."""
- from bzrlib.branch import BzrBranchFormat4
+ from bzrlib.branch_weave import BzrBranchFormat4
format = BzrBranchFormat4()
self._check_supported(format, unsupported)
return format.open(self, name, _found=True)
@@ -1823,8 +1823,8 @@
return "Bazaar-NG branch, format 5\n"
def get_branch_format(self):
- from bzrlib import branch
- return branch.BzrBranchFormat4()
+ from bzrlib import branch_weave
+ return branch_weave.BzrBranchFormat4()
def get_format_description(self):
"""See BzrDirFormat.get_format_description()."""
@@ -1844,7 +1844,7 @@
Except when they are being cloned.
"""
- from bzrlib.branch import BzrBranchFormat4
+ from bzrlib.branch_weave import BzrBranchFormat4
from bzrlib.repofmt.weaverepo import RepositoryFormat5
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
RepositoryFormat5().initialize(result, _internal=True)
@@ -1888,8 +1888,8 @@
return "All-in-one format 6"
def get_branch_format(self):
- from bzrlib import branch
- return branch.BzrBranchFormat4()
+ from bzrlib import branch_weave
+ return branch_weave.BzrBranchFormat4()
def get_converter(self, format=None):
"""See BzrDirFormat.get_converter()."""
@@ -1905,7 +1905,7 @@
Except when they are being cloned.
"""
- from bzrlib.branch import BzrBranchFormat4
+ from bzrlib.branch_weave import BzrBranchFormat4
from bzrlib.repofmt.weaverepo import RepositoryFormat6
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
RepositoryFormat6().initialize(result, _internal=True)
More information about the bazaar-commits
mailing list