# HG changeset patch # User Nicolas Dumazet # Date 1280239650 -32400 # Node ID 4147a292c508508fb2a188254c4915ef5d0667b9 # Parent 8a08b12ae88ed7c918cd62ad4e348bbd353b80c5 filectx: use ctx.size comparisons to speed up ctx.cmp Comparing sizes is cheaper than comparing file contents, as it does not involve reading the file on disk or from the filelog. It is however not always possible: some extensions, or encode filters, change data when extracting it to the working directory. diff -r 8a08b12ae88e -r 4147a292c508 hgext/keyword.py --- a/hgext/keyword.py Sun Oct 10 18:58:45 2010 +0200 +++ b/hgext/keyword.py Tue Jul 27 23:07:30 2010 +0900 @@ -82,7 +82,7 @@ {desc}" expands to the first line of the changeset description. ''' -from mercurial import commands, cmdutil, dispatch, filelog, extensions +from mercurial import commands, context, cmdutil, dispatch, filelog, extensions from mercurial import localrepo, match, patch, templatefilters, templater, util from mercurial.hgweb import webcommands from mercurial.i18n import _ @@ -586,6 +586,12 @@ repo.__class__ = kwrepo + def kwfilectx_cmp(orig, self, fctx): + # keyword affects data size, comparing wdir and filelog size does + # not make sense + return self._filelog.cmp(self._filenode, fctx.data()) + extensions.wrapfunction(context.filectx, 'cmp', kwfilectx_cmp) + extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) extensions.wrapfunction(patch, 'diff', kw_diff) extensions.wrapfunction(cmdutil, 'copy', kw_copy) diff -r 8a08b12ae88e -r 4147a292c508 mercurial/context.py --- a/mercurial/context.py Sun Oct 10 18:58:45 2010 +0200 +++ b/mercurial/context.py Tue Jul 27 23:07:30 2010 +0900 @@ -357,6 +357,9 @@ returns True if different than fctx. """ + if not self._repo._encodefilterpats and self.size() != fctx.size(): + return True + return self._filelog.cmp(self._filenode, fctx.data()) def renamed(self):