comparison mercurial/copies.py @ 46562:c692384bb559

copies: rearrange all value comparison conditional To properly handle the newly tested case (chaining of merges) we will need to detect more accurately when an actualy merging of the copy information (and superseed the two existing data). Before starting to do so, we need to reorganise the values comparison to introduce different conditional branches when such actual merging is needed/detected. To avoid mixing too many change in this complicated code, we do the reorganisation before adding the "overwrite detection" logic in the next changesets. Differential Revision: https://phab.mercurial-scm.org/D9612
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 14 Dec 2020 19:26:33 +0100
parents 892eb7c5edaa
children c19c662097e1
comparison
equal deleted inserted replaced
46561:388a92023a1a 46562:c692384bb559
479 minor[dest] = value 479 minor[dest] = value
480 return minor 480 return minor
481 481
482 482
483 def _compare_values(changes, isancestor, dest, minor, major): 483 def _compare_values(changes, isancestor, dest, minor, major):
484 """compare two value within a _merge_copies_dict loop iteration""" 484 """compare two value within a _merge_copies_dict loop iteration
485
486 return pick
487
488 - pick is one of PICK_MINOR, PICK_MAJOR or PICK_EITHER
489 """
485 major_tt, major_value = major 490 major_tt, major_value = major
486 minor_tt, minor_value = minor 491 minor_tt, minor_value = minor
487 492
488 # evacuate some simple case first:
489 if major_tt == minor_tt: 493 if major_tt == minor_tt:
490 # if it comes from the same revision it must be the same value 494 # if it comes from the same revision it must be the same value
491 assert major_value == minor_value 495 assert major_value == minor_value
492 return PICK_EITHER 496 return PICK_EITHER
493 elif major[1] == minor[1]: 497 elif (
494 return PICK_EITHER 498 changes is not None
495 499 and minor_value is not None
496 # actual merging needed: content from "major" wins, unless it is older than 500 and major_value is None
497 # the branch point or there is a merge 501 and dest in changes.salvaged
498 elif changes is not None and major[1] is None and dest in changes.salvaged: 502 ):
503 # In this case, a deletion was reverted, the "alive" value overwrite
504 # the deleted one.
499 return PICK_MINOR 505 return PICK_MINOR
500 elif changes is not None and minor[1] is None and dest in changes.salvaged: 506 elif (
507 changes is not None
508 and major_value is not None
509 and minor_value is None
510 and dest in changes.salvaged
511 ):
512 # In this case, a deletion was reverted, the "alive" value overwrite
513 # the deleted one.
501 return PICK_MAJOR 514 return PICK_MAJOR
502 elif changes is not None and dest in changes.merged: 515 elif isancestor(minor_tt, major_tt):
516 if changes is not None and dest in changes.merged:
517 # change to dest happened on the branch without copy-source change,
518 # so both source are valid and "major" wins.
519 return PICK_MAJOR
520 else:
521 return PICK_MAJOR
522 elif isancestor(major_tt, minor_tt):
523 if changes is not None and dest in changes.merged:
524 # change to dest happened on the branch without copy-source change,
525 # so both source are valid and "major" wins.
526 return PICK_MAJOR
527 else:
528 return PICK_MINOR
529 elif minor_value is None:
530 # in case of conflict, the "alive" side wins.
503 return PICK_MAJOR 531 return PICK_MAJOR
504 elif not isancestor(major_tt, minor_tt): 532 elif major_value is None:
505 if major[1] is not None: 533 # in case of conflict, the "alive" side wins.
506 return PICK_MAJOR 534 return PICK_MINOR
507 elif isancestor(minor_tt, major_tt): 535 else:
508 return PICK_MAJOR 536 # in case of conflict where both side are alive, major wins.
509 return PICK_MINOR 537 return PICK_MAJOR
510 538
511 539
512 def _revinfo_getter_extra(repo): 540 def _revinfo_getter_extra(repo):
513 """return a function that return multiple data given a <rev>"i 541 """return a function that return multiple data given a <rev>"i
514 542