# HG changeset patch # User Matt Harbison # Date 2020-02-19 18:33:58 # Node ID 98f7b9cf7bfc9a3539f44ea6dcf0e5ecfade060d # Parent 5e2d74e5f4500f241f89926023d66be45e6515dc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it Currently, removed binaries aren't marked as binaries on the left side, which sends the raw file view to a bad URL in the web interface. (See D8009) In order to handle marking the file as binary in the removed case, both contexts need to be provided by the caller, since there is no current fctx in the removed case. Having an explicit old fctx will also be useful to support a `--no-stack` option that rolls up the commit stack into a single review. The bug isn't fixed with this change- there's a missing call to it in `addremoved()` as well. But instead of spamming the list with a bunch of test diffs, all of the missing binary issues will be fixed at once later. Differential Revision: https://phab.mercurial-scm.org/D8218 diff --git a/hgext/phabricator.py b/hgext/phabricator.py --- a/hgext/phabricator.py +++ b/hgext/phabricator.py @@ -747,12 +747,14 @@ def uploadfile(fctx): 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 @@ def addmodified(pdiff, ctx, modified): 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 @@ def addadded(pdiff, ctx, added, removed) if fctx.isbinary() or notutf8(fctx): makebinary(pchange, fctx) if renamed: - addoldbinary(pchange, fctx) + addoldbinary(pchange, fctx.p1(), fctx) else: maketext(pchange, ctx, fname)