Mercurial > public > mercurial-scm > hg
comparison hgext/phabricator.py @ 44426:66a05dbb8b4c
phabricator: don't infer the old `fctx` in `notutf8()`
This is used along with `fctx.isbinary()` to gate `addoldbinary()`, so it seems
like a good idea to provide the caller similar control over the current and
parent filecontext. Unlike `addoldbinary()`, it doesn't need both previous and
current contexts at the same time, so make the caller responsible for testing
both cases, as appropriate. I haven't worked out all of the problems around
marking files as binary for move/remove/copy, but this will definitely help with
`--no-stack` too.
It also turns out to have been doing too much- in the remove case, it tested not
just the removed file in the parent context (which is what gets passed in that
case), but also in the parent of the parent context (which should be
irrelevant). The previous code also required the `fctx.parents()` check to work
in the add (but without rename) case. Now the add and remove cases test only
what they need to. But now that it is written this way, the fact that only the
current `fctx` is checked to be binary in the case of modification or being
renamed seems wrong.
Differential Revision: https://phab.mercurial-scm.org/D8220
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 20 Feb 2020 10:46:43 -0500 |
parents | aa9979bb6853 |
children | 4ce2330f2d0b |
comparison
equal
deleted
inserted
replaced
44425:aa9979bb6853 | 44426:66a05dbb8b4c |
---|---|
794 """detect non-UTF-8 text files since Phabricator requires them to be marked | 794 """detect non-UTF-8 text files since Phabricator requires them to be marked |
795 as binary | 795 as binary |
796 """ | 796 """ |
797 try: | 797 try: |
798 fctx.data().decode('utf-8') | 798 fctx.data().decode('utf-8') |
799 if fctx.parents(): | |
800 fctx.p1().data().decode('utf-8') | |
801 return False | 799 return False |
802 except UnicodeDecodeError: | 800 except UnicodeDecodeError: |
803 fctx.repo().ui.write( | 801 fctx.repo().ui.write( |
804 _(b'file %s detected as non-UTF-8, marked as binary\n') | 802 _(b'file %s detected as non-UTF-8, marked as binary\n') |
805 % fctx.path() | 803 % fctx.path() |
823 | 821 |
824 def addmodified(pdiff, ctx, modified): | 822 def addmodified(pdiff, ctx, modified): |
825 """add modified files to the phabdiff""" | 823 """add modified files to the phabdiff""" |
826 for fname in modified: | 824 for fname in modified: |
827 fctx = ctx[fname] | 825 fctx = ctx[fname] |
826 oldfctx = fctx.p1() | |
828 pchange = phabchange(currentPath=fname, oldPath=fname) | 827 pchange = phabchange(currentPath=fname, oldPath=fname) |
829 filemode = gitmode[ctx[fname].flags()] | 828 filemode = gitmode[ctx[fname].flags()] |
830 originalmode = gitmode[ctx.p1()[fname].flags()] | 829 originalmode = gitmode[ctx.p1()[fname].flags()] |
831 if filemode != originalmode: | 830 if filemode != originalmode: |
832 pchange.addoldmode(originalmode) | 831 pchange.addoldmode(originalmode) |
833 pchange.addnewmode(filemode) | 832 pchange.addnewmode(filemode) |
834 | 833 |
835 if fctx.isbinary() or notutf8(fctx): | 834 if fctx.isbinary() or notutf8(fctx) or notutf8(oldfctx): |
836 makebinary(pchange, fctx) | 835 makebinary(pchange, fctx) |
837 addoldbinary(pchange, fctx.p1(), fctx) | 836 addoldbinary(pchange, fctx.p1(), fctx) |
838 else: | 837 else: |
839 maketext(pchange, ctx, fname) | 838 maketext(pchange, ctx, fname) |
840 | 839 |
847 # additional copies we can mark them (moves get removed from removed) | 846 # additional copies we can mark them (moves get removed from removed) |
848 copiedchanges = {} | 847 copiedchanges = {} |
849 movedchanges = {} | 848 movedchanges = {} |
850 for fname in added: | 849 for fname in added: |
851 fctx = ctx[fname] | 850 fctx = ctx[fname] |
851 oldfctx = None | |
852 pchange = phabchange(currentPath=fname) | 852 pchange = phabchange(currentPath=fname) |
853 | 853 |
854 filemode = gitmode[ctx[fname].flags()] | 854 filemode = gitmode[ctx[fname].flags()] |
855 renamed = fctx.renamed() | 855 renamed = fctx.renamed() |
856 | 856 |
857 if renamed: | 857 if renamed: |
858 originalfname = renamed[0] | 858 originalfname = renamed[0] |
859 originalmode = gitmode[ctx.p1()[originalfname].flags()] | 859 oldfctx = ctx.p1()[originalfname] |
860 originalmode = gitmode[oldfctx.flags()] | |
860 pchange.oldPath = originalfname | 861 pchange.oldPath = originalfname |
861 | 862 |
862 if originalfname in removed: | 863 if originalfname in removed: |
863 origpchange = phabchange( | 864 origpchange = phabchange( |
864 currentPath=originalfname, | 865 currentPath=originalfname, |
889 pchange.addnewmode(filemode) | 890 pchange.addnewmode(filemode) |
890 else: # Brand-new file | 891 else: # Brand-new file |
891 pchange.addnewmode(gitmode[fctx.flags()]) | 892 pchange.addnewmode(gitmode[fctx.flags()]) |
892 pchange.type = DiffChangeType.ADD | 893 pchange.type = DiffChangeType.ADD |
893 | 894 |
894 if fctx.isbinary() or notutf8(fctx): | 895 if fctx.isbinary() or notutf8(fctx) or (oldfctx and notutf8(oldfctx)): |
895 makebinary(pchange, fctx) | 896 makebinary(pchange, fctx) |
896 if renamed: | 897 if renamed: |
897 addoldbinary(pchange, fctx.p1(), fctx) | 898 addoldbinary(pchange, oldfctx, fctx) |
898 else: | 899 else: |
899 maketext(pchange, ctx, fname) | 900 maketext(pchange, ctx, fname) |
900 | 901 |
901 pdiff.addchange(pchange) | 902 pdiff.addchange(pchange) |
902 | 903 |