~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to patchsource.py

  • Committer: Michael Ellerman
  • Date: 2006-02-06 13:52:53 UTC
  • mto: (0.1.73 shelf-tmp)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20060206135253-46d07a6db0239dbb
For the moment at least storing scads of stuff under .bzr isn't really
supported by the bzr API, so move the shelf back out of .bzr into .shelf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from bzrlib import patches
 
1
import patches
2
2
 
3
3
class PatchSource(object):
4
4
    def __iter__(self):
7
7
                yield p
8
8
        return iterator(self)
9
9
 
 
10
    def can_live_update(self):
 
11
        return False
 
12
 
10
13
    def readlines(self):
11
14
        raise NotImplementedError()
12
15
 
24
27
 
25
28
class BzrPatchSource(PatchSource):
26
29
    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
        from bzrlib.branch import Branch
30
31
        self.revision = revision
31
 
 
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()
36
 
            else:
37
 
                self.old_tree = self.tree.branch.basis_tree()
 
32
        self.file_list = file_list
 
33
        if file_list is not None and len(file_list) > 0:
 
34
            location = file_list[0]
38
35
        else:
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)
42
 
            else:
43
 
                self.old_tree = self.tree.branch.revision_tree(revision_id)
 
36
            location = '.'
 
37
        self.branch = Branch.open_containing(location)[0]
44
38
 
45
39
        PatchSource.__init__(self)
46
40
 
 
41
    def can_live_update(self):
 
42
        return True
 
43
 
47
44
    def readlines(self):
48
 
        from bzrlib.diff import show_diff_trees
49
45
        from StringIO import StringIO
 
46
        from bzrlib.diff import show_diff
50
47
        f = StringIO()
51
 
 
52
 
        show_diff_trees(self.old_tree, self.tree, f, self.file_list,
53
 
                        old_label='', new_label='')
54
 
 
 
48
        show_diff(self.branch, self.revision,
 
49
                specific_files=self.file_list, output=f)
55
50
        f.seek(0)
56
51
        return f.readlines()