Patchwork D8218: phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it

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

Comments

phabricator - March 4, 2020, 7:07 p.m.
Closed by commit rHG98f7b9cf7bfc: phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it (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/D8218?vs=20466&id=20480

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

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

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
@@ -747,12 +747,14 @@ 
     return fphid
 
 
-def addoldbinary(pchange, fctx):
+def addoldbinary(pchange, oldfctx, fctx):
     """add the metadata for the previous version of a binary file to the
     phabchange for the new version
+
+    ``oldfctx`` is the previous version of the file; ``fctx`` is the new
+    version of the file, or None if the file is being removed.
     """
-    oldfctx = fctx.p1()
-    if fctx.cmp(oldfctx):
+    if not fctx or fctx.cmp(oldfctx):
         # Files differ, add the old one
         pchange.metadata[b'old:file:size'] = oldfctx.size()
         mimeguess, _enc = mimetypes.guess_type(
@@ -832,7 +834,7 @@ 
 
         if fctx.isbinary() or notutf8(fctx):
             makebinary(pchange, fctx)
-            addoldbinary(pchange, fctx)
+            addoldbinary(pchange, fctx.p1(), fctx)
         else:
             maketext(pchange, ctx, fname)
 
@@ -892,7 +894,7 @@ 
         if fctx.isbinary() or notutf8(fctx):
             makebinary(pchange, fctx)
             if renamed:
-                addoldbinary(pchange, fctx)
+                addoldbinary(pchange, fctx.p1(), fctx)
         else:
             maketext(pchange, ctx, fname)