comparison mercurial/copies.py @ 42707:3cffc7bbec26

copies: extract an explicit `computechangesetcopie` method from context Right now, the logic around changeset centric copies data are buried into the "changectx" code. We extract this code in a dedicated method (in the copies module) for clarity. This clarity will help to explicitly compute and caches these data in the future.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 06 Aug 2019 03:17:40 +0200
parents 8c5a36805d5d
children f3bcae1e9e23
comparison
equal deleted inserted replaced
42706:60789444acd6 42707:3cffc7bbec26
807 for dst, src in pathcopies(repo[fromrev], repo[rev]).iteritems(): 807 for dst, src in pathcopies(repo[fromrev], repo[rev]).iteritems():
808 if dst in exclude: 808 if dst in exclude:
809 continue 809 continue
810 if dst in wctx: 810 if dst in wctx:
811 wctx[dst].markcopied(src) 811 wctx[dst].markcopied(src)
812
813 def computechangesetcopies(ctx):
814 """return the copies data for a changeset
815
816 The copies data are returned as a pair of dictionnary (p1copies, p2copies).
817
818 Each dictionnary are in the form: `{newname: oldname}`
819 """
820 p1copies = {}
821 p2copies = {}
822 p1 = ctx.p1()
823 p2 = ctx.p2()
824 narrowmatch = ctx._repo.narrowmatch()
825 for dst in ctx.files():
826 if not narrowmatch(dst) or dst not in ctx:
827 continue
828 copied = ctx[dst].renamed()
829 if not copied:
830 continue
831 src, srcnode = copied
832 if src in p1 and p1[src].filenode() == srcnode:
833 p1copies[dst] = src
834 elif src in p2 and p2[src].filenode() == srcnode:
835 p2copies[dst] = src
836 return p1copies, p2copies