mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
change diff checksum arg name to hash (#3384)
This commit is contained in:
+5
-5
@@ -28,7 +28,7 @@ class CmdDiff(CmdBase):
|
||||
dir/
|
||||
dir/1
|
||||
|
||||
An example of a diff formatted when entries contain checksums:
|
||||
An example of a diff formatted when entries contain hash:
|
||||
|
||||
Added:
|
||||
d3b07384 foo
|
||||
@@ -66,7 +66,7 @@ class CmdDiff(CmdBase):
|
||||
|
||||
for entry in entries:
|
||||
path = entry["path"]
|
||||
checksum = entry.get("checksum")
|
||||
checksum = entry.get("hash")
|
||||
summary[state] += 1 if not path.endswith(os.sep) else 0
|
||||
content.append(
|
||||
"{space}{checksum}{separator}{path}".format(
|
||||
@@ -100,10 +100,10 @@ class CmdDiff(CmdBase):
|
||||
if not any(diff.values()):
|
||||
return 0
|
||||
|
||||
if not self.args.checksums:
|
||||
if not self.args.show_hash:
|
||||
for _, entries in diff.items():
|
||||
for entry in entries:
|
||||
del entry["checksum"]
|
||||
del entry["hash"]
|
||||
|
||||
if self.args.show_json:
|
||||
res = json.dumps(diff)
|
||||
@@ -149,7 +149,7 @@ def add_parser(subparsers, parent_parser):
|
||||
default=False,
|
||||
)
|
||||
diff_parser.add_argument(
|
||||
"--checksums",
|
||||
"--show-hash",
|
||||
help="Display hash value for each entry",
|
||||
action="store_true",
|
||||
default=False,
|
||||
|
||||
+3
-3
@@ -66,10 +66,10 @@ def diff(self, a_rev="HEAD", b_rev=None):
|
||||
modified = sorted(set(old) & set(new))
|
||||
|
||||
return {
|
||||
"added": [{"path": path, "checksum": new[path]} for path in added],
|
||||
"deleted": [{"path": path, "checksum": old[path]} for path in deleted],
|
||||
"added": [{"path": path, "hash": new[path]} for path in added],
|
||||
"deleted": [{"path": path, "hash": old[path]} for path in deleted],
|
||||
"modified": [
|
||||
{"path": path, "checksum": {"old": old[path], "new": new[path]}}
|
||||
{"path": path, "hash": {"old": old[path], "new": new[path]}}
|
||||
for path in modified
|
||||
if old[path] != new[path]
|
||||
],
|
||||
|
||||
@@ -21,7 +21,7 @@ _dvc_commit='-f --force -d --with-deps -R --recursive'
|
||||
_dvc_commit_COMPGEN=_dvc_compgen_DVCFiles
|
||||
_dvc_config='-u --unset --local --system --global'
|
||||
_dvc_destroy='-f --force'
|
||||
_dvc_diff='-t --show-json --checksums'
|
||||
_dvc_diff='-t --show-json --show-hash'
|
||||
_dvc_fetch='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive'
|
||||
_dvc_fetch_COMPGEN=_dvc_compgen_DVCFiles
|
||||
_dvc_get_url=''
|
||||
|
||||
@@ -99,7 +99,7 @@ _dvc_destroy=(
|
||||
|
||||
_dvc_diff=(
|
||||
"--show-json[Format the output into a JSON]"
|
||||
"--checksums[Display checksums for each entry]"
|
||||
"--show-hash[Display hash value for each entry]"
|
||||
"1:Old Git commit to compare (defaults to HEAD):"
|
||||
"2:New Git commit to compare (defaults to the current workspace):"
|
||||
)
|
||||
@@ -254,7 +254,6 @@ _dvc_run=(
|
||||
|
||||
_dvc_status=(
|
||||
{-j,--jobs}"[Number of jobs to run simultaneously.]:Number of jobs:"
|
||||
"--show-checksums[Show checksums instead of file names.]"
|
||||
{-q,--quiet}"[Suppresses all output. Exit with 0 if pipelines are up to date, otherwise 1.]"
|
||||
{-c,--cloud}"[Show status of a local cache compared to a remote repository.]"
|
||||
{-r,--remote}"[Remote repository to compare local cache to.]:Remote repository:"
|
||||
|
||||
+17
-23
@@ -22,7 +22,7 @@ def test_added(tmp_dir, scm, dvc):
|
||||
tmp_dir.dvc_gen("file", "text")
|
||||
|
||||
assert dvc.diff() == {
|
||||
"added": [{"path": "file", "checksum": digest("text")}],
|
||||
"added": [{"path": "file", "hash": digest("text")}],
|
||||
"deleted": [],
|
||||
"modified": [],
|
||||
}
|
||||
@@ -41,15 +41,15 @@ def test_no_cache_entry(tmp_dir, scm, dvc):
|
||||
|
||||
assert dvc.diff() == {
|
||||
"added": [
|
||||
{"path": os.path.join("dir", ""), "checksum": dir_checksum},
|
||||
{"path": os.path.join("dir", "1"), "checksum": digest("1")},
|
||||
{"path": os.path.join("dir", "2"), "checksum": digest("2")},
|
||||
{"path": os.path.join("dir", ""), "hash": dir_checksum},
|
||||
{"path": os.path.join("dir", "1"), "hash": digest("1")},
|
||||
{"path": os.path.join("dir", "2"), "hash": digest("2")},
|
||||
],
|
||||
"deleted": [],
|
||||
"modified": [
|
||||
{
|
||||
"path": "file",
|
||||
"checksum": {"old": digest("first"), "new": digest("second")},
|
||||
"hash": {"old": digest("first"), "new": digest("second")},
|
||||
}
|
||||
],
|
||||
}
|
||||
@@ -61,7 +61,7 @@ def test_deleted(tmp_dir, scm, dvc):
|
||||
|
||||
assert dvc.diff() == {
|
||||
"added": [],
|
||||
"deleted": [{"path": "file", "checksum": digest("text")}],
|
||||
"deleted": [{"path": "file", "hash": digest("text")}],
|
||||
"modified": [],
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ def test_modified(tmp_dir, scm, dvc):
|
||||
"modified": [
|
||||
{
|
||||
"path": "file",
|
||||
"checksum": {"old": digest("first"), "new": digest("second")},
|
||||
"hash": {"old": digest("first"), "new": digest("second")},
|
||||
}
|
||||
],
|
||||
}
|
||||
@@ -94,17 +94,13 @@ def test_refs(tmp_dir, scm, dvc):
|
||||
assert dvc.diff("HEAD~1") == {
|
||||
"added": [],
|
||||
"deleted": [],
|
||||
"modified": [
|
||||
{"path": "file", "checksum": {"old": HEAD_1, "new": HEAD}}
|
||||
],
|
||||
"modified": [{"path": "file", "hash": {"old": HEAD_1, "new": HEAD}}],
|
||||
}
|
||||
|
||||
assert dvc.diff("HEAD~2", "HEAD~1") == {
|
||||
"added": [],
|
||||
"deleted": [],
|
||||
"modified": [
|
||||
{"path": "file", "checksum": {"old": HEAD_2, "new": HEAD_1}}
|
||||
],
|
||||
"modified": [{"path": "file", "hash": {"old": HEAD_2, "new": HEAD_1}}],
|
||||
}
|
||||
|
||||
with pytest.raises(DvcException, match=r"unknown Git revision 'missing'"):
|
||||
@@ -128,42 +124,40 @@ def test_directories(tmp_dir, scm, dvc):
|
||||
"added": [
|
||||
{
|
||||
"path": os.path.join("dir", ""),
|
||||
"checksum": "5fb6b29836c388e093ca0715c872fe2a.dir",
|
||||
"hash": "5fb6b29836c388e093ca0715c872fe2a.dir",
|
||||
},
|
||||
{"path": os.path.join("dir", "1"), "checksum": digest("1")},
|
||||
{"path": os.path.join("dir", "2"), "checksum": digest("2")},
|
||||
{"path": os.path.join("dir", "1"), "hash": digest("1")},
|
||||
{"path": os.path.join("dir", "2"), "hash": digest("2")},
|
||||
],
|
||||
"deleted": [],
|
||||
"modified": [],
|
||||
}
|
||||
|
||||
assert dvc.diff(":/directory", ":/modify") == {
|
||||
"added": [{"path": os.path.join("dir", "3"), "checksum": digest("3")}],
|
||||
"added": [{"path": os.path.join("dir", "3"), "hash": digest("3")}],
|
||||
"deleted": [],
|
||||
"modified": [
|
||||
{
|
||||
"path": os.path.join("dir", ""),
|
||||
"checksum": {
|
||||
"hash": {
|
||||
"old": "5fb6b29836c388e093ca0715c872fe2a.dir",
|
||||
"new": "9b5faf37366b3370fd98e3e60ca439c1.dir",
|
||||
},
|
||||
},
|
||||
{
|
||||
"path": os.path.join("dir", "2"),
|
||||
"checksum": {"old": digest("2"), "new": digest("two")},
|
||||
"hash": {"old": digest("2"), "new": digest("two")},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
assert dvc.diff(":/modify", ":/delete") == {
|
||||
"added": [],
|
||||
"deleted": [
|
||||
{"path": os.path.join("dir", "2"), "checksum": digest("two")}
|
||||
],
|
||||
"deleted": [{"path": os.path.join("dir", "2"), "hash": digest("two")}],
|
||||
"modified": [
|
||||
{
|
||||
"path": os.path.join("dir", ""),
|
||||
"checksum": {
|
||||
"hash": {
|
||||
"old": "9b5faf37366b3370fd98e3e60ca439c1.dir",
|
||||
"new": "83ae82fb367ac9926455870773ff09e6.dir",
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ def test_default(mocker, caplog):
|
||||
args = parse_args(["diff"])
|
||||
cmd = args.func(args)
|
||||
diff = {
|
||||
"added": [{"path": "file", "checksum": "00000000"}],
|
||||
"added": [{"path": "file", "hash": "00000000"}],
|
||||
"deleted": [],
|
||||
"modified": [],
|
||||
}
|
||||
@@ -23,21 +23,18 @@ def test_default(mocker, caplog):
|
||||
) in caplog.text
|
||||
|
||||
|
||||
def test_checksums(mocker, caplog):
|
||||
args = parse_args(["diff", "--checksums"])
|
||||
def test_show_hash(mocker, caplog):
|
||||
args = parse_args(["diff", "--show-hash"])
|
||||
cmd = args.func(args)
|
||||
diff = {
|
||||
"added": [],
|
||||
"deleted": [
|
||||
{"path": os.path.join("data", ""), "checksum": "XXXXXXXX.dir"},
|
||||
{"path": os.path.join("data", "bar"), "checksum": "00000000"},
|
||||
{"path": os.path.join("data", "foo"), "checksum": "11111111"},
|
||||
{"path": os.path.join("data", ""), "hash": "XXXXXXXX.dir"},
|
||||
{"path": os.path.join("data", "bar"), "hash": "00000000"},
|
||||
{"path": os.path.join("data", "foo"), "hash": "11111111"},
|
||||
],
|
||||
"modified": [
|
||||
{
|
||||
"path": "file",
|
||||
"checksum": {"old": "AAAAAAAA", "new": "BBBBBBBB"},
|
||||
}
|
||||
{"path": "file", "hash": {"old": "AAAAAAAA", "new": "BBBBBBBB"}}
|
||||
],
|
||||
}
|
||||
mocker.patch("dvc.repo.Repo.diff", return_value=diff)
|
||||
@@ -55,11 +52,11 @@ def test_checksums(mocker, caplog):
|
||||
) in caplog.text
|
||||
|
||||
|
||||
def test_json(mocker, caplog):
|
||||
def test_show_json(mocker, caplog):
|
||||
args = parse_args(["diff", "--show-json"])
|
||||
cmd = args.func(args)
|
||||
diff = {
|
||||
"added": [{"path": "file", "checksum": "00000000"}],
|
||||
"added": [{"path": "file", "hash": "00000000"}],
|
||||
"deleted": [],
|
||||
"modified": [],
|
||||
}
|
||||
@@ -71,16 +68,14 @@ def test_json(mocker, caplog):
|
||||
assert '"modified": []' in caplog.text
|
||||
|
||||
|
||||
def test_json_checksums(mocker, caplog):
|
||||
args = parse_args(["diff", "--show-json", "--checksums"])
|
||||
def test_show_json_and_hash(mocker, caplog):
|
||||
args = parse_args(["diff", "--show-json", "--show-hash"])
|
||||
cmd = args.func(args)
|
||||
|
||||
diff = {
|
||||
"added": [
|
||||
# py35: maintain a consistent key order for tests purposes
|
||||
collections.OrderedDict(
|
||||
[("path", "file"), ("checksum", "00000000")]
|
||||
)
|
||||
collections.OrderedDict([("path", "file"), ("hash", "00000000")])
|
||||
],
|
||||
"deleted": [],
|
||||
"modified": [],
|
||||
@@ -88,6 +83,6 @@ def test_json_checksums(mocker, caplog):
|
||||
mocker.patch("dvc.repo.Repo.diff", return_value=diff)
|
||||
|
||||
assert 0 == cmd.run()
|
||||
assert '"added": [{"path": "file", "checksum": "00000000"}]' in caplog.text
|
||||
assert '"added": [{"path": "file", "hash": "00000000"}]' in caplog.text
|
||||
assert '"deleted": []' in caplog.text
|
||||
assert '"modified": []' in caplog.text
|
||||
|
||||
Reference in New Issue
Block a user