init: add hgsql requirement during repo init and clone

Summary:
We don't want to allow commands to run in the repo if hgsql is not
enabled, so let's add a requirement.

This will not affect existing repositories, since they don't have the flag in
their requires, but the flag can be added manually once this is deployed.

Test Plan: Added a test

Reviewers: #sourcecontrol, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar

Differential Revision: https://phabricator.intern.facebook.com/D3239263

Signature: t1:3239263:1461923217:b8fb59498292e1f9d317d98d5de7ce8513685ba6
This commit is contained in:
Durham Goode 2016-04-29 09:55:23 -07:00
parent 031d404a34
commit c58a61d5cd
3 changed files with 41 additions and 2 deletions

View File

@ -35,7 +35,7 @@ UNIQUE KEY bookmarkindex (repo, namespace, name)
from mercurial.node import bin, hex, nullid, nullrev
from mercurial.i18n import _
from mercurial.extensions import wrapfunction, wrapcommand
from mercurial import error, cmdutil, revlog
from mercurial import error, cmdutil, revlog, localrepo
from mercurial import wireproto, bookmarks, repair, commands, hg, mdiff, phases
from mercurial import util, changegroup, exchange, bundle2, bundlerepo
from mercurial import demandimport
@ -60,6 +60,16 @@ INITIAL_SYNC_FORCE = 'force'
initialsync = INITIAL_SYNC_NORMAL
cls = localrepo.localrepository
for reqs in ['supportedformats', 'openerreqs', '_basesupported']:
getattr(cls, reqs).add('hgsql')
def newreporequirements(orig, repo):
reqs = orig(repo)
if repo.ui.configbool('format', 'usehgsql', True):
reqs.add('hgsql')
return reqs
class CorruptionException(Exception):
pass
@ -70,6 +80,8 @@ def cansyncwithsql(repo):
return issqlrepo(repo) and not isinstance(repo, bundlerepo.bundlerepository)
def uisetup(ui):
wrapfunction(localrepo, 'newreporequirements', newreporequirements)
# Enable SQL for local commands that write to the repository.
wrapcommand(commands.table, 'pull', pull)
wrapcommand(commands.table, 'commit', commit)

View File

@ -39,7 +39,7 @@ UNIQUE KEY bookmarkindex (repo, namespace, name)
);' 2>/dev/null
function initserver() {
hg init $1
hg init --config extensions.hgsql=$TESTDIR/../hgsql.py $1
configureserver $1 $2
}

27
tests/test-requires.t Normal file
View File

@ -0,0 +1,27 @@
$ . "$TESTDIR/library.sh"
# Populate the db with an initial commit
$ initclient client
$ cd client
$ echo x > x
$ hg commit -qAm x
$ cd ..
$ initserver master masterrepo
$ cd master
$ hg log
$ hg pull -q ../client
Test that hgsql is a requirement
$ hg log -r tip --config extensions.hgsql=!
abort: repository requires features unknown to this Mercurial: hgsql!
(see https://mercurial-scm.org/wiki/MissingRequirement for more information)
[255]
$ hg log -r tip
changeset: 0:b292c1e3311f
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: x