[patch] use correct bzrlib version in performance history
Martin Pool
mbp at canonical.com
Wed Aug 16 03:49:37 BST 2006
On 15 Aug 2006, Aaron Bentley <aaron.bentley at utoronto.ca> wrote:
> Martin Pool wrote:
> > Jan's patch to record performance history to a file got some +1s before
> > with comments, so I'm going to review it and send it in.
> >
> > I did have one change, which is
>
> Shouldn't that be WorkingTree.last_revision?
OK,
* unify "what revision of bzrlib am i using" between benchmarks, bzr
--version, and others
* delete old deprecated function which does this
* report the working tree version, not the branch version
* add a smoke test. there's also an existing blackbox test for
--version
--
Martin
-------------- next part --------------
=== added file 'bzrlib/tests/test_version.py'
--- bzrlib/tests/test_version.py 1970-01-01 00:00:00 +0000
+++ bzrlib/tests/test_version.py 2006-08-16 02:23:35 +0000
@@ -0,0 +1,35 @@
+# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+"""Tests for versioning of bzrlib."""
+
+from bzrlib import version
+from bzrlib.tests import TestCase, TestSkipped
+
+class TestBzrlibVersioning(TestCase):
+
+ def test_get_bzr_source_tree(self):
+ """Get tree for bzr source, if any."""
+ # We don't know if these tests are being run from a checkout or branch
+ # of bzr, from an installed copy, or from source unpacked from a
+ # tarball. We don't construct a branch just for testing this, so we
+ # just assert that it must either return None or the tree.
+ src_tree = version._get_bzr_source_tree()
+ if src_tree is None:
+ raise TestSkipped("bzr tests aren't run from a bzr working tree")
+ else:
+ source_version = src_tree.last_revision()
=== added file 'bzrlib/version.py'
--- bzrlib/version.py 1970-01-01 00:00:00 +0000
+++ bzrlib/version.py 2006-08-16 02:36:28 +0000
@@ -0,0 +1,67 @@
+# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Report on version of bzrlib"""
+
+import os
+import sys
+
+import bzrlib
+from bzrlib import errors, osutils
+from bzrlib.branch import Branch
+
+
+def show_version():
+ print "Bazaar (bzr) %s" % bzrlib.__version__
+ # is bzrlib itself in a branch?
+ src_tree = _get_bzr_source_tree()
+ if src_tree:
+ src_revision_id = src_tree.last_revision()
+ revno = src_tree.branch.revision_id_to_revno(src_revision_id)
+ print " from bzr checkout", src_tree.basedir
+ print " revision:", revno
+ print " revid:", src_revision_id
+ print " branch nick:", src_tree.branch.nick
+ print "Using python interpreter:", sys.executable
+ import site
+ print "Using python standard library:", os.path.dirname(site.__file__)
+ print "Using bzrlib:",
+ if len(bzrlib.__path__) > 1:
+ # print repr, which is a good enough way of making it clear it's
+ # more than one element (eg ['/foo/bar', '/foo/bzr'])
+ print repr(bzrlib.__path__)
+ else:
+ print bzrlib.__path__[0]
+
+ print
+ print bzrlib.__copyright__
+ print "http://bazaar-vcs.org/"
+ print
+ print "bzr comes with ABSOLUTELY NO WARRANTY. bzr is free software, and"
+ print "you may use, modify and redistribute it under the terms of the GNU"
+ print "General Public License version 2 or later."
+
+
+def _get_bzr_source_tree():
+ """Return the WorkingTree for bzr source, if any.
+
+ If bzr is not being run from its working tree, returns None.
+ """
+ try:
+ from bzrlib.workingtree import WorkingTree
+ return WorkingTree.open_containing(__file__)[0]
+ except errors.NotBranchError:
+ return None
=== modified file 'bzrlib/__init__.py'
--- bzrlib/__init__.py 2006-08-14 13:35:31 +0000
+++ bzrlib/__init__.py 2006-08-16 01:54:55 +0000
@@ -60,23 +60,6 @@
'Consider using bzrlib.ignores.add_unique_user_ignores'
' or bzrlib.ignores.add_runtime_ignores')
-
- at deprecated_function(zero_seven)
-def get_bzr_revision():
- """If bzr is run from a branch, return (revno,revid) or None."""
- import bzrlib.errors
- from bzrlib.branch import Branch
-
- try:
- branch = Branch.open(os.path.dirname(__path__[0]))
- rh = branch.revision_history()
- if rh:
- return len(rh), rh[-1]
- else:
- return None
- except bzrlib.errors.BzrError:
- return None
-
def test_suite():
import tests
return tests.test_suite()
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2006-08-15 12:39:42 +0000
+++ bzrlib/builtins.py 2006-08-16 01:58:14 +0000
@@ -1993,54 +1993,12 @@
ui.ui_factory = save_ui
-def _get_bzr_branch():
- """If bzr is run from a branch, return Branch or None"""
- from os.path import dirname
-
- try:
- branch = Branch.open(dirname(osutils.abspath(dirname(__file__))))
- return branch
- except errors.BzrError:
- return None
-
-
-def show_version():
- import bzrlib
- print "Bazaar (bzr) %s" % bzrlib.__version__
- # is bzrlib itself in a branch?
- branch = _get_bzr_branch()
- if branch:
- rh = branch.revision_history()
- revno = len(rh)
- print " bzr checkout, revision %d" % (revno,)
- print " nick: %s" % (branch.nick,)
- if rh:
- print " revid: %s" % (rh[-1],)
- print "Using python interpreter:", sys.executable
- import site
- print "Using python standard library:", os.path.dirname(site.__file__)
- print "Using bzrlib:",
- if len(bzrlib.__path__) > 1:
- # print repr, which is a good enough way of making it clear it's
- # more than one element (eg ['/foo/bar', '/foo/bzr'])
- print repr(bzrlib.__path__)
- else:
- print bzrlib.__path__[0]
-
- print
- print bzrlib.__copyright__
- print "http://bazaar-vcs.org/"
- print
- print "bzr comes with ABSOLUTELY NO WARRANTY. bzr is free software, and"
- print "you may use, modify and redistribute it under the terms of the GNU"
- print "General Public License version 2 or later."
-
-
class cmd_version(Command):
"""Show version of bzr."""
@display_command
def run(self):
+ from bzrlib.version import show_version
show_version()
=== modified file 'bzrlib/commands.py'
--- bzrlib/commands.py 2006-07-15 14:29:03 +0000
+++ bzrlib/commands.py 2006-08-16 01:57:30 +0000
@@ -621,7 +621,7 @@
return 0
if argv[0] == '--version':
- from bzrlib.builtins import show_version
+ from bzrlib.version import show_version
show_version()
return 0
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py 2006-08-15 14:02:53 +0000
+++ bzrlib/tests/__init__.py 2006-08-16 02:45:28 +0000
@@ -139,12 +139,21 @@
def __init__(self, stream, descriptions, verbosity, pb=None,
bench_history=None):
+ """Construct new TestResult.
+
+ :param bench_history: Optionally, a writable file object to accumulate
+ benchmark results.
+ """
unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
self.pb = pb
if bench_history is not None:
- # XXX: If there's no branch, what should we do?
- branch = bzrlib.branch.Branch.open_containing(__file__)[0]
- revision_id = branch.last_revision()
+ from bzrlib.version import _get_bzr_source_tree
+ src_tree = _get_bzr_source_tree()
+ if src_tree:
+ revision_id = src_tree.last_revision()
+ else:
+ # XXX: If there's no branch, what should we do?
+ revision_id = ''
bench_history.write("--date %s %s\n" % (time.time(), revision_id))
self._bench_history = bench_history
@@ -411,7 +420,6 @@
class TestSkipped(Exception):
"""Indicates that a test was intentionally skipped, rather than failing."""
- # XXX: Not used yet
class CommandFailed(Exception):
@@ -1358,6 +1366,7 @@
'bzrlib.tests.test_upgrade',
'bzrlib.tests.test_urlutils',
'bzrlib.tests.test_versionedfile',
+ 'bzrlib.tests.test_version',
'bzrlib.tests.test_weave',
'bzrlib.tests.test_whitebox',
'bzrlib.tests.test_workingtree',
More information about the bazaar
mailing list