~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2006-05-31 03:42:18 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20060531034218-a3933f36350bb69f
Fix test suite

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
        path = self.__path_from_user(patch)
59
59
        os.rename(path, '%s~' % path)
60
60
 
61
 
    def display(self, patch=None):
62
 
        if patch is None:
63
 
            path = self.last_patch()
64
 
        else:
65
 
            path = self.__path_from_user(patch)
 
61
    def display(self, patch):
 
62
        path = self.__path_from_user(patch)
66
63
        sys.stdout.write(open(path).read())
67
64
 
68
65
    def list(self):
81
78
    def __path_from_user(self, patch_id):
82
79
        try:
83
80
            patch_index = int(patch_id)
84
 
        except (TypeError, ValueError):
 
81
        except TypeError:
85
82
            raise CommandError("Invalid patch name '%s'" % patch_id)
86
83
 
87
84
        path = self.__path(patch_index)
133
130
            return None
134
131
        return patch[len(self.MESSAGE_PREFIX):patch.index('\n')]
135
132
 
136
 
    def unshelve(self, patch_source, patch_name=None, all=False, force=False):
 
133
    def unshelve(self, patch_source, all=False, force=False):
137
134
        self._check_upgrade()
138
135
 
 
136
        patch_name = self.last_patch()
 
137
 
139
138
        if patch_name is None:
140
 
            patch_path = self.last_patch()
141
 
        else:
142
 
            patch_path = self.__path_from_user(patch_name)
143
 
 
144
 
        if patch_path is None:
145
139
            raise CommandError("No patch found on shelf %s" % self.name)
146
140
 
147
 
        patches = FilePatchSource(patch_path).readpatches()
 
141
        patches = FilePatchSource(patch_name).readpatches()
148
142
        if all:
149
143
            to_unshelve = patches
150
144
            to_remain = []
154
148
        if len(to_unshelve) == 0:
155
149
            raise CommandError('Nothing to unshelve')
156
150
 
157
 
        message = self.get_patch_message(patch_path)
 
151
        message = self.get_patch_message(patch_name)
158
152
        if message is None:
159
153
            message = "No message saved with patch."
160
154
        self.log('Unshelving from %s/%s: "%s"\n' % \
161
 
                (self.name, os.path.basename(patch_path), message))
 
155
                (self.name, os.path.basename(patch_name), message))
162
156
 
163
157
        try:
164
158
            self._run_patch(to_unshelve, dry_run=True)
180
174
                    "longer applies cleanly to the working tree!")
181
175
 
182
176
        # Backup the shelved patch
183
 
        os.rename(patch_path, '%s~' % patch_path)
 
177
        os.rename(patch_name, '%s~' % patch_name)
184
178
 
185
179
        if len(to_remain) > 0:
186
 
            f = open(patch_path, 'w')
 
180
            f = open(patch_name, 'w')
187
181
            for patch in to_remain:
188
182
                f.write(str(patch))
189
183
            f.close()
205
199
            timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
206
200
            message = "Changes shelved on %s" % timestamp
207
201
 
208
 
        patch_path = self.next_patch()
 
202
        patch_name = self.next_patch()
209
203
        self.log('Shelving to %s/%s: "%s"\n' % \
210
 
                (self.name, os.path.basename(patch_path), message))
 
204
                (self.name, os.path.basename(patch_name), message))
211
205
 
212
 
        f = open(patch_path, 'a')
 
206
        f = open(patch_name, 'a')
213
207
 
214
208
        assert '\n' not in message
215
209
        f.write("%s%s\n" % (self.MESSAGE_PREFIX, message))