mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 22:37:37 +03:00
add json format option for hg cloud check
command
Summary: add json format option for `hg cloud check` command Reviewed By: mitrandir77 Differential Revision: D41519613 fbshipit-source-id: 367cbb324c3144f1ca55a4ce55cb346e8f01ba37
This commit is contained in:
parent
bd62e73d60
commit
b349df3818
@ -113,6 +113,21 @@ This test also checks file content deduplication. We upload 1 file content and 1
|
|||||||
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False
|
||||||
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 not backed up
|
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 not backed up
|
||||||
|
|
||||||
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False --remote
|
||||||
|
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 not backed up
|
||||||
|
|
||||||
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --json
|
||||||
|
{"536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9": false} (no-eol)
|
||||||
|
|
||||||
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --remote --json
|
||||||
|
{"536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9": false} (no-eol)
|
||||||
|
|
||||||
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False --json
|
||||||
|
{"536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9": false} (no-eol)
|
||||||
|
|
||||||
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False --remote --json
|
||||||
|
{"536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9": false} (no-eol)
|
||||||
|
|
||||||
$ EDENSCM_LOG="edenapi::client=info" hgedenapi cloud upload
|
$ EDENSCM_LOG="edenapi::client=info" hgedenapi cloud upload
|
||||||
INFO edenapi::client: Requesting capabilities for repo repo
|
INFO edenapi::client: Requesting capabilities for repo repo
|
||||||
INFO edenapi::client: Requesting lookup for 1 item(s)
|
INFO edenapi::client: Requesting lookup for 1 item(s)
|
||||||
@ -135,14 +150,29 @@ This test also checks file content deduplication. We upload 1 file content and 1
|
|||||||
|
|
||||||
$ EDENSCM_LOG="edenapi::client=info" hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 # no remote check
|
$ EDENSCM_LOG="edenapi::client=info" hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 # no remote check
|
||||||
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 backed up
|
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 backed up
|
||||||
|
|
||||||
|
$ EDENSCM_LOG="edenapi::client=info" hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --json # no remote check (json)
|
||||||
|
{"536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9": true} (no-eol)
|
||||||
|
|
||||||
$ EDENSCM_LOG="edenapi::client=info" hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --remote # remote check
|
$ EDENSCM_LOG="edenapi::client=info" hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --remote # remote check
|
||||||
INFO edenapi::client: Requesting lookup for 1 item(s)
|
INFO edenapi::client: Requesting lookup for 1 item(s)
|
||||||
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 backed up
|
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 backed up
|
||||||
|
|
||||||
|
$ EDENSCM_LOG="edenapi::client=info" hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --remote --json 2>/dev/null # remote check (json)
|
||||||
|
{"536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9": true} (no-eol)
|
||||||
|
|
||||||
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False
|
||||||
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 backed up
|
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 backed up
|
||||||
|
|
||||||
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False --json # legacy code (json)
|
||||||
|
{"536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9": true} (no-eol)
|
||||||
|
|
||||||
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False --remote # legacy code remote check
|
||||||
|
536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 backed up
|
||||||
|
|
||||||
|
$ hgedenapi cloud check -r 536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9 --config commitcloud.usehttpupload=False --remote --json # legacy remote check (json)
|
||||||
|
{"536d3fb3929eab4b01e63ab7fc9b25a5c8a08bc9": true} (no-eol)
|
||||||
|
|
||||||
|
|
||||||
Make another commit in the first client and upload it
|
Make another commit in the first client and upload it
|
||||||
The files of the second commit are identical to the files of the first commit, so we don't expect any new content uploads
|
The files of the second commit are identical to the files of the first commit, so we don't expect any new content uploads
|
||||||
|
@ -21,7 +21,6 @@ from edenscm import (
|
|||||||
pycompat,
|
pycompat,
|
||||||
registrar,
|
registrar,
|
||||||
scmutil,
|
scmutil,
|
||||||
templatefilters,
|
|
||||||
util,
|
util,
|
||||||
visibility,
|
visibility,
|
||||||
)
|
)
|
||||||
@ -1355,6 +1354,7 @@ def cloudrecover(ui, repo, **opts):
|
|||||||
[
|
[
|
||||||
("r", "rev", [], _("show the specified revision or revset"), _("REV")),
|
("r", "rev", [], _("show the specified revision or revset"), _("REV")),
|
||||||
("", "remote", None, _("check on the remote server")),
|
("", "remote", None, _("check on the remote server")),
|
||||||
|
("", "json", None, _("output in json format instead of human-readable")),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def cloudcheck(ui, repo, **opts):
|
def cloudcheck(ui, repo, **opts):
|
||||||
@ -1364,45 +1364,55 @@ def cloudcheck(ui, repo, **opts):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
remote = opts.get("remote")
|
remote = opts.get("remote")
|
||||||
|
jsondisplayer = opts.get("json")
|
||||||
revs = opts.get("rev")
|
revs = opts.get("rev")
|
||||||
|
|
||||||
if not revs:
|
if not revs:
|
||||||
revs = ["."]
|
revs = ["."]
|
||||||
|
|
||||||
if ui.configbool("commitcloud", "usehttpupload") and remote:
|
|
||||||
# eden api based lookup
|
|
||||||
nodestocheck = [repo[r].node() for r in scmutil.revrange(repo, revs)]
|
|
||||||
missingnodes = set(edenapi_upload._filtercommits(repo, nodestocheck))
|
|
||||||
for n in nodestocheck:
|
|
||||||
ui.write(nodemod.hex(n), " ")
|
|
||||||
ui.write(_("backed up") if not (n in missingnodes) else _("not backed up"))
|
|
||||||
ui.write(_("\n"))
|
|
||||||
return
|
|
||||||
|
|
||||||
unfi = repo
|
unfi = repo
|
||||||
revs = scmutil.revrange(repo, revs)
|
revs = scmutil.revrange(repo, revs)
|
||||||
nodestocheck = [repo[r].hex() for r in revs]
|
helperkey = "results"
|
||||||
|
|
||||||
if remote:
|
if ui.configbool("commitcloud", "usehttpupload") and remote:
|
||||||
# wireproto based lookup
|
# eden api based lookup
|
||||||
remotepath = ccutil.getremotepath(ui)
|
nodestocheck = [repo[r].node() for r in revs]
|
||||||
getconnection = lambda: repo.connectionpool.get(remotepath, opts)
|
missingnodes = set(edenapi_upload._filtercommits(repo, nodestocheck))
|
||||||
isbackedup = {
|
results = {
|
||||||
nodestocheck[i]: res
|
helperkey: {nodemod.hex(n): n not in missingnodes for n in nodestocheck}
|
||||||
for i, res in enumerate(
|
|
||||||
dependencies.infinitepush.isbackedupnodes(getconnection, nodestocheck)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
# local backup state based lookup
|
nodestocheck = [repo[r].hex() for r in revs]
|
||||||
backeduprevs = unfi.revs("backedup()")
|
if remote:
|
||||||
isbackedup = {
|
# wireproto based lookup
|
||||||
node: (unfi[node].rev() in backeduprevs) or not unfi[node].mutable()
|
remotepath = ccutil.getremotepath(ui)
|
||||||
for node in nodestocheck
|
getconnection = lambda: repo.connectionpool.get(remotepath, opts)
|
||||||
}
|
isbackedup = {
|
||||||
|
nodestocheck[i]: res
|
||||||
|
for i, res in enumerate(
|
||||||
|
dependencies.infinitepush.isbackedupnodes(
|
||||||
|
getconnection, nodestocheck
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# local backup state based lookup
|
||||||
|
backeduprevs = unfi.revs("backedup()")
|
||||||
|
isbackedup = {
|
||||||
|
node: (unfi[node].rev() in backeduprevs) or not unfi[node].mutable()
|
||||||
|
for node in nodestocheck
|
||||||
|
}
|
||||||
|
|
||||||
for n in nodestocheck:
|
results = {helperkey: isbackedup}
|
||||||
|
|
||||||
|
if jsondisplayer:
|
||||||
|
text = cmdutil.rendertemplate(ui, "{%s|json}" % helperkey, results)
|
||||||
|
ui.write(text)
|
||||||
|
return
|
||||||
|
|
||||||
|
for n, result in results[helperkey].items():
|
||||||
ui.write(n, " ")
|
ui.write(n, " ")
|
||||||
ui.write(_("backed up") if isbackedup[n] else _("not backed up"))
|
ui.write(_("backed up") if result else _("not backed up"))
|
||||||
ui.write(_("\n"))
|
ui.write(_("\n"))
|
||||||
|
|
||||||
|
|
||||||
@ -1604,6 +1614,7 @@ def pushbackup(ui, repo, *revs, **opts):
|
|||||||
[
|
[
|
||||||
("r", "rev", [], _("show the specified revision or revset"), _("REV")),
|
("r", "rev", [], _("show the specified revision or revset"), _("REV")),
|
||||||
("", "remote", None, _("check on the remote server")),
|
("", "remote", None, _("check on the remote server")),
|
||||||
|
("", "json", None, _("output in json format instead of human-readable")),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def isbackedup(ui, repo, **opts):
|
def isbackedup(ui, repo, **opts):
|
||||||
|
@ -255,6 +255,8 @@ Create logs directory and set correct permissions
|
|||||||
112478962961147124edd43549aedd1a335e44bf backed up
|
112478962961147124edd43549aedd1a335e44bf backed up
|
||||||
b18e25de2cf5fc4699a029ed635882849e53ef73 backed up
|
b18e25de2cf5fc4699a029ed635882849e53ef73 backed up
|
||||||
26805aba1e600a82e93661149f2313866a221a7b backed up
|
26805aba1e600a82e93661149f2313866a221a7b backed up
|
||||||
|
$ hg cloud check -r ':' --json
|
||||||
|
{"112478962961147124edd43549aedd1a335e44bf": true, "26805aba1e600a82e93661149f2313866a221a7b": true, "426bada5c67598ca65036d57d9e4b64b0c1ce7a0": true, "7e6a6fd9c7c8c8c307ee14678f03d63af3a7b455": true, "b18e25de2cf5fc4699a029ed635882849e53ef73": true} (no-eol)
|
||||||
$ hg rebase -s B -d D --config infinitepushbackup.autobackup=True --config infinitepushbackup.logdir=$TESTTMP/logs
|
$ hg rebase -s B -d D --config infinitepushbackup.autobackup=True --config infinitepushbackup.logdir=$TESTTMP/logs
|
||||||
rebasing 112478962961 "B" (B)
|
rebasing 112478962961 "B" (B)
|
||||||
rebasing 26805aba1e60 "C" (C)
|
rebasing 26805aba1e60 "C" (C)
|
||||||
@ -277,6 +279,8 @@ Create logs directory and set correct permissions
|
|||||||
$ hg cloud check -r 'ffeec75ec + 1ef11233b7'
|
$ hg cloud check -r 'ffeec75ec + 1ef11233b7'
|
||||||
ffeec75ec60331057b875fc5356c57c3ff204500 backed up
|
ffeec75ec60331057b875fc5356c57c3ff204500 backed up
|
||||||
1ef11233b74dfa8b57e8285fd6f546096af8f4c2 backed up
|
1ef11233b74dfa8b57e8285fd6f546096af8f4c2 backed up
|
||||||
|
$ hg cloud check -r 'ffeec75ec + 1ef11233b7' --json
|
||||||
|
{"1ef11233b74dfa8b57e8285fd6f546096af8f4c2": true, "ffeec75ec60331057b875fc5356c57c3ff204500": true} (no-eol)
|
||||||
|
|
||||||
Throw in an empty transaction - this should not trigger a backup.
|
Throw in an empty transaction - this should not trigger a backup.
|
||||||
$ hg debugshell --command "l = repo.lock(); repo.transaction('backup-test')" --config infinitepushbackup.autobackup=True --config infinitepushbackup.logdir=$TESTTMP/logs
|
$ hg debugshell --command "l = repo.lock(); repo.transaction('backup-test')" --config infinitepushbackup.autobackup=True --config infinitepushbackup.logdir=$TESTTMP/logs
|
||||||
@ -325,6 +329,8 @@ Fail to push a backup by setting the server maxbundlesize very low
|
|||||||
[2]
|
[2]
|
||||||
$ hg cloud check -r .
|
$ hg cloud check -r .
|
||||||
73e861ba66d5dc1998052f3ae2cf8cf7924ed863 not backed up
|
73e861ba66d5dc1998052f3ae2cf8cf7924ed863 not backed up
|
||||||
|
$ hg cloud check -r . --json
|
||||||
|
{"73e861ba66d5dc1998052f3ae2cf8cf7924ed863": false} (no-eol)
|
||||||
$ scratchnodes | grep 73e861ba66d5dc1998052f3ae2cf8cf7924ed863
|
$ scratchnodes | grep 73e861ba66d5dc1998052f3ae2cf8cf7924ed863
|
||||||
[1]
|
[1]
|
||||||
|
|
||||||
@ -339,6 +345,8 @@ Set the limit back high, and try again
|
|||||||
remote: 73e861ba66d5 toobig
|
remote: 73e861ba66d5 toobig
|
||||||
$ hg cloud check -r .
|
$ hg cloud check -r .
|
||||||
73e861ba66d5dc1998052f3ae2cf8cf7924ed863 backed up
|
73e861ba66d5dc1998052f3ae2cf8cf7924ed863 backed up
|
||||||
|
$ hg cloud check -r . --json
|
||||||
|
{"73e861ba66d5dc1998052f3ae2cf8cf7924ed863": true} (no-eol)
|
||||||
$ scratchnodes | grep 73e861ba66d5dc1998052f3ae2cf8cf7924ed863
|
$ scratchnodes | grep 73e861ba66d5dc1998052f3ae2cf8cf7924ed863
|
||||||
73e861ba66d5dc1998052f3ae2cf8cf7924ed863 1b5db94fc7daec8da5284b7b989fff125cb6f35b
|
73e861ba66d5dc1998052f3ae2cf8cf7924ed863 1b5db94fc7daec8da5284b7b989fff125cb6f35b
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user