Rev 4363: (Jelmer) Move dpush to InterBranch. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu May 14 12:32:54 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4363
revision-id: pqm at pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz
parent: pqm at pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc
parent: jelmer at samba.org-20090510012654-jp9ufxquekaokbeo
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-05-14 12:32:50 +0100
message:
(Jelmer) Move dpush to InterBranch.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/foreign.py foreign.py-20081112170002-olsxmandkk8qyfuq-1
bzrlib/tests/blackbox/test_dpush.py test_dpush.py-20090108125928-st1td6le59g0vyv2-1
bzrlib/tests/test_foreign.py test_foreign.py-20081125004048-ywb901edgp9lluxo-1
------------------------------------------------------------
revno: 4347.2.3
revision-id: jelmer at samba.org-20090510012654-jp9ufxquekaokbeo
parent: jelmer at samba.org-20090509171628-21e57jdgnrowayek
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: interbranch-dpull
timestamp: Sun 2009-05-10 03:26:54 +0200
message:
Clarify name for LossyPushToSameVCS exception.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/foreign.py foreign.py-20081112170002-olsxmandkk8qyfuq-1
------------------------------------------------------------
revno: 4347.2.2
revision-id: jelmer at samba.org-20090509171628-21e57jdgnrowayek
parent: jelmer at samba.org-20090509165346-rt96a2xxa0r2qpfu
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: interbranch-dpull
timestamp: Sat 2009-05-09 19:16:28 +0200
message:
Rename dpush to lossy_push.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/foreign.py foreign.py-20081112170002-olsxmandkk8qyfuq-1
bzrlib/tests/blackbox/test_dpush.py test_dpush.py-20090108125928-st1td6le59g0vyv2-1
bzrlib/tests/test_foreign.py test_foreign.py-20081125004048-ywb901edgp9lluxo-1
------------------------------------------------------------
revno: 4347.2.1
revision-id: jelmer at samba.org-20090509165346-rt96a2xxa0r2qpfu
parent: pqm at pqm.ubuntu.com-20090508195148-cw1mw95i0qo39ggg
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: interbranch-dpull
timestamp: Sat 2009-05-09 18:53:46 +0200
message:
Move dpush onto an InterBranch object.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/foreign.py foreign.py-20081112170002-olsxmandkk8qyfuq-1
bzrlib/tests/blackbox/test_dpush.py test_dpush.py-20090108125928-st1td6le59g0vyv2-1
bzrlib/tests/test_foreign.py test_foreign.py-20081125004048-ywb901edgp9lluxo-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-05-07 05:08:46 +0000
+++ b/bzrlib/branch.py 2009-05-10 01:26:54 +0000
@@ -867,6 +867,26 @@
return InterBranch.get(self, target).push(overwrite, stop_revision,
*args, **kwargs)
+ def lossy_push(self, target, stop_revision=None):
+ """Push deltas into another branch.
+
+ :note: This does not, like push, retain the revision ids from
+ the source branch and will, rather than adding bzr-specific
+ metadata, push only those semantics of the revision that can be
+ natively represented by this branch' VCS.
+
+ :param target: Target branch
+ :param stop_revision: Revision to push, defaults to last revision.
+ :return: Dictionary mapping revision ids from the target branch
+ to new revision ids in the target branch, for each
+ revision that was pushed.
+ """
+ inter = InterBranch.get(self, target)
+ lossy_push = getattr(inter, "lossy_push", None)
+ if lossy_push is None:
+ raise errors.LossyPushToSameVCS(self, target)
+ return lossy_push(stop_revision)
+
def basis_tree(self):
"""Return `Tree` object for last revision."""
return self.repository.revision_tree(self.last_revision())
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2009-05-06 05:36:28 +0000
+++ b/bzrlib/errors.py 2009-05-10 01:26:54 +0000
@@ -3025,3 +3025,15 @@
def __init__(self, repository):
self.repository = repository
+
+
+class LossyPushToSameVCS(BzrError):
+
+ _fmt = ("Lossy push not possible between %(source_branch)r and "
+ "%(target_branch)r that are in the same VCS.")
+
+ internal_error = True
+
+ def __init__(self, source_branch, target_branch):
+ self.source_branch = source_branch
+ self.target_branch = target_branch
=== modified file 'bzrlib/foreign.py'
--- a/bzrlib/foreign.py 2009-04-15 11:13:59 +0000
+++ b/bzrlib/foreign.py 2009-05-10 01:26:54 +0000
@@ -18,7 +18,10 @@
"""Foreign branch utilities."""
-from bzrlib.branch import Branch
+from bzrlib.branch import (
+ Branch,
+ InterBranch,
+ )
from bzrlib.commands import Command, Option
from bzrlib.repository import Repository
from bzrlib.revision import Revision
@@ -253,22 +256,6 @@
self.mapping = mapping
super(ForeignBranch, self).__init__()
- def dpull(self, source, stop_revision=None):
- """Pull deltas from another branch.
-
- :note: This does not, like pull, retain the revision ids from
- the source branch and will, rather than adding bzr-specific
- metadata, push only those semantics of the revision that can be
- natively represented by this branch' VCS.
-
- :param source: Source branch
- :param stop_revision: Revision to pull, defaults to last revision.
- :return: Dictionary mapping revision ids from the source branch
- to new revision ids in the target branch, for each
- revision that was pull.
- """
- raise NotImplementedError(self.dpull)
-
def update_workingtree_fileids(wt, target_tree):
"""Update the file ids in a working tree based on another tree.
@@ -340,13 +327,13 @@
bzrdir = BzrDir.open(location)
target_branch = bzrdir.open_branch()
- dpull = getattr(target_branch, "dpull", None)
- if dpull is None:
- raise BzrCommandError("%r is not a foreign branch, use "
- "regular push." % target_branch)
target_branch.lock_write()
try:
- revid_map = dpull(source_branch)
+ try:
+ revid_map = source_branch.lossy_push(target_branch)
+ except errors.LossyPushToSameVCS:
+ raise BzrCommandError("%r is not a foreign branch, use regular "
+ "push." % target_branch)
# We successfully created the target, remember it
if source_branch.get_push_location() is None or remember:
source_branch.set_push_location(target_branch.base)
@@ -364,3 +351,22 @@
source_wt.unlock()
finally:
target_branch.unlock()
+
+
+class InterToForeignBranch(InterBranch):
+
+ def lossy_push(self, stop_revision=None):
+ """Push deltas into another branch.
+
+ :note: This does not, like push, retain the revision ids from
+ the source branch and will, rather than adding bzr-specific
+ metadata, push only those semantics of the revision that can be
+ natively represented by this branch' VCS.
+
+ :param target: Target branch
+ :param stop_revision: Revision to push, defaults to last revision.
+ :return: Dictionary mapping revision ids from the target branch
+ to new revision ids in the target branch, for each
+ revision that was pushed.
+ """
+ raise NotImplementedError(self.lossy_push)
=== modified file 'bzrlib/tests/blackbox/test_dpush.py'
--- a/bzrlib/tests/blackbox/test_dpush.py 2009-04-09 21:50:23 +0000
+++ b/bzrlib/tests/blackbox/test_dpush.py 2009-05-09 17:16:28 +0000
@@ -22,6 +22,7 @@
from bzrlib.branch import (
Branch,
+ InterBranch,
)
from bzrlib.bzrdir import (
BzrDirFormat,
@@ -38,6 +39,7 @@
)
from bzrlib.tests.test_foreign import (
DummyForeignVcsDirFormat,
+ InterToDummyVcsBranch,
)
@@ -45,6 +47,7 @@
def setUp(self):
BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
+ InterBranch.register_optimiser(InterToDummyVcsBranch)
self.addCleanup(self.unregister_format)
super(TestDpush, self).setUp()
@@ -53,6 +56,7 @@
BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
except ValueError:
pass
+ InterBranch.unregister_optimiser(InterToDummyVcsBranch)
def make_dummy_builder(self, relpath):
builder = self.make_branch_builder(relpath,
=== modified file 'bzrlib/tests/test_foreign.py'
--- a/bzrlib/tests/test_foreign.py 2009-04-15 11:13:59 +0000
+++ b/bzrlib/tests/test_foreign.py 2009-05-09 17:16:28 +0000
@@ -101,27 +101,36 @@
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
*args, **kwargs)
- def dpull(self, source, stop_revision=None):
- source.lock_read()
+
+class InterToDummyVcsBranch(branch.GenericInterBranch,
+ foreign.InterToForeignBranch):
+
+ @staticmethod
+ def is_compatible(source, target):
+ return isinstance(target, DummyForeignVcsBranch)
+
+ def lossy_push(self, stop_revision=None):
+ self.source.lock_read()
try:
# This just handles simple cases, but that's good enough for tests
- my_history = self.revision_history()
- their_history = source.revision_history()
+ my_history = self.target.revision_history()
+ their_history = self.source.revision_history()
if their_history[:min(len(my_history), len(their_history))] != my_history:
- raise errors.DivergedBranches(self, source)
+ raise errors.DivergedBranches(self.target, self.source)
todo = their_history[len(my_history):]
revidmap = {}
for revid in todo:
- rev = source.repository.get_revision(revid)
- tree = source.repository.revision_tree(revid)
+ rev = self.source.repository.get_revision(revid)
+ tree = self.source.repository.revision_tree(revid)
def get_file_with_stat(file_id, path=None):
return (tree.get_file(file_id), None)
tree.get_file_with_stat = get_file_with_stat
- new_revid = self.mapping.revision_id_foreign_to_bzr(
- (str(rev.timestamp), str(rev.timezone), str(self.revno())))
- parent_revno, parent_revid= self.last_revision_info()
- builder = self.get_commit_builder([parent_revid],
- self.get_config(), rev.timestamp,
+ new_revid = self.target.mapping.revision_id_foreign_to_bzr(
+ (str(rev.timestamp), str(rev.timezone),
+ str(self.target.revno())))
+ parent_revno, parent_revid= self.target.last_revision_info()
+ builder = self.target.get_commit_builder([parent_revid],
+ self.target.get_config(), rev.timestamp,
rev.timezone, rev.committer, rev.properties,
new_revid)
try:
@@ -129,7 +138,7 @@
new_ie = ie.copy()
new_ie.revision = None
builder.record_entry_contents(new_ie,
- [self.repository.get_inventory(parent_revid)],
+ [self.target.repository.get_inventory(parent_revid)],
path, tree,
(ie.kind, ie.text_size, ie.executable, ie.text_sha1))
builder.finish_inventory()
@@ -137,11 +146,12 @@
builder.abort()
raise
revidmap[revid] = builder.commit(rev.message)
- self.set_last_revision_info(parent_revno+1, revidmap[revid])
+ self.target.set_last_revision_info(parent_revno+1,
+ revidmap[revid])
trace.mutter('lossily pushed revision %s -> %s',
revid, revidmap[revid])
finally:
- source.unlock()
+ self.source.unlock()
return revidmap
@@ -336,6 +346,7 @@
def setUp(self):
BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
+ branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
self.addCleanup(self.unregister)
super(DummyForeignVcsTests, self).setUp()
@@ -344,6 +355,7 @@
BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
except ValueError:
pass
+ branch.InterBranch.unregister_optimiser(InterToDummyVcsBranch)
def test_create(self):
"""Test we can create dummies."""
More information about the bazaar-commits
mailing list