~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2006-07-13 13:25:20 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060713132520-2fabfab51affb82f
Update clean-tree docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
1
3
import os
2
4
import sys
3
5
import subprocess
4
6
from datetime import datetime
5
 
from errors import CommandError, PatchFailed, PatchInvokeError
 
7
from errors import CommandError, PatchFailed
6
8
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
7
9
from patchsource import PatchSource, FilePatchSource
8
10
from bzrlib.osutils import rename
132
134
            return None
133
135
        return patch[len(self.MESSAGE_PREFIX):patch.index('\n')]
134
136
 
135
 
    def unshelve(self, patch_source, patch_name=None, all=False, force=False,
136
 
                 no_color=False):
 
137
    def unshelve(self, patch_source, patch_name=None, all=False, force=False):
137
138
        self._check_upgrade()
138
139
 
139
 
        if no_color is False:
140
 
            color = None
141
 
        else:
142
 
            color = False
143
140
        if patch_name is None:
144
141
            patch_path = self.last_patch()
145
142
        else:
153
150
            to_unshelve = patches
154
151
            to_remain = []
155
152
        else:
156
 
            hs = UnshelveHunkSelector(patches, color)
157
 
            to_unshelve, to_remain = hs.select()
 
153
            to_unshelve, to_remain = UnshelveHunkSelector(patches).select()
158
154
 
159
155
        if len(to_unshelve) == 0:
160
156
            raise CommandError('Nothing to unshelve')
193
189
                f.write(str(patch))
194
190
            f.close()
195
191
 
196
 
    def shelve(self, patch_source, all=False, message=None, no_color=False):
 
192
    def shelve(self, patch_source, all=False, message=None):
197
193
        self._check_upgrade()
198
 
        if no_color is False:
199
 
            color = None
200
 
        else:
201
 
            color = False
202
194
 
203
195
        patches = patch_source.readpatches()
204
196
 
205
197
        if all:
206
198
            to_shelve = patches
207
199
        else:
208
 
            to_shelve = ShelveHunkSelector(patches, color).select()[0]
 
200
            to_shelve = ShelveHunkSelector(patches).select()[0]
209
201
 
210
202
        if len(to_shelve) == 0:
211
203
            raise CommandError('Nothing to shelve')
255
247
        else:
256
248
            stdout = stderr = None
257
249
 
258
 
        try:
259
 
            process = subprocess.Popen(args, stdin=subprocess.PIPE,
260
 
                                       stdout=stdout, stderr=stderr)
261
 
            for patch in patches:
262
 
                process.stdin.write(str(patch))
263
 
 
264
 
        except IOError, e:
265
 
            raise PatchInvokeError(e, process.stderr.read())
 
250
        process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=stdout,
 
251
                        stderr=stderr)
 
252
        for patch in patches:
 
253
            process.stdin.write(str(patch))
266
254
 
267
255
        process.communicate()
268
256