mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
sqldirstate: extract the upgrade and downgrade logic
Summary: This is to make implementation of automatic upgrade easier. Test Plan: Will add a test for it in one of the next diffs Reviewers: #mercurial, durham, ttung Subscribers: mjpieters Differential Revision: https://phabricator.intern.facebook.com/D3356494
This commit is contained in:
parent
576dc9525e
commit
d19764dd10
@ -71,6 +71,33 @@ def wrapshelveaborttransaction(orig, repo):
|
||||
else:
|
||||
return orig(repo)
|
||||
|
||||
def upgrade(ui, repo):
|
||||
if issqldirstate(repo):
|
||||
raise error.Abort('repo already has sqldirstate')
|
||||
wlock = repo.wlock()
|
||||
try:
|
||||
repo.dirstate._read()
|
||||
tosql(repo.dirstate)
|
||||
repo.requirements.add('sqldirstate')
|
||||
repo._writerequirements()
|
||||
repo.dirstate._opener.unlink('dirstate')
|
||||
del repo.dirstate
|
||||
finally:
|
||||
wlock.release()
|
||||
|
||||
def downgrade(ui, repo):
|
||||
if not issqldirstate(repo):
|
||||
raise error.Abort('repo doesn\'t have sqldirstate')
|
||||
wlock = repo.lock()
|
||||
try:
|
||||
toflat(repo.dirstate)
|
||||
repo.requirements.remove('sqldirstate')
|
||||
repo._writerequirements()
|
||||
repo.dirstate._opener.unlink('dirstate.sqlite3')
|
||||
del repo.dirstate
|
||||
finally:
|
||||
wlock.release()
|
||||
|
||||
def featuresetup(ui, supported):
|
||||
# don't die on seeing a repo with the sqldirstate requirement
|
||||
supported |= set(['sqldirstate'])
|
||||
@ -92,25 +119,14 @@ def uisetup(ui):
|
||||
# debug commands
|
||||
cmdtable = {}
|
||||
command = cmdutil.command(cmdtable)
|
||||
|
||||
@command('debugsqldirstate', [], 'hg debugsqldirstate [on|off]')
|
||||
def debugsqldirstate(ui, repo, cmd, **opts):
|
||||
""" migrate to sqldirstate """
|
||||
|
||||
if cmd == "on":
|
||||
if 'sqldirstate' not in repo.requirements:
|
||||
repo.dirstate._read()
|
||||
tosql(repo.dirstate)
|
||||
repo.requirements.add('sqldirstate')
|
||||
repo._writerequirements()
|
||||
repo.dirstate._opener.unlink('dirstate')
|
||||
else:
|
||||
raise error.Abort("sqldirstate is already enabled")
|
||||
|
||||
if cmd == "off":
|
||||
if 'sqldirstate' in repo.requirements:
|
||||
toflat(repo.dirstate)
|
||||
repo.requirements.remove('sqldirstate')
|
||||
repo._writerequirements()
|
||||
repo.dirstate._opener.unlink('dirstate.sqlite3')
|
||||
else:
|
||||
raise error.Abort("sqldirstate is disabled")
|
||||
upgrade(ui, repo)
|
||||
elif cmd == "off":
|
||||
downgrade(ui, repo)
|
||||
else:
|
||||
raise error.Abort("bad command")
|
||||
|
@ -416,7 +416,11 @@ def makedirstate(cls):
|
||||
return sqldirstate
|
||||
|
||||
def tosql(dirstate):
|
||||
# converts a flat dirstate to sqldirstate
|
||||
"""" converts flat dirstate to sqldirstate
|
||||
|
||||
note: the sole responsibility of this function is to write the new dirstate
|
||||
it's not touching anything but the DBFILE
|
||||
"""
|
||||
sqlfilename = dirstate._opener.join(DBFILE)
|
||||
try:
|
||||
os.unlink(sqlfilename)
|
||||
@ -455,6 +459,11 @@ def tosql(dirstate):
|
||||
sqlconn.commit()
|
||||
|
||||
def toflat(sqldirstate):
|
||||
"""" converts sqldirstate to flat dirstate
|
||||
|
||||
note: the sole responsibility of this function is to write the new dirstate
|
||||
it's not touching anything but the dirstate file
|
||||
"""
|
||||
# converts a sqldirstate to a flat one
|
||||
st = sqldirstate._opener("dirstate", "w", atomictemp=True)
|
||||
newmap = {}
|
||||
|
Loading…
Reference in New Issue
Block a user