3
from bzrlib import patches
5
from bzrlib.plugins.bzrtools import errors
7
class PatchSource(object):
15
raise NotImplementedError()
17
def readpatches(self):
18
return patches.parse_patches(self.readlines())
20
class FilePatchSource(PatchSource):
21
def __init__(self, filename):
22
self.filename = filename
23
PatchSource.__init__(self)
26
f = open(self.filename, 'r')
29
class BzrPatchSource(PatchSource):
30
def __init__(self, revision=None, file_list=None):
31
from bzrlib.builtins import tree_files
32
self.tree, self.file_list = tree_files(file_list)
33
self.base = self.tree.basedir
34
self.revision = revision
36
# Hacks to cope with v0.7 and v0.8 of bzr
37
if self.revision is None:
38
if hasattr(self.tree, 'basis_tree'):
39
self.old_tree = self.tree.basis_tree()
41
self.old_tree = self.tree.branch.basis_tree()
43
revision_id = self.revision.in_store(self.tree.branch).rev_id
44
if hasattr(self.tree.branch, 'repository'):
45
self.old_tree = self.tree.branch.repository.revision_tree(revision_id)
47
self.old_tree = self.tree.branch.revision_tree(revision_id)
49
PatchSource.__init__(self)
52
from bzrlib.diff import show_diff_trees
53
from StringIO import StringIO
56
show_diff_trees(self.old_tree, self.tree, f, self.file_list,
57
old_label='', new_label='')
58
if re.search('Binary files .* differ', f.getvalue()):
59
raise errors.ChangedBinaryFiles()