~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

Added more docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
337
337
    history_based = False
338
338
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
339
339
                 reprocess=False, show_base=False):
 
340
        """Initialize the merger object and perform the merge."""
340
341
        object.__init__(self)
341
342
        self.this_tree = working_tree
342
343
        self.base_tree = base_tree
368
369
       
369
370
    @staticmethod
370
371
    def parent(entry, file_id):
 
372
        """Determine the parent for a file_id (used as a key method)"""
371
373
        if entry is None:
372
374
            return None
373
375
        return entry.parent_id
374
376
 
375
377
    @staticmethod
376
378
    def name(entry, file_id):
 
379
        """Determine the name for a file_id (used as a key method)"""
377
380
        if entry is None:
378
381
            return None
379
382
        return entry.name
380
383
    
381
384
    @staticmethod
382
385
    def contents_sha1(tree, file_id):
 
386
        """Determine the sha1 of the file contents (used as a key method)."""
383
387
        if file_id not in tree:
384
388
            return None
385
389
        return tree.get_file_sha1(file_id)
386
390
 
387
391
    @staticmethod
388
392
    def executable(tree, file_id):
 
393
        """Determine the executability of a file-id (used as a key method)."""
389
394
        if file_id not in tree:
390
395
            return None
391
396
        if tree.kind(file_id) != "file":
394
399
 
395
400
    @staticmethod
396
401
    def kind(tree, file_id):
 
402
        """Determine the kind of a file-id (used as a key method)."""
397
403
        if file_id not in tree:
398
404
            return None
399
405
        return tree.kind(file_id)
419
425
            return "other"
420
426
 
421
427
    def merge_names(self, file_id):
 
428
        """Perform a merge on file_id names and parents"""
422
429
        def get_entry(tree):
423
430
            if file_id in tree.inventory:
424
431
                return tree.inventory[file_id]
464
471
 
465
472
 
466
473
    def merge_contents(self, file_id):
 
474
        """Performa a merge on file_id contents."""
467
475
        def contents_pair(tree):
468
476
            if file_id not in tree:
469
477
                return (None, None)
535
543
                self._raw_conflicts.append(('contents conflict', file_group))
536
544
 
537
545
    def get_lines(self, tree, file_id):
 
546
        """Return the lines in a file, or an empty list."""
538
547
        if file_id in tree:
539
548
            return tree.get_file(file_id).readlines()
540
549
        else:
586
595
    def _dump_conflicts(self, name, parent_id, file_id, this_lines=None, 
587
596
                        base_lines=None, other_lines=None, set_version=False,
588
597
                        no_base=False):
 
598
        """Emit conflict files.
 
599
        If this_lines, base_lines, or other_lines are omitted, they will be
 
600
        determined automatically.  If set_version is true, the .OTHER, .THIS
 
601
        or .BASE (in that order) will be created as versioned files.
 
602
        """
589
603
        data = [('OTHER', self.other_tree, other_lines), 
590
604
                ('THIS', self.this_tree, this_lines)]
591
605
        if not no_base:
604
618
           
605
619
    def _conflict_file(self, name, parent_id, tree, file_id, suffix, 
606
620
                       lines=None):
 
621
        """Emit a single conflict file."""
607
622
        name = name + '.' + suffix
608
623
        trans_id = self.tt.create_path(name, parent_id)
609
624
        entry = tree.inventory[file_id]
611
626
        return trans_id
612
627
 
613
628
    def merge_executable(self, file_id, file_status):
 
629
        """Perform a merge on the execute bit."""
614
630
        if file_status == "deleted":
615
631
            return
616
632
        trans_id = self.tt.get_trans_id(file_id)
702
718
 
703
719
 
704
720
def conflicts_strings(conflicts):
 
721
    """Generate strings for the provided conflicts"""
705
722
    for conflict in conflicts:
706
723
        conflict_type = conflict[0]
707
724
        if conflict_type == 'text conflict':
713
730
 
714
731
 
715
732
class WeaveMerger(Merge3Merger):
 
733
    """Merger that does weave merges."""
716
734
    supports_reprocess = False
717
735
    supports_show_base = False
718
736
 
723
741
                                          base_tree, other_tree)
724
742
 
725
743
    def _get_revision_tree(self, tree):
 
744
        """Return a revision tree releated to this tree.
 
745
        If the tree is a WorkingTree, the basis will be returned.
 
746
        """
726
747
        if getattr(tree, 'get_weave', False) is False:
727
748
            # If we have a WorkingTree, try using the basis
728
749
            return tree.branch.basis_tree()
753
774
        return weave.weave_merge(plan)
754
775
 
755
776
    def text_merge(self, file_id, trans_id):
 
777
        """Perform a (weave) text merge for a given file and file-id.
 
778
        If conflicts are encountered, .THIS and .OTHER files will be emitted,
 
779
        and a conflict will be noted.
 
780
        """
756
781
        self._check_file(file_id)
757
782
        lines = self._merged_lines(file_id)
758
783
        conflicts = '<<<<<<<\n' in lines
777
802
        return out_path
778
803
 
779
804
    def text_merge(self, file_id, trans_id):
 
805
        """Perform a diff3 merge using a specified file-id and trans-id.
 
806
        If conflicts are encountered, .BASE, .THIS. and .OTHER conflict files
 
807
        will be dumped, and a will be conflict noted.
 
808
        """
780
809
        import bzrlib.patch
781
810
        temp_dir = mkdtemp(prefix="bzr-")
782
811
        try: