comparison hgext/phabricator.py @ 44424:98f7b9cf7bfc

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
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 19 Feb 2020 13:33:58 -0500
parents 5e2d74e5f450
children aa9979bb6853
comparison
equal deleted inserted replaced
44423:5e2d74e5f450 44424:98f7b9cf7bfc
745 raise error.Abort(b'Upload of %s failed.' % bytes(fctx)) 745 raise error.Abort(b'Upload of %s failed.' % bytes(fctx))
746 746
747 return fphid 747 return fphid
748 748
749 749
750 def addoldbinary(pchange, fctx): 750 def addoldbinary(pchange, oldfctx, fctx):
751 """add the metadata for the previous version of a binary file to the 751 """add the metadata for the previous version of a binary file to the
752 phabchange for the new version 752 phabchange for the new version
753 """ 753
754 oldfctx = fctx.p1() 754 ``oldfctx`` is the previous version of the file; ``fctx`` is the new
755 if fctx.cmp(oldfctx): 755 version of the file, or None if the file is being removed.
756 """
757 if not fctx or fctx.cmp(oldfctx):
756 # Files differ, add the old one 758 # Files differ, add the old one
757 pchange.metadata[b'old:file:size'] = oldfctx.size() 759 pchange.metadata[b'old:file:size'] = oldfctx.size()
758 mimeguess, _enc = mimetypes.guess_type( 760 mimeguess, _enc = mimetypes.guess_type(
759 encoding.unifromlocal(oldfctx.path()) 761 encoding.unifromlocal(oldfctx.path())
760 ) 762 )
830 pchange.addoldmode(originalmode) 832 pchange.addoldmode(originalmode)
831 pchange.addnewmode(filemode) 833 pchange.addnewmode(filemode)
832 834
833 if fctx.isbinary() or notutf8(fctx): 835 if fctx.isbinary() or notutf8(fctx):
834 makebinary(pchange, fctx) 836 makebinary(pchange, fctx)
835 addoldbinary(pchange, fctx) 837 addoldbinary(pchange, fctx.p1(), fctx)
836 else: 838 else:
837 maketext(pchange, ctx, fname) 839 maketext(pchange, ctx, fname)
838 840
839 pdiff.addchange(pchange) 841 pdiff.addchange(pchange)
840 842
890 pchange.type = DiffChangeType.ADD 892 pchange.type = DiffChangeType.ADD
891 893
892 if fctx.isbinary() or notutf8(fctx): 894 if fctx.isbinary() or notutf8(fctx):
893 makebinary(pchange, fctx) 895 makebinary(pchange, fctx)
894 if renamed: 896 if renamed:
895 addoldbinary(pchange, fctx) 897 addoldbinary(pchange, fctx.p1(), fctx)
896 else: 898 else:
897 maketext(pchange, ctx, fname) 899 maketext(pchange, ctx, fname)
898 900
899 pdiff.addchange(pchange) 901 pdiff.addchange(pchange)
900 902