# HG changeset patch # User Brendan Cully # Date 2006-09-22 15:19:25 # Node ID e69a0cbe268ef51843ef2bf98e6db9390744db01 # Parent e4ea47c214806b1617a5d43160a7c3c036e30c23 filectx.annotate: return filectx for each line instead of rev diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -604,29 +604,14 @@ def annotate(ui, repo, *pats, **opts): detects as binary. With -a, annotate will generate an annotation anyway, probably with undesirable results. """ - def getnode(rev): - return short(repo.changelog.node(rev)) - - ucache = {} - def getname(rev): - try: - return ucache[rev] - except: - u = trimuser(ui, repo.changectx(rev).user(), rev, ucache) - ucache[rev] = u - return u - - dcache = {} - def getdate(rev): - datestr = dcache.get(rev) - if datestr is None: - datestr = dcache[rev] = util.datestr(repo.changectx(rev).date()) - return datestr + getdate = util.cachefunc(lambda x: util.datestr(x.date())) if not pats: raise util.Abort(_('at least one file name or pattern required')) - opmap = [['user', getname], ['number', str], ['changeset', getnode], + opmap = [['user', lambda x: ui.shortuser(x.user())], + ['number', lambda x: str(x.rev())], + ['changeset', lambda x: short(x.node())], ['date', getdate]] if not opts['user'] and not opts['changeset'] and not opts['date']: opts['number'] = 1 diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -7,7 +7,7 @@ from node import * from demandload import demandload -demandload(globals(), "ancestor") +demandload(globals(), "ancestor util") class changectx(object): """A changecontext object makes access to data related to a particular @@ -155,7 +155,12 @@ class filectx(object): filelog=self._filelog) for x in c ] def annotate(self): - return self._filelog.annotate(self._filenode) + getctx = util.cachefunc(lambda x: filectx(self._repo, self._path, + changeid=x, + filelog=self._filelog)) + hist = self._filelog.annotate(self._filenode) + + return [(getctx(rev), line) for rev, line in hist] def ancestor(self, fc2): """