Mercurial > hg
comparison mercurial/context.py @ 19292:e0aa6fff8f02
annotate: simplify annotate parent function
The annotate algorithm used a custom parents() function to try to reuse
filectx and filelogs. I simplified it a bit to rely more heavily on the
self.parents() which makes it work well with alternative filectx
implementations. I tested performance on a file with 5000+ revisions
but no renames, and on a file with 500 revisions repeating a series of
4 edits+renames and saw zero performance hit. In fact, it was reliably a
couple milliseconds faster now.
Added the perfannotate command to contrib/perf.py for future use.
author | Durham Goode <durham@fb.com> |
---|---|
date | Thu, 30 May 2013 19:29:03 -0700 |
parents | ec367f203cb5 |
children | bc82abe500a9 |
comparison
equal
deleted
inserted
replaced
19291:93635f69c93b | 19292:e0aa6fff8f02 |
---|---|
647 if t == '=': | 647 if t == '=': |
648 child[0][b1:b2] = parent[0][a1:a2] | 648 child[0][b1:b2] = parent[0][a1:a2] |
649 return child | 649 return child |
650 | 650 |
651 getlog = util.lrucachefunc(lambda x: self._repo.file(x)) | 651 getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
652 def getctx(path, fileid): | |
653 log = path == self._path and self._filelog or getlog(path) | |
654 return filectx(self._repo, path, fileid=fileid, filelog=log) | |
655 getctx = util.lrucachefunc(getctx) | |
656 | 652 |
657 def parents(f): | 653 def parents(f): |
658 # we want to reuse filectx objects as much as possible | 654 pl = f.parents() |
659 p = f._path | 655 |
660 if f._filerev is None: # working dir | 656 # Don't return renamed parents if we aren't following. |
661 pl = [(n.path(), n.filerev()) for n in f.parents()] | 657 if not follow: |
662 else: | 658 pl = [p for p in pl if p.path() == f.path()] |
663 pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] | 659 |
664 | 660 # renamed filectx won't have a filelog yet, so set it |
665 if follow: | 661 # from the cache to save time |
666 r = f.renamed() | 662 for p in pl: |
667 if r: | 663 if not '_filelog' in p.__dict__: |
668 pl[0] = (r[0], getlog(r[0]).rev(r[1])) | 664 p._filelog = getlog(p.path()) |
669 | 665 |
670 return [getctx(p, n) for p, n in pl if n != nullrev] | 666 return pl |
671 | 667 |
672 # use linkrev to find the first changeset where self appeared | 668 # use linkrev to find the first changeset where self appeared |
673 if self.rev() != self.linkrev(): | 669 if self.rev() != self.linkrev(): |
674 base = self.filectx(self.filerev()) | 670 base = self.filectx(self.filerev()) |
675 else: | 671 else: |