~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to patchsource.py

  • Committer: Michael Ellerman
  • Date: 2005-11-29 01:41:52 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20051129014152-f5ede8888bcebc48
HunkSelector was broken if you did a "done" followed by "status/invert" etc.
Fixup to make pychecker happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import patches
2
 
 
3
 
class PatchSource(object):
4
 
    def __iter__(self):
5
 
        def iterator(obj):
6
 
            for p in obj.read():
7
 
                yield p
8
 
        return iterator(self)
9
 
 
10
 
    def can_live_update(self):
11
 
        return False
12
 
 
13
 
    def readlines(self):
14
 
        raise NotImplementedError()
15
 
 
16
 
    def readpatches(self):
17
 
        return patches.parse_patches(self.readlines())
18
 
 
19
 
class FilePatchSource(PatchSource):
20
 
    def __init__(self, filename):
21
 
        self.filename = filename
22
 
        PatchSource.__init__(self)
23
 
 
24
 
    def readlines(self):
25
 
        f = open(self.filename, 'r')
26
 
        return f.readlines()
27
 
 
28
 
class BzrPatchSource(PatchSource):
29
 
    def __init__(self, revision=None, file_list=None):
30
 
        from bzrlib.branch import Branch
31
 
        self.revision = revision
32
 
        self.file_list = file_list
33
 
        if file_list is not None and len(file_list) > 0:
34
 
            location = file_list[0]
35
 
        else:
36
 
            location = '.'
37
 
        self.branch = Branch.open_containing(location)[0]
38
 
 
39
 
        PatchSource.__init__(self)
40
 
 
41
 
    def can_live_update(self):
42
 
        return True
43
 
 
44
 
    def readlines(self):
45
 
        from StringIO import StringIO
46
 
        from bzrlib.diff import show_diff
47
 
        f = StringIO()
48
 
        show_diff(self.branch, self.revision,
49
 
                specific_files=self.file_list, output=f)
50
 
        f.seek(0)
51
 
        return f.readlines()