filectx.annotate: return filectx for each line instead of rev
authorBrendan Cully <brendan@kublai.com>
Fri, 22 Sep 2006 08:19:25 -0700
changeset 3146 e69a0cbe268e
parent 3145 e4ea47c21480
child 3147 97420a49188d
filectx.annotate: return filectx for each line instead of rev
mercurial/commands.py
mercurial/context.py
--- a/mercurial/commands.py	Fri Sep 22 08:19:25 2006 -0700
+++ b/mercurial/commands.py	Fri Sep 22 08:19:25 2006 -0700
@@ -604,29 +604,14 @@
     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
--- a/mercurial/context.py	Fri Sep 22 08:19:25 2006 -0700
+++ b/mercurial/context.py	Fri Sep 22 08:19:25 2006 -0700
@@ -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 @@
                          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):
         """