Patchwork [4,of,4] trydiff: call util.binary in only one place

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 6, 2015, midnight
Message ID <914241af8a67fa52e23d.1423180846@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7696/
State Accepted
Commit d1fcff9400c984c521a0af89bdf8eb192824ddd8
Headers show

Comments

Martin von Zweigbergk - Feb. 6, 2015, midnight
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421994129 28800
#      Thu Jan 22 22:22:09 2015 -0800
# Node ID 914241af8a67fa52e23d288b3cfc27cf492f2c94
# Parent  282e35936726d0267ffcf58f949c56d8de1b33f8
trydiff: call util.binary in only one place

It's practically free to call util.binary on empty or None content. By
relying on that, we can replace the current four call sites by one.
Matt Mackall - Feb. 6, 2015, 7:09 p.m.
On Thu, 2015-02-05 at 16:00 -0800, Martin von Zweigbergk wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1421994129 28800
> #      Thu Jan 22 22:22:09 2015 -0800
> # Node ID 914241af8a67fa52e23d288b3cfc27cf492f2c94
> # Parent  282e35936726d0267ffcf58f949c56d8de1b33f8
> trydiff: call util.binary in only one place

These are queued for default, thanks.

Patch

diff -r 282e35936726 -r 914241af8a67 mercurial/patch.py
--- a/mercurial/patch.py	Thu Jan 22 21:35:57 2015 -0800
+++ b/mercurial/patch.py	Thu Jan 22 22:22:09 2015 -0800
@@ -1796,7 +1796,6 @@ 
                         else:
                             copyop = 'copy'
                         content1 = getfilectx(f1, ctx1).data()
-                binary = util.binary(content1) or util.binary(content2)
             elif f in removedset:
                 if opts.git:
                     # have we already reported a copy above?
@@ -1805,13 +1804,11 @@ 
                         continue
                     else:
                         flag1 = ctx1.flags(f)
-                        binary = util.binary(content1)
-                else:
-                    binary = util.binary(content1)
             else:
                 flag1 = ctx1.flags(f)
                 flag2 = ctx2.flags(f)
-                binary = util.binary(content1) or util.binary(content2)
+
+            binary = util.binary(content1) or util.binary(content2)
 
         if losedatafn and not opts.git:
             if (binary or