~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2006-06-13 02:31:28 UTC
  • mfrom: (0.1.119 shelf)
  • Revision ID: aaron.bentley@utoronto.ca-20060613023128-20f2ff3a212a6ea2
Pull in latest shelf stuff

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