39
class PatchApply(object):
40
"""Patch application as a kind of content change"""
41
def __init__(self, contents):
44
:param contents: The text of the patch to apply
45
:type contents: str"""
46
self.contents = contents
48
def __eq__(self, other):
49
if not isinstance(other, PatchApply):
51
elif self.contents != other.contents:
56
def __ne__(self, other):
57
return not (self == other)
59
def apply(self, filename, conflict_handler, reverse=False):
60
"""Applies the patch to the specified file.
62
:param filename: the file to apply the patch to
64
:param reverse: If true, apply the patch in reverse
67
input_name = filename+".orig"
69
os.rename(filename, input_name)
71
if e.errno != errno.ENOENT:
73
if conflict_handler.patch_target_missing(filename, self.contents)\
76
os.rename(filename, input_name)
79
status = patch.patch(self.contents, input_name, filename,
81
os.chmod(filename, os.stat(input_name).st_mode)
85
conflict_handler.failed_hunks(filename)
88
40
class ChangeUnixPermissions(object):
89
41
"""This is two-way change, suitable for file modification, creation,
1471
1423
if stat_a.st_ino == stat_b.st_ino and \
1472
1424
stat_a.st_dev == stat_b.st_dev:
1474
if file(full_path_a, "rb").read() == \
1475
file(full_path_b, "rb").read():
1478
patch_contents = patch.diff(full_path_a,
1479
file(full_path_b, "rb").read())
1480
if patch_contents is None:
1482
return PatchApply(patch_contents)
1484
1427
a_contents = self.get_contents(stat_a, full_path_a)
1485
1428
b_contents = self.get_contents(stat_b, full_path_b)