commitcloud: store cloud sync status in the store vfs

Summary:
Commit cloud sync works at the store granularity, so the status should be
stored in the store vfs.  Move it there.

Improve the output of `hg cloud status` by logging more information about the workspace.

Reviewed By: quark-zju

Differential Revision: D20419223

fbshipit-source-id: 4f0d6b9aab55d2bbeaf89b489606f0bc25400de5
This commit is contained in:
Mark Thomas 2020-03-12 12:55:27 -07:00 committed by Facebook GitHub Bot
parent 7a22f95631
commit d4cfd6f918
4 changed files with 77 additions and 34 deletions

View File

@ -161,6 +161,7 @@ from . import (
dependencies,
obsmarkers,
status,
sync,
syncstate,
util as ccutil,
workspace,
@ -201,6 +202,7 @@ def extsetup(ui):
localrepo.localrepository._wlockfreeprefix.add(backupstate.BackupState.prefix)
localrepo.localrepository._wlockfreeprefix.add(background._autobackupstatefile)
localrepo.localrepository._lockfreeprefix.add(syncstate.SyncState.prefix)
localrepo.localrepository._lockfreeprefix.add(sync._syncstatusfile)
def wrapsmartlog(loaded):
if not loaded:

View File

@ -813,23 +813,34 @@ def cloudstatus(ui, repo, **opts):
if workspacename is None:
ui.write(_("You are not connected to any workspace\n"))
return
ui.write(_("Workspace: %s\n") % workspacename)
autosync = "ON" if background.autobackupenabled(repo) else "OFF"
currentsyncstate = syncstate.SyncState(repo, workspacename)
syncupdatetime = time.ctime(currentsyncstate.lastupdatetime)
if repo.localvfs.isfile("lastsync.log"):
state = repo.localvfs.read("lastsync.log")
else:
state = "Not logged"
ui.write(_("Automatic Sync: %s\n") % autosync)
state = syncstate.SyncState(repo, workspacename)
ui.write(_("Last Sync Version: %s\n") % state.version)
if state.maxage is not None:
ui.write(_("Last Sync Maximum Commit Age: %s days\n") % state.maxage)
ui.write(
_(
"Workspace: %s\n"
"Automatic Sync: %s\n"
"Last Sync: %s\n"
"Last Sync State: %s\n"
)
% (workspacename, autosync, syncupdatetime, state)
_("Last Sync Heads: %d (%d omitted)\n")
% (len(state.heads), len(state.omittedheads))
)
ui.write(
_("Last Sync Bookmarks: %d (%d omitted)\n")
% (len(state.bookmarks), len(state.omittedbookmarks))
)
ui.write(_("Last Sync Remote Bookmarks: %d\n") % (len(state.remotebookmarks)))
ui.write(_("Last Sync Snapshots: %d\n") % (len(state.snapshots)))
ui.write(_("Last Sync Time: %s\n") % time.ctime(state.lastupdatetime))
if repo.svfs.isfile(sync._syncstatusfile):
status = repo.svfs.read(sync._syncstatusfile)
else:
status = "Not logged"
ui.write(_("Last Sync Status: %s\n") % status)
@command("debugwaitbackup", [("", "timeout", "", "timeout value")])

View File

@ -42,6 +42,10 @@ from . import (
)
# Sync status file. Contains whether the previous sync was successful or not.
_syncstatusfile = "commitcloudsyncstatus"
def _isremotebookmarkssyncenabled(ui):
return ui.configbool("remotenames", "selectivepull") and ui.configbool(
"commitcloud", "remotebookmarkssync"
@ -92,7 +96,16 @@ def _getsnapshots(repo, lastsyncstate):
@perftrace.tracefunc("Cloud Sync")
def sync(repo, *args, **kwargs):
with backuplock.lock(repo):
return _sync(repo, *args, **kwargs)
try:
rc, synced = _sync(repo, *args, **kwargs)
if synced is not None:
with repo.svfs(_syncstatusfile, "w+") as fp:
fp.write(encodeutf8("Success" if synced else "Failed"))
except BaseException as e:
with repo.svfs(_syncstatusfile, "w+") as fp:
fp.write(encodeutf8("Exception (%s)" % repr(e)))
raise
return rc
def _sync(
@ -147,7 +160,7 @@ def _sync(
# another is for edenfs checkout. If edenfs backing repo sync runs first then it will sync
# all the commits and bookmarks but it won't move working copy of the checkout.
# The line below makes sure that working copy is updated.
return _maybeupdateworkingcopy(repo, startnode)
return _maybeupdateworkingcopy(repo, startnode), None
backupsnapshots = False
try:
@ -228,15 +241,7 @@ def _sync(
# Check that Scm Service is running and a subscription exists
subscription.check(repo)
# log whether the sync was successful
with repo.wlock():
fp = repo.localvfs("lastsync.log", "w+")
if synced and not failed:
fp.write(encodeutf8("Success"))
else:
fp.write(encodeutf8("Failed"))
fp.close()
return _maybeupdateworkingcopy(repo, startnode)
return _maybeupdateworkingcopy(repo, startnode), synced and not failed
def logsyncop(

View File

@ -97,8 +97,13 @@ Run cloud status after setting a workspace
$ hg cloud status
Workspace: user/test/feature
Automatic Sync: OFF
Last Sync: * (glob)
Last Sync State: Success
Last Sync Version: 1
Last Sync Heads: 0 (0 omitted)
Last Sync Bookmarks: 0 (0 omitted)
Last Sync Remote Bookmarks: 0
Last Sync Snapshots: 0
Last Sync Time: * (glob)
Last Sync Status: Success
$ hg cloud leave
commitcloud: this repository is now disconnected from Commit Cloud Sync
@ -135,8 +140,13 @@ Run cloud status after setting workspace
$ hg cloud status
Workspace: user/test/default
Automatic Sync: OFF
Last Sync: * (glob)
Last Sync State: Success
Last Sync Version: 1
Last Sync Heads: 0 (0 omitted)
Last Sync Bookmarks: 0 (0 omitted)
Last Sync Remote Bookmarks: 0
Last Sync Snapshots: 0
Last Sync Time: * (glob)
Last Sync Status: Success
Enable autosync
$ setconfig infinitepushbackup.autobackup=true
@ -145,8 +155,13 @@ Run cloud status after enabling autosync
$ hg cloud status
Workspace: user/test/default
Automatic Sync: ON
Last Sync: * (glob)
Last Sync State: Success
Last Sync Version: 1
Last Sync Heads: 0 (0 omitted)
Last Sync Bookmarks: 0 (0 omitted)
Last Sync Remote Bookmarks: 0
Last Sync Snapshots: 0
Last Sync Time: * (glob)
Last Sync Status: Success
Disable autosync
$ setconfig infinitepushbackup.autobackup=false
@ -154,8 +169,13 @@ Run cloud status after disabling autosync
$ hg cloud status
Workspace: user/test/default
Automatic Sync: OFF
Last Sync: * (glob)
Last Sync State: Success
Last Sync Version: 1
Last Sync Heads: 0 (0 omitted)
Last Sync Bookmarks: 0 (0 omitted)
Last Sync Remote Bookmarks: 0
Last Sync Snapshots: 0
Last Sync Time: * (glob)
Last Sync Status: Success
$ cd ..
@ -851,8 +871,13 @@ Run cloud status after failing to synchronize
$ hg cloud status
Workspace: user/test/default
Automatic Sync: OFF
Last Sync: * (glob)
Last Sync State: Failed
Last Sync Version: 17
Last Sync Heads: 1 (0 omitted)
Last Sync Bookmarks: 1 (0 omitted)
Last Sync Remote Bookmarks: 0
Last Sync Snapshots: 0
Last Sync Time: * (glob)
Last Sync Status: Failed
$ hg cloud check -r .
9bd68ef10d6bdb8ebf3273a7b91bc4f3debe2a87 not backed up