Rev 3306: Get rid of .in_branch(need_revno=False) in favor of simpler .as_revision_id() in http://bzr.arbash-meinel.com/branches/bzr/1.4-dev/get_rev_id

John Arbash Meinel john at arbash-meinel.com
Thu Mar 20 22:48:14 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.4-dev/get_rev_id

------------------------------------------------------------
revno: 3306
revision-id: john at arbash-meinel.com-20080320224535-l3h1k92yaa6sr910
parent: john at arbash-meinel.com-20080320223558-c51frzshaj11bw29
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: get_rev_id
timestamp: Thu 2008-03-20 17:45:35 -0500
message:
  Get rid of .in_branch(need_revno=False) in favor of simpler .as_revision_id()
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
  bzrlib/revisionspec.py         revisionspec.py-20050907152633-17567659fd5c0ddb
  bzrlib/status.py               status.py-20050505062338-431bfa63ec9b19e6
  bzrlib/tests/test_revisionspec.py testrevisionnamespaces.py-20050711050225-8b4af89e6b1efe84
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-03-20 17:19:26 +0000
+++ b/bzrlib/builtins.py	2008-03-20 22:45:35 +0000
@@ -466,7 +466,7 @@
                     raise errors.BzrCommandError(
                         'bzr inventory --revision takes exactly one revision'
                         ' identifier')
-                revision_id = revision[0].in_branch(work_tree.branch, need_revno=False).rev_id
+                revision_id = revision[0].as_revision_id(work_tree.branch)
                 tree = work_tree.branch.repository.revision_tree(revision_id)
 
                 extra_trees = [work_tree]
@@ -655,7 +655,7 @@
 
         if revision is not None:
             if len(revision) == 1:
-                revision_id = revision[0].in_branch(branch_from, need_revno=False).rev_id
+                revision_id = revision[0].as_revision_id(branch_from)
             else:
                 raise errors.BzrCommandError(
                     'bzr pull --revision takes one value.')
@@ -916,8 +916,7 @@
         br_from.lock_read()
         try:
             if len(revision) == 1 and revision[0] is not None:
-                revision_id = revision[0].in_branch(br_from,
-                                                    need_revno=False).rev_id
+                revision_id = revision[0].as_revision_id(br_from)
             else:
                 # FIXME - wt.last_revision, fallback to branch, fall back to
                 # None or perhaps NULL_REVISION to mean copy nothing
@@ -1011,8 +1010,7 @@
         if files_from is not None:
             accelerator_tree = WorkingTree.open(files_from)
         if len(revision) == 1 and revision[0] is not None:
-            revision_id = _mod_revision.ensure_null(
-                revision[0].in_branch(source, need_revno=False).rev_id)
+            revision_id = revision[0].as_revision_id(source)
         else:
             revision_id = None
         if to_location is None:
@@ -1872,7 +1870,7 @@
             relpath += '/'
         if revision is not None:
             tree = branch.repository.revision_tree(
-                revision[0].in_branch(branch, need_revno=False).rev_id)
+                revision[0].as_revision_id(branch))
         elif tree is None:
             tree = branch.basis_tree()
 
@@ -2137,7 +2135,7 @@
         else:
             if len(revision) != 1:
                 raise errors.BzrCommandError('bzr export --revision takes exactly 1 argument')
-            rev_id = revision[0].in_branch(b, need_revno=False).rev_id
+            rev_id = revision[0].as_revision_id(b)
         t = b.repository.revision_tree(rev_id)
         try:
             export(t, dest, format, root)
@@ -2182,7 +2180,7 @@
         if revision is None:
             revision_id = b.last_revision()
         else:
-            revision_id = revision[0].in_branch(b, need_revno=False).rev_id
+            revision_id = revision[0].as_revision_id(b)
 
         cur_file_id = tree.path2id(relpath)
         rev_tree = b.repository.revision_tree(revision_id)
@@ -2978,14 +2976,10 @@
             other_revision_id = _mod_revision.ensure_null(
                 other_branch.last_revision())
         else:
-            other_revision_id = \
-                _mod_revision.ensure_null(
-                    revision[-1].in_branch(other_branch, need_revno=False).rev_id)
+            other_revision_id = revision[-1].as_revision_id(other_branch)
         if (revision is not None and len(revision) == 2
             and revision[0] is not None):
-            base_revision_id = \
-                _mod_revision.ensure_null(
-                    revision[0].in_branch(base_branch, need_revno=False).rev_id)
+            base_revision_id = revision[0].as_revision_id(base_branch)
         else:
             base_revision_id = None
         # Remember where we merge from
@@ -3204,7 +3198,7 @@
         elif len(revision) != 1:
             raise errors.BzrCommandError('bzr revert --revision takes exactly 1 argument')
         else:
-            rev_id = revision[0].in_branch(tree.branch, need_revno=False).rev_id
+            rev_id = revision[0].as_revision_id(tree.branch)
         pb = ui.ui_factory.nested_progress_bar()
         try:
             tree.revert(file_list,
@@ -3455,7 +3449,7 @@
             if revision is None:
                 rev_id = b.last_revision()
             else:
-                rev_id = revision[0].in_branch(b, need_revno=False).rev_id
+                rev_id = revision[0].as_revision_id(b)
             t = testament_class.from_revision(b.repository, rev_id)
             if long:
                 sys.stdout.writelines(t.as_text_lines())
@@ -3502,7 +3496,7 @@
             elif len(revision) != 1:
                 raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
             else:
-                revision_id = revision[0].in_branch(branch, need_revno=False).rev_id
+                revision_id = revision[0].as_revision_id(branch)
             tree = branch.repository.revision_tree(revision_id)
             if wt is not None:
                 file_id = wt.path2id(relpath)
@@ -3997,12 +3991,9 @@
             if len(revision) > 2:
                 raise errors.BzrCommandError('bzr merge-directive takes '
                     'at most two one revision identifiers')
-            revision_id = revision[-1].in_branch(branch,
-                                                 need_revno=False).rev_id
+            revision_id = revision[-1].as_revision_id(branch)
             if len(revision) == 2:
-                base_revision_id = revision[0].in_branch(
-                    branch, need_revno=False).rev_id
-                base_revision_id = ensure_null(base_revision_id)
+                base_revision_id = revision[0].as_revision_id(branch)
         else:
             revision_id = branch.last_revision()
         revision_id = ensure_null(revision_id)
@@ -4166,9 +4157,9 @@
                 if len(revision) > 2:
                     raise errors.BzrCommandError('bzr send takes '
                         'at most two one revision identifiers')
-                revision_id = revision[-1].in_branch(branch, need_revno=False).rev_id
+                revision_id = revision[-1].as_revision_id(branch)
                 if len(revision) == 2:
-                    base_revision_id = revision[0].in_branch(branch, need_revno=False).rev_id
+                    base_revision_id = revision[0].as_revision_id(branch)
             if revision_id is None:
                 revision_id = branch.last_revision()
             if revision_id == NULL_REVISION:
@@ -4334,7 +4325,7 @@
                         raise errors.BzrCommandError(
                             "Tags can only be placed on a single revision, "
                             "not on a range")
-                    revision_id = revision[0].in_branch(branch, need_revno=False).rev_id
+                    revision_id = revision[0].as_revision_id(branch)
                 else:
                     revision_id = branch.last_revision()
                 if (not force) and branch.tags.has_tag(tag_name):

=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py	2008-03-20 17:19:26 +0000
+++ b/bzrlib/diff.py	2008-03-20 22:45:35 +0000
@@ -314,9 +314,9 @@
 
     def spec_tree(spec):
         if tree:
-            revision = spec.in_branch(tree.branch, need_revno=False)
+            revision = spec.as_revision_id(tree.branch)
         else:
-            revision = spec.in_branch(None, need_revno=False)
+            revision = spec.as_revision_id(None)
         revision_id = revision.rev_id
         branch = revision.branch
         return branch.repository.revision_tree(revision_id)

=== modified file 'bzrlib/revisionspec.py'
--- a/bzrlib/revisionspec.py	2008-03-20 22:30:38 +0000
+++ b/bzrlib/revisionspec.py	2008-03-20 22:45:35 +0000
@@ -232,10 +232,7 @@
     # aliases for now, when we fix the core logic, then they
     # will do what you expect.
     in_store = in_history
-    # in_branch = in_store
-
-    def in_branch(self, branch, need_revno=True):
-        return self.in_history(branch)
+    in_branch = in_store
 
     def as_revision_id(self, context_branch):
         """Return just the revision_id for this revisions spec.

=== modified file 'bzrlib/status.py'
--- a/bzrlib/status.py	2008-03-20 17:19:26 +0000
+++ b/bzrlib/status.py	2008-03-20 22:45:35 +0000
@@ -84,15 +84,13 @@
             old = new.basis_tree()
         elif len(revision) > 0:
             try:
-                rev_id = revision[0].in_branch(wt.branch,
-                                               need_revno=False).rev_id
+                rev_id = revision[0].as_revision_id(wt.branch)
                 old = wt.branch.repository.revision_tree(rev_id)
             except errors.NoSuchRevision, e:
                 raise errors.BzrCommandError(str(e))
             if (len(revision) > 1) and (revision[1].spec is not None):
                 try:
-                    rev_id = revision[1].in_branch(wt.branch,
-                                                   need_revno=False).rev_id
+                    rev_id = revision[1].as_revision_id(wt.branch)
                     new = wt.branch.repository.revision_tree(rev_id)
                     new_is_working_tree = False
                 except errors.NoSuchRevision, e:

=== modified file 'bzrlib/tests/test_revisionspec.py'
--- a/bzrlib/tests/test_revisionspec.py	2008-03-20 22:35:58 +0000
+++ b/bzrlib/tests/test_revisionspec.py	2008-03-20 22:45:35 +0000
@@ -37,11 +37,6 @@
     return RevisionSpec.from_string(spec).in_history(branch)
 
 
-def spec_in_branch(spec, branch, *args, **kwargs):
-    """A simple helper to change a revision spec into a branch search"""
-    return RevisionSpec.from_string(spec).in_branch(branch, *args, **kwargs)
-
-
 # Basic class, which just creates a really basic set of revisions
 class TestRevisionSpec(TestCaseWithTransport):
 
@@ -70,9 +65,6 @@
     def get_in_history(self, revision_spec):
         return spec_in_history(revision_spec, self.tree.branch)
 
-    def get_in_branch(self, revision_spec, *args, **kwargs):
-        return spec_in_branch(revision_spec, self.tree.branch, *args, **kwargs)
-
     def assertInHistoryIs(self, exp_revno, exp_revision_id, revision_spec):
         rev_info = self.get_in_history(revision_spec)
         self.assertEqual(exp_revno, rev_info.revno,
@@ -93,27 +85,6 @@
             self.fail('Expected InvalidRevisionSpec to be raised for %s'
                       % (revision_spec,))
 
-    def assertInBranchSupportsNeedRevno(self, revision_spec,
-                                        has_simple_revno=True):
-        """Assert that the in_branch() helper supports need_revno
-
-        If need_revno=False, then the RevisionInfo can have None for revno.
-        But if it has a real number, then it should be the same as when
-        need_revno=True is passed.
-
-        :param revision_spec: The revision spec to test.
-        :param has_simple_revno: If true, then 'need_revno=True' must set the
-            .revno property to something other than None.
-        """
-        info_true = self.get_in_branch(revision_spec, need_revno=True)
-        if has_simple_revno:
-            self.assertIsNot(None, info_true.revno)
-        else:
-            self.assertIs(None, info_true.revno)
-        info_false = self.get_in_branch(revision_spec, need_revno=False)
-        if info_false.revno is not None:
-            self.assertEqual(info_true.revno, info_false.revno)
-
     def assertAsRevisionId(self, revision_id, revision_spec):
         """Calling as_revision_id() should return the specified id."""
         spec = RevisionSpec.from_string(revision_spec)
@@ -283,12 +254,6 @@
         self.assertEqual((2, 'b at r-0-2'),
                          spec_in_history('revno:2:b/', None))
 
-    def test_supports_need_revno(self):
-        self.assertInBranchSupportsNeedRevno('1')
-        self.assertInBranchSupportsNeedRevno('2')
-        self.assertInBranchSupportsNeedRevno('1.1.1',
-            has_simple_revno=False)
-
     def test_as_revision_id(self):
         self.assertAsRevisionId('r1', '1')
         self.assertAsRevisionId('r2', '2')
@@ -332,12 +297,6 @@
         self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
         self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
 
-    def test_supports_need_revno(self):
-        self.assertInBranchSupportsNeedRevno('revid:r1')
-        self.assertInBranchSupportsNeedRevno('revid:r2')
-        self.assertInBranchSupportsNeedRevno('revid:alt_r2',
-            has_simple_revno=False)
-
     def test_as_revision_id(self):
         self.assertAsRevisionId('r1', 'revid:r1')
         self.assertAsRevisionId('r2', 'revid:r2')
@@ -374,9 +333,6 @@
             pass
         self.assertInvalid('last:Y', extra='\n' + str(e))
 
-    def test_supports_need_revno(self):
-        self.assertInBranchSupportsNeedRevno('last:1')
-
     def test_as_revision_id(self):
         self.assertAsRevisionId('r2', 'last:1')
         self.assertAsRevisionId('r1', 'last:2')
@@ -412,10 +368,6 @@
                                           revision_id='new_r1')
         self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
 
-    def test_supports_need_revno(self):
-        self.assertInBranchSupportsNeedRevno('before:2')
-        self.assertInBranchSupportsNeedRevno('before:revid:r2')
-
     def test_as_revision_id(self):
         self.tree.lock_read()
         self.addCleanup(self.tree.unlock)
@@ -448,10 +400,6 @@
             self.get_in_history,
             'tag:some-random-tag')
 
-    def test_supports_need_revno(self):
-        self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
-        self.assertInBranchSupportsNeedRevno('tag:bzr-0.14')
-
     def test_as_revision_id(self):
         self.tree.branch.tags.set_tag('my-tag', 'r2')
         self.assertAsRevisionId('r2', 'tag:my-tag')
@@ -493,9 +441,6 @@
         self.assertInHistoryIs(2, 'new_r2',
             'date:%04d-%02d-%02d' % (now.year, now.month, now.day))
 
-    def test_supports_need_revno(self):
-        self.assertInBranchSupportsNeedRevno('date:today')
-
     def test_as_revision_id(self):
         self.assertAsRevisionId('new_r2', 'date:today')
 
@@ -542,10 +487,6 @@
                           spec_in_history, 'ancestor:tree',
                                            new_tree.branch)
 
-    def test_supports_need_revno(self):
-        self.assertInBranchSupportsNeedRevno('ancestor:tree2',
-            has_simple_revno=False)
-
     def test_as_revision_id(self):
         self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
 
@@ -583,10 +524,6 @@
         self.assertRaises(errors.NoCommits,
                           self.get_in_history, 'branch:new_tree')
 
-    def test_supports_need_revno(self):
-        self.assertInBranchSupportsNeedRevno('branch:tree2',
-            has_simple_revno=False)
-
     def test_as_revision_id(self):
         self.assertAsRevisionId('alt_r2', 'branch:tree2')
 
@@ -606,11 +543,6 @@
         self.tree.branch.set_submit_branch('tree2')
         self.assertInHistoryIs(None, 'alt_r2', 'submit:')
 
-    def test_supports_need_revno(self):
-        self.tree.branch.set_submit_branch('tree2')
-        self.assertInBranchSupportsNeedRevno('submit:',
-            has_simple_revno=False)
-
     def test_as_revision_id(self):
         self.tree.branch.set_submit_branch('tree2')
         self.assertAsRevisionId('alt_r2', 'branch:tree2')



More information about the bazaar-commits mailing list