hgext/phabricator.py
changeset 44424 98f7b9cf7bfc
parent 44423 5e2d74e5f450
child 44425 aa9979bb6853
--- a/hgext/phabricator.py	Wed Mar 04 10:25:07 2020 -0500
+++ b/hgext/phabricator.py	Wed Feb 19 13:33:58 2020 -0500
@@ -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)