diff: address comments from review

* OSError -> FileNotFoundError
* Make `a_ref` optional
* Use absolute imports for unrelated packages
* Relpath: `str(output.path_info)` -> `str(output)`
* `a_ref` defaults to `HEAD` at the signature and parser level
This commit is contained in:
Mr. Outis
2020-01-24 10:05:44 -06:00
parent 198bf55aaf
commit ebd5a5a7f3
2 changed files with 10 additions and 10 deletions
+5 -2
View File
@@ -32,13 +32,16 @@ def add_parser(subparsers, parent_parser):
formatter_class=argparse.RawDescriptionHelpFormatter,
)
diff_parser.add_argument(
"a_ref", help="Git reference from which diff calculates"
"a_ref",
help="Git reference from which diff calculates (defaults to HEAD)",
nargs="?",
default="HEAD"
)
diff_parser.add_argument(
"b_ref",
help=(
"Git reference until which diff calculates, if omitted "
"diff shows the difference between current HEAD and a_ref"
"diff shows the difference between the working tree and a_ref"
),
nargs="?",
)
+5 -8
View File
@@ -1,8 +1,8 @@
import os
import collections
from . import locked
from ..compat import fspath
from dvc.repo import locked
from dvc.compat import fspath
Diffable = collections.namedtuple("Diffable", "filename, checksum, size")
@@ -12,16 +12,14 @@ Diffable.__doc__ = "Common interface for comparable entries."
def diffable_from_output(output):
try:
size = os.path.getsize(fspath(output.path_info))
except OSError:
except FileNotFoundError:
size = None
return Diffable(
filename=str(output.path_info), checksum=output.checksum, size=size
)
return Diffable(filename=str(output), checksum=output.checksum, size=size)
@locked
def diff(self, a_ref=None, b_ref=None, *, target=None):
def diff(self, a_ref="HEAD", b_ref=None, *, target=None):
"""
By default, it compares the working tree with the last commit's tree.
@@ -30,7 +28,6 @@ def diff(self, a_ref=None, b_ref=None, *, target=None):
This implementation differs from `git diff`, since DVC doesn't have
the concept of `index`, `dvc diff` would be the same as `dvc diff HEAD`.
"""
a_ref = a_ref or "HEAD"
outs = {}
for branch in self.brancher(revs=[a_ref, b_ref]):