# HG changeset patch # User Martin von Zweigbergk # Date 2015-01-23 07:18:43 # Node ID 0f8baebcdbea49182845abc209915b6704feaf8c # Parent b6f434729b976e26edbda2331adaffd0eb9e99c8 trydiff: read file data in only one place This moves getfilectx() out of the initial block in the loop, leaving that block to be only about finding pairs of filenames in ctx1 and ctx2 to diff. diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1772,13 +1772,7 @@ def trydiff(repo, revs, ctx1, ctx2, modi if f not in ctx1: addedset.add(f) for f in sorted(modified + added + removed): - content1 = None - content2 = None copyop = None - if f not in addedset: - content1 = getfilectx(f, ctx1).data() - if f not in removedset: - content2 = getfilectx(f, ctx2).data() f1, f2 = f, f if f in addedset: f1 = None @@ -1790,7 +1784,6 @@ def trydiff(repo, revs, ctx1, ctx2, modi gone.add(f1) else: copyop = 'copy' - content1 = getfilectx(f1, ctx1).data() elif f in removedset: f2 = None if opts.git: @@ -1799,6 +1792,12 @@ def trydiff(repo, revs, ctx1, ctx2, modi and copy[copyto[f]] == f): continue + content1 = None + content2 = None + if f1: + content1 = getfilectx(f1, ctx1).data() + if f2: + content2 = getfilectx(f2, ctx2).data() flag1 = None flag2 = None binary = False