Patchwork D8220: phabricator: don't infer the old `fctx` in `notutf8()`

login
register
mail settings
Submitter phabricator
Date March 4, 2020, 7:07 p.m.
Message ID <0bc672a21ae03e8e134f02aa625635c5@localhost.localdomain>
Download mbox | patch
Permalink /patch/45479/
State Not Applicable
Headers show

Comments

phabricator - March 4, 2020, 7:07 p.m.
Closed by commit rHG66a05dbb8b4c: phabricator: don&#039;t infer the old `fctx` in `notutf8()` (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8220?vs=20468&id=20482

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8220/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8220

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: Kwan, mercurial-devel

Patch

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -796,8 +796,6 @@ 
     """
     try:
         fctx.data().decode('utf-8')
-        if fctx.parents():
-            fctx.p1().data().decode('utf-8')
         return False
     except UnicodeDecodeError:
         fctx.repo().ui.write(
@@ -825,6 +823,7 @@ 
     """add modified files to the phabdiff"""
     for fname in modified:
         fctx = ctx[fname]
+        oldfctx = fctx.p1()
         pchange = phabchange(currentPath=fname, oldPath=fname)
         filemode = gitmode[ctx[fname].flags()]
         originalmode = gitmode[ctx.p1()[fname].flags()]
@@ -832,7 +831,7 @@ 
             pchange.addoldmode(originalmode)
             pchange.addnewmode(filemode)
 
-        if fctx.isbinary() or notutf8(fctx):
+        if fctx.isbinary() or notutf8(fctx) or notutf8(oldfctx):
             makebinary(pchange, fctx)
             addoldbinary(pchange, fctx.p1(), fctx)
         else:
@@ -849,6 +848,7 @@ 
     movedchanges = {}
     for fname in added:
         fctx = ctx[fname]
+        oldfctx = None
         pchange = phabchange(currentPath=fname)
 
         filemode = gitmode[ctx[fname].flags()]
@@ -856,7 +856,8 @@ 
 
         if renamed:
             originalfname = renamed[0]
-            originalmode = gitmode[ctx.p1()[originalfname].flags()]
+            oldfctx = ctx.p1()[originalfname]
+            originalmode = gitmode[oldfctx.flags()]
             pchange.oldPath = originalfname
 
             if originalfname in removed:
@@ -891,10 +892,10 @@ 
             pchange.addnewmode(gitmode[fctx.flags()])
             pchange.type = DiffChangeType.ADD
 
-        if fctx.isbinary() or notutf8(fctx):
+        if fctx.isbinary() or notutf8(fctx) or (oldfctx and notutf8(oldfctx)):
             makebinary(pchange, fctx)
             if renamed:
-                addoldbinary(pchange, fctx.p1(), fctx)
+                addoldbinary(pchange, oldfctx, fctx)
         else:
             maketext(pchange, ctx, fname)