~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2011-01-12 01:01:53 UTC
  • mfrom: (5597 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5599.
  • Revision ID: john@arbash-meinel.com-20110112010153-op19823r9e6hy7u6
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt

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
26
24
import sys
27
25
import time
28
26
 
2052
2050
    @display_command
2053
2051
    def run(self, null=False, directory=u'.'):
2054
2052
        tree = WorkingTree.open_containing(directory)[0]
 
2053
        self.add_cleanup(tree.lock_read().unlock)
2055
2054
        td = tree.changes_from(tree.basis_tree())
 
2055
        self.cleanup_now()
2056
2056
        for path, id, kind, text_modified, meta_modified in td.modified:
2057
2057
            if null:
2058
2058
                self.outf.write(path + '\0')
5482
5482
    takes_options = [
5483
5483
        custom_help('directory',
5484
5484
            help='Branch whose tags should be displayed.'),
5485
 
        RegistryOption.from_kwargs('sort',
 
5485
        RegistryOption('sort',
5486
5486
            'Sort tags by different criteria.', title='Sorting',
5487
 
            natural='Sort numeric substrings as numbers:'
5488
 
                    ' suitable for version numbers. (default)',
5489
 
            alpha='Sort tags lexicographically.',
5490
 
            time='Sort tags chronologically.',
 
5487
            lazy_registry=('bzrlib.tag', 'tag_sort_methods')
5491
5488
            ),
5492
5489
        'show-ids',
5493
5490
        'revision',
5494
5491
    ]
5495
5492
 
5496
5493
    @display_command
5497
 
    def run(self,
5498
 
            directory='.',
5499
 
            sort='natural',
5500
 
            show_ids=False,
5501
 
            revision=None,
5502
 
            ):
 
5494
    def run(self, directory='.', sort=None, show_ids=False, revision=None):
 
5495
        from bzrlib.tag import tag_sort_methods
5503
5496
        branch, relpath = Branch.open_containing(directory)
5504
5497
 
5505
5498
        tags = branch.tags.get_tag_dict().items()
5514
5507
            # only show revisions between revid1 and revid2 (inclusive)
5515
5508
            tags = [(tag, revid) for tag, revid in tags if
5516
5509
                graph.is_between(revid, revid1, revid2)]
5517
 
        if sort == 'natural':
5518
 
            def natural_sort_key(tag):
5519
 
                return [f(s) for f,s in 
5520
 
                        zip(itertools.cycle((unicode.lower,int)),
5521
 
                                            re.split('([0-9]+)', tag[0]))]
5522
 
            tags.sort(key=natural_sort_key)
5523
 
        elif sort == 'alpha':
5524
 
            tags.sort()
5525
 
        elif sort == 'time':
5526
 
            timestamps = {}
5527
 
            for tag, revid in tags:
5528
 
                try:
5529
 
                    revobj = branch.repository.get_revision(revid)
5530
 
                except errors.NoSuchRevision:
5531
 
                    timestamp = sys.maxint # place them at the end
5532
 
                else:
5533
 
                    timestamp = revobj.timestamp
5534
 
                timestamps[revid] = timestamp
5535
 
            tags.sort(key=lambda x: timestamps[x[1]])
 
5510
        if sort is None:
 
5511
            sort = tag_sort_methods.get()
 
5512
        sort(branch, tags)
5536
5513
        if not show_ids:
5537
5514
            # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5538
5515
            for index, (tag, revid) in enumerate(tags):