[PATCH] commands.log: getrenamed simplification

Alexander Solovyov piranha at piranha.org.ua
Sun Nov 22 13:51:11 CST 2009


# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1258919452 -7200
# Node ID b01f7257fc2dbae5cd02e4e796467bf9e17622b9
# Parent  95517eb3c9a736947eafbe5f8c79e3e3b84e3f66
commands.log: getrenamed simplification

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2016,37 +2016,14 @@ def log(ui, repo, *pats, **opts):
         endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
     else:
         endrev = len(repo)
-    rcache = {}
-    ncache = {}
-    def getrenamed(fn, rev):
-        '''looks up all renames for a file (up to endrev) the first
-        time the file is given. It indexes on the changerev and only
-        parses the manifest if linkrev != changerev.
-        Returns rename info for fn at changerev rev.'''
-        if fn not in rcache:
-            rcache[fn] = {}
-            ncache[fn] = {}
-            fl = repo.file(fn)
-            for i in fl:
-                node = fl.node(i)
-                lr = fl.linkrev(i)
-                renamed = fl.renamed(node)
-                rcache[fn][lr] = renamed
-                if renamed:
-                    ncache[fn][node] = renamed
-                if lr >= endrev:
-                    break
-        if rev in rcache[fn]:
-            return rcache[fn][rev]
-
-        # If linkrev != rev (i.e. rev not found in rcache) fallback to
-        # filectx logic.
-
-        try:
-            return repo[rev][fn].renamed()
-        except error.LookupError:
-            pass
-        return None
+
+    def getrenamed(ctx):
+        for fn in ctx.files():
+            if not fn in ctx.manifest():
+                continue
+            cp = ctx.filectx(fn).renamed()
+            if cp:
+                yield (fn, cp[0])
 
     df = False
     if opts["date"]:
@@ -2076,13 +2053,7 @@ def log(ui, repo, *pats, **opts):
             else:
                 return
 
-        copies = []
-        if opts.get('copies') and rev:
-            for fn in ctx.files():
-                rename = getrenamed(fn, rev)
-                if rename:
-                    copies.append((fn, rename[0]))
-
+        copies = opts.get('copies') and list(getrenamed(ctx)) or []
         displayer.show(ctx, copies=copies)
 
     for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep):


More information about the Mercurial-devel mailing list