269
270
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)
273
def update_workingtree_fileids(wt, target_tree):
274
"""Update the file ids in a working tree based on another tree.
276
:param wt: Working tree in which to update file ids
277
:param target_tree: Tree to retrieve new file ids from, based on path
279
tt = transform.TreeTransform(wt)
281
for f, p, c, v, d, n, k, e in target_tree.iter_changes(wt):
282
if v == (True, False):
283
trans_id = tt.trans_id_tree_path(p[0])
284
tt.unversion_file(trans_id)
285
elif v == (False, True):
286
trans_id = tt.trans_id_tree_path(p[1])
287
tt.version_file(f, trans_id)
291
if len(wt.get_parent_ids()) == 1:
292
wt.set_parent_trees([(target_tree.get_revision_id(), target_tree)])
294
wt.set_last_revision(target_tree.get_revision_id())
325
297
class cmd_dpush(Command):