1
from bzrlib import patches
3
class PatchSource(object):
11
raise NotImplementedError()
13
def readpatches(self):
14
return patches.parse_patches(self.readlines())
16
class FilePatchSource(PatchSource):
17
def __init__(self, filename):
18
self.filename = filename
19
PatchSource.__init__(self)
22
f = open(self.filename, 'r')
25
class BzrPatchSource(PatchSource):
26
def __init__(self, revision=None, file_list=None):
27
from bzrlib.builtins import tree_files
28
self.tree, self.file_list = tree_files(file_list)
29
self.base = self.tree.basedir
30
self.revision = revision
32
# Hacks to cope with v0.7 and v0.8 of bzr
33
if self.revision is None:
34
if hasattr(self.tree, 'basis_tree'):
35
self.old_tree = self.tree.basis_tree()
37
self.old_tree = self.tree.branch.basis_tree()
39
revision_id = self.revision.in_store(self.tree.branch).rev_id
40
if hasattr(self.tree.branch, 'repository'):
41
self.old_tree = self.tree.branch.repository.revision_tree(revision_id)
43
self.old_tree = self.tree.branch.revision_tree(revision_id)
45
PatchSource.__init__(self)
48
from bzrlib.diff import show_diff_trees
49
from StringIO import StringIO
52
show_diff_trees(self.old_tree, self.tree, f, self.file_list,
53
old_label='', new_label='')