Mercurial > hg
comparison hgext/phabricator.py @ 43258:d5d1edf66091
phabricator: add addadded function
This is the most complicated part of the new code, and is responsible for
adding all added files, whether brand new, copied, or moved. This also
includes creating the phabchanges for the original files that have been moved
or copied from, since they might need their awayPaths and type updating if
multiple copies are involved.
Differential Revision: https://phab.mercurial-scm.org/D7050
author | Ian Moody <moz-ian@perix.co.uk> |
---|---|
date | Sun, 06 Oct 2019 17:21:26 +0100 |
parents | c19b327017b9 |
children | 162b81e65e60 |
comparison
equal
deleted
inserted
replaced
43257:675c776fbcd1 | 43258:d5d1edf66091 |
---|---|
718 addoldbinary(pchange, fctx, fname) | 718 addoldbinary(pchange, fctx, fname) |
719 else: | 719 else: |
720 maketext(pchange, ctx, fname) | 720 maketext(pchange, ctx, fname) |
721 | 721 |
722 pdiff.addchange(pchange) | 722 pdiff.addchange(pchange) |
723 | |
724 | |
725 def addadded(pdiff, ctx, added, removed): | |
726 """add file adds to the phabdiff, both new files and copies/moves""" | |
727 # Keep track of files that've been recorded as moved/copied, so if there are | |
728 # additional copies we can mark them (moves get removed from removed) | |
729 copiedchanges = {} | |
730 movedchanges = {} | |
731 for fname in added: | |
732 fctx = ctx[fname] | |
733 pchange = phabchange(currentPath=fname) | |
734 | |
735 filemode = gitmode[ctx[fname].flags()] | |
736 renamed = fctx.renamed() | |
737 | |
738 if renamed: | |
739 originalfname = renamed[0] | |
740 originalmode = gitmode[ctx.p1()[originalfname].flags()] | |
741 pchange.oldPath = originalfname | |
742 | |
743 if originalfname in removed: | |
744 origpchange = phabchange( | |
745 currentPath=originalfname, | |
746 oldPath=originalfname, | |
747 type=DiffChangeType.MOVE_AWAY, | |
748 awayPaths=[fname], | |
749 ) | |
750 movedchanges[originalfname] = origpchange | |
751 removed.remove(originalfname) | |
752 pchange.type = DiffChangeType.MOVE_HERE | |
753 elif originalfname in movedchanges: | |
754 movedchanges[originalfname].type = DiffChangeType.MULTICOPY | |
755 movedchanges[originalfname].awayPaths.append(fname) | |
756 pchange.type = DiffChangeType.COPY_HERE | |
757 else: # pure copy | |
758 if originalfname not in copiedchanges: | |
759 origpchange = phabchange( | |
760 currentPath=originalfname, type=DiffChangeType.COPY_AWAY | |
761 ) | |
762 copiedchanges[originalfname] = origpchange | |
763 else: | |
764 origpchange = copiedchanges[originalfname] | |
765 origpchange.awayPaths.append(fname) | |
766 pchange.type = DiffChangeType.COPY_HERE | |
767 | |
768 if filemode != originalmode: | |
769 pchange.addoldmode(originalmode) | |
770 pchange.addnewmode(filemode) | |
771 else: # Brand-new file | |
772 pchange.addnewmode(gitmode[fctx.flags()]) | |
773 pchange.type = DiffChangeType.ADD | |
774 | |
775 if fctx.isbinary(): | |
776 makebinary(pchange, fctx) | |
777 if renamed: | |
778 addoldbinary(pchange, fctx, originalfname) | |
779 else: | |
780 maketext(pchange, ctx, fname) | |
781 | |
782 pdiff.addchange(pchange) | |
783 | |
784 for _path, copiedchange in copiedchanges.items(): | |
785 pdiff.addchange(copiedchange) | |
786 for _path, movedchange in movedchanges.items(): | |
787 pdiff.addchange(movedchange) | |
723 | 788 |
724 | 789 |
725 def creatediff(ctx): | 790 def creatediff(ctx): |
726 """create a Differential Diff""" | 791 """create a Differential Diff""" |
727 repo = ctx.repo() | 792 repo = ctx.repo() |