~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-08-27 04:42:41 UTC
  • mfrom: (1092.1.43)
  • mto: (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1178.
  • Revision ID: aaron.bentley@utoronto.ca-20050827044241-23d676133b9fc981
Merge of robertc@robertcollins.net-20050826013321-52eee1f1da679ee9

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
import os
 
18
import os.path
19
19
import tempfile
20
20
import shutil
21
21
import errno
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 Branch
30
 
from bzrlib.errors import BzrCommandError, UnrelatedBranches, NoCommonAncestor
31
 
from bzrlib.errors import NoCommits
 
29
from bzrlib.branch import find_branch
 
30
from bzrlib.errors import BzrCommandError, UnrelatedBranches
32
31
from bzrlib.delta import compare_trees
33
32
from bzrlib.trace import mutter, warning
34
33
from bzrlib.fetch import greedy_fetch
47
46
    conflict that are not explicitly handled cause an exception and
48
47
    terminate the merge.
49
48
    """
50
 
    def __init__(self, ignore_zero=False):
51
 
        ExceptionConflictHandler.__init__(self)
 
49
    def __init__(self, dir, ignore_zero=False):
 
50
        ExceptionConflictHandler.__init__(self, dir)
52
51
        self.conflicts = 0
53
52
        self.ignore_zero = ignore_zero
54
53
 
134
133
            
135
134
def get_tree(treespec, temp_root, label, local_branch=None):
136
135
    location, revno = treespec
137
 
    branch = Branch.open(location)
 
136
    branch = find_branch(location)
138
137
    if revno is None:
139
138
        revision = None
140
139
    elif revno == -1:
141
140
        revision = branch.last_patch()
142
141
    else:
143
 
        revision = branch.get_rev_id(revno)
 
142
        revision = branch.lookup_revision(revno)
144
143
    return branch, get_revid_tree(branch, revision, temp_root, label,
145
144
                                  local_branch)
146
145
 
244
243
    try:
245
244
        if this_dir is None:
246
245
            this_dir = '.'
247
 
        this_branch = Branch.open_containing(this_dir)
 
246
        this_branch = find_branch(this_dir)
248
247
        this_rev_id = this_branch.last_patch()
249
248
        if this_rev_id is None:
250
249
            raise BzrCommandError("This branch has no commits")
257
256
                                            this_branch)
258
257
        if other_revision[1] == -1:
259
258
            other_rev_id = other_branch.last_patch()
260
 
            if other_rev_id is None:
261
 
                raise NoCommits(other_branch)
262
259
            other_basis = other_rev_id
263
260
        elif other_revision[1] is not None:
264
 
            other_rev_id = other_branch.get_rev_id(other_revision[1])
 
261
            other_rev_id = other_branch.lookup_revision(other_revision[1])
265
262
            other_basis = other_rev_id
266
263
        else:
267
264
            other_rev_id = None
268
265
            other_basis = other_branch.last_patch()
269
 
            if other_basis is None:
270
 
                raise NoCommits(other_branch)
271
266
        if base_revision == [None, None]:
272
 
            try:
273
 
                base_rev_id = common_ancestor(this_rev_id, other_basis, 
274
 
                                              this_branch)
275
 
            except NoCommonAncestor:
 
267
            base_rev_id = common_ancestor(this_rev_id, other_basis, 
 
268
                                          this_branch)
 
269
            if base_rev_id is None:
276
270
                raise UnrelatedBranches()
277
271
            base_tree = get_revid_tree(this_branch, base_rev_id, tempdir, 
278
272
                                       "base", None)
284
278
            elif base_revision[1] is None:
285
279
                base_rev_id = None
286
280
            else:
287
 
                base_rev_id = base_branch.get_rev_id(base_revision[1])
288
 
            multi_source = MultipleRevisionSources(this_branch, base_branch)
289
 
            base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
290
 
                                           multi_source)
 
281
                base_rev_id = base_branch.lookup_revision(base_revision[1])
 
282
            if base_rev_id is not None:
 
283
                base_is_ancestor = is_ancestor(this_rev_id, base_rev_id, 
 
284
                                               MultipleRevisionSources(this_branch, 
 
285
                                                                       base_branch))
 
286
            else:
 
287
                base_is_ancestor = False
291
288
        if file_list is None:
292
289
            interesting_ids = None
293
290
        else:
307
304
        merge_inner(this_branch, other_tree, base_tree, tempdir, 
308
305
                    ignore_zero=ignore_zero, backup_files=backup_files, 
309
306
                    merge_type=merge_type, interesting_ids=interesting_ids)
310
 
        if base_is_ancestor and other_rev_id is not None\
311
 
            and other_rev_id not in this_branch.revision_history():
 
307
        if base_is_ancestor and other_rev_id is not None:
312
308
            this_branch.add_pending_merge(other_rev_id)
313
309
    finally:
314
310
        shutil.rmtree(tempdir)
349
345
 
350
346
    inv_changes = merge_flex(this_tree, base_tree, other_tree,
351
347
                             generate_cset_optimized, get_inventory,
352
 
                             MergeConflictHandler(ignore_zero=ignore_zero),
 
348
                             MergeConflictHandler(base_tree.root,
 
349
                                                  ignore_zero=ignore_zero),
353
350
                             merge_factory=merge_factory, 
354
351
                             interesting_ids=interesting_ids)
355
352
 
359
356
            if path == '.':
360
357
                path = ''
361
358
            else:
362
 
                assert path.startswith('.' + os.sep), "path is %s" % path
 
359
                assert path.startswith('./'), "path is %s" % path
363
360
            path = path[2:]
364
361
        adjust_ids.append((path, id))
365
362
    if len(adjust_ids) > 0: