Patchwork [5,of,7] trydiff: read file data in only one place

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 7, 2015, 1:13 a.m.
Message ID <6a073eba9b3212c07074.1423271614@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7734/
State Accepted
Headers show

Comments

Martin von Zweigbergk - Feb. 7, 2015, 1:13 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421997523 28800
#      Thu Jan 22 23:18:43 2015 -0800
# Node ID 6a073eba9b3212c07074efb4e303239700edb0ec
# Parent  b66e35f2e7ee0f247e90ee032f1b1559c998722b
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.

Patch

diff -r b66e35f2e7ee -r 6a073eba9b32 mercurial/patch.py
--- a/mercurial/patch.py	Thu Jan 22 23:13:48 2015 -0800
+++ b/mercurial/patch.py	Thu Jan 22 23:18:43 2015 -0800
@@ -1772,13 +1772,7 @@ 
         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 @@ 
                         gone.add(f1)
                     else:
                         copyop = 'copy'
-                    content1 = getfilectx(f1, ctx1).data()
         elif f in removedset:
             f2 = None
             if opts.git:
@@ -1799,6 +1792,12 @@ 
                     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