~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2007-06-10 17:55:08 UTC
  • mfrom: (531.2.2 bzrtools)
  • Revision ID: aaron.bentley@utoronto.ca-20070610175508-gex1oxvmfv0qoagi
Merge whitespace cleanups

Show diffs side-by-side

added added

removed removed

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