Rev 5464: (mbp) Change bzr tags to use a natural sort order by default (Neil in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Oct 7 08:55:13 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5464 [merge]
revision-id: pqm at pqm.ubuntu.com-20101007075509-u808nnwozm7hlt2x
parent: pqm at pqm.ubuntu.com-20101007065722-lemnu8cjldl3d0j4
parent: nmb at wartburg.edu-20101006041452-nnbhe8tji0ys6gqq
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-10-07 08:55:09 +0100
message:
(mbp) Change bzr tags to use a natural sort order by default (Neil
Martinsen-Burrell)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_tags.py test_tags.py-20070116132048-5h4qak2cm22jlb9e-1
doc/en/whats-new/whats-new-in-2.3.txt whatsnewin2.3.txt-20100818072501-x2h25r7jbnknvy30-1
=== modified file 'NEWS'
--- a/NEWS 2010-10-07 03:23:27 +0000
+++ b/NEWS 2010-10-07 07:55:09 +0000
@@ -13,6 +13,11 @@
Compatibility Breaks
********************
+* The ``bzr tags`` command sorts tag names using a natural sort by
+ default (so tag2 sorts before tag10). The previous default was
+ strictly "asciibetical". That behavior is still available as ``bzr tags
+ --sort=alpha``. (Neil Martinsen-Burrell, #640760)
+
New Features
************
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2010-10-01 08:49:39 +0000
+++ b/bzrlib/builtins.py 2010-10-06 04:14:52 +0000
@@ -21,6 +21,8 @@
from bzrlib.lazy_import import lazy_import
lazy_import(globals(), """
import cStringIO
+import itertools
+import re
import sys
import time
@@ -5397,7 +5399,9 @@
help='Branch whose tags should be displayed.'),
RegistryOption.from_kwargs('sort',
'Sort tags by different criteria.', title='Sorting',
- alpha='Sort tags lexicographically (default).',
+ natural='Sort numeric substrings as numbers:'
+ ' suitable for version numbers. (default)',
+ alpha='Sort tags lexicographically.',
time='Sort tags chronologically.',
),
'show-ids',
@@ -5407,7 +5411,7 @@
@display_command
def run(self,
directory='.',
- sort='alpha',
+ sort='natural',
show_ids=False,
revision=None,
):
@@ -5425,7 +5429,13 @@
# only show revisions between revid1 and revid2 (inclusive)
tags = [(tag, revid) for tag, revid in tags if
graph.is_between(revid, revid1, revid2)]
- if sort == 'alpha':
+ if sort == 'natural':
+ def natural_sort_key(tag):
+ return [f(s) for f,s in
+ zip(itertools.cycle((unicode.lower,int)),
+ re.split('([0-9]+)', tag[0]))]
+ tags.sort(key=natural_sort_key)
+ elif sort == 'alpha':
tags.sort()
elif sort == 'time':
timestamps = {}
=== modified file 'bzrlib/tests/blackbox/test_tags.py'
--- a/bzrlib/tests/blackbox/test_tags.py 2010-03-24 14:16:15 +0000
+++ b/bzrlib/tests/blackbox/test_tags.py 2010-10-03 05:08:21 +0000
@@ -132,33 +132,42 @@
b1 = tree1.branch
# note how the tag for revid-1 sorts after the one for revid-2
- b1.tags.set_tag(u'tagA\u30d0', 'revid-2')
- b1.tags.set_tag(u'tagB\u30d0', 'missing') # not present in repository
- b1.tags.set_tag(u'tagC\u30d0', 'revid-1')
+ b1.tags.set_tag(u'tag1\u30d0', 'revid-2')
+ b1.tags.set_tag(u'tag10\u30d0', 'missing') # not present in repository
+ b1.tags.set_tag(u'tag2\u30d0', 'revid-1')
+
+ # natural order
+ out, err = self.run_bzr('tags -d branch1',
+ encoding='utf-8')
+ self.assertEquals(err, '')
+ self.assertContainsRe(out, (u'^tag1\u30d0 *2\ntag2\u30d0 *1\n' +
+ u'tag10\u30d0 *\\?\n').encode('utf-8'))
# lexicographical order
- out, err = self.run_bzr('tags -d branch1', encoding='utf-8')
+ out, err = self.run_bzr('tags --sort=alpha -d branch1',
+ encoding='utf-8')
self.assertEquals(err, '')
- self.assertContainsRe(out, (u'^tagA\u30d0 *2\ntagB\u30d0 *\\?\n' +
- u'tagC\u30d0 *1\n').encode('utf-8'))
+ self.assertContainsRe(out, (u'^tag10\u30d0 *\\?\ntag1\u30d0 *2\n' +
+ u'tag2\u30d0 *1\n').encode('utf-8'))
- out, err = self.run_bzr('tags --show-ids -d branch1', encoding='utf-8')
+ out, err = self.run_bzr('tags --sort=alpha --show-ids -d branch1',
+ encoding='utf-8')
self.assertEquals(err, '')
- self.assertContainsRe(out, (u'^tagA\u30d0 *revid-2\n' +
- u'tagB\u30d0 *missing\ntagC\u30d0 *revid-1\n').encode('utf-8'))
+ self.assertContainsRe(out, (u'^tag10\u30d0 *missing\n' +
+ u'tag1\u30d0 *revid-2\ntag2\u30d0 *revid-1\n').encode('utf-8'))
# chronological order
out, err = self.run_bzr('tags --sort=time -d branch1',
encoding='utf-8')
self.assertEquals(err, '')
- self.assertContainsRe(out, (u'^tagC\u30d0 *1\ntagA\u30d0 *2\n' +
- u'tagB\u30d0 *\\?\n').encode('utf-8'))
+ self.assertContainsRe(out, (u'^tag2\u30d0 *1\ntag1\u30d0 *2\n' +
+ u'tag10\u30d0 *\\?\n').encode('utf-8'))
out, err = self.run_bzr('tags --sort=time --show-ids -d branch1',
encoding='utf-8')
self.assertEquals(err, '')
- self.assertContainsRe(out, (u'^tagC\u30d0 *revid-1\n' +
- u'tagA\u30d0 *revid-2\ntagB\u30d0 *missing\n').encode('utf-8'))
+ self.assertContainsRe(out, (u'^tag2\u30d0 *revid-1\n' +
+ u'tag1\u30d0 *revid-2\ntag10\u30d0 *missing\n').encode('utf-8'))
# now test dotted revnos
tree2 = tree1.bzrdir.sprout('branch2').open_workingtree()
=== modified file 'doc/en/whats-new/whats-new-in-2.3.txt'
--- a/doc/en/whats-new/whats-new-in-2.3.txt 2010-09-24 02:19:28 +0000
+++ b/doc/en/whats-new/whats-new-in-2.3.txt 2010-10-06 04:14:52 +0000
@@ -25,6 +25,12 @@
bytecode files.
(Andrea Corbellini, #626687)
+* The default sort order for the ``bzr tags`` command now uses a natural sort
+ where numeric substrings are sorted numerically. The previous default was
+ "asciibetical" where tags were sorted by the characters they contained. To
+ get the old behavior, one can use ``bzr tags --sort=alpha``.
+ (Neil Martinsen-Burrell, #640760)
+
Launchpad integration
*********************
More information about the bazaar-commits
mailing list