~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-10 07:46:15 UTC
  • mfrom: (5844 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5845.
  • Revision ID: jelmer@samba.org-20110510074615-eptod049ndjxc4i7
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
lazy_import(globals(), """
21
21
from bzrlib import (
22
22
    branch as _mod_branch,
 
23
    cleanup,
23
24
    conflicts as _mod_conflicts,
24
25
    debug,
25
26
    generate_ids,
37
38
    versionedfile,
38
39
    workingtree,
39
40
    )
40
 
from bzrlib.cleanup import OperationWithCleanups
41
41
""")
42
42
from bzrlib import (
43
43
    decorators,
53
53
 
54
54
def transform_tree(from_tree, to_tree, interesting_ids=None):
55
55
    from_tree.lock_tree_write()
56
 
    operation = OperationWithCleanups(merge_inner)
 
56
    operation = cleanup.OperationWithCleanups(merge_inner)
57
57
    operation.add_cleanup(from_tree.unlock)
58
58
    operation.run_simple(from_tree.branch, to_tree, from_tree,
59
59
        ignore_zero=True, interesting_ids=interesting_ids, this_tree=from_tree)
62
62
class MergeHooks(hooks.Hooks):
63
63
 
64
64
    def __init__(self):
65
 
        hooks.Hooks.__init__(self)
66
 
        self.create_hook(hooks.HookPoint('merge_file_content',
 
65
        hooks.Hooks.__init__(self, "bzrlib.merge", "Merger.hooks")
 
66
        self.add_hook('merge_file_content',
67
67
            "Called with a bzrlib.merge.Merger object to create a per file "
68
68
            "merge object when starting a merge. "
69
69
            "Should return either None or a subclass of "
73
73
            "side has deleted the file and the other has changed it). "
74
74
            "See the AbstractPerFileMerger API docs for details on how it is "
75
75
            "used by merge.",
76
 
            (2, 1), None))
 
76
            (2, 1))
77
77
 
78
78
 
79
79
class AbstractPerFileMerger(object):
458
458
    @deprecated_method(deprecated_in((2, 1, 0)))
459
459
    def file_revisions(self, file_id):
460
460
        self.ensure_revision_trees()
461
 
        def get_id(tree, file_id):
462
 
            revision_id = tree.inventory[file_id].revision
463
 
            return revision_id
464
461
        if self.this_rev_id is None:
465
462
            if self.this_basis_tree.get_file_sha1(file_id) != \
466
463
                self.this_tree.get_file_sha1(file_id):
467
464
                raise errors.WorkingTreeNotRevision(self.this_tree)
468
465
 
469
466
        trees = (self.this_basis_tree, self.other_tree)
470
 
        return [get_id(tree, file_id) for tree in trees]
 
467
        return [tree.get_file_revision(file_id) for tree in trees]
471
468
 
472
469
    @deprecated_method(deprecated_in((2, 1, 0)))
473
470
    def check_basis(self, check_clean, require_commits=True):
501
498
    def _add_parent(self):
502
499
        new_parents = self.this_tree.get_parent_ids() + [self.other_rev_id]
503
500
        new_parent_trees = []
504
 
        operation = OperationWithCleanups(self.this_tree.set_parent_trees)
 
501
        operation = cleanup.OperationWithCleanups(
 
502
            self.this_tree.set_parent_trees)
505
503
        for revision_id in new_parents:
506
504
            try:
507
505
                tree = self.revision_tree(revision_id)
565
563
 
566
564
    def _maybe_fetch(self, source, target, revision_id):
567
565
        if not source.repository.has_same_location(target.repository):
568
 
            try:
569
 
                tags_to_fetch = set(source.tags.get_reverse_tag_dict())
570
 
            except errors.TagsNotSupported:
571
 
                tags_to_fetch = None
572
 
            fetch_spec = _mod_graph.NotInOtherForRevs(target.repository,
573
 
                source.repository, [revision_id],
574
 
                if_present_ids=tags_to_fetch).execute()
575
 
            target.fetch(source, fetch_spec=fetch_spec)
 
566
            target.fetch(source, revision_id)
576
567
 
577
568
    def find_base(self):
578
569
        revisions = [_mod_revision.ensure_null(self.this_basis),
708
699
        return merge
709
700
 
710
701
    def do_merge(self):
711
 
        operation = OperationWithCleanups(self._do_merge_to)
 
702
        operation = cleanup.OperationWithCleanups(self._do_merge_to)
712
703
        self.this_tree.lock_tree_write()
713
704
        operation.add_cleanup(self.this_tree.unlock)
714
705
        if self.base_tree is not None:
820
811
            warnings.warn("pb argument to Merge3Merger is deprecated")
821
812
 
822
813
    def do_merge(self):
823
 
        operation = OperationWithCleanups(self._do_merge)
 
814
        operation = cleanup.OperationWithCleanups(self._do_merge)
824
815
        self.this_tree.lock_tree_write()
825
816
        operation.add_cleanup(self.this_tree.unlock)
826
817
        self.base_tree.lock_read()
841
832
            pass
842
833
 
843
834
    def make_preview_transform(self):
844
 
        operation = OperationWithCleanups(self._make_preview_transform)
 
835
        operation = cleanup.OperationWithCleanups(self._make_preview_transform)
845
836
        self.base_tree.lock_read()
846
837
        operation.add_cleanup(self.base_tree.unlock)
847
838
        self.other_tree.lock_read()
910
901
        """
911
902
        result = []
912
903
        iterator = self.other_tree.iter_changes(self.base_tree,
913
 
                include_unchanged=True, specific_files=self.interesting_files,
 
904
                specific_files=self.interesting_files,
914
905
                extra_trees=[self.this_tree])
915
906
        this_entries = dict((e.file_id, e) for p, e in
916
907
                            self.this_tree.iter_entries_by_dir(
1125
1116
        # 'other_tree.inventory.root' is not present in this tree. We are
1126
1117
        # calling adjust_path for children which *want* to be present with a
1127
1118
        # correct place to go.
1128
 
        for thing, child in self.other_tree.inventory.root.children.iteritems():
 
1119
        for _, child in self.other_tree.inventory.root.children.iteritems():
1129
1120
            trans_id = self.tt.trans_id_file_id(child.file_id)
1130
1121
            if not other_root_is_present:
1131
1122
                if self.tt.final_kind(trans_id) is not None:
1133
1124
                    # to go already.
1134
1125
                    continue
1135
1126
            # Move the item into the root
1136
 
            self.tt.adjust_path(self.tt.final_name(trans_id),
1137
 
                                self.tt.root, trans_id)
 
1127
            try:
 
1128
                final_name = self.tt.final_name(trans_id)
 
1129
            except errors.NoFinalPath:
 
1130
                # This file is not present anymore, ignore it.
 
1131
                continue
 
1132
            self.tt.adjust_path(final_name, self.tt.root, trans_id)
1138
1133
        if other_root_is_present:
1139
1134
            self.tt.cancel_creation(other_root)
1140
1135
            self.tt.cancel_versioning(other_root)