25
25
class BzrPatchSource(PatchSource):
26
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
27
self.file_list = file_list
28
if file_list is not None and len(file_list) > 0:
29
location = file_list[0]
33
# Hack to cope with 0.7 and 0.8 bzr
35
from bzrlib.workingtree import WorkingTree
36
self.wt = WorkingTree.open_containing(location)[0]
37
self.base = self.wt.basedir
38
self.__readlines = self._v08_readlines
40
from bzrlib.branch import Branch
41
self.branch = Branch.open_containing(location)[0]
42
self.base = self.branch.base
43
self.__readlines = self._v07_readlines
30
45
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
47
PatchSource.__init__(self)
47
49
def readlines(self):
48
from bzrlib.diff import show_diff_trees
49
50
from StringIO import StringIO
52
show_diff_trees(self.old_tree, self.tree, f, self.file_list,
53
old_label='', new_label='')
56
54
return f.readlines()
56
def _v07_readlines(self, output):
57
from bzrlib.diff import show_diff
58
show_diff(self.branch, self.revision,
59
specific_files=self.file_list, output=output)
61
def _v08_readlines(self, output):
63
from bzrlib.diff import diff_cmd_helper
66
# FIXME diff_cmd_helper() should take an output parameter
67
diff_cmd_helper(self.wt, self.file_list, external_diff_options=None,
68
old_revision_spec=self.revision)