~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Robert Collins
  • Date: 2005-11-22 21:28:30 UTC
  • mfrom: (1185.33.32 bzr.dev)
  • Revision ID: robertc@robertcollins.net-20051122212830-885c284847f0b17b
Merge from mpool.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
                           NoCommits,
34
34
                           WorkingTreeNotRevision,
35
35
                           NotBranchError,
36
 
                           NotVersionedError)
 
36
                           NotVersionedError,
 
37
                           BzrError)
37
38
from bzrlib.delta import compare_trees
38
39
from bzrlib.trace import mutter, warning, note
39
40
from bzrlib.fetch import greedy_fetch, fetch
150
151
        Handle weave conflicts by producing a .THIS, and .OTHER.  The
151
152
        main file will be a version with diff3-style conflicts.
152
153
        """
153
 
        self.add_suffix(filename, ".THIS")
 
154
        self.add_suffix(filename, ".THIS", fix_inventory=False)
154
155
        out_file.commit()
155
156
        self.dump(weave.get_iter(other_i), filename+".OTHER")
156
157
        self.conflict("Text conflict encountered in %s" % filename)
275
276
    transform_tree(this_branch.working_tree(), this_branch.basis_tree())
276
277
 
277
278
 
278
 
def transform_tree(from_tree, to_tree):
279
 
    merge_inner(from_tree.branch, to_tree, from_tree, ignore_zero=True)
 
279
def transform_tree(from_tree, to_tree, interesting_ids=None):
 
280
    merge_inner(from_tree.branch, to_tree, from_tree, ignore_zero=True,
 
281
                interesting_ids=interesting_ids)
280
282
 
281
283
 
282
284
def merge(other_revision, base_revision,
324
326
    merger.check_basis(check_clean)
325
327
    merger.set_other(other_revision)
326
328
    merger.set_base(base_revision)
 
329
    if merger.base_rev_id == merger.other_rev_id:
 
330
        note('Nothing to do.')
 
331
        return 0
327
332
    merger.backup_files = backup_files
328
333
    merger.merge_type = merge_type 
329
334
    merger.set_interesting_files(file_list)
338
343
    return conflicts
339
344
 
340
345
def merge_inner(this_branch, other_tree, base_tree, ignore_zero=False,
341
 
                backup_files=False, merge_type=ApplyMerge3, 
342
 
                interesting_ids=None, show_base=False, reprocess=False,
 
346
                backup_files=False, 
 
347
                merge_type=ApplyMerge3, 
 
348
                interesting_ids=None, 
 
349
                show_base=False, 
 
350
                reprocess=False, 
 
351
                other_rev_id=None,
343
352
                interesting_files=None):
344
353
    """Primary interface for merging. 
345
354
 
360
369
    merger.conflict_handler = MergeConflictHandler(merger.this_tree, base_tree, 
361
370
                                                   other_tree,
362
371
                                                   ignore_zero=ignore_zero)
 
372
    merger.other_rev_id = other_rev_id
 
373
    merger.other_basis = other_rev_id
363
374
    return merger.do_merge()
364
375
 
365
376
 
371
382
        self.this_rev_id = None
372
383
        self.this_tree = this_branch.working_tree()
373
384
        self.this_revision_tree = None
 
385
        self.this_basis_tree = None
374
386
        self.other_tree = other_tree
375
387
        self.base_tree = base_tree
376
388
        self.ignore_zero = False
386
398
 
387
399
    def ensure_revision_trees(self):
388
400
        if self.this_revision_tree is None:
389
 
            if self.this_rev_id is None:
390
 
                self.compare_basis()
391
 
            if self.this_rev_id is None:
392
 
                raise WorkingTreeNotRevision(self.this_tree)
393
 
            self.this_revision_tree = self.this_branch.revision_tree(
394
 
                self.this_rev_id)
 
401
            self.this_basis_tree = self.this_branch.revision_tree(
 
402
                self.this_basis)
 
403
            if self.this_basis == self.this_rev_id:
 
404
                self.this_revision_tree = self.this_basis_tree
 
405
 
395
406
 
396
407
        if self.other_rev_id is None:
397
408
            other_basis_tree = self.revision_tree(self.other_basis)
408
419
            revision_id = tree.inventory[file_id].revision
409
420
            assert revision_id is not None
410
421
            return revision_id
411
 
        trees = (self.this_revision_tree, self.other_tree)
 
422
        if self.this_rev_id is None:
 
423
            if self.this_basis_tree.get_file_sha1(file_id) != \
 
424
                self.this_tree.get_file_sha1(file_id):
 
425
                raise WorkingTreeNotRevision(self.this_tree)
 
426
 
 
427
        trees = (self.this_basis_tree, self.other_tree)
412
428
        return [get_id(tree, file_id) for tree in trees]
413
429
            
414
430
 
415
431
    def merge_factory(self, file_id, base, other):
416
432
        if self.merge_type.history_based:
 
433
            if self.show_base is True:
 
434
                raise BzrError("Cannot show base for hisory-based merges")
 
435
            if self.reprocess is True:
 
436
                raise BzrError("Cannot reprocess history-based merges")
 
437
                
417
438
            t_revid, o_revid = self.file_revisions(file_id)
418
 
            weave = self.this_revision_tree.get_weave(file_id)
 
439
            weave = self.this_basis_tree.get_weave(file_id)
419
440
            contents_change = self.merge_type(weave, t_revid, o_revid)
420
441
        else:
421
442
            if self.show_base is True or self.reprocess is True:
524
545
    def do_merge(self):
525
546
        def get_inventory(tree):
526
547
            return tree.inventory
527
 
 
 
548
        
528
549
        inv_changes = merge_flex(self.this_tree, self.base_tree, 
529
550
                                 self.other_tree,
530
551
                                 generate_changeset, get_inventory,