~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-10-07 07:55:09 UTC
  • mfrom: (5459.2.6 640760-natural-sort-tags)
  • Revision ID: pqm@pqm.ubuntu.com-20101007075509-u808nnwozm7hlt2x
(mbp) Change bzr tags to use a natural sort order by default (Neil
 Martinsen-Burrell)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib.lazy_import import lazy_import
22
22
lazy_import(globals(), """
23
23
import cStringIO
 
24
import itertools
 
25
import re
24
26
import sys
25
27
import time
26
28
 
5397
5399
            help='Branch whose tags should be displayed.'),
5398
5400
        RegistryOption.from_kwargs('sort',
5399
5401
            'Sort tags by different criteria.', title='Sorting',
5400
 
            alpha='Sort tags lexicographically (default).',
 
5402
            natural='Sort numeric substrings as numbers:'
 
5403
                    ' suitable for version numbers. (default)',
 
5404
            alpha='Sort tags lexicographically.',
5401
5405
            time='Sort tags chronologically.',
5402
5406
            ),
5403
5407
        'show-ids',
5407
5411
    @display_command
5408
5412
    def run(self,
5409
5413
            directory='.',
5410
 
            sort='alpha',
 
5414
            sort='natural',
5411
5415
            show_ids=False,
5412
5416
            revision=None,
5413
5417
            ):
5425
5429
            # only show revisions between revid1 and revid2 (inclusive)
5426
5430
            tags = [(tag, revid) for tag, revid in tags if
5427
5431
                graph.is_between(revid, revid1, revid2)]
5428
 
        if sort == 'alpha':
 
5432
        if sort == 'natural':
 
5433
            def natural_sort_key(tag):
 
5434
                return [f(s) for f,s in 
 
5435
                        zip(itertools.cycle((unicode.lower,int)),
 
5436
                                            re.split('([0-9]+)', tag[0]))]
 
5437
            tags.sort(key=natural_sort_key)
 
5438
        elif sort == 'alpha':
5429
5439
            tags.sort()
5430
5440
        elif sort == 'time':
5431
5441
            timestamps = {}