98
98
raise NotImplementedError(self.revision_id_bzr_to_foreign)
101
class ForeignBranch(Branch):
102
"""Branch that exists in a foreign version control system."""
104
def __init__(self, mapping):
105
self.mapping = mapping
106
super(ForeignBranch, self).__init__()
108
def dpull(self, source, stop_revision=None):
109
"""Pull deltas from another branch.
111
:note: This does not, like pull, retain the revision ids from
112
the source branch and will, rather than adding bzr-specific metadata,
113
push only those semantics of the revision that can be natively
114
represented in this branch.
116
:param source: Source branch
117
:param stop_revision: Revision to pull, defaults to last revision.
119
raise NotImplementedError(self.pull)
122
class cmd_dpush(Command):
123
"""Push diffs into a foreign version control system without any
124
Bazaar-specific metadata.
126
This will afterwards rebase the local Bazaar branch on the remote
127
branch unless the --no-rebase option is used, in which case
128
the two branches will be out of sync.
130
takes_args = ['location?']
131
takes_options = ['remember', Option('directory',
132
help='Branch to push from, '
133
'rather than the one containing the working directory.',
137
Option('no-rebase', help="Don't rebase after push")]
139
def run(self, location=None, remember=False, directory=None,
141
from bzrlib import urlutils
142
from bzrlib.bzrdir import BzrDir
143
from bzrlib.errors import BzrCommandError, NoWorkingTree
144
from bzrlib.trace import info
145
from bzrlib.workingtree import WorkingTree
147
if directory is None:
150
source_wt = WorkingTree.open_containing(directory)[0]
151
source_branch = source_wt.branch
152
except NoWorkingTree:
153
source_branch = Branch.open_containing(directory)[0]
155
stored_loc = source_branch.get_push_location()
157
if stored_loc is None:
158
raise BzrCommandError("No push location known or specified.")
160
display_url = urlutils.unescape_for_display(stored_loc,
162
self.outf.write("Using saved location: %s\n" % display_url)
163
location = stored_loc
165
bzrdir = BzrDir.open(location)
166
target_branch = bzrdir.open_branch()
167
target_branch.lock_write()
168
if not isinstance(target_branch, ForeignBranch):
169
info("target branch is not a foreign branch, using regular push.")
170
target_branch.pull(source_branch)
173
revid_map = target_branch.dpull(source_branch)
174
# We successfully created the target, remember it
175
if source_branch.get_push_location() is None or remember:
176
source_branch.set_push_location(target_branch.base)
178
_, old_last_revid = source_branch.last_revision_info()
179
new_last_revid = revid_map[old_last_revid]
180
if source_wt is not None:
181
source_wt.pull(target_branch, overwrite=True,
182
stop_revision=new_last_revid)
184
source_branch.pull(target_branch, overwrite=True,
185
stop_revision=new_last_revid)
188
101
class ForeignRevision(Revision):
189
102
"""A Revision from a Foreign repository. Remembers
190
103
information about foreign revision id and mapping.