comparison hgext/largefiles/overrides.py @ 45274:0e18861f96ab

merge: return a mergeresult obj from manifestmerge(), calculateupdates() (API) Earlier, manifestmerge() and calculateupdates() returns a tuple of three things. I wanted to add one more thing to return value. Introducing a special class which represents results of a merge will help understand better and also ease adding new return values. Differential Revision: https://phab.mercurial-scm.org/D8799
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 23 Jul 2020 18:03:14 +0530
parents b7808443ed6a
children b442920ab1de
comparison
equal deleted inserted replaced
45270:c8655782ef19 45274:0e18861f96ab
541 @eh.wrapfunction(merge, b'calculateupdates') 541 @eh.wrapfunction(merge, b'calculateupdates')
542 def overridecalculateupdates( 542 def overridecalculateupdates(
543 origfn, repo, p1, p2, pas, branchmerge, force, acceptremote, *args, **kwargs 543 origfn, repo, p1, p2, pas, branchmerge, force, acceptremote, *args, **kwargs
544 ): 544 ):
545 overwrite = force and not branchmerge 545 overwrite = force and not branchmerge
546 actions, diverge, renamedelete = origfn( 546 mresult = origfn(
547 repo, p1, p2, pas, branchmerge, force, acceptremote, *args, **kwargs 547 repo, p1, p2, pas, branchmerge, force, acceptremote, *args, **kwargs
548 ) 548 )
549 549
550 if overwrite: 550 if overwrite:
551 return actions, diverge, renamedelete 551 return mresult
552 552
553 # Convert to dictionary with filename as key and action as value. 553 # Convert to dictionary with filename as key and action as value.
554 lfiles = set() 554 lfiles = set()
555 for f in actions: 555 for f in mresult.actions:
556 splitstandin = lfutil.splitstandin(f) 556 splitstandin = lfutil.splitstandin(f)
557 if splitstandin is not None and splitstandin in p1: 557 if splitstandin is not None and splitstandin in p1:
558 lfiles.add(splitstandin) 558 lfiles.add(splitstandin)
559 elif lfutil.standin(f) in p1: 559 elif lfutil.standin(f) in p1:
560 lfiles.add(f) 560 lfiles.add(f)
561 561
562 for lfile in sorted(lfiles): 562 for lfile in sorted(lfiles):
563 standin = lfutil.standin(lfile) 563 standin = lfutil.standin(lfile)
564 (lm, largs, lmsg) = actions.get(lfile, (None, None, None)) 564 (lm, largs, lmsg) = mresult.actions.get(lfile, (None, None, None))
565 (sm, sargs, smsg) = actions.get(standin, (None, None, None)) 565 (sm, sargs, smsg) = mresult.actions.get(standin, (None, None, None))
566 if sm in (b'g', b'dc') and lm != b'r': 566 if sm in (b'g', b'dc') and lm != b'r':
567 if sm == b'dc': 567 if sm == b'dc':
568 f1, f2, fa, move, anc = sargs 568 f1, f2, fa, move, anc = sargs
569 sargs = (p2[f2].flags(), False) 569 sargs = (p2[f2].flags(), False)
570 # Case 1: normal file in the working copy, largefile in 570 # Case 1: normal file in the working copy, largefile in
576 b'$$ &Largefile $$ &Normal file' 576 b'$$ &Largefile $$ &Normal file'
577 ) 577 )
578 % lfile 578 % lfile
579 ) 579 )
580 if repo.ui.promptchoice(usermsg, 0) == 0: # pick remote largefile 580 if repo.ui.promptchoice(usermsg, 0) == 0: # pick remote largefile
581 actions[lfile] = (b'r', None, b'replaced by standin') 581 mresult.actions[lfile] = (b'r', None, b'replaced by standin')
582 actions[standin] = (b'g', sargs, b'replaces standin') 582 mresult.actions[standin] = (b'g', sargs, b'replaces standin')
583 else: # keep local normal file 583 else: # keep local normal file
584 actions[lfile] = (b'k', None, b'replaces standin') 584 mresult.actions[lfile] = (b'k', None, b'replaces standin')
585 if branchmerge: 585 if branchmerge:
586 actions[standin] = (b'k', None, b'replaced by non-standin') 586 mresult.actions[standin] = (
587 b'k',
588 None,
589 b'replaced by non-standin',
590 )
587 else: 591 else:
588 actions[standin] = (b'r', None, b'replaced by non-standin') 592 mresult.actions[standin] = (
593 b'r',
594 None,
595 b'replaced by non-standin',
596 )
589 elif lm in (b'g', b'dc') and sm != b'r': 597 elif lm in (b'g', b'dc') and sm != b'r':
590 if lm == b'dc': 598 if lm == b'dc':
591 f1, f2, fa, move, anc = largs 599 f1, f2, fa, move, anc = largs
592 largs = (p2[f2].flags(), False) 600 largs = (p2[f2].flags(), False)
593 # Case 2: largefile in the working copy, normal file in 601 # Case 2: largefile in the working copy, normal file in
601 % lfile 609 % lfile
602 ) 610 )
603 if repo.ui.promptchoice(usermsg, 0) == 0: # keep local largefile 611 if repo.ui.promptchoice(usermsg, 0) == 0: # keep local largefile
604 if branchmerge: 612 if branchmerge:
605 # largefile can be restored from standin safely 613 # largefile can be restored from standin safely
606 actions[lfile] = (b'k', None, b'replaced by standin') 614 mresult.actions[lfile] = (
607 actions[standin] = (b'k', None, b'replaces standin') 615 b'k',
616 None,
617 b'replaced by standin',
618 )
619 mresult.actions[standin] = (b'k', None, b'replaces standin')
608 else: 620 else:
609 # "lfile" should be marked as "removed" without 621 # "lfile" should be marked as "removed" without
610 # removal of itself 622 # removal of itself
611 actions[lfile] = ( 623 mresult.actions[lfile] = (
612 b'lfmr', 624 b'lfmr',
613 None, 625 None,
614 b'forget non-standin largefile', 626 b'forget non-standin largefile',
615 ) 627 )
616 628
617 # linear-merge should treat this largefile as 're-added' 629 # linear-merge should treat this largefile as 're-added'
618 actions[standin] = (b'a', None, b'keep standin') 630 mresult.actions[standin] = (b'a', None, b'keep standin')
619 else: # pick remote normal file 631 else: # pick remote normal file
620 actions[lfile] = (b'g', largs, b'replaces standin') 632 mresult.actions[lfile] = (b'g', largs, b'replaces standin')
621 actions[standin] = (b'r', None, b'replaced by non-standin') 633 mresult.actions[standin] = (
622 634 b'r',
623 return actions, diverge, renamedelete 635 None,
636 b'replaced by non-standin',
637 )
638
639 return mresult
624 640
625 641
626 @eh.wrapfunction(mergestatemod, b'recordupdates') 642 @eh.wrapfunction(mergestatemod, b'recordupdates')
627 def mergerecordupdates(orig, repo, actions, branchmerge, getfiledata): 643 def mergerecordupdates(orig, repo, actions, branchmerge, getfiledata):
628 if b'lfmr' in actions: 644 if b'lfmr' in actions: