~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Michael Ellerman
  • Date: 2006-03-11 13:19:21 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-20060311131921-8565bcc3ac4a10b6
I'm sure someone will complain about this, but remove the diffstat after
shelve/unshelve. If you want diffstat after shelve/unshelve then run diffstat!
Make the shelve and unshelve messages symmetrical, and make sure if there's
no message in the patch we print something when unshelving.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import subprocess
6
6
from errors import CommandError
7
7
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
8
 
from diffstat import DiffStat
9
8
from patchsource import PatchSource, FilePatchSource
10
9
 
11
10
class Shelf(object):
122
121
            return None
123
122
        return patch[len(self.MESSAGE_PREFIX):patch.index('\n')]
124
123
 
125
 
    def __show_status(self, source):
126
 
        if source.can_live_update():
127
 
            diff_stat = str(DiffStat(source.readlines()))
128
 
            if len(diff_stat) > 0:
129
 
                self.log('Diff status is now:\n' + diff_stat + '\n')
130
 
            else:
131
 
                self.log('No changes left in working tree.\n')
132
 
 
133
124
    def unshelve(self, patch_source, pick_hunks=False):
134
125
        patch_name = self.last_patch()
135
126
 
148
139
 
149
140
        message = self.get_patch_message(patch_name)
150
141
        if message is None:
151
 
            message = ""
152
 
        self.log('Reapplying shelved patches "%s"\n' % message)
 
142
            message = "No message saved with patch."
 
143
        self.log('Unshelving from %s/%s: "%s"\n' % \
 
144
                (self.name, os.path.basename(patch_name), message))
153
145
 
154
146
        try:
155
147
            self._run_patch(to_unshelve, dry_run=True)
166
158
                f.write(str(hunk))
167
159
            f.close()
168
160
 
169
 
        self.__show_status(patch_source)
170
 
 
171
161
    def shelve(self, patch_source, pick_hunks=False, message=None):
172
162
        from datetime import datetime
173
163
 
202
192
        patch.close()
203
193
 
204
194
        self._run_patch(to_shelve, reverse=True)
205
 
        self.__show_status(patch_source)
206
195
 
207
196
    def _run_patch(self, patches, reverse=False, dry_run=False):
208
197
        args = ['patch', '-d', self.base, '-s', '-p1', '-f']