Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the number of calls to git to get source information #275

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions rebench/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down