From 1bf94fac44a93728caa09df2883b726d17b1dce3 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Sun, 17 Nov 2024 20:50:39 +0000 Subject: [PATCH] Reduce the number of calls to git to get source information MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s a notable delay when ReBench starts, and this might be one source of it. Instead of doing repeated calls to `git show`, pack everything into one call and use \0 as delimiter. Signed-off-by: Stefan Marr --- rebench/environment.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/rebench/environment.py b/rebench/environment.py index f350aa33..c9810f32 100644 --- a/rebench/environment.py +++ b/rebench/environment.py @@ -46,6 +46,17 @@ def git_repo_not_initialized(): return _exec(["git", "rev-parse"]) is None +_commit_info_format = { + "branchOrTag": "%D", + "commitMsg": "%B", + "authorName": "%aN", + "committerName": "%cN", + "authorEmail": "%aE", + "committerEmail": "%cE" +} + +_commit_info_format_str = "%x00".join(_commit_info_format.values()) + def determine_source_details(configurator): global _source # pylint: disable=global-statement if _source: @@ -56,7 +67,8 @@ def determine_source_details(configurator): if configurator and configurator.options and configurator.options.git_repo: git_cmd += ["-C", configurator.options.git_repo] - is_git_repo = _exec(git_cmd + ["rev-parse"]) is not None + commit_id = _exec(git_cmd + ["rev-parse", "HEAD"]) + is_git_repo = commit_id is not None if not is_git_repo: result["repoURL"] = None result["branchOrTag"] = None @@ -80,13 +92,17 @@ def determine_source_details(configurator): netloc="{}@{}".format(parsed.username, parsed.hostname)) result['repoURL'] = _encode_str(parsed.geturl()) - result['branchOrTag'] = extract_base(_exec(git_cmd + ['show', '-s', '--format=%D', 'HEAD'])) - result['commitId'] = _exec(git_cmd + ['rev-parse', 'HEAD']) - result['commitMsg'] = _exec(git_cmd + ['show', '-s', '--format=%B', 'HEAD']) - result['authorName'] = _exec(git_cmd + ['show', '-s', '--format=%aN', 'HEAD']) - result['committerName'] = _exec(git_cmd + ['show', '-s', '--format=%cN', 'HEAD']) - result['authorEmail'] = _exec(git_cmd + ['show', '-s', '--format=%aE', 'HEAD']) - result['committerEmail'] = _exec(git_cmd + ['show', '-s', '--format=%cE', 'HEAD']) + commit_info = _exec(git_cmd + ['show', '-s', '--format=' + _commit_info_format_str, 'HEAD']) + info = commit_info.split("\x00") + assert len(info) == len(_commit_info_format), "Unexpected number of fields in commit info" + + result['branchOrTag'] = extract_base(info[0]) + result['commitId'] = commit_id + result['commitMsg'] = info[1] + result['authorName'] = info[2] + result['committerName'] = info[3] + result['authorEmail'] = info[4] + result['committerEmail'] = info[5] _source = result return result