/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Adeodato Simó
  • Date: 2007-10-26 10:49:21 UTC
  • mto: (2968.1.1 tags)
  • mto: This revision was merged to the branch mainline in revision 2972.
  • Revision ID: dato@net.com.org.es-20071026104921-zfwb0z5iqu36xm3a
Don't sort by revno; only by time if --sort=time is passed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4164
4164
            short_name='d',
4165
4165
            type=unicode,
4166
4166
            ),
 
4167
        RegistryOption.from_kwargs('sort',
 
4168
            'Sort tags by different criteria.', title='Sorting',
 
4169
            alpha='Sort tags lexicographically (default).',
 
4170
            time='Sort tags chronologically.',
 
4171
            ),
4167
4172
        'show-ids',
4168
4173
    ]
4169
4174
 
4170
4175
    @display_command
4171
4176
    def run(self,
4172
4177
            directory='.',
 
4178
            sort='alpha',
4173
4179
            show_ids=False,
4174
4180
            ):
4175
4181
        branch, relpath = Branch.open_containing(directory)
4176
 
        revno_map = branch.get_revision_id_to_revno_map()
4177
 
        tags = []
4178
 
        for tag_name, revid in branch.tags.get_tag_dict().items():
4179
 
            revno = revno_map.get(revid, ('?',))
4180
 
            tags.append(((revno, revid), tag_name))
4181
 
        for (revno, revid), tag_name in sorted(tags):
4182
 
            if show_ids:
4183
 
                revspec = revid
4184
 
            else:
4185
 
                revspec = '.'.join(str(x) for x in revno)
4186
 
            self.outf.write('%-20s %s\n' % (tag_name, revspec))
 
4182
        tags = branch.tags.get_tag_dict().items()
 
4183
        if sort == 'alpha':
 
4184
            tags.sort()
 
4185
        elif sort == 'time':
 
4186
            timestamps = {}
 
4187
            for tag, revid in tags:
 
4188
                try:
 
4189
                    revobj = branch.repository.get_revision(revid)
 
4190
                except errors.NoSuchRevision:
 
4191
                    timestamp = sys.maxint # place them at the end
 
4192
                else:
 
4193
                    timestamp = revobj.timestamp
 
4194
                timestamps[revid] = timestamp
 
4195
            tags.sort(key=lambda x: timestamps[x[1]])
 
4196
        if not show_ids:
 
4197
            # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
 
4198
            revno_map = branch.get_revision_id_to_revno_map()
 
4199
            tags = [ (tag, '.'.join(map(str, revno_map.get(revid, ('?',)))))
 
4200
                        for tag, revid in tags ]
 
4201
        for tag, revspec in tags:
 
4202
            self.outf.write('%-20s %s\n' % (tag, revspec))
4187
4203
 
4188
4204
 
4189
4205
class cmd_reconfigure(Command):