~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset.py

  • Committer: Aaron Bentley
  • Date: 2005-08-10 17:39:16 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: abentley@panoramicfeedback.com-20050810173916-77580019d21a0e82
Removed MergeTree.inventory

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import patch
19
19
import stat
20
20
from bzrlib.trace import mutter
21
 
 
22
 
# XXX: mbp: I'm not totally convinced that we should handle conflicts
23
 
# as part of changeset application, rather than only in the merge
24
 
# operation.
25
 
 
26
 
"""Represent and apply a changeset
27
 
 
28
 
Conflicts in applying a changeset are represented as exceptions.
29
 
"""
30
 
 
 
21
"""
 
22
Represent and apply a changeset
 
23
"""
31
24
__docformat__ = "restructuredtext"
32
25
 
33
26
NULL_ID = "!NULL"
326
319
 
327
320
 
328
321
class Diff3Merge(object):
329
 
    def __init__(self, file_id, base, other):
330
 
        self.file_id = file_id
331
 
        self.base = base
332
 
        self.other = other
 
322
    def __init__(self, base_file, other_file):
 
323
        self.base_file = base_file
 
324
        self.other_file = other_file
333
325
 
334
326
    def __eq__(self, other):
335
327
        if not isinstance(other, Diff3Merge):
336
328
            return False
337
 
        return (self.base == other.base and 
338
 
                self.other == other.other and self.file_id == other.file_id)
 
329
        return (self.base_file == other.base_file and 
 
330
                self.other_file == other.other_file)
339
331
 
340
332
    def __ne__(self, other):
341
333
        return not (self == other)
342
334
 
343
335
    def apply(self, filename, conflict_handler, reverse=False):
344
 
        new_file = filename+".new"
345
 
        base_file = self.base.readonly_path(self.file_id)
346
 
        other_file = self.other.readonly_path(self.file_id)
 
336
        new_file = filename+".new" 
347
337
        if not reverse:
348
 
            base = base_file
349
 
            other = other_file
 
338
            base = self.base_file
 
339
            other = self.other_file
350
340
        else:
351
 
            base = other_file
352
 
            other = base_file
 
341
            base = self.other_file
 
342
            other = self.base_file
353
343
        status = patch.diff3(new_file, filename, base, other)
354
344
        if status == 0:
355
345
            os.chmod(new_file, os.stat(filename).st_mode)
357
347
            return
358
348
        else:
359
349
            assert(status == 1)
360
 
            def get_lines(filename):
361
 
                my_file = file(base, "rb")
362
 
                lines = my_file.readlines()
363
 
                my_file.close()
364
 
            base_lines = get_lines(base)
365
 
            other_lines = get_lines(other)
366
 
            conflict_handler.merge_conflict(new_file, filename, base_lines, 
367
 
                                            other_lines)
 
350
            conflict_handler.merge_conflict(new_file, filename, base, other)
368
351
 
369
352
 
370
353
def CreateDir():
997
980
 
998
981
 
999
982
class ExceptionConflictHandler(object):
1000
 
    """Default handler for merge exceptions.
1001
 
 
1002
 
    This throws an error on any kind of conflict.  Conflict handlers can
1003
 
    descend from this class if they have a better way to handle some or
1004
 
    all types of conflict.
1005
 
    """
1006
983
    def __init__(self, dir):
1007
984
        self.dir = dir
1008
985
    
1022
999
    def rename_conflict(self, id, this_name, base_name, other_name):
1023
1000
        raise RenameConflict(id, this_name, base_name, other_name)
1024
1001
 
1025
 
    def move_conflict(self, id, this_dir, base_dir, other_dir):
 
1002
    def move_conflict(self, id, inventory):
 
1003
        this_dir = inventory.this.get_dir(id)
 
1004
        base_dir = inventory.base.get_dir(id)
 
1005
        other_dir = inventory.other.get_dir(id)
1026
1006
        raise MoveConflict(id, this_dir, base_dir, other_dir)
1027
1007
 
1028
 
    def merge_conflict(self, new_file, this_path, base_lines, other_lines):
 
1008
    def merge_conflict(self, new_file, this_path, base_path, other_path):
1029
1009
        os.unlink(new_file)
1030
1010
        raise MergeConflict(this_path)
1031
1011
 
1059
1039
    def missing_for_rename(self, filename):
1060
1040
        raise MissingForRename(filename)
1061
1041
 
1062
 
    def missing_for_merge(self, file_id, other_path):
1063
 
        raise MissingForMerge(other_path)
 
1042
    def missing_for_merge(self, file_id, inventory):
 
1043
        raise MissingForMerge(inventory.other.get_path(file_id))
1064
1044
 
1065
1045
    def new_contents_conflict(self, filename, other_contents):
1066
1046
        raise NewContentsConflict(filename)