comparison mercurial/merge.py @ 21551:bde505f47141

merge: fix stupid indentation left over from previous refactorings
author Mads Kiilerich <madski@unity3d.com>
date Fri, 02 May 2014 01:09:14 +0200
parents 43eecb4e23f8
children 46308fadaa15 b27c3beaaf30
comparison
equal deleted inserted replaced
21550:b4f0e15d1dab 21551:bde505f47141
565 wjoin = repo.wjoin 565 wjoin = repo.wjoin
566 audit = repo.wopener.audit 566 audit = repo.wopener.audit
567 i = 0 567 i = 0
568 for f, args, msg in actions: 568 for f, args, msg in actions:
569 repo.ui.debug(" %s: %s -> r\n" % (f, msg)) 569 repo.ui.debug(" %s: %s -> r\n" % (f, msg))
570 if True: 570 if verbose:
571 if verbose: 571 repo.ui.note(_("removing %s\n") % f)
572 repo.ui.note(_("removing %s\n") % f) 572 audit(f)
573 audit(f) 573 try:
574 try: 574 unlink(wjoin(f), ignoremissing=True)
575 unlink(wjoin(f), ignoremissing=True) 575 except OSError, inst:
576 except OSError, inst: 576 repo.ui.warn(_("update failed to remove %s: %s!\n") %
577 repo.ui.warn(_("update failed to remove %s: %s!\n") % 577 (f, inst.strerror))
578 (f, inst.strerror))
579 if i == 100: 578 if i == 100:
580 yield i, f 579 yield i, f
581 i = 0 580 i = 0
582 i += 1 581 i += 1
583 if i > 0: 582 if i > 0:
594 fctx = mctx.filectx 593 fctx = mctx.filectx
595 wwrite = repo.wwrite 594 wwrite = repo.wwrite
596 i = 0 595 i = 0
597 for f, args, msg in actions: 596 for f, args, msg in actions:
598 repo.ui.debug(" %s: %s -> g\n" % (f, msg)) 597 repo.ui.debug(" %s: %s -> g\n" % (f, msg))
599 if True: 598 if verbose:
600 if verbose: 599 repo.ui.note(_("getting %s\n") % f)
601 repo.ui.note(_("getting %s\n") % f) 600 wwrite(f, fctx(f).data(), args[0])
602 wwrite(f, fctx(f).data(), args[0])
603 if i == 100: 601 if i == 100:
604 yield i, f 602 yield i, f
605 i = 0 603 i = 0
606 i += 1 604 i += 1
607 if i > 0: 605 if i > 0:
624 for m, l in actions.items(): 622 for m, l in actions.items():
625 l.sort() 623 l.sort()
626 624
627 # prescan for merges 625 # prescan for merges
628 for f, args, msg in actions['m']: 626 for f, args, msg in actions['m']:
629 if True: 627 f1, f2, fa, move, anc = args
630 f1, f2, fa, move, anc = args 628 if f == '.hgsubstate': # merged internally
631 if f == '.hgsubstate': # merged internally 629 continue
632 continue 630 repo.ui.debug(" preserving %s for resolve of %s\n" % (f1, f))
633 repo.ui.debug(" preserving %s for resolve of %s\n" % (f1, f)) 631 fcl = wctx[f1]
634 fcl = wctx[f1] 632 fco = mctx[f2]
635 fco = mctx[f2] 633 actx = repo[anc]
636 actx = repo[anc] 634 if fa in actx:
637 if fa in actx: 635 fca = actx[fa]
638 fca = actx[fa] 636 else:
639 else: 637 fca = repo.filectx(f1, fileid=nullrev)
640 fca = repo.filectx(f1, fileid=nullrev) 638 ms.add(fcl, fco, fca, f)
641 ms.add(fcl, fco, fca, f) 639 if f1 != f and move:
642 if f1 != f and move: 640 moves.append(f1)
643 moves.append(f1)
644 641
645 audit = repo.wopener.audit 642 audit = repo.wopener.audit
646 _updating = _('updating') 643 _updating = _('updating')
647 _files = _('files') 644 _files = _('files')
648 progress = repo.ui.progress 645 progress = repo.ui.progress
675 updated = len(actions['g']) 672 updated = len(actions['g'])
676 673
677 if [a for a in actions['g'] if a[0] == '.hgsubstate']: 674 if [a for a in actions['g'] if a[0] == '.hgsubstate']:
678 subrepo.submerge(repo, wctx, mctx, wctx, overwrite) 675 subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
679 676
680 if True: 677 # forget (manifest only, just log it) (must come first)
681 678 for f, args, msg in actions['f']:
682 # forget (manifest only, just log it) (must come first) 679 repo.ui.debug(" %s: %s -> f\n" % (f, msg))
683 for f, args, msg in actions['f']: 680 z += 1
684 repo.ui.debug(" %s: %s -> f\n" % (f, msg)) 681 progress(_updating, z, item=f, total=numupdates, unit=_files)
685 z += 1 682
686 progress(_updating, z, item=f, total=numupdates, unit=_files) 683 # re-add (manifest only, just log it)
687 684 for f, args, msg in actions['a']:
688 # re-add (manifest only, just log it) 685 repo.ui.debug(" %s: %s -> a\n" % (f, msg))
689 for f, args, msg in actions['a']: 686 z += 1
690 repo.ui.debug(" %s: %s -> a\n" % (f, msg)) 687 progress(_updating, z, item=f, total=numupdates, unit=_files)
691 z += 1 688
692 progress(_updating, z, item=f, total=numupdates, unit=_files) 689 # keep (noop, just log it)
693 690 for f, args, msg in actions['k']:
694 # keep (noop, just log it) 691 repo.ui.debug(" %s: %s -> k\n" % (f, msg))
695 for f, args, msg in actions['k']: 692 # no progress
696 repo.ui.debug(" %s: %s -> k\n" % (f, msg)) 693
697 # no progress 694 # merge
698 695 for f, args, msg in actions['m']:
699 # merge 696 repo.ui.debug(" %s: %s -> m\n" % (f, msg))
700 for f, args, msg in actions['m']: 697 z += 1
701 repo.ui.debug(" %s: %s -> m\n" % (f, msg)) 698 progress(_updating, z, item=f, total=numupdates, unit=_files)
702 z += 1 699 f1, f2, fa, move, anc = args
703 progress(_updating, z, item=f, total=numupdates, unit=_files) 700 if f == '.hgsubstate': # subrepo states need updating
704 f1, f2, fa, move, anc = args 701 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
705 if f == '.hgsubstate': # subrepo states need updating 702 overwrite)
706 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx), 703 continue
707 overwrite) 704 audit(f)
708 continue 705 r = ms.resolve(f, wctx, labels=labels)
709 audit(f) 706 if r is not None and r > 0:
710 r = ms.resolve(f, wctx, labels=labels) 707 unresolved += 1
711 if r is not None and r > 0: 708 else:
712 unresolved += 1 709 if r is None:
710 updated += 1
713 else: 711 else:
714 if r is None: 712 merged += 1
715 updated += 1 713
716 else: 714 # directory rename, move local
717 merged += 1 715 for f, args, msg in actions['dm']:
718 716 repo.ui.debug(" %s: %s -> dm\n" % (f, msg))
719 # directory rename, move local 717 z += 1
720 for f, args, msg in actions['dm']: 718 progress(_updating, z, item=f, total=numupdates, unit=_files)
721 repo.ui.debug(" %s: %s -> dm\n" % (f, msg)) 719 f0, flags = args
722 z += 1 720 repo.ui.note(_("moving %s to %s\n") % (f0, f))
723 progress(_updating, z, item=f, total=numupdates, unit=_files) 721 audit(f)
724 f0, flags = args 722 repo.wwrite(f, wctx.filectx(f0).data(), flags)
725 repo.ui.note(_("moving %s to %s\n") % (f0, f)) 723 util.unlinkpath(repo.wjoin(f0))
726 audit(f) 724 updated += 1
727 repo.wwrite(f, wctx.filectx(f0).data(), flags) 725
728 util.unlinkpath(repo.wjoin(f0)) 726 # local directory rename, get
729 updated += 1 727 for f, args, msg in actions['dg']:
730 728 repo.ui.debug(" %s: %s -> dg\n" % (f, msg))
731 # local directory rename, get 729 z += 1
732 for f, args, msg in actions['dg']: 730 progress(_updating, z, item=f, total=numupdates, unit=_files)
733 repo.ui.debug(" %s: %s -> dg\n" % (f, msg)) 731 f0, flags = args
734 z += 1 732 repo.ui.note(_("getting %s to %s\n") % (f0, f))
735 progress(_updating, z, item=f, total=numupdates, unit=_files) 733 repo.wwrite(f, mctx.filectx(f0).data(), flags)
736 f0, flags = args 734 updated += 1
737 repo.ui.note(_("getting %s to %s\n") % (f0, f)) 735
738 repo.wwrite(f, mctx.filectx(f0).data(), flags) 736 # divergent renames
739 updated += 1 737 for f, args, msg in actions['dr']:
740 738 repo.ui.debug(" %s: %s -> dr\n" % (f, msg))
741 # divergent renames 739 z += 1
742 for f, args, msg in actions['dr']: 740 progress(_updating, z, item=f, total=numupdates, unit=_files)
743 repo.ui.debug(" %s: %s -> dr\n" % (f, msg)) 741 fl, = args
744 z += 1 742 repo.ui.warn(_("note: possible conflict - %s was renamed "
745 progress(_updating, z, item=f, total=numupdates, unit=_files) 743 "multiple times to:\n") % f)
746 fl, = args 744 for nf in fl:
747 repo.ui.warn(_("note: possible conflict - %s was renamed " 745 repo.ui.warn(" %s\n" % nf)
748 "multiple times to:\n") % f) 746
749 for nf in fl: 747 # rename and delete
750 repo.ui.warn(" %s\n" % nf) 748 for f, args, msg in actions['rd']:
751 749 repo.ui.debug(" %s: %s -> rd\n" % (f, msg))
752 # rename and delete 750 z += 1
753 for f, args, msg in actions['rd']: 751 progress(_updating, z, item=f, total=numupdates, unit=_files)
754 repo.ui.debug(" %s: %s -> rd\n" % (f, msg)) 752 fl, = args
755 z += 1 753 repo.ui.warn(_("note: possible conflict - %s was deleted "
756 progress(_updating, z, item=f, total=numupdates, unit=_files) 754 "and renamed to:\n") % f)
757 fl, = args 755 for nf in fl:
758 repo.ui.warn(_("note: possible conflict - %s was deleted " 756 repo.ui.warn(" %s\n" % nf)
759 "and renamed to:\n") % f) 757
760 for nf in fl: 758 # exec
761 repo.ui.warn(" %s\n" % nf) 759 for f, args, msg in actions['e']:
762 760 repo.ui.debug(" %s: %s -> e\n" % (f, msg))
763 # exec 761 z += 1
764 for f, args, msg in actions['e']: 762 progress(_updating, z, item=f, total=numupdates, unit=_files)
765 repo.ui.debug(" %s: %s -> e\n" % (f, msg)) 763 flags, = args
766 z += 1 764 audit(f)
767 progress(_updating, z, item=f, total=numupdates, unit=_files) 765 util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags)
768 flags, = args 766 updated += 1
769 audit(f)
770 util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags)
771 updated += 1
772 767
773 ms.commit() 768 ms.commit()
774 progress(_updating, None, total=numupdates, unit=_files) 769 progress(_updating, None, total=numupdates, unit=_files)
775 770
776 return updated, merged, removed, unresolved 771 return updated, merged, removed, unresolved
846 actions[m].append(l[0]) 841 actions[m].append(l[0])
847 continue 842 continue
848 repo.ui.note(_('end of auction\n\n')) 843 repo.ui.note(_('end of auction\n\n'))
849 844
850 # Prompt and create actions. TODO: Move this towards resolve phase. 845 # Prompt and create actions. TODO: Move this towards resolve phase.
851 if True: 846 for f, args, msg in actions['cd']:
852 for f, args, msg in actions['cd']: 847 if repo.ui.promptchoice(
853 if repo.ui.promptchoice( 848 _("local changed %s which remote deleted\n"
854 _("local changed %s which remote deleted\n" 849 "use (c)hanged version or (d)elete?"
855 "use (c)hanged version or (d)elete?" 850 "$$ &Changed $$ &Delete") % f, 0):
856 "$$ &Changed $$ &Delete") % f, 0): 851 actions['r'].append((f, None, "prompt delete"))
857 actions['r'].append((f, None, "prompt delete")) 852 else:
858 else: 853 actions['a'].append((f, None, "prompt keep"))
859 actions['a'].append((f, None, "prompt keep")) 854 del actions['cd'][:]
860 del actions['cd'][:] 855
861 856 for f, args, msg in actions['dc']:
862 for f, args, msg in actions['dc']: 857 flags, = args
863 flags, = args 858 if repo.ui.promptchoice(
864 if repo.ui.promptchoice( 859 _("remote changed %s which local deleted\n"
865 _("remote changed %s which local deleted\n" 860 "use (c)hanged version or leave (d)eleted?"
866 "use (c)hanged version or leave (d)eleted?" 861 "$$ &Changed $$ &Deleted") % f, 0) == 0:
867 "$$ &Changed $$ &Deleted") % f, 0) == 0: 862 actions['g'].append((f, (flags,), "prompt recreating"))
868 actions['g'].append((f, (flags,), "prompt recreating")) 863 del actions['dc'][:]
869 del actions['dc'][:]
870 864
871 if wctx.rev() is None: 865 if wctx.rev() is None:
872 ractions, factions = _forgetremoved(wctx, mctx, branchmerge) 866 ractions, factions = _forgetremoved(wctx, mctx, branchmerge)
873 actions['r'].extend(ractions) 867 actions['r'].extend(ractions)
874 actions['f'].extend(factions) 868 actions['f'].extend(factions)
875 869
876 return actions 870 return actions
877 871
878 def recordupdates(repo, actions, branchmerge): 872 def recordupdates(repo, actions, branchmerge):
879 "record merge actions to the dirstate" 873 "record merge actions to the dirstate"
880 if True: 874 # remove (must come first)
881 # remove (must come first) 875 for f, args, msg in actions['r']:
882 for f, args, msg in actions['r']: 876 if branchmerge:
883 if branchmerge: 877 repo.dirstate.remove(f)
884 repo.dirstate.remove(f) 878 else:
885 else:
886 repo.dirstate.drop(f)
887
888 # forget (must come first)
889 for f, args, msg in actions['f']:
890 repo.dirstate.drop(f) 879 repo.dirstate.drop(f)
891 880
892 # re-add 881 # forget (must come first)
893 for f, args, msg in actions['a']: 882 for f, args, msg in actions['f']:
894 if not branchmerge: 883 repo.dirstate.drop(f)
895 repo.dirstate.add(f) 884
896 885 # re-add
897 # exec change 886 for f, args, msg in actions['a']:
898 for f, args, msg in actions['e']: 887 if not branchmerge:
899 repo.dirstate.normallookup(f) 888 repo.dirstate.add(f)
900 889
901 # keep 890 # exec change
902 for f, args, msg in actions['k']: 891 for f, args, msg in actions['e']:
903 pass 892 repo.dirstate.normallookup(f)
904 893
905 # get 894 # keep
906 for f, args, msg in actions['g']: 895 for f, args, msg in actions['k']:
907 if branchmerge: 896 pass
908 repo.dirstate.otherparent(f) 897
909 else: 898 # get
910 repo.dirstate.normal(f) 899 for f, args, msg in actions['g']:
911 900 if branchmerge:
912 # merge 901 repo.dirstate.otherparent(f)
913 for f, args, msg in actions['m']: 902 else:
914 f1, f2, fa, move, anc = args 903 repo.dirstate.normal(f)
915 if branchmerge: 904
916 # We've done a branch merge, mark this file as merged 905 # merge
917 # so that we properly record the merger later 906 for f, args, msg in actions['m']:
918 repo.dirstate.merge(f) 907 f1, f2, fa, move, anc = args
919 if f1 != f2: # copy/rename 908 if branchmerge:
920 if move: 909 # We've done a branch merge, mark this file as merged
921 repo.dirstate.remove(f1) 910 # so that we properly record the merger later
922 if f1 != f: 911 repo.dirstate.merge(f)
923 repo.dirstate.copy(f1, f) 912 if f1 != f2: # copy/rename
924 else:
925 repo.dirstate.copy(f2, f)
926 else:
927 # We've update-merged a locally modified file, so
928 # we set the dirstate to emulate a normal checkout
929 # of that file some time in the past. Thus our
930 # merge will appear as a normal local file
931 # modification.
932 if f2 == f: # file not locally copied/moved
933 repo.dirstate.normallookup(f)
934 if move: 913 if move:
935 repo.dirstate.drop(f1) 914 repo.dirstate.remove(f1)
936 915 if f1 != f:
937 # directory rename, move local 916 repo.dirstate.copy(f1, f)
938 for f, args, msg in actions['dm']: 917 else:
939 f0, flag = args 918 repo.dirstate.copy(f2, f)
940 if f0 not in repo.dirstate: 919 else:
941 # untracked file moved 920 # We've update-merged a locally modified file, so
942 continue 921 # we set the dirstate to emulate a normal checkout
943 if branchmerge: 922 # of that file some time in the past. Thus our
944 repo.dirstate.add(f) 923 # merge will appear as a normal local file
945 repo.dirstate.remove(f0) 924 # modification.
946 repo.dirstate.copy(f0, f) 925 if f2 == f: # file not locally copied/moved
947 else: 926 repo.dirstate.normallookup(f)
948 repo.dirstate.normal(f) 927 if move:
949 repo.dirstate.drop(f0) 928 repo.dirstate.drop(f1)
950 929
951 # directory rename, get 930 # directory rename, move local
952 for f, args, msg in actions['dg']: 931 for f, args, msg in actions['dm']:
953 f0, flag = args 932 f0, flag = args
954 if branchmerge: 933 if f0 not in repo.dirstate:
955 repo.dirstate.add(f) 934 # untracked file moved
956 repo.dirstate.copy(f0, f) 935 continue
957 else: 936 if branchmerge:
958 repo.dirstate.normal(f) 937 repo.dirstate.add(f)
938 repo.dirstate.remove(f0)
939 repo.dirstate.copy(f0, f)
940 else:
941 repo.dirstate.normal(f)
942 repo.dirstate.drop(f0)
943
944 # directory rename, get
945 for f, args, msg in actions['dg']:
946 f0, flag = args
947 if branchmerge:
948 repo.dirstate.add(f)
949 repo.dirstate.copy(f0, f)
950 else:
951 repo.dirstate.normal(f)
959 952
960 def update(repo, node, branchmerge, force, partial, ancestor=None, 953 def update(repo, node, branchmerge, force, partial, ancestor=None,
961 mergeancestor=False, labels=None): 954 mergeancestor=False, labels=None):
962 """ 955 """
963 Perform a merge between the working directory and the given node 956 Perform a merge between the working directory and the given node