# HG changeset patch # User Martin von Zweigbergk # Date 2014-12-23 18:41:45 # Node ID dbd60f8d88d510e6fe3c16b18c9973b6ed4b0a12 # Parent 1ec6dbb9b2164dd434bc2aecf236c197f7c8d45d trydiff: use sets, not lists, for containment checks This only has a noticeable effect on diffs touching A LOT of files. For example, it takes hg diff -r FIREFOX_AURORA_30_BASE -r FIREFOX_AURORA_35_BASE from 1m55.465s to 1m32.354s. That diff has over 50k files. diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1794,6 +1794,7 @@ def trydiff(repo, revs, ctx1, ctx2, modi if opts.git: revs = None + modifiedset, addedset, removedset = set(modified), set(added), set(removed) for f in sorted(modified + added + removed): to = None tn = None @@ -1801,11 +1802,11 @@ def trydiff(repo, revs, ctx1, ctx2, modi header = [] if f in man1: to = getfilectx(f, ctx1).data() - if f not in removed: + if f not in removedset: tn = getfilectx(f, ctx2).data() a, b = f, f if opts.git or losedatafn: - if f in added or (f in modified and to is None): + if f in addedset or (f in modifiedset and to is None): mode = gitmode[ctx2.flags(f)] if f in copy or f in copyto: if opts.git: @@ -1815,7 +1816,7 @@ def trydiff(repo, revs, ctx1, ctx2, modi a = copyto[f] omode = gitmode[man1.flags(a)] addmodehdr(header, omode, mode) - if a in removed and a not in gone: + if a in removedset and a not in gone: op = 'rename' gone.add(a) else: @@ -1841,12 +1842,12 @@ def trydiff(repo, revs, ctx1, ctx2, modi if not opts.git and not tn: # regular diffs cannot represent new empty file losedatafn(f) - elif f in removed or (f in modified and tn is None): + elif f in removedset or (f in modifiedset and tn is None): if opts.git: # have we already reported a copy above? - if ((f in copy and copy[f] in added + if ((f in copy and copy[f] in addedset and copyto[copy[f]] == f) or - (f in copyto and copyto[f] in added + (f in copyto and copyto[f] in addedset and copy[copyto[f]] == f)): dodiff = False else: