diff options
author | Mike Frysinger <vapier@google.com> | 2021-05-06 00:28:32 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-05-06 18:36:25 +0000 |
commit | 8e768eaaa722a99405f6542ac718880c8c22f060 (patch) | |
tree | 652e0b64c3b1ac810162acc4b9d35f4f265bb6a2 /git_command.py | |
parent | 2f8fdbecde985e2a5ecf498d97d0d3ea9d1a6865 (diff) | |
download | git-repo-8e768eaaa722a99405f6542ac718880c8c22f060.tar.gz |
git_command: switch version caches to functools
Simplifies the code a bit to use the stdlib cache helper.
Change-Id: I778e90100ce748a71cc3a5a5d67dda403334315e
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/305482
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'git_command.py')
-rw-r--r-- | git_command.py | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/git_command.py b/git_command.py index d06fc77c..f8cb280c 100644 --- a/git_command.py +++ b/git_command.py | |||
@@ -12,6 +12,7 @@ | |||
12 | # See the License for the specific language governing permissions and | 12 | # See the License for the specific language governing permissions and |
13 | # limitations under the License. | 13 | # limitations under the License. |
14 | 14 | ||
15 | import functools | ||
15 | import os | 16 | import os |
16 | import re | 17 | import re |
17 | import sys | 18 | import sys |
@@ -45,7 +46,6 @@ LAST_CWD = None | |||
45 | _ssh_proxy_path = None | 46 | _ssh_proxy_path = None |
46 | _ssh_sock_path = None | 47 | _ssh_sock_path = None |
47 | _ssh_clients = [] | 48 | _ssh_clients = [] |
48 | _ssh_version = None | ||
49 | 49 | ||
50 | 50 | ||
51 | def _run_ssh_version(): | 51 | def _run_ssh_version(): |
@@ -64,16 +64,14 @@ def _parse_ssh_version(ver_str=None): | |||
64 | return () | 64 | return () |
65 | 65 | ||
66 | 66 | ||
67 | @functools.lru_cache(maxsize=None) | ||
67 | def ssh_version(): | 68 | def ssh_version(): |
68 | """return ssh version as a tuple""" | 69 | """return ssh version as a tuple""" |
69 | global _ssh_version | 70 | try: |
70 | if _ssh_version is None: | 71 | return _parse_ssh_version() |
71 | try: | 72 | except subprocess.CalledProcessError: |
72 | _ssh_version = _parse_ssh_version() | 73 | print('fatal: unable to detect ssh version', file=sys.stderr) |
73 | except subprocess.CalledProcessError: | 74 | sys.exit(1) |
74 | print('fatal: unable to detect ssh version', file=sys.stderr) | ||
75 | sys.exit(1) | ||
76 | return _ssh_version | ||
77 | 75 | ||
78 | 76 | ||
79 | def ssh_sock(create=True): | 77 | def ssh_sock(create=True): |
@@ -125,18 +123,14 @@ def terminate_ssh_clients(): | |||
125 | _ssh_clients = [] | 123 | _ssh_clients = [] |
126 | 124 | ||
127 | 125 | ||
128 | _git_version = None | ||
129 | |||
130 | |||
131 | class _GitCall(object): | 126 | class _GitCall(object): |
127 | @functools.lru_cache(maxsize=None) | ||
132 | def version_tuple(self): | 128 | def version_tuple(self): |
133 | global _git_version | 129 | ret = Wrapper().ParseGitVersion() |
134 | if _git_version is None: | 130 | if ret is None: |
135 | _git_version = Wrapper().ParseGitVersion() | 131 | print('fatal: unable to detect git version', file=sys.stderr) |
136 | if _git_version is None: | 132 | sys.exit(1) |
137 | print('fatal: unable to detect git version', file=sys.stderr) | 133 | return ret |
138 | sys.exit(1) | ||
139 | return _git_version | ||
140 | 134 | ||
141 | def __getattr__(self, name): | 135 | def __getattr__(self, name): |
142 | name = name.replace('_', '-') | 136 | name = name.replace('_', '-') |