Dvc: Support @ as HEAD

Created on 22 Oct 2020  路  4Comments  路  Source: iterative/dvc

Git supports the usage of the at symbol @ and it is equivalent to HEAD (more details).

If I am not mistaken, dvc does not support it. At least the following command fails for dvc==1.8.4:

dvc metrics diff master @
ERROR: failed to show metrics diff - unknown Git revision '@'   

Thank you in advance for the response!

bug good first issue help wanted

Most helpful comment

If no one is taking this issue. I will take this - https://github.com/iterative/dvc/pull/4824

All 4 comments

For the record: verbose log:

2020-10-23 00:16:30,921 DEBUG: Check for update is enabled.
2020-10-23 00:16:30,927 DEBUG: fetched: [(3,)]
2020-10-23 00:16:30,944 DEBUG: fetched: [(0,)]
2020-10-23 00:16:30,957 DEBUG: fetched: [(3,)]
2020-10-23 00:16:30,961 DEBUG: fetched: [(0,)]
2020-10-23 00:16:30,966 ERROR: failed to show metrics diff - unknown Git revision '@'
------------------------------------------------------------
Traceback (most recent call last):
  File "/home/efiop/git/indhupriya/dvc/dvc/scm/git.py", line 418, in _resolve_rev
    return self.repo.rev_parse(name).hexsha
  File "/home/efiop/git/GitPython/git/repo/fun.py", line 325, in rev_parse
    raise ValueError("Invalid token: %r" % token)
ValueError: Invalid token: '@'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/efiop/git/indhupriya/dvc/dvc/command/metrics.py", line 129, in run
    diff = self.repo.metrics.diff(
  File "/home/efiop/git/indhupriya/dvc/dvc/repo/metrics/__init__.py", line 13, in diff
    return diff(self.repo, *args, **kwargs)
  File "/home/efiop/git/indhupriya/dvc/dvc/repo/metrics/diff.py", line 23, in diff
    new = _get_metrics(repo, *args, **kwargs, rev=b_rev)
  File "/home/efiop/git/indhupriya/dvc/dvc/repo/metrics/diff.py", line 8, in _get_metrics
    metrics = repo.metrics.show(
  File "/home/efiop/git/indhupriya/dvc/dvc/repo/metrics/__init__.py", line 8, in show
    return show(self.repo, *args, **kwargs)
  File "/home/efiop/git/indhupriya/dvc/dvc/repo/__init__.py", line 51, in wrapper
    return f(repo, *args, **kwargs)
  File "/home/efiop/git/indhupriya/dvc/dvc/repo/metrics/show.py", line 84, in show
    for rev in repo.brancher(
  File "/home/efiop/git/indhupriya/dvc/dvc/repo/brancher.py", line 55, in brancher
    for sha, names in group_by(scm.resolve_rev, revs).items():
  File "/home/efiop/.pyenv/versions/3.8.3/envs/dvc-3.8.3/lib/python3.8/site-packages/funcy/seqs.py", line 317, in group_by
    result[f(item)].append(item)
  File "/home/efiop/git/indhupriya/dvc/dvc/scm/git.py", line 426, in resolve_rev
    sha = _resolve_rev(rev)
  File "/home/efiop/git/indhupriya/dvc/dvc/scm/git.py", line 423, in _resolve_rev
    raise RevError(f"unknown Git revision '{name}'")
dvc.scm.base.RevError: unknown Git revision '@'
------------------------------------------------------------
2020-10-23 00:16:30,968 DEBUG: Analytics is enabled.
2020-10-23 00:16:31,008 DEBUG: Trying to spawn '['daemon', '-q', 'analytics', '/tmp/tmpi2np7eyi']'
2020-10-23 00:16:31,009 DEBUG: Spawned '['daemon', '-q', 'analytics', '/tmp/tmpi2np7eyi']'

Yep, can confirm that changing https://github.com/iterative/dvc/blob/ec05e6026f73e6912db5a25ed091aca1f1b828b0/dvc/scm/git.py#L418 to repo.git.rev_parse does solve the issue. We use gitpython's pure-python implementation for rev-parse because it is faster and we fallback to git's rev-parse if it is not implemented in gitpython. We might try to fallback to it on ValueError as well though, but need to check if that won't degrade the performance for the happy path.

Another (much better) option is to fix it on gitpython's side https://github.com/gitpython-developers/GitPython/blob/master/git/repo/fun.py#L325 . Likely just need to add this special case to the logic. And we could also add that special case to our codebase while we are waiting for gitpython's release with the fix.

If no one is taking this issue. I will take this - https://github.com/iterative/dvc/pull/4824

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GildedHonour picture GildedHonour  路  3Comments

ghost picture ghost  路  3Comments

gregfriedland picture gregfriedland  路  3Comments

TezRomacH picture TezRomacH  路  3Comments

analystanand picture analystanand  路  3Comments