# HG changeset patch # User Martin von Zweigbergk # Date 1614983212 28800 # Node ID eca88f5fbcb26488397c2df60f173c6d624d6394 # Parent 86ee73018e62f13f4141aa69776710e15fef6a8c copies: extract function _backwardcopies() for reversing renames I'll add another callers in the next patch. Differential Revision: https://phab.mercurial-scm.org/D10118 diff -r 86ee73018e62 -r eca88f5fbcb2 mercurial/copies.py --- a/mercurial/copies.py Fri Mar 05 10:16:44 2021 -0800 +++ b/mercurial/copies.py Fri Mar 05 14:26:52 2021 -0800 @@ -704,22 +704,28 @@ def _backwardrenames(a, b, match): + """find renames from a to b""" if a._repo.ui.config(b'experimental', b'copytrace') == b'off': return {} + # We don't want to pass in "match" here, since that would filter + # the destination by it. Since we're reversing the copies, we want + # to filter the source instead. + copies = _forwardcopies(b, a) + return _reverse_renames(copies, a, match) + + +def _reverse_renames(copies, dst, match): + """given copies to context 'dst', finds renames from that context""" # Even though we're not taking copies into account, 1:n rename situations # can still exist (e.g. hg cp a b; hg mv a c). In those cases we # arbitrarily pick one of the renames. - # We don't want to pass in "match" here, since that would filter - # the destination by it. Since we're reversing the copies, we want - # to filter the source instead. - f = _forwardcopies(b, a) r = {} - for k, v in sorted(pycompat.iteritems(f)): + for k, v in sorted(pycompat.iteritems(copies)): if match and not match(v): continue # remove copies - if v in a: + if v in dst: continue r[v] = k return r