Rev 3244: Support --shallow on branch. in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
Robert Collins
robertc at robertcollins.net
Wed Feb 27 21:50:28 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
------------------------------------------------------------
revno: 3244
revision-id:robertc at robertcollins.net-20080227215016-gn12tusha7cstpm3
parent: robertc at robertcollins.net-20080227121821-2s5wrjlwsd7vy4ii
committer: Robert Collins <robertc at robertcollins.net>
branch nick: branch.shallow
timestamp: Thu 2008-02-28 08:50:16 +1100
message:
Support --shallow on branch.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
=== modified file 'NEWS'
--- a/NEWS 2008-02-27 11:42:40 +0000
+++ b/NEWS 2008-02-27 21:50:16 +0000
@@ -31,6 +31,9 @@
* Restore auto-detection of plink.exe on Windows. (Dmitry Vasiliev)
+ * Shallow branches are now supported. See ``bzr help branch`` and
+ ``bzr help push``. (Robert Collins)
+
FEATURES:
* ``branch`` and ``checkout`` can hard-link working tree files, which is
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2008-02-27 12:18:21 +0000
+++ b/bzrlib/branch.py 2008-02-27 21:50:16 +0000
@@ -731,13 +731,6 @@
else:
if parent:
destination.set_parent(parent)
- try:
- shallow_url = self.get_stacked_on()
- except (errors.NotStacked, errors.UnstackableBranchFormat,
- errors.UnstackableRepositoryFormat):
- pass
- else:
- destination.set_stacked_on(shallow_url)
self.tags.merge_to(destination.tags)
@needs_read_lock
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2008-02-27 12:18:21 +0000
+++ b/bzrlib/builtins.py 2008-02-27 21:50:16 +0000
@@ -912,11 +912,16 @@
_see_also = ['checkout']
takes_args = ['from_location', 'to_location?']
takes_options = ['revision', Option('hardlink',
- help='Hard-link working tree files where possible.')]
+ help='Hard-link working tree files where possible.'),
+ Option('shallow',
+ help='Create a shallow branch referring to the source branch. '
+ 'The new branch will depend on the availability of the source '
+ 'branch for all operations.'),
+ ]
aliases = ['get', 'clone']
def run(self, from_location, to_location=None, revision=None,
- hardlink=False):
+ hardlink=False, shallow=False):
from bzrlib.tag import _merge_tags_if_possible
if revision is None:
revision = [None]
@@ -955,7 +960,7 @@
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
possible_transports=[to_transport],
accelerator_tree=accelerator_tree,
- hardlink=hardlink)
+ hardlink=hardlink, shallow=shallow)
branch = dir.open_branch()
except errors.NoSuchRevision:
to_transport.delete_tree('.')
@@ -968,7 +973,7 @@
note('Created new shallow branch referring to %s.' %
branch.get_stacked_on())
except (errors.NotStacked, errors.UnstackableBranchFormat,
- errors.UnstackableRepositoryFormat):
+ errors.UnstackableRepositoryFormat), e:
note('Branched %d revision(s).' % branch.revno())
finally:
br_from.unlock()
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2008-02-27 12:18:21 +0000
+++ b/bzrlib/bzrdir.py 2008-02-27 21:50:16 +0000
@@ -890,7 +890,7 @@
def sprout(self, url, revision_id=None, force_new_repo=False,
recurse='down', possible_transports=None,
- accelerator_tree=None, hardlink=False):
+ accelerator_tree=None, hardlink=False, shallow=False):
"""Create a copy of this bzrdir prepared for use as a new line of
development.
@@ -914,15 +914,18 @@
target_transport.ensure_base()
cloning_format = self.cloning_metadir()
result = cloning_format.initialize_on_transport(target_transport)
- shallow_branch_url = False
try:
source_branch = self.open_branch()
source_repository = source_branch.repository
- try:
- shallow_branch_url = source_branch.get_stacked_on()
- except (errors.NotStacked, errors.UnstackableBranchFormat,
- errors.UnstackableRepositoryFormat):
+ if shallow:
+ shallow_branch_url = self.root_transport.base
+ else:
shallow_branch_url = None
+ try:
+ shallow_branch_url = source_branch.get_stacked_on()
+ except (errors.NotStacked, errors.UnstackableBranchFormat,
+ errors.UnstackableRepositoryFormat):
+ shallow_branch_url = None
except errors.NotBranchError:
source_branch = None
try:
@@ -941,9 +944,10 @@
elif source_repository is None and result_repo is None:
# no repo available, make a new one
result.create_repository()
- elif result_repo is None and shallow_branch_url:
- result_repo = source_repository._format.initialize(result)
- stacked_dir = BzrDirPreSplitOut.open(shallow_branch_url)
+ elif shallow_branch_url:
+ if result_repo is None:
+ result_repo = source_repository._format.initialize(result)
+ stacked_dir = BzrDir.open(shallow_branch_url)
try:
stacked_repo = stacked_dir.open_branch().repository
except errors.NotBranchError:
@@ -963,9 +967,11 @@
# so we can override the copy method
result_repo.fetch(source_repository, revision_id=revision_id)
if source_branch is not None:
- source_branch.sprout(result, revision_id=revision_id)
+ result_branch = source_branch.sprout(result, revision_id=revision_id)
else:
- result.create_branch()
+ result_branch = result.create_branch()
+ if shallow_branch_url:
+ result_branch.set_stacked_on(shallow_branch_url)
if isinstance(target_transport, LocalTransport) and (
result_repo is None or result_repo.make_working_trees()):
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py 2008-02-27 12:18:21 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py 2008-02-27 21:50:16 +0000
@@ -127,6 +127,20 @@
self.assertShallow(branch_tree.last_revision(),
trunk_tree.branch.base)
+ def test_branch_shallow(self):
+ # We have a mainline
+ trunk_tree = self.make_branch_and_tree('mainline',
+ format='development')
+ trunk_tree.commit('mainline')
+ # and make branch from it which is shallow
+ out, err = self.run_bzr(['branch', '--shallow', 'mainline', 'newbranch'])
+ self.assertEqual('', out)
+ self.assertEqual('Created new shallow branch referring to %s.\n' %
+ trunk_tree.branch.base, err)
+ new_tree = WorkingTree.open('newbranch')
+ new_revid = new_tree.commit('new work')
+ self.assertShallow(new_revid, trunk_tree.branch.base)
+
class TestRemoteBranch(TestCaseWithSFTPServer):
More information about the bazaar-commits
mailing list