[PATCH] commands.log: getrenamed simplification
Martin Geisler
mg at lazybytes.net
Sat Nov 28 16:13:17 CST 2009
Alexander Solovyov <piranha at piranha.org.ua> writes:
> # HG changeset patch
> # User Alexander Solovyov <piranha at piranha.org.ua>
> # Date 1258919452 -7200
> # Node ID b01f7257fc2dbae5cd02e4e796467bf9e17622b9
> # Parent 95517eb3c9a736947eafbe5f8c79e3e3b84e3f66
> commands.log: getrenamed simplification
Wow, nice simplification! I assume it passes the test suite, but I'm
also wondering if the caches you delete wont effect performance?
It would be nice with a bigger commit message that shows that you have
thought about this: will the context object cache things internally or
are the caches simply not worth having?
> 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):
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20091128/ff1ce1f2/attachment.pgp>
More information about the Mercurial-devel
mailing list