~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-08-09 02:34:50 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: aaron.bentley@utoronto.ca-20050809023450-ddb4910cc8d810cd
Removed use of patch and diff in merge, removed patch.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    return newdict
37
37
 
38
38
 
39
 
class PatchApply(object):
40
 
    """Patch application as a kind of content change"""
41
 
    def __init__(self, contents):
42
 
        """Constructor.
43
 
 
44
 
        :param contents: The text of the patch to apply
45
 
        :type contents: str"""
46
 
        self.contents = contents
47
 
 
48
 
    def __eq__(self, other):
49
 
        if not isinstance(other, PatchApply):
50
 
            return False
51
 
        elif self.contents != other.contents:
52
 
            return False
53
 
        else:
54
 
            return True
55
 
 
56
 
    def __ne__(self, other):
57
 
        return not (self == other)
58
 
 
59
 
    def apply(self, filename, conflict_handler, reverse=False):
60
 
        """Applies the patch to the specified file.
61
 
 
62
 
        :param filename: the file to apply the patch to
63
 
        :type filename: str
64
 
        :param reverse: If true, apply the patch in reverse
65
 
        :type reverse: bool
66
 
        """
67
 
        input_name = filename+".orig"
68
 
        try:
69
 
            os.rename(filename, input_name)
70
 
        except OSError, e:
71
 
            if e.errno != errno.ENOENT:
72
 
                raise
73
 
            if conflict_handler.patch_target_missing(filename, self.contents)\
74
 
                == "skip":
75
 
                return
76
 
            os.rename(filename, input_name)
77
 
            
78
 
 
79
 
        status = patch.patch(self.contents, input_name, filename, 
80
 
                                    reverse)
81
 
        os.chmod(filename, os.stat(input_name).st_mode)
82
 
        if status == 0:
83
 
            os.unlink(input_name)
84
 
        elif status == 1:
85
 
            conflict_handler.failed_hunks(filename)
86
 
 
87
 
        
 
39
       
88
40
class ChangeUnixPermissions(object):
89
41
    """This is two-way change, suitable for file modification, creation,
90
42
    deletion"""
1471
1423
            if stat_a.st_ino == stat_b.st_ino and \
1472
1424
                stat_a.st_dev == stat_b.st_dev:
1473
1425
                return None
1474
 
            if file(full_path_a, "rb").read() == \
1475
 
                file(full_path_b, "rb").read():
1476
 
                return None
1477
 
 
1478
 
            patch_contents = patch.diff(full_path_a, 
1479
 
                                        file(full_path_b, "rb").read())
1480
 
            if patch_contents is None:
1481
 
                return None
1482
 
            return PatchApply(patch_contents)
1483
1426
 
1484
1427
        a_contents = self.get_contents(stat_a, full_path_a)
1485
1428
        b_contents = self.get_contents(stat_b, full_path_b)