~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Michael Ellerman
  • Date: 2005-11-29 07:41:58 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-20051129074158-ae00afb20c9dcbee
Cleanup exceptions/status in shelf.py. Raise exceptions for errors, otherwise
things work. Remove unused QuitException.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from bzrlib.commands import Command
7
7
from bzrlib.branch import Branch
8
8
from bzrlib import DEFAULT_IGNORE
 
9
from bzrlib.errors import BzrCommandError
9
10
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
10
11
from diffstat import DiffStat
11
12
 
12
13
DEFAULT_IGNORE.append('./.bzr-shelf*')
13
14
 
14
 
class QuitException(Exception):
15
 
    pass
16
 
 
17
15
class Shelf(object):
18
16
    def __init__(self, location, name='default'):
19
17
        self.branch = Branch.open_containing(location)[0]
57
55
        shelf = self.last_shelf()
58
56
 
59
57
        if shelf is None:
60
 
            raise Exception("No shelf found in '%s'" % self.branch.base)
 
58
            raise BzrCommandError("No shelf found in branch '%s'" % \
 
59
                self.branch.base)
61
60
 
62
61
        patches = parse_patches(open(shelf, 'r').readlines())
63
62
        if pick_hunks:
64
 
            try:
65
 
                to_unshelve, to_remain = UnshelveHunkSelector(patches).select()
66
 
            except QuitException:
67
 
                return False
 
63
            to_unshelve, to_remain = UnshelveHunkSelector(patches).select()
68
64
        else:
69
65
            to_unshelve = patches
70
66
            to_remain = []
71
67
 
72
68
        if len(to_unshelve) == 0:
73
 
            print >>sys.stderr, 'Nothing to unshelve'
74
 
            return True
 
69
            raise BzrCommandError('Nothing to unshelve')
75
70
 
76
71
        print >>sys.stderr, "Reapplying shelved patches",
77
72
        message = self.get_shelf_message(open(shelf, 'r').read())
86
81
        pipe.flush()
87
82
 
88
83
        if pipe.close() is not None:
89
 
            raise Exception("Failed running patch!")
 
84
            raise BzrCommandError("Failed running patch!")
90
85
 
91
86
        if len(to_remain) == 0:
92
87
            os.remove(shelf)
99
94
        diff_stat = DiffStat(self.get_patches(None, None))
100
95
        print 'Diff status is now:\n', diff_stat
101
96
 
102
 
        return True
103
 
 
104
97
    def get_patches(self, revision, file_list):
105
98
        from StringIO import StringIO
106
99
        from bzrlib.diff import show_diff
114
107
        patches = parse_patches(self.get_patches(revision, file_list))
115
108
 
116
109
        if pick_hunks:
117
 
            try:
118
 
                to_shelve = ShelveHunkSelector(patches).select()[0]
119
 
            except QuitException:
120
 
                return False
 
110
            to_shelve = ShelveHunkSelector(patches).select()[0]
121
111
        else:
122
112
            to_shelve = patches
123
113
 
124
114
        if len(to_shelve) == 0:
125
 
            print >>sys.stderr, 'Nothing to shelve'
126
 
            return True
 
115
            raise BzrCommandError('Nothing to shelve')
127
116
 
128
117
        shelf = self.next_shelf()
129
118
        print >>sys.stderr, "Saving shelved patches to", shelf
145
134
        pipe.flush()
146
135
 
147
136
        if pipe.close() is not None:
148
 
            raise Exception("Failed running patch!")
 
137
            raise BzrCommandError("Failed running patch!")
149
138
 
150
139
        diff_stat = DiffStat(self.get_patches(None, None))
151
140
        print 'Diff status is now:\n', diff_stat
152
 
 
153
 
        return True
154