~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Michael Ellerman
  • Date: 2006-02-06 13:41: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-20060206134153-189a1851eb08cb35
Factor out patch generation into PatchSource classes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
from patches import parse_patches
4
3
import os
5
4
import sys
6
5
from bzrlib.commands import Command
8
7
from bzrlib.errors import BzrCommandError
9
8
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
10
9
from diffstat import DiffStat
 
10
from patchsource import PatchSource, FilePatchSource
11
11
 
12
12
class Shelf(object):
13
13
    def __init__(self, location, name='default'):
48
48
            return None
49
49
        return shelf[len(prefix):shelf.index('\n')]
50
50
 
51
 
    def unshelve(self, pick_hunks=False):
 
51
    def __show_status(self, source):
 
52
        if source.can_live_update():
 
53
            diff_stat = DiffStat(source.readlines())
 
54
            print 'Diff status is now:\n', diff_stat
 
55
 
 
56
    def unshelve(self, patch_source, pick_hunks=False):
52
57
        shelf = self.last_shelf()
53
58
 
54
59
        if shelf is None:
55
60
            raise BzrCommandError("No shelf found in branch '%s'" % \
56
61
                self.branch.base)
57
62
 
58
 
        patches = parse_patches(open(shelf, 'r').readlines())
 
63
        patches = FilePatchSource(shelf).readpatches()
59
64
        if pick_hunks:
60
65
            to_unshelve, to_remain = UnshelveHunkSelector(patches).select()
61
66
        else:
88
93
                f.write(str(patch))
89
94
            f.close()
90
95
 
91
 
        diff_stat = DiffStat(self.get_patches(None, None))
92
 
        print 'Diff status is now:\n', diff_stat
93
 
 
94
 
    def get_patches(self, revision, file_list):
95
 
        from StringIO import StringIO
96
 
        from bzrlib.diff import show_diff
97
 
        out = StringIO()
98
 
        show_diff(self.branch, revision, specific_files=file_list, output=out)
99
 
        out.seek(0)
100
 
        return out.readlines()
101
 
 
102
 
    def shelve(self, pick_hunks=False, message=None, revision=None,
103
 
             file_list=None):
104
 
        patches = parse_patches(self.get_patches(revision, file_list))
 
96
        self.__show_status(patch_source)
 
97
 
 
98
    def shelve(self, patch_source, pick_hunks=False, message=None):
 
99
        patches = patch_source.readpatches()
105
100
 
106
101
        if pick_hunks:
107
102
            to_shelve = ShelveHunkSelector(patches).select()[0]
133
128
        if pipe.close() is not None:
134
129
            raise BzrCommandError("Failed running patch!")
135
130
 
136
 
        diff_stat = DiffStat(self.get_patches(None, None))
137
 
        print 'Diff status is now:\n', diff_stat
 
131
        self.__show_status(patch_source)