Skip to content

Commit

Permalink
Add TAGS as range parameter, fixes #488 fixes #1027
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Sep 13, 2024
1 parent ee3b187 commit d655133
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
23 changes: 15 additions & 8 deletions asv/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ def _setup_arguments(cls, parser, env_default_same=False):
rev-list``; or Mercurial log command. See 'specifying ranges'
section of the `gitrevisions` manpage, or 'hg help revisions',
for more info. Also accepts the
special values 'NEW', 'ALL', 'EXISTING', and 'HASHFILE:xxx'.
special values 'NEW', 'ALL', 'EXISTING', 'TAGS', and
'HASHFILE:xxx'.
'NEW' will benchmark all commits since the latest
benchmarked on this machine. 'ALL' will benchmark all
commits in the project. 'EXISTING' will benchmark against
all commits for which there are existing benchmarks on any
machine. 'HASHFILE:xxx' will benchmark only a specific set
of hashes given in the file named 'xxx' ('-' means stdin),
which must have one hash per line. By default, will benchmark
benchmarked on this machine.
'ALL' will benchmark all commits in the project.
'EXISTING' will benchmark against all commits for which there
are existing benchmarks on any machine.
'TAGS' will benchmark against all tags in the project.
'HASHFILE:xxx' will benchmark only a specific set of hashes
given in the file named 'xxx' ('-' means stdin), which must
have one hash per line.
By default, will benchmark
the head of each configured of the branches.""")
parser.add_argument(
"--date-period", type=common_args.time_period, default=None,
Expand Down Expand Up @@ -232,12 +236,15 @@ def run(cls, conf, range_spec=None, steps=None, date_period=None,
branch in conf.branches]))
except NoSuchNameError as exc:
raise util.UserError(f'Unknown branch {exc} in configuration')
elif range_spec == 'EXISTING':
elif range_spec == "EXISTING":
commit_hashes = get_existing_hashes(conf.results_dir)
elif range_spec == "NEW":
# New commits on each configured branches
old_commit_hashes = get_existing_hashes(conf.results_dir)
commit_hashes = repo.get_new_branch_commits(conf.branches, old_commit_hashes)
elif range_spec == "TAGS":
# All tags on each configured branches
commit_hashes = list(reversed(list(repo.get_tags().keys())))
elif range_spec == "ALL":
# All commits on each configured branches
commit_hashes = repo.get_new_branch_commits(conf.branches, [])
Expand Down
7 changes: 6 additions & 1 deletion test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def test_run_spec(basic_conf_2):
conf.build_cache_size = 5

extra_branches = [(f'{util.git_default_branch()}~1', 'some-branch', [12])]
tags = (2, 12)
dvcs_path = os.path.join(tmpdir, 'test_repo2')
dvcs = tools.generate_test_repo(dvcs_path, [1, 2],
extra_branches=extra_branches)
extra_branches=extra_branches,
tags=tags)
conf.repo = dvcs.path

initial_commit = dvcs.get_hash(f"{util.git_default_branch()}~1")
Expand Down Expand Up @@ -103,6 +105,9 @@ def _test_run(range_spec, branches, expected_commits):
for range_spec in (None, "NEW", "ALL"):
_test_run(range_spec, branches, expected_commits)

expected_tag_runs = (initial_commit, "tag2", "tag12")
_test_run("TAGS", [None], expected_tag_runs)

# test the HASHFILE version of range_spec'ing
expected_commits = (initial_commit, branch_commit)
with open(os.path.join(tmpdir, 'hashes_to_benchmark'), 'w') as f:
Expand Down
15 changes: 12 additions & 3 deletions test/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ def copy_template(src, dst, dvcs, values):


def generate_test_repo(tmpdir, values=[0], dvcs_type='git',
extra_branches=(), subdir=''):
extra_branches=(), tags=(),
subdir=''):
"""
Generate a test repository
Expand All @@ -363,6 +364,8 @@ def generate_test_repo(tmpdir, values=[0], dvcs_type='git',
For branch start commits, use relative references, e.g.,
the format 'main~10' or 'default~10' works both for Hg
and Git.
tags: list
List of of values from `values` to tag in the repository.
subdir
A relative subdirectory inside the repository to copy the
test project into.
Expand Down Expand Up @@ -400,7 +403,11 @@ def generate_test_repo(tmpdir, values=[0], dvcs_type='git',
copy_template(template_path, project_path, dvcs, mapping)

dvcs.commit(f"Revision {i}")
dvcs.tag(i)
if tags:
if value in tags:
dvcs.tag(value)
else:
dvcs.tag(i)

if extra_branches:
for start_commit, branch_name, values in extra_branches:
Expand All @@ -412,7 +419,9 @@ def generate_test_repo(tmpdir, values=[0], dvcs_type='git',
}
copy_template(template_path, project_path, dvcs, mapping)
dvcs.commit(f"Revision {branch_name}.{i}")

if tags:
if value in tags:
dvcs.tag(value)
return dvcs


Expand Down

0 comments on commit d655133

Please sign in to comment.