~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: John Arbash Meinel
  • Date: 2009-12-04 00:59:09 UTC
  • mto: This revision was merged to the branch mainline in revision 4889.
  • Revision ID: john@arbash-meinel.com-20091204005909-r5htm5irxu7n44di
Start working on the ability to drop a .BASE file for --weave and --lca merge.

The main issue at this point is what to do about LCA's 'conflicted' states.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1416
1416
    supports_reverse_cherrypick = False
1417
1417
    history_based = True
1418
1418
 
1419
 
    def _merged_lines(self, file_id):
1420
 
        """Generate the merged lines.
1421
 
        There is no distinction between lines that are meant to contain <<<<<<<
1422
 
        and conflicts.
1423
 
        """
1424
 
        if self.cherrypick:
1425
 
            base = self.base_tree
1426
 
        else:
1427
 
            base = None
1428
 
        plan = self.this_tree.plan_file_merge(file_id, self.other_tree,
 
1419
    def _generate_merge_plan(self, file_id, base):
 
1420
        return self.this_tree.plan_file_merge(file_id, self.other_tree,
1429
1421
                                              base=base)
 
1422
 
 
1423
    def _merged_lines(self, file_id):
 
1424
        """Generate the merged lines.
 
1425
        There is no distinction between lines that are meant to contain <<<<<<<
 
1426
        and conflicts.
 
1427
        """
 
1428
        if self.cherrypick:
 
1429
            base = self.base_tree
 
1430
        else:
 
1431
            base = None
 
1432
        plan = self._generate_merge_plan(file_id, base)
1430
1433
        if 'merge' in debug.debug_flags:
1431
1434
            plan = list(plan)
1432
1435
            trans_id = self.tt.trans_id_file_id(file_id)
1435
1438
            self.tt.new_file(name, self.tt.final_parent(trans_id), contents)
1436
1439
        textmerge = PlanWeaveMerge(plan, '<<<<<<< TREE\n',
1437
1440
            '>>>>>>> MERGE-SOURCE\n')
1438
 
        return textmerge.merge_lines(self.reprocess)
 
1441
        lines, conflicts = textmerge.merge_lines(self.reprocess)
 
1442
        if conflicts:
 
1443
            base_lines = textmerge.base_from_plan()
 
1444
        else:
 
1445
            base_lines = None
 
1446
        return lines, base_lines
1439
1447
 
1440
1448
    def text_merge(self, file_id, trans_id):
1441
1449
        """Perform a (weave) text merge for a given file and file-id.
1442
1450
        If conflicts are encountered, .THIS and .OTHER files will be emitted,
1443
1451
        and a conflict will be noted.
1444
1452
        """
1445
 
        lines, conflicts = self._merged_lines(file_id)
 
1453
        lines, base_lines = self._merged_lines(file_id)
1446
1454
        lines = list(lines)
1447
1455
        # Note we're checking whether the OUTPUT is binary in this case,
1448
1456
        # because we don't want to get into weave merge guts.
1449
1457
        check_text_lines(lines)
1450
1458
        self.tt.create_file(lines, trans_id)
1451
 
        if conflicts:
 
1459
        if base_lines is not None:
 
1460
            # Conflict
1452
1461
            self._raw_conflicts.append(('text conflict', trans_id))
1453
1462
            name = self.tt.final_name(trans_id)
1454
1463
            parent_id = self.tt.final_parent(trans_id)
1455
1464
            file_group = self._dump_conflicts(name, parent_id, file_id,
1456
 
                                              no_base=True)
 
1465
                                              no_base=False,
 
1466
                                              base_lines=base_lines)
1457
1467
            file_group.append(trans_id)
1458
1468
 
1459
1469
 
1460
1470
class LCAMerger(WeaveMerger):
1461
1471
 
1462
 
    def _merged_lines(self, file_id):
1463
 
        """Generate the merged lines.
1464
 
        There is no distinction between lines that are meant to contain <<<<<<<
1465
 
        and conflicts.
1466
 
        """
1467
 
        if self.cherrypick:
1468
 
            base = self.base_tree
1469
 
        else:
1470
 
            base = None
1471
 
        plan = self.this_tree.plan_file_lca_merge(file_id, self.other_tree,
 
1472
    def _generate_merge_plan(self, file_id, base):
 
1473
        return self.this_tree.plan_file_lca_merge(file_id, self.other_tree,
1472
1474
                                                  base=base)
1473
 
        if 'merge' in debug.debug_flags:
1474
 
            plan = list(plan)
1475
 
            trans_id = self.tt.trans_id_file_id(file_id)
1476
 
            name = self.tt.final_name(trans_id) + '.plan'
1477
 
            contents = ('%10s|%s' % l for l in plan)
1478
 
            self.tt.new_file(name, self.tt.final_parent(trans_id), contents)
1479
 
        textmerge = PlanWeaveMerge(plan, '<<<<<<< TREE\n',
1480
 
            '>>>>>>> MERGE-SOURCE\n')
1481
 
        return textmerge.merge_lines(self.reprocess)
1482
 
 
 
1475
        
1483
1476
 
1484
1477
class Diff3Merger(Merge3Merger):
1485
1478
    """Three-way merger using external diff3 for text merging"""