diff --git a/treedirstate/__init__.py b/treedirstate/__init__.py --- a/treedirstate/__init__.py +++ b/treedirstate/__init__.py @@ -2,6 +2,7 @@ """Tree-based Dirstate Implementation""" from mercurial import ( + commands, dirstate, dispatch, encoding, @@ -29,14 +30,19 @@ dirstateheader = b'########################treedirstate####' treedirstateversion = 1 treefileprefix = 'dirstate.tree.' -useinnewrepos = True + +configtable = {} +configitem = registrar.configitem(configtable) +configitem('treedirstate', 'useinnewrepos', default=False) +configitem('treedirstate', 'upgradeonpull', default=False) +configitem('treedirstate', 'downgradeonpull', default=False) # Minimum size the treedirstate file can be before auto-repacking. -minrepackthreshold = 1024 * 1024 +configitem('treedirstate', 'minrepackthreshold', default=1024 * 1024) # Number of times the treedirstate file can grow by, compared to its initial # size, before auto-repacking. -repackfactor = 3 +configitem('treedirstate', 'repackfactor', 3) class _reader(object): def __init__(self, data, offset): @@ -404,6 +410,9 @@ else: def nonnormadd(f): pass + repackfactor = self._ui.configint('treedirstate', 'repackfactor') + minrepackthreshold = self._ui.configint('treedirstate', + 'minrepackthreshold') repackthreshold = max(self._packedsize * repackfactor, minrepackthreshold) if self._rmap.storeoffset() > repackthreshold: @@ -614,6 +623,19 @@ reqs.add('treedirstate') return reqs +def wrappull(orig, ui, repo, *args, **kwargs): + if (ui.configbool('treedirstate', 'downgradeonpull') and + istreedirstate(repo)): + ui.status(_('disabling treedirstate...\n')) + downgrade(ui, repo) + elif (ui.configbool('treedirstate', 'upgradeonpull') and + not istreedirstate(repo)): + ui.status(_('migrating your repo to treedirstate which will make your ' + 'hg commands faster...\n')) + upgrade(ui, repo) + + return orig(ui, repo, *args, **kwargs) + def featuresetup(ui, supported): supported |= {'treedirstate'} @@ -623,6 +645,7 @@ ui.warn(_("this version of Mercurial doesn't support treedirstate\n")) return + useinnewrepos = ui.configbool('treedirstate', 'useinnewrepos') if useinnewrepos and util.safehasattr(localrepo, 'newreporequirements'): extensions.wrapfunction(localrepo, 'newreporequirements', wrapnewreporequirements) @@ -632,6 +655,7 @@ wrapdirstate) extensions.wrapfunction(scmutil, 'casecollisionauditor', wrapcca) extensions.wrapfunction(dispatch, 'runcommand', wrapruncommand) + extensions.wrapcommand(commands.table, 'pull', wrappull) def reposetup(ui, repo): ui.setconfig('treedirstate', 'enabled', istreedirstate(repo))