Patchwork [2,of,5,V2] diff: use fctx.size() to test empty

login
register
mail settings
Submitter Jun Wu
Date May 6, 2017, 1:27 a.m.
Message ID <4f31a8ae3b30f6ca5fd8.1494034039@x1c>
Download mbox | patch
Permalink /patch/20465/
State Accepted
Headers show

Comments

Jun Wu - May 6, 2017, 1:27 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1493875244 25200
#      Wed May 03 22:20:44 2017 -0700
# Node ID 4f31a8ae3b30f6ca5fd8770a25b59f9638a48d6b
# Parent  1db00a094f91000d89bda7ee14771fb14498c9b1
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 4f31a8ae3b30
diff: use fctx.size() to test empty

fctx.size() could have a fast path that does not require loading content.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2509,4 +2509,7 @@  def trydiff(repo, revs, ctx1, ctx2, modi
         return 'diff %s %s' % (revinfo, f)
 
+    def isempty(fctx):
+        return fctx is None or fctx.size() == 0
+
     date1 = util.datestr(ctx1.date())
     date2 = util.datestr(ctx2.date())
@@ -2547,7 +2550,7 @@  def trydiff(repo, revs, ctx1, ctx2, modi
                 f2 in copy or
                 # empty file creation
-                (not f1 and not content2) or
+                (not f1 and isempty(fctx2)) or
                 # empty file deletion
-                (not content1 and not f2) or
+                (isempty(fctx1) and not f2) or
                 # create with flags
                 (not f1 and flag2) or