Permalink
Browse files

Cache the version number.

The version number is checked on each commit. We only need to
check once and remember.
  • Loading branch information...
1 parent 38904f7 commit c9ea59bd1fa315e6a8f162bc256f75436b3f78b7 @friedelwolff friedelwolff committed Apr 25, 2012
Showing with 19 additions and 3 deletions.
  1. +9 −1 translate/storage/versioncontrol/bzr.py
  2. +10 −2 translate/storage/versioncontrol/hg.py
@@ -30,8 +30,15 @@ def is_available():
return exitcode == 0
+_version = None
+
+
def get_version():
"""return a tuple of (major, minor) for the installed bazaar client"""
+ global _version
+ if _version:
+ return _version
+
import re
command = ["bzr", "--version"]
exitcode, output, error = run_command(command)
@@ -41,7 +48,8 @@ def get_version():
if version_match:
major, minor = version_match.group().split(".")
if (major.isdigit() and minor.isdigit()):
- return (int(major), int(minor))
+ _version = (int(major), int(minor))
+ return _version
# if anything broke before, then we return the invalid version number
return (0, 0)
@@ -29,8 +29,15 @@ def is_available():
return exitcode == 0
+_version = None
+
+
def get_version():
- """return a tuple of (major, minor) for the installed bazaar client"""
+ """Return a tuple of (major, minor) for the installed mercurial client."""
+ global _version
+ if _version:
+ return _version
+
import re
command = ["hg", "--version"]
exitcode, output, error = run_command(command)
@@ -40,7 +47,8 @@ def get_version():
if version_match:
major, minor = version_match.group().split(".")
if (major.isdigit() and minor.isdigit()):
- return (int(major), int(minor))
+ _version = (int(major), int(minor))
+ return _version
# if anything broke before, then we return the invalid version number
return (0, 0)

0 comments on commit c9ea59b

Please sign in to comment.