# HG changeset patch # User Alexis S. L. Carvalho # Date 2008-02-14 20:08:16 # Node ID 41bb88cb913e96996635c3e2a5329bdd73e90c30 # Parent cb2f7652ad1bd84644537882aafe4984651dc0c3 commands.revert: don't call hg.revert commands.revert calculates everything that has to be done and then calls hg.revert to checkout and remove files. Unfortunately, hg.revert has to recalculate everything and that can take a long while, since it always operates on the whole working dir. Changing commands.revert to manually checkout and remove files makes things considerably faster, especially if we're reverting a single file in a repo with a huge number of files. This should be enough to close issue857. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2251,7 +2251,6 @@ def revert(ui, repo, *pats, **opts): remove = ([], _('removing %s\n')) forget = ([], _('forgetting %s\n')) undelete = ([], _('undeleting %s\n')) - update = {} disptable = ( # dispatch table: @@ -2274,7 +2273,6 @@ def revert(ui, repo, *pats, **opts): target = repo.wjoin(abs) def handle(xlist, dobackup): xlist[0].append(abs) - update[abs] = 1 if dobackup and not opts['no_backup'] and util.lexists(target): bakname = "%s.orig" % rel ui.note(_('saving current version of %s as %s\n') % @@ -2317,16 +2315,32 @@ def revert(ui, repo, *pats, **opts): handle(remove, False) if not opts.get('dry_run'): + def checkout(f): + fc = ctx[f] + repo.wwrite(f, fc.data(), fc.fileflags()) + for f in forget[0]: repo.dirstate.forget(f) - r = hg.revert(repo, node, update.has_key) + + for f in revert[0]: + checkout(f) + for f in add[0]: + checkout(f) repo.dirstate.add(f) + for f in undelete[0]: + checkout(f) repo.dirstate.normal(f) + + audit_path = util.path_auditor(repo.root) for f in remove[0]: + audit_path(f) + try: + util.unlink(repo.wjoin(f)) + except OSError: + pass repo.dirstate.remove(f) - return r finally: del wlock diff --git a/tests/test-revert.out b/tests/test-revert.out --- a/tests/test-revert.out +++ b/tests/test-revert.out @@ -26,8 +26,6 @@ e %% should verbosely save backup to e.orig saving current version of e as e.orig reverting e -resolving manifests -getting e %% should say no changes needed no changes needed to a %% should say file not managed