commitcloud: add option to select only commits related to the user in the default workspace

Summary:
this is usefull when a user have a lot of other users commits in the default workspace

the set of commits includes all the stacks where at least one commit is user's own

the option is for the default workspace only, it doesn't apply for other workspaces a user may collaborate in

the idea is that the client code will never offer other user's commits to sync, so cloud sync will perfectly work with some extra commit might present on any machine.

this allow users to continue have other users commits in their workspace for review or other purposes even if it is very very large, but provides reliable backup and sync solution for user's own work.

the option works for all commands `hg cloud join` `hg cloud rejoin` `hg cloud sync` and `hg cloud recover`

Reviewed By: simpkins

Differential Revision: D9645571

fbshipit-source-id: 9adb68568083c87c22bb86c19fb7a5bb0f639265
This commit is contained in:
Liubov Dmitrieva 2018-09-05 17:34:45 -07:00 committed by Facebook Github Bot
parent a0358711b6
commit e638e652e9
3 changed files with 38 additions and 9 deletions

View File

@ -66,8 +66,17 @@
# %i is substituted with the user identity
scm_daemon_log_path = /path/to/%i/logfile
# Use secrets_tool for token
# Use secrets_tool for token backup between machines
use_secrets_tool = true
# Default workspace only! Take into account user's only commits
# This includes all the stacks where at least one commit is user's own
# Caution: using this option may leave some local commits unbacked up
user_commits_only = true
# Default workspace only! Take into account only custom set of commits
# Caution: using this option may leave some local commits unbacked up
custom_push_revs = draft()
"""
from __future__ import absolute_import

View File

@ -453,6 +453,26 @@ def _docloudsync(ui, repo, checkbackedup=False, cloudrefs=None, **opts):
if cloudrefs is None:
cloudrefs = serv.getreferences(reponame, workspace, lastsyncstate.version)
# apply config setting to filter heads client code will include
# in 'new heads' to send to the server,
# this allows `cloud sync` works with some extra
# local only unbacked up commits on any machine
if not opts.get("push_revs") and (
workspace == getdefaultrepoworkspace(ui, repo)[1]
):
pushrevs = ""
if ui.configbool("commitcloud", "user_commits_only"):
pushrevs += " & author(%s)" % util.emailuser(ui.username())
if ui.config("commitcloud", "custom_push_revs"):
pushrevs += " & (%s)" % ui.config("commitcloud", "custom_push_revs")
if pushrevs:
opts["push_revs"] = ["draft() " + pushrevs]
revspec = opts.get("push_revs")
synced = False
pushfailures = set()
while not synced:
@ -463,7 +483,6 @@ def _docloudsync(ui, repo, checkbackedup=False, cloudrefs=None, **opts):
localbookmarks = _getbookmarks(repo)
obsmarkers = commitcloudutil.getsyncingobsmarkers(repo)
revspec = opts.get("push_revs")
if revspec:
revs = scmutil.revrange(repo, revspec)
pushheads = [ctx.hex() for ctx in repo.set("heads(%ld::)", revs)]
@ -693,12 +712,15 @@ def _update(ui, repo, destination):
def _filterpushside(ui, repo, pushheads, localheads, lastsyncstateheads):
"""filter push side to include only the specified push heads to the delta"""
if pushheads:
listmsg = _("except with heads '%s' ") % ", ".join([ph[:6] for ph in pushheads])
else:
listmsg = ""
# local - allowed - synced
skipped = set(localheads) - set(pushheads) - set(lastsyncstateheads)
if skipped:
highlightstatus(
ui,
_("push filter: the stacks with heads '%s' are not included in the sync\n")
% ", ".join([ph[:6] for ph in skipped]),
)
highlightstatus(ui, _("all unsynced stacks are skipped %s\n") % listmsg)
return list(set(localheads) & (set(lastsyncstateheads) | set(pushheads)))

View File

@ -235,7 +235,6 @@ Try to push selectively
$ hg cloud sync --push-revs '.'
#commitcloud synchronizing 'server' with 'user/test/default'
#commitcloud all unsynced stacks are skipped except with heads '48610b'
backing up stack rooted at a7bb357e7299
remote: pushing 2 commits:
remote: a7bb357e7299 commit1 amended
@ -244,7 +243,6 @@ Try to push selectively
$ hg cloud sync --push-revs 48610b1a7ec0
#commitcloud synchronizing 'server' with 'user/test/default'
#commitcloud all unsynced stacks are skipped except with heads '48610b'
#commitcloud commits synchronized
$ hg cloud sync