1428
1428
# rather than a key tuple. We will just map that directly to no common
1430
1430
parent_map = {}
1431
mutter('finding lcas for:\n%s, %s', self.a_rev, self.b_rev)
1432
1433
next_lcas = self.graph.find_lca(*cur_ancestors)
1433
1434
# Map a plain NULL_REVISION to a simple no-ancestors
1434
1435
if next_lcas == set([NULL_REVISION]):
1436
# Order the lca's based on when they were merged into the first
1437
# tip. While weave merge uses a set() of active revisions, the
1438
# order of insertion *does* effect the implicit ordering of the
1440
next_lcas = tuple(self.graph.find_merge_order(cur_ancestors[0],
1437
# Order the lca's based on when they were merged into the tip
1438
# While the actual merge portion of weave merge uses a set() of
1439
# active revisions, the order of insertion *does* effect the
1440
# implicit ordering of the texts.
1442
1441
for rev_key in cur_ancestors:
1443
parent_map[rev_key] = next_lcas
1442
ordered_parents = tuple(self.graph.find_merge_order(rev_key,
1444
mutter('found %s => %s', rev_key[-1], [p[-1] for p
1445
in ordered_parents])
1446
parent_map[rev_key] = ordered_parents
1444
1447
if len(next_lcas) == 0:
1446
1449
elif len(next_lcas) == 1:
1447
parent_map[next_lcas[0]] = ()
1450
parent_map[list(next_lcas)[0]] = ()
1450
1453
# More than 2 lca's, fall back to grabbing all nodes between
1531
1534
tip_key = self._key_prefix + (_mod_revision.CURRENT_REVISION,)
1532
1535
parent_map[tip_key] = (self.a_key, self.b_key)
1534
1538
for seq_num, key, depth, eom in reversed(tsort.merge_sort(parent_map,
1536
1540
if key == tip_key:
1542
# for key in tsort.topo_sort(parent_map):
1538
1543
parent_keys = parent_map[key]
1539
1544
revision_id = key[-1]
1545
ordering.append(revision_id)
1540
1546
parent_ids = [k[-1] for k in parent_keys]
1541
1547
self._weave.add_lines(revision_id, parent_ids,
1542
1548
all_texts[revision_id])
1549
mutter('order in weave: %s', ordering)
1544
1551
def plan_merge(self):
1545
1552
"""Generate a 'plan' for merging the two revisions.