~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: Aaron Bentley
  • Date: 2008-10-27 14:14:29 UTC
  • mto: (0.16.88 shelf-ui)
  • mto: This revision was merged to the branch mainline in revision 3820.
  • Revision ID: aaron@aaronbentley.com-20081027141429-rhxskhw57uz1qec5
Use names of the form shelf-5 for shelves

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
import errno
 
19
import re
19
20
 
20
21
from bzrlib import (
21
22
    errors,
286
287
        self.transport = transport.clone('shelf')
287
288
        self.transport.ensure_base()
288
289
 
 
290
    def get_shelf_filename(self, shelf_id):
 
291
        return 'shelf-%d' % shelf_id
 
292
 
 
293
    def get_shelf_ids(self, filenames):
 
294
        matcher = re.compile('shelf-([1-9][0-9]*)')
 
295
        shelf_ids = []
 
296
        for filename in filenames:
 
297
            match = matcher.match(filename)
 
298
            if match is not None:
 
299
                shelf_ids.append(int(match.group(1)))
 
300
        return shelf_ids
 
301
 
289
302
    def new_shelf(self):
290
303
        """Return a file object and id for a new set of shelved changes."""
291
304
        last_shelf = self.last_shelf()
293
306
            next_shelf = 1
294
307
        else:
295
308
            next_shelf = last_shelf + 1
296
 
        shelf_file = open(self.transport.local_abspath(str(next_shelf)), 'wb')
 
309
        filename = self.get_shelf_filename(next_shelf)
 
310
        shelf_file = open(self.transport.local_abspath(filename), 'wb')
297
311
        return next_shelf, shelf_file
298
312
 
299
313
    def shelve_changes(self, creator, message=None):
311
325
 
312
326
        :param shelf_id: The id of the shelf to retrive the file for.
313
327
        """
 
328
        filename = self.get_shelf_filename(shelf_id)
314
329
        try:
315
 
            return open(self.transport.local_abspath(str(shelf_id)), 'rb')
 
330
            return open(self.transport.local_abspath(filename), 'rb')
316
331
        except IOError, e:
317
332
            if e.errno != errno.ENOENT:
318
333
                raise
335
350
 
336
351
        :param shelf_id: id of the shelved changes to delete.
337
352
        """
338
 
        self.transport.delete(str(shelf_id))
 
353
        filename = self.get_shelf_filename(shelf_id)
 
354
        self.transport.delete(filename)
339
355
 
340
356
    def active_shelves(self):
341
357
        """Return a list of shelved changes."""
342
 
        return [int(f) for f in self.transport.list_dir('.')]
 
358
        active = self.get_shelf_ids(self.transport.list_dir('.'))
 
359
        active.sort()
 
360
        return active
343
361
 
344
362
    def last_shelf(self):
345
363
        """Return the id of the last-created shelved change."""
346
364
        active = self.active_shelves()
347
365
        if len(active) > 0:
348
 
            return max(active)
 
366
            return active[-1]
349
367
        else:
350
368
            return None