~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to patchsource.py

  • Committer: Michael Ellerman
  • Date: 2006-03-14 08:52:39 UTC
  • mto: (325.1.2 bzrtools) (0.3.1 shelf-dev)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20060314085239-47db02c515fb04dd
Support for bzr 0.7 and 0.8 in BzrPatchSource. Big thanks to marienz
for help with testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
class BzrPatchSource(PatchSource):
26
26
    def __init__(self, revision=None, file_list=None):
27
 
        from bzrlib.bzrdir import BzrDir
28
 
 
29
27
        self.file_list = file_list
30
28
        if file_list is not None and len(file_list) > 0:
31
29
            location = file_list[0]
32
30
        else:
33
31
            location = '.'
34
32
 
35
 
        self.bzrdir = BzrDir.open_containing(location)[0]
36
 
        self.base = self.bzrdir.open_branch().base
 
33
        # Hack to cope with 0.7 and 0.8 bzr
 
34
        try:
 
35
            from bzrlib.bzrdir import BzrDir
 
36
            self.bzrdir = BzrDir.open_containing(location)[0]
 
37
            self.base = self.bzrdir.open_branch().base
 
38
            self.__readlines = self._v08_readlines
 
39
        except ImportError:
 
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
37
44
 
38
45
        self.revision = revision
39
46
 
40
47
        PatchSource.__init__(self)
41
48
 
42
49
    def readlines(self):
 
50
        from StringIO import StringIO
 
51
        f = StringIO()
 
52
        self.__readlines(f)
 
53
        f.seek(0)
 
54
        return f.readlines()
 
55
 
 
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)
 
60
 
 
61
    def _v08_readlines(self, output):
43
62
        import sys
44
 
        from StringIO import StringIO
45
63
        from bzrlib.diff import diff_cmd_helper
46
 
 
 
64
        tmp = sys.stdout
 
65
        sys.stdout = output
47
66
        # FIXME diff_cmd_helper() should take an output parameter
48
 
        f = StringIO()
49
 
        tmp = sys.stdout
50
 
        sys.stdout = f
51
67
        diff_cmd_helper(self.bzrdir.open_workingtree(), self.file_list,
52
 
                external_diff_options=None, old_revision_spec=self.revision)
 
68
                    external_diff_options=None, old_revision_spec=self.revision)
53
69
        sys.stdout = tmp
54
 
        f.seek(0)
55
 
        return f.readlines()