~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Matthieu Moy
  • Date: 2006-07-08 19:32:30 UTC
  • mfrom: (1845 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1857.
  • Revision ID: Matthieu.Moy@imag.fr-20060708193230-3eb72d871471bd5b
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006 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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
import os
19
19
import errno
20
20
from tempfile import mkdtemp
 
21
import warnings
21
22
 
22
 
import bzrlib
23
23
from bzrlib.branch import Branch
24
24
from bzrlib.conflicts import ConflictList, Conflict
25
25
from bzrlib.delta import compare_trees
41
41
from bzrlib.osutils import rename, pathjoin, rmtree
42
42
from progress import DummyProgress, ProgressPhase
43
43
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
44
 
from bzrlib.symbol_versioning import *
45
44
from bzrlib.textfile import check_text_lines
46
45
from bzrlib.trace import mutter, warning, note
47
46
from bzrlib.transform import (TreeTransform, resolve_conflicts, cook_conflicts,
48
47
                              FinalPaths, create_by_entry, unique_add)
49
48
from bzrlib.versionedfile import WeaveMerge
50
 
import bzrlib.ui
 
49
from bzrlib import ui
51
50
 
52
51
# TODO: Report back as changes are merged in
53
52
 
120
119
            changes = compare_trees(self.other_tree, other_basis_tree)
121
120
            if changes.has_changed():
122
121
                raise WorkingTreeNotRevision(self.this_tree)
123
 
            other_rev_id = other_basis
 
122
            other_rev_id = self.other_basis
124
123
            self.other_tree = other_basis_tree
125
124
 
126
125
    def file_revisions(self, file_id):
137
136
        trees = (self.this_basis_tree, self.other_tree)
138
137
        return [get_id(tree, file_id) for tree in trees]
139
138
 
140
 
    def check_basis(self, check_clean):
141
 
        if self.this_basis is None:
 
139
    def check_basis(self, check_clean, require_commits=True):
 
140
        if self.this_basis is None and require_commits is True:
142
141
            raise BzrCommandError("This branch has no commits")
143
142
        if check_clean:
144
143
            self.compare_basis()
205
204
        if other_branch.base != self.this_branch.base:
206
205
            self.this_branch.fetch(other_branch, last_revision=self.other_basis)
207
206
 
 
207
    def find_base(self):
 
208
        self.set_base([None, None])
 
209
 
208
210
    def set_base(self, base_revision):
209
211
        mutter("doing merge() with no base_revision specified")
210
212
        if base_revision == [None, None]:
365
367
        self.tt = TreeTransform(working_tree, self.pb)
366
368
        try:
367
369
            self.pp.next_phase()
368
 
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
370
            child_pb = ui.ui_factory.nested_progress_bar()
369
371
            try:
370
372
                for num, file_id in enumerate(all_ids):
371
373
                    child_pb.update('Preparing file merge', num, len(all_ids))
376
378
                child_pb.finished()
377
379
                
378
380
            self.pp.next_phase()
379
 
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
381
            child_pb = ui.ui_factory.nested_progress_bar()
380
382
            try:
381
383
                fs_conflicts = resolve_conflicts(self.tt, child_pb)
382
384
            finally:
388
390
            results = self.tt.apply()
389
391
            self.write_modified(results)
390
392
            try:
391
 
                working_tree.set_conflicts(ConflictList(self.cooked_conflicts))
 
393
                working_tree.add_conflicts(self.cooked_conflicts)
392
394
            except UnsupportedOperation:
393
395
                pass
394
396
        finally:
395
 
            try:
396
 
                self.tt.finalize()
397
 
            except:
398
 
                pass
 
397
            self.tt.finalize()
399
398
            working_tree.unlock()
400
399
            self.pb.clear()
401
400
 
691
690
        if winner == "conflict":
692
691
        # There must be a None in here, if we have a conflict, but we
693
692
        # need executability since file status was not deleted.
694
 
            if self.other_tree.is_executable(file_id) is None:
 
693
            if self.executable(self.other_tree, file_id) is None:
695
694
                winner = "this"
696
695
            else:
697
696
                winner = "other"
789
788
                                          pb=pb, pp=pp, reprocess=reprocess)
790
789
 
791
790
    def _get_revision_tree(self, tree):
792
 
        """Return a revision tree releated to this tree.
 
791
        """Return a revision tree related to this tree.
793
792
        If the tree is a WorkingTree, the basis will be returned.
794
793
        """
795
794
        if getattr(tree, 'get_weave', False) is False:
843
842
 
844
843
class Diff3Merger(Merge3Merger):
845
844
    """Three-way merger using external diff3 for text merging"""
 
845
 
846
846
    def dump_file(self, temp_dir, name, tree, file_id):
847
847
        out_path = pathjoin(temp_dir, name)
848
 
        out_file = file(out_path, "wb")
849
 
        in_file = tree.get_file(file_id)
850
 
        for line in in_file:
851
 
            out_file.write(line)
 
848
        out_file = open(out_path, "wb")
 
849
        try:
 
850
            in_file = tree.get_file(file_id)
 
851
            for line in in_file:
 
852
                out_file.write(line)
 
853
        finally:
 
854
            out_file.close()
852
855
        return out_path
853
856
 
854
857
    def text_merge(self, file_id, trans_id):
866
869
            status = bzrlib.patch.diff3(new_file, this, base, other)
867
870
            if status not in (0, 1):
868
871
                raise BzrError("Unhandled diff3 exit code")
869
 
            self.tt.create_file(file(new_file, "rb"), trans_id)
 
872
            f = open(new_file, 'rb')
 
873
            try:
 
874
                self.tt.create_file(f, trans_id)
 
875
            finally:
 
876
                f.close()
870
877
            if status == 1:
871
878
                name = self.tt.final_name(trans_id)
872
879
                parent_id = self.tt.final_parent(trans_id)
893
900
                     branch.get_revision_tree(base_revision))'
894
901
        """
895
902
    if this_tree is None:
896
 
        warn("bzrlib.merge.merge_inner requires a this_tree parameter as of "
 
903
        warnings.warn("bzrlib.merge.merge_inner requires a this_tree parameter as of "
897
904
             "bzrlib version 0.8.",
898
905
             DeprecationWarning,
899
906
             stacklevel=2)