Mercurial > hg
changeset 46161:3a0c41336961
copies: extract value comparison in the python copy tracing
This mirror what we did in the Rust code. This is useful to prepare rework for
this comparison logic that we will need to handle more advanced chaining cases
(when merges are chained).
Differential Revision: https://phab.mercurial-scm.org/D9590
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 14 Dec 2020 01:30:32 +0100 |
parents | 1d6aac94e6d5 |
children | 6b9d65298484 |
files | mercurial/copies.py |
diffstat | 1 files changed, 33 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/copies.py Sun Dec 13 19:18:10 2020 +0100 +++ b/mercurial/copies.py Mon Dec 14 01:30:32 2020 +0100 @@ -446,6 +446,12 @@ return final_copies +# constant to decide which side to pick with _merge_copies_dict +PICK_MINOR = 0 +PICK_MAJOR = 1 +PICK_EITHER = 2 + + def _merge_copies_dict(minor, major, isancestor, changes): """merge two copies-mapping together, minor and major @@ -464,36 +470,37 @@ if other is None: minor[dest] = value else: - new_tt = value[0] - other_tt = other[0] - if value[1] == other[1]: - continue - # content from "major" wins, unless it is older - # than the branch point or there is a merge - if new_tt == other_tt: + pick = _compare_values(changes, isancestor, dest, other, value) + if pick == PICK_MAJOR: minor[dest] = value - elif ( - changes is not None - and value[1] is None - and dest in changes.salvaged - ): - pass - elif ( - changes is not None - and other[1] is None - and dest in changes.salvaged - ): - minor[dest] = value - elif changes is not None and dest in changes.merged: - minor[dest] = value - elif not isancestor(new_tt, other_tt): - if value[1] is not None: - minor[dest] = value - elif isancestor(other_tt, new_tt): - minor[dest] = value return minor +def _compare_values(changes, isancestor, dest, other, value): + """compare two value within a _merge_copies_dict loop iteration""" + new_tt = value[0] + other_tt = other[0] + + if value[1] == other[1]: + return PICK_EITHER + # content from "major" wins, unless it is older + # than the branch point or there is a merge + if new_tt == other_tt: + return PICK_MAJOR + elif changes is not None and value[1] is None and dest in changes.salvaged: + return PICK_MINOR + elif changes is not None and other[1] is None and dest in changes.salvaged: + return PICK_MAJOR + elif changes is not None and dest in changes.merged: + return PICK_MAJOR + elif not isancestor(new_tt, other_tt): + if value[1] is not None: + return PICK_MAJOR + elif isancestor(other_tt, new_tt): + return PICK_MAJOR + return PICK_MINOR + + def _revinfo_getter_extra(repo): """return a function that return multiple data given a <rev>"i