experiments: fix --all-tags/--all-branches bug (#4612)

* brancher: add sha_only option to omit branch/tag names

* experiments: resolve branches/tags into commit objects during `exp show`
This commit is contained in:
Peter Rowlands (변기호)
2020-09-24 22:48:57 +03:00
committed by GitHub
parent 2f030e870b
commit 36935bdce2
2 changed files with 22 additions and 3 deletions
+11 -2
View File
@@ -4,7 +4,12 @@ from dvc.tree.local import LocalTree
def brancher( # noqa: E302
self, revs=None, all_branches=False, all_tags=False, all_commits=False
self,
revs=None,
all_branches=False,
all_tags=False,
all_commits=False,
sha_only=False,
):
"""Generator that iterates over specified revisions.
@@ -13,6 +18,7 @@ def brancher( # noqa: E302
all_branches (bool): iterate over all available branches.
all_commits (bool): iterate over all commits.
all_tags (bool): iterate over all available tags.
sha_only (bool): only return git SHA for a revision.
Yields:
str: the display name for the currently selected tree, it could be:
@@ -53,6 +59,9 @@ def brancher( # noqa: E302
# ignore revs that don't contain repo root
# (i.e. revs from before a subdir=True repo was init'ed)
if self.tree.exists(self.root_dir):
yield ", ".join(names)
if sha_only:
yield sha
else:
yield ", ".join(names)
finally:
self.tree = saved_tree
+11 -1
View File
@@ -17,7 +17,7 @@ def _collect_experiment(repo, branch, stash=False, sha_only=True):
if rev == "workspace":
res["timestamp"] = None
else:
commit = repo.scm.repo.rev_parse(rev)
commit = _resolve_commit(repo, rev)
res["timestamp"] = datetime.fromtimestamp(commit.committed_date)
configs = _collect_configs(repo)
@@ -44,6 +44,15 @@ def _collect_experiment(repo, branch, stash=False, sha_only=True):
return res
def _resolve_commit(repo, rev):
from git.objects.tag import TagObject
commit = repo.scm.repo.rev_parse(rev)
if isinstance(commit, TagObject):
commit = commit.object
return commit
@locked
def show(
repo,
@@ -65,6 +74,7 @@ def show(
all_branches=all_branches,
all_tags=all_tags,
all_commits=all_commits,
sha_only=True,
)
)