119
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)
122
137
class ForeignVcs(object):
123
138
"""A foreign version control system."""
127
repository_format = None
129
def __init__(self, mapping_registry, abbreviation=None):
130
"""Create a new foreign vcs instance.
132
:param mapping_registry: Registry with mappings for this VCS.
133
:param abbreviation: Optional abbreviation ('bzr', 'svn', 'git', etc)
135
self.abbreviation = abbreviation
140
def __init__(self, mapping_registry):
136
141
self.mapping_registry = mapping_registry
138
143
def show_foreign_revid(self, foreign_revid):
233
252
self.mapping = mapping
234
253
super(ForeignBranch, self).__init__()
237
def update_workingtree_fileids(wt, target_tree):
238
"""Update the file ids in a working tree based on another tree.
240
:param wt: Working tree in which to update file ids
241
:param target_tree: Tree to retrieve new file ids from, based on path
243
tt = transform.TreeTransform(wt)
245
for f, p, c, v, d, n, k, e in target_tree.iter_changes(wt):
246
if v == (True, False):
247
trans_id = tt.trans_id_tree_path(p[0])
248
tt.unversion_file(trans_id)
249
elif v == (False, True):
250
trans_id = tt.trans_id_tree_path(p[1])
251
tt.version_file(f, trans_id)
255
if len(wt.get_parent_ids()) == 1:
256
wt.set_parent_trees([(target_tree.get_revision_id(), target_tree)])
258
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)
261
325
class cmd_dpush(Command):
262
__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.
264
This will afterwards rebase the local branch on the remote
329
This will afterwards rebase the local Bazaar branch on the remote
265
330
branch unless the --no-rebase option is used, in which case
266
the two branches will be out of sync after the push.
331
the two branches will be out of sync.
269
334
takes_args = ['location?']
273
help='Branch to push from, '
274
'rather than the one containing the working directory.',
278
Option('no-rebase', help="Do not rebase after push."),
280
help='Refuse to push if there are uncommitted changes in'
281
' 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.")]
284
def run(self, location=None, remember=False, directory=None,
285
no_rebase=False, strict=None):
343
def run(self, location=None, remember=False, directory=None,
286
345
from bzrlib import urlutils
287
346
from bzrlib.bzrdir import BzrDir
288
347
from bzrlib.errors import BzrCommandError, NoWorkingTree
348
from bzrlib.trace import info
289
349
from bzrlib.workingtree import WorkingTree
291
351
if directory is None:
331
385
if source_wt is not None and old_last_revid != new_last_revid:
332
386
source_wt.lock_write()
334
target = source_wt.branch.repository.revision_tree(
336
update_workingtree_fileids(source_wt, target)
388
update_workinginv_fileids(source_wt,
389
source_wt.branch.repository.get_inventory(
391
source_wt.branch.repository.get_inventory(
338
394
source_wt.unlock()
339
push_result.report(self.outf)
341
396
target_branch.unlock()
344
class InterToForeignBranch(InterBranch):
346
def lossy_push(self, stop_revision=None):
347
"""Push deltas into another branch.
349
:note: This does not, like push, retain the revision ids from
350
the source branch and will, rather than adding bzr-specific
351
metadata, push only those semantics of the revision that can be
352
natively represented by this branch' VCS.
354
:param target: Target branch
355
:param stop_revision: Revision to push, defaults to last revision.
356
:return: BranchPushResult with an extra member revidmap:
357
A dictionary mapping revision ids from the target branch
358
to new revision ids in the target branch, for each
359
revision that was pushed.
361
raise NotImplementedError(self.lossy_push)