diff --git a/hgext3rd/treedirstate.py b/hgext3rd/treedirstate.py --- a/hgext3rd/treedirstate.py +++ b/hgext3rd/treedirstate.py @@ -530,6 +530,15 @@ def istreedirstate(repo): return 'treedirstate' in getattr(repo, 'requirements', set()) +def activealternativedirstates(repo): + """ + Returns a set containing the names of any alternative dirstate + implementations in use. + """ + alternatives = {'eden', 'sqldirstate'} + requirements = getattr(repo, 'requirements', set()) + return alternatives & requirements + def newtree(opener): while True: treeid = ''.join([random.choice(string.digits) for _c in range(8)]) @@ -551,6 +560,10 @@ def upgrade(ui, repo): if istreedirstate(repo): raise error.Abort('repo already has treedirstate') + alternatives = activealternativedirstates(repo) + if alternatives: + raise error.Abort('repo has alternative dirstate active: %s' + % ', '.join(alternatives)) with repo.wlock(): newmap = treedirstatemap(ui, repo.dirstate._opener, repo.root, importmap=repo.dirstate._map) @@ -687,7 +700,7 @@ ui.status(_('disabling treedirstate...\n')) downgrade(ui, repo) elif (ui.configbool('treedirstate', 'upgradeonpull') and - not istreedirstate(repo)): + not istreedirstate(repo) and not activealternativedirstates(repo)): ui.status(_('migrating your repo to treedirstate which will make your ' 'hg commands faster...\n')) upgrade(ui, repo) diff --git a/tests/test-treedirstate.t b/tests/test-treedirstate.t --- a/tests/test-treedirstate.t +++ b/tests/test-treedirstate.t @@ -133,7 +133,7 @@ .hg/dirstate.tree.* (glob) .hg/dirstate.tree.* (glob) -Test downgrade and upgrade on pull +Test downgrade on pull $ for f in 1 2 3 4 5 ; do mkdir dir$f ; echo $f > dir$f/file$f ; hg add dir$f/file$f ; done $ echo x > a @@ -172,6 +172,29 @@ a 0 -1 * newfile (glob) $ grep treedirstate .hg/requires [1] + +Test upgrade on pull with conflicting dirstate reimplementation + + $ cat > $TESTTMP/fakesqldirstate.py << EOF + > from mercurial import localrepo + > def featuresetup(ui, supported): + > supported |= {'sqldirstate'} + > def extsetup(ui): + > localrepo.localrepository.featuresetupfuncs.add(featuresetup) + > EOF + $ cp .hg/requires .hg/requires.test-backup + $ echo sqldirstate >> .hg/requires + $ hg pull --config treedirstate.upgradeonpull=true --config extensions.fakesqldirstate=$TESTTMP/fakesqldirstate.py + pulling from $TESTTMP/repo (glob) + searching for changes + no changes found + $ hg debugtreedirstate on --config extensions.fakesqldirstate=$TESTTMP/fakesqldirstate.py + abort: repo has alternative dirstate active: sqldirstate + [255] + $ mv -f .hg/requires.test-backup .hg/requires + +Test upgrade on pull + $ hg pull --config treedirstate.upgradeonpull=true migrating your repo to treedirstate which will make your hg commands faster... pulling from $TESTTMP/repo (glob)