Rev 3909: (Marius) Support showing revisions in a specific range in 'bzr tags'. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Dec 16 17:36:16 GMT 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3909
revision-id: pqm at pqm.ubuntu.com-20081216173612-rj1jkrqcezr6sb3b
parent: pqm at pqm.ubuntu.com-20081216050844-csmbt4az61zghcxf
parent: amanic at gmail.com-20081216160528-rsp1kz89fj3x884e
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2008-12-16 17:36:12 +0000
message:
  (Marius) Support showing revisions in a specific range in 'bzr tags'.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_tags.py test_tags.py-20070116132048-5h4qak2cm22jlb9e-1
    ------------------------------------------------------------
    revno: 3904.2.4
    revision-id: amanic at gmail.com-20081216160528-rsp1kz89fj3x884e
    parent: amanic at gmail.com-20081214033703-ezazxwmb2shulxc5
    committer: Marius Kruger <amanic at gmail.com>
    branch nick: bzr.tags_revision
    timestamp: Tue 2008-12-16 18:05:28 +0200
    message:
      * rename _get2Revisions to _get_revision_range
      * add doc string
      * fix a error message to not refer to `log`, if it was actually called by `tag`.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
    ------------------------------------------------------------
    revno: 3904.2.3
    revision-id: amanic at gmail.com-20081214033703-ezazxwmb2shulxc5
    parent: amanic at gmail.com-20081214032201-lx059v3ts0pihvcf
    committer: Marius Kruger <amanic at gmail.com>
    branch nick: bzr.tags_revision
    timestamp: Sun 2008-12-14 05:37:03 +0200
    message:
      add news
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3904.2.2
    revision-id: amanic at gmail.com-20081214032201-lx059v3ts0pihvcf
    parent: amanic at gmail.com-20081214024753-xy1xljs3rx6pwcti
    committer: Marius Kruger <amanic at gmail.com>
    branch nick: bzr.tags_revision
    timestamp: Sun 2008-12-14 05:22:01 +0200
    message:
      add test_list_tags_revision_filtering
    modified:
      bzrlib/tests/blackbox/test_tags.py test_tags.py-20070116132048-5h4qak2cm22jlb9e-1
    ------------------------------------------------------------
    revno: 3904.2.1
    revision-id: amanic at gmail.com-20081214024753-xy1xljs3rx6pwcti
    parent: pqm at pqm.ubuntu.com-20081213000403-r1acnqhux25xhil1
    committer: Marius Kruger <amanic at gmail.com>
    branch nick: bzr.tags_revision
    timestamp: Sun 2008-12-14 04:47:53 +0200
    message:
      * factor out _get2Revisions from cmd_log to be able to reuse how revesions is determined by log.
      * implement revsion filtering for `bzr tags` which works like log's revision filtering. 
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
=== modified file 'NEWS'
--- a/NEWS	2008-12-15 04:37:10 +0000
+++ b/NEWS	2008-12-16 17:36:12 +0000
@@ -23,6 +23,9 @@
     * ``shelve --list`` can now be used to list shelved changes.
       (Aaron Bentley)
 
+    * Add support for `bzr tags -r 1..2`, that is we now support showing
+      tags applicable for a specified revision range. (Marius Kruger)
+
   IMPROVEMENTS:
 
     * Add trailing slash to directories in all output of ``bzr ls``, except

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-12-12 12:14:01 +0000
+++ b/bzrlib/builtins.py	2008-12-16 16:05:28 +0000
@@ -1848,25 +1848,7 @@
 
         b.lock_read()
         try:
-            if revision is None:
-                rev1 = None
-                rev2 = None
-            elif len(revision) == 1:
-                rev1 = rev2 = revision[0].in_history(b)
-            elif len(revision) == 2:
-                if revision[1].get_branch() != revision[0].get_branch():
-                    # b is taken from revision[0].get_branch(), and
-                    # show_log will use its revision_history. Having
-                    # different branches will lead to weird behaviors.
-                    raise errors.BzrCommandError(
-                        "Log doesn't accept two revisions in different"
-                        " branches.")
-                rev1 = revision[0].in_history(b)
-                rev2 = revision[1].in_history(b)
-            else:
-                raise errors.BzrCommandError(
-                    'bzr log --revision takes one or two values.')
-
+            rev1, rev2 = _get_revision_range(revision, b, self.name())
             if log_format is None:
                 log_format = log.log_formatter_registry.get_default(b)
 
@@ -1886,6 +1868,32 @@
         finally:
             b.unlock()
 
+def _get_revision_range(revisionspec_list, branch, command_name):
+    """Take the input of a revision option and turn it into a revision range.
+
+    It returns RevisionInfo objects which can be used to obtain the rev_id's
+    of the desired revisons. It does some user input validations.
+    """
+    if revisionspec_list is None:
+        rev1 = None
+        rev2 = None
+    elif len(revisionspec_list) == 1:
+        rev1 = rev2 = revisionspec_list[0].in_history(branch)
+    elif len(revisionspec_list) == 2:
+        if revisionspec_list[1].get_branch() != revisionspec_list[0
+                ].get_branch():
+            # b is taken from revision[0].get_branch(), and
+            # show_log will use its revision_history. Having
+            # different branches will lead to weird behaviors.
+            raise errors.BzrCommandError(
+                "bzr %s doesn't accept two revisions in different"
+                " branches." % command_name)
+        rev1 = revisionspec_list[0].in_history(branch)
+        rev2 = revisionspec_list[1].in_history(branch)
+    else:
+        raise errors.BzrCommandError(
+            'bzr %s --revision takes one or two values.' % command_name)
+    return rev1, rev2
 
 def get_log_format(long=False, short=False, line=False, default='long'):
     log_format = default
@@ -4576,6 +4584,7 @@
             time='Sort tags chronologically.',
             ),
         'show-ids',
+        'revision',
     ]
 
     @display_command
@@ -4583,11 +4592,28 @@
             directory='.',
             sort='alpha',
             show_ids=False,
+            revision=None,
             ):
         branch, relpath = Branch.open_containing(directory)
+
         tags = branch.tags.get_tag_dict().items()
         if not tags:
             return
+
+        if revision:
+            branch.lock_read()
+            try:
+                graph = branch.repository.get_graph()
+                rev1, rev2 = _get_revision_range(revision, branch, self.name())
+                revid1, revid2 = rev1.rev_id, rev2.rev_id
+                # only show revisions between revid1 and revid2 (inclusive)
+                tags = [(tag, revid) for tag, revid in tags if
+                     (revid2 is None or
+                         graph.is_ancestor(revid, revid2)) and
+                     (revid1 is None or
+                         graph.is_ancestor(revid1, revid))]
+            finally:
+                branch.unlock()
         if sort == 'alpha':
             tags.sort()
         elif sort == 'time':

=== modified file 'bzrlib/tests/blackbox/test_tags.py'
--- a/bzrlib/tests/blackbox/test_tags.py	2007-10-26 10:49:21 +0000
+++ b/bzrlib/tests/blackbox/test_tags.py	2008-12-14 03:22:01 +0000
@@ -160,6 +160,44 @@
         self.assertEquals(err, '')
         self.assertContainsRe(out, r'tagD  *3\n')
 
+    def test_list_tags_revision_filtering(self):
+        tree1 = self.make_branch_and_tree('.')
+        tree1.commit(allow_pointless=True, message='revision 1',
+                rev_id='revid-1')
+        tree1.commit(allow_pointless=True, message='revision 2',
+                rev_id='revid-2')
+        tree1.commit(allow_pointless=True, message='revision 3',
+                rev_id='revid-3')
+        tree1.commit(allow_pointless=True, message='revision 4',
+                rev_id='revid-4')
+        b1 = tree1.branch
+        b1.tags.set_tag(u'tag 1', 'revid-1')
+        b1.tags.set_tag(u'tag 2', 'revid-2')
+        b1.tags.set_tag(u'tag 3', 'revid-3')
+        b1.tags.set_tag(u'tag 4', 'revid-4')
+        self._check_tag_filter('', (1, 2, 3, 4))
+        self._check_tag_filter('-r ..', (1, 2, 3, 4))
+        self._check_tag_filter('-r ..2', (1, 2))
+        self._check_tag_filter('-r 2..', (2, 3, 4))
+        self._check_tag_filter('-r 2..3', (2, 3))
+        self._check_tag_filter('-r 3..2', ())
+        self.run_bzr_error(args="tags -r 123",
+            error_regexes=["bzr: ERROR: Requested revision: '123' "
+                "does not exist in branch:"])
+        self.run_bzr_error(args="tags -r ..123",
+            error_regexes=["bzr: ERROR: Requested revision: '123' "
+                "does not exist in branch:"])
+        self.run_bzr_error(args="tags -r 123.123",
+            error_regexes=["bzr: ERROR: Requested revision: '123.123' "
+                "does not exist in branch:"])
+
+    def _check_tag_filter(self, argstr, expected_revnos):
+        #upper bound of laziness
+        out, err = self.run_bzr('tags ' + argstr)
+        self.assertEquals(err, '')
+        self.assertContainsRe(out, "^" + ''.join(["tag %s +%s\n" % (
+            revno, revno) for revno in expected_revnos]) + "$")
+
     def test_conflicting_tags(self):
         # setup two empty branches with different tags
         t1 = self.make_branch_and_tree('one')




More information about the bazaar-commits mailing list