diff --git a/hgext3rd/perftweaks.py b/hgext3rd/perftweaks.py --- a/hgext3rd/perftweaks.py +++ b/hgext3rd/perftweaks.py @@ -16,8 +16,10 @@ from mercurial import ( branchmap, + commands, dispatch, extensions, + localrepo, merge, namespaces, obsutil, @@ -41,6 +43,7 @@ wrapfunction(branchmap, 'read', _branchmapread) wrapfunction(branchmap, 'replacecache', _branchmapreplacecache) wrapfunction(branchmap, 'updatecache', _branchmapupdatecache) + wrapfunction(commands, '_docommit', _docommit) if ui.configbool('perftweaks', 'preferdeltas'): wrapfunction(revlog.revlog, '_isgooddelta', _isgooddelta) @@ -162,6 +165,22 @@ partial.update(repo, None) repo._branchcaches[repo.filtername] = partial +# _docommit accesses "branchheads" just to decide whether to show "(created new +# head)" or not. Accessing branchheads requires calling "headrevs()" which is +# expensive since it scans entire changelog. We don't use named branches and +# do not worry about multiple heads. +def _docommit(orig, ui, repo, *pats, **opts): + # developer config: perftweaks.disableheaddetection + if not repo.ui.configbool('perftweaks', 'disableheaddetection'): + return orig(ui, repo, *pats, **opts) + + def _fakedbranchheads(orig, repo, *args, **kwargs): + # Make "." a "head" so the "created new head" message won't be printed. + return [repo['.'].node()] + with extensions.wrappedfunction(localrepo.localrepository, + 'branchheads', _fakedbranchheads): + return orig(ui, repo, *pats, **opts) + def _branchmapwrite(orig, self, repo): if repo.ui.configbool('perftweaks', 'disablebranchcache2'): # Since we don't read the branchcache, don't bother writing it. diff --git a/tests/test-perftweaks.t b/tests/test-perftweaks.t --- a/tests/test-perftweaks.t +++ b/tests/test-perftweaks.t @@ -1,5 +1,6 @@ $ cat >> $HGRCPATH << EOF > [extensions] + > drawdag=$RUNTESTDIR/drawdag.py > perftweaks=$TESTDIR/../hgext3rd/perftweaks.py > EOF @@ -102,6 +103,25 @@ $ cd .. +Test avoiding calculating head changes during commit + + $ hg init branchatcommit + $ cd branchatcommit + $ hg debugdrawdag<<'EOS' + > B + > | + > A + > EOS + $ hg up -q A + $ echo C > C + $ hg commit -m C -A C + created new head + $ hg up -q A + $ echo D > D + $ hg commit -m D -A D --config perftweaks.disableheaddetection=1 + + $ cd .. + Test changing the delta heuristic (this isn't a good test, but it executes the code path) $ hg init preferdeltaserver