117
115
self.mapping = mapping
118
def show_foreign_properties(rev):
119
"""Custom log displayer for foreign revision identifiers.
121
:param rev: Revision object.
123
# Revision comes directly from a foreign repository
124
if isinstance(rev, ForeignRevision):
125
return rev.mapping.vcs.show_foreign_revid(rev.foreign_revid)
127
# Revision was once imported from a foreign repository
129
foreign_revid, mapping = \
130
foreign_vcs_registry.parse_revision_id(rev.revision_id)
131
except errors.InvalidRevisionId:
134
return mapping.vcs.show_foreign_revid(foreign_revid)
120
137
class ForeignVcs(object):
121
138
"""A foreign version control system."""
125
repository_format = None
127
def __init__(self, mapping_registry, abbreviation=None):
128
"""Create a new foreign vcs instance.
130
:param mapping_registry: Registry with mappings for this VCS.
131
:param abbreviation: Optional abbreviation ('bzr', 'svn', 'git', etc)
133
self.abbreviation = abbreviation
140
def __init__(self, mapping_registry):
134
141
self.mapping_registry = mapping_registry
136
143
def show_foreign_revid(self, foreign_revid):
231
252
self.mapping = mapping
232
253
super(ForeignBranch, self).__init__()
235
def update_workingtree_fileids(wt, target_tree):
236
"""Update the file ids in a working tree based on another tree.
238
:param wt: Working tree in which to update file ids
239
:param target_tree: Tree to retrieve new file ids from, based on path
241
tt = transform.TreeTransform(wt)
243
for f, p, c, v, d, n, k, e in target_tree.iter_changes(wt):
244
if v == (True, False):
245
trans_id = tt.trans_id_tree_path(p[0])
246
tt.unversion_file(trans_id)
247
elif v == (False, True):
248
trans_id = tt.trans_id_tree_path(p[1])
249
tt.version_file(f, trans_id)
253
if len(wt.get_parent_ids()) == 1:
254
wt.set_parent_trees([(target_tree.get_revision_id(), target_tree)])
256
wt.set_last_revision(target_tree.get_revision_id())
255
def dpull(self, source, stop_revision=None):
256
"""Pull deltas from another branch.
258
:note: This does not, like pull, retain the revision ids from
259
the source branch and will, rather than adding bzr-specific
260
metadata, push only those semantics of the revision that can be
261
natively represented by this branch' VCS.
263
:param source: Source branch
264
:param stop_revision: Revision to pull, defaults to last revision.
265
:return: Dictionary mapping revision ids from the source branch
266
to new revision ids in the target branch, for each
267
revision that was pull.
269
raise NotImplementedError(self.dpull)
272
def _determine_fileid_renames(old_inv, new_inv):
273
"""Determine the file ids based on a old and a new inventory that
274
are equal in content.
276
:param old_inv: Old inventory
277
:param new_inv: New inventory
278
:return: Dictionary a (old_id, new_id) tuple for each path in the
282
if len(old_inv) != len(new_inv):
283
raise AssertionError("Inventories are not of the same size")
284
for old_file_id in old_inv:
285
path = old_inv.id2path(old_file_id)
286
new_file_id = new_inv.path2id(path)
287
if new_file_id is None:
288
raise AssertionError(
289
"Unable to find %s in new inventory" % old_file_id)
290
ret[path] = (old_file_id, new_file_id)
294
def update_workinginv_fileids(wt, old_inv, new_inv):
295
"""Update all file ids in wt according to old_tree/new_tree.
297
old_tree and new_tree should be two RevisionTree's that differ only
300
fileid_renames = _determine_fileid_renames(old_inv, new_inv)
304
# Adjust file ids in working tree
305
# Sorted, so we process parents before children
306
for path in sorted(fileid_renames.keys()):
307
(old_fileid, new_fileid) = fileid_renames[path]
309
new_fileids.append((path, new_fileid))
310
# unversion() works recursively so we only have to unversion the
311
# top-level. Unfortunately unversioning / is not supported yet,
312
# so unversion its children instead and use set_root_id() for /
313
if old_inv[old_fileid].parent_id == old_inv.root.file_id:
314
old_fileids.append(old_fileid)
316
new_root_id = new_fileid
317
new_fileids.reverse()
318
wt.unversion(old_fileids)
319
if new_root_id is not None:
320
wt.set_root_id(new_root_id)
321
wt.add([x[0] for x in new_fileids], [x[1] for x in new_fileids])
322
wt.set_last_revision(new_inv.revision_id)
259
325
class cmd_dpush(Command):
260
__doc__ = """Push into a different VCS without any custom bzr metadata.
326
"""Push diffs into a foreign version control system without any
327
Bazaar-specific metadata.
262
This will afterwards rebase the local branch on the remote
329
This will afterwards rebase the local Bazaar branch on the remote
263
330
branch unless the --no-rebase option is used, in which case
264
the two branches will be out of sync after the push.
331
the two branches will be out of sync.
267
334
takes_args = ['location?']
271
help='Branch to push from, '
272
'rather than the one containing the working directory.',
276
Option('no-rebase', help="Do not rebase after push."),
278
help='Refuse to push if there are uncommitted changes in'
279
' the working tree, --no-strict disables the check.'),
335
takes_options = ['remember', Option('directory',
336
help='Branch to push from, '
337
'rather than the one containing the working directory.',
341
Option('no-rebase', help="Do not rebase after push.")]
282
def run(self, location=None, remember=False, directory=None,
283
no_rebase=False, strict=None):
343
def run(self, location=None, remember=False, directory=None,
284
345
from bzrlib import urlutils
285
346
from bzrlib.bzrdir import BzrDir
286
347
from bzrlib.errors import BzrCommandError, NoWorkingTree
348
from bzrlib.trace import info
287
349
from bzrlib.workingtree import WorkingTree
289
351
if directory is None: