~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Robert Collins
  • Date: 2005-09-28 05:37:53 UTC
  • mfrom: (1092.3.4)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050928053753-68e6e4c0642eccea
merge from symlink branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
27
27
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
28
28
from bzrlib.changeset import Inventory, Diff3Merge
29
 
from bzrlib.branch import find_branch
30
 
from bzrlib.errors import BzrCommandError, UnrelatedBranches
 
29
from bzrlib.branch import Branch
 
30
from bzrlib.errors import BzrCommandError, UnrelatedBranches, NoCommonAncestor
 
31
from bzrlib.errors import NoCommits
31
32
from bzrlib.delta import compare_trees
32
33
from bzrlib.trace import mutter, warning
33
34
from bzrlib.fetch import greedy_fetch
34
35
from bzrlib.revision import is_ancestor
 
36
from bzrlib.osutils import rename
 
37
 
35
38
 
36
39
# comments from abentley on irc: merge happens in two stages, each
37
40
# of which generates a changeset object
46
49
    conflict that are not explicitly handled cause an exception and
47
50
    terminate the merge.
48
51
    """
49
 
    def __init__(self, dir, ignore_zero=False):
50
 
        ExceptionConflictHandler.__init__(self, dir)
 
52
    def __init__(self, ignore_zero=False):
 
53
        ExceptionConflictHandler.__init__(self)
51
54
        self.conflicts = 0
52
55
        self.ignore_zero = ignore_zero
53
56
 
83
86
            last_new_name = name
84
87
        new_name = last_new_name+suffix
85
88
        try:
86
 
            os.rename(name, new_name)
 
89
            rename(name, new_name)
87
90
            return new_name
88
91
        except OSError, e:
89
92
            if e.errno != errno.EEXIST and e.errno != errno.ENOTEMPTY:
107
110
        self.add_suffix(this_path, ".THIS")
108
111
        self.dump(base_lines, this_path+".BASE")
109
112
        self.dump(other_lines, this_path+".OTHER")
110
 
        os.rename(new_file, this_path)
 
113
        rename(new_file, this_path)
111
114
        self.conflict("Diff3 conflict encountered in %s" % this_path)
112
115
 
113
116
    def new_contents_conflict(self, filename, other_contents):
133
136
            
134
137
def get_tree(treespec, temp_root, label, local_branch=None):
135
138
    location, revno = treespec
136
 
    branch = find_branch(location)
 
139
    branch = Branch.open_containing(location)
137
140
    if revno is None:
138
141
        revision = None
139
142
    elif revno == -1:
140
143
        revision = branch.last_patch()
141
144
    else:
142
 
        revision = branch.lookup_revision(revno)
 
145
        revision = branch.get_rev_id(revno)
143
146
    return branch, get_revid_tree(branch, revision, temp_root, label,
144
147
                                  local_branch)
145
148
 
251
254
    try:
252
255
        if this_dir is None:
253
256
            this_dir = '.'
254
 
        this_branch = find_branch(this_dir)
 
257
        this_branch = Branch.open_containing(this_dir)
255
258
        this_rev_id = this_branch.last_patch()
256
259
        if this_rev_id is None:
257
260
            raise BzrCommandError("This branch has no commits")
264
267
                                            this_branch)
265
268
        if other_revision[1] == -1:
266
269
            other_rev_id = other_branch.last_patch()
 
270
            if other_rev_id is None:
 
271
                raise NoCommits(other_branch)
267
272
            other_basis = other_rev_id
268
273
        elif other_revision[1] is not None:
269
 
            other_rev_id = other_branch.lookup_revision(other_revision[1])
 
274
            other_rev_id = other_branch.get_rev_id(other_revision[1])
270
275
            other_basis = other_rev_id
271
276
        else:
272
277
            other_rev_id = None
273
278
            other_basis = other_branch.last_patch()
 
279
            if other_basis is None:
 
280
                raise NoCommits(other_branch)
274
281
        if base_revision == [None, None]:
275
 
            base_rev_id = common_ancestor(this_rev_id, other_basis, 
276
 
                                          this_branch)
277
 
            if base_rev_id is None:
 
282
            try:
 
283
                base_rev_id = common_ancestor(this_rev_id, other_basis, 
 
284
                                              this_branch)
 
285
            except NoCommonAncestor:
278
286
                raise UnrelatedBranches()
279
287
            base_tree = get_revid_tree(this_branch, base_rev_id, tempdir, 
280
288
                                       "base", None)
286
294
            elif base_revision[1] is None:
287
295
                base_rev_id = None
288
296
            else:
289
 
                base_rev_id = base_branch.lookup_revision(base_revision[1])
290
 
            if base_rev_id is not None:
291
 
                base_is_ancestor = is_ancestor(this_rev_id, base_rev_id, 
292
 
                                               MultipleRevisionSources(this_branch, 
293
 
                                                                       base_branch))
294
 
            else:
295
 
                base_is_ancestor = False
 
297
                base_rev_id = base_branch.get_rev_id(base_revision[1])
 
298
            multi_source = MultipleRevisionSources(this_branch, base_branch)
 
299
            base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
 
300
                                           multi_source)
296
301
        if file_list is None:
297
302
            interesting_ids = None
298
303
        else:
354
359
 
355
360
    inv_changes = merge_flex(this_tree, base_tree, other_tree,
356
361
                             generate_cset_optimized, get_inventory,
357
 
                             MergeConflictHandler(base_tree.root,
358
 
                                                  ignore_zero=ignore_zero),
 
362
                             MergeConflictHandler(ignore_zero=ignore_zero),
359
363
                             merge_factory=merge_factory, 
360
364
                             interesting_ids=interesting_ids)
361
365