8
from bzrlib.plugins.bzrtools import errors
10
class PatchSource(object):
18
raise NotImplementedError()
20
def readpatches(self):
21
return patches.parse_patches(self.readlines())
23
class FilePatchSource(PatchSource):
24
def __init__(self, filename):
25
self.filename = filename
26
PatchSource.__init__(self)
29
f = open(self.filename, 'r')
32
class BzrPatchSource(PatchSource):
33
def __init__(self, revision=None, file_list=None):
34
open_containing_paths = workingtree.WorkingTree.open_containing_paths
35
self.tree, self.file_list = open_containing_paths(file_list)
36
self.base = self.tree.basedir
37
self.revision = revision
39
# Hacks to cope with v0.7 and v0.8 of bzr
40
if self.revision is None:
41
if hasattr(self.tree, 'basis_tree'):
42
self.old_tree = self.tree.basis_tree()
44
self.old_tree = self.tree.branch.basis_tree()
46
revision_id = self.revision.in_store(self.tree.branch).rev_id
47
if hasattr(self.tree.branch, 'repository'):
48
self.old_tree = self.tree.branch.repository.revision_tree(revision_id)
50
self.old_tree = self.tree.branch.revision_tree(revision_id)
52
PatchSource.__init__(self)
55
from bzrlib.diff import show_diff_trees
56
from StringIO import StringIO
59
show_diff_trees(self.old_tree, self.tree, f, self.file_list,
60
old_label='', new_label='')
61
if re.search('Binary files .* differ', f.getvalue()):
62
raise errors.ChangedBinaryFiles()