comparison mercurial/merge.py @ 21391:cb15835456cb

merge: change debug logging - test output changes but no real changes Preparing for action list split-up, making sure the final change don't have any test changes. The patch moves debug statements around without really changing anything. Arguably, it temporarily makes the code worse. The only justification is that it makes it easier to review the test changes ... and in the end the big change will not change test output at all. The changes to test output are due to changes in the ordering of debug output. That is mainly because we now do the debug logging for files when we actually process them. Files are also processed in a slightly different but still correct order. It is now primarily ordered by action type, secondarily by filename. The patch introduces some redundancy. Some of it will be removed again, some of it will in the end help code readability and efficiency. It is possible that we later on could introduce a "process this action list and do some logging and progress reporting and apply this function". The "preserving X for resolve" debug statements will only have single space indentation. It will no longer have a leading single space indented "f: msg -> m" message. Having this message double indented would thus no longer make sense. The bid actions will temporarily be sorted using a custom sort key that happens to match the sort order the simplified code will have in the end.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 22 Apr 2014 02:10:25 +0200
parents 26b84128c54d
children b1ce47dadbdf
comparison
equal deleted inserted replaced
21390:26b84128c54d 21391:cb15835456cb
589 wjoin = repo.wjoin 589 wjoin = repo.wjoin
590 fctx = mctx.filectx 590 fctx = mctx.filectx
591 wwrite = repo.wwrite 591 wwrite = repo.wwrite
592 audit = repo.wopener.audit 592 audit = repo.wopener.audit
593 i = 0 593 i = 0
594 for arg in args: 594 for f, m, args, msg in args:
595 f = arg[0] 595 repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
596 if arg[1] == 'r': 596 if m == 'r':
597 if verbose: 597 if verbose:
598 repo.ui.note(_("removing %s\n") % f) 598 repo.ui.note(_("removing %s\n") % f)
599 audit(f) 599 audit(f)
600 try: 600 try:
601 unlink(wjoin(f), ignoremissing=True) 601 unlink(wjoin(f), ignoremissing=True)
603 repo.ui.warn(_("update failed to remove %s: %s!\n") % 603 repo.ui.warn(_("update failed to remove %s: %s!\n") %
604 (f, inst.strerror)) 604 (f, inst.strerror))
605 else: 605 else:
606 if verbose: 606 if verbose:
607 repo.ui.note(_("getting %s\n") % f) 607 repo.ui.note(_("getting %s\n") % f)
608 wwrite(f, fctx(f).data(), arg[2][0]) 608 wwrite(f, fctx(f).data(), args[0])
609 if i == 100: 609 if i == 100:
610 yield i, f 610 yield i, f
611 i = 0 611 i = 0
612 i += 1 612 i += 1
613 if i > 0: 613 if i > 0:
630 actions.sort(key=actionkey) 630 actions.sort(key=actionkey)
631 631
632 # prescan for merges 632 # prescan for merges
633 for a in actions: 633 for a in actions:
634 f, m, args, msg = a 634 f, m, args, msg = a
635 repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
636 if m == "m": # merge 635 if m == "m": # merge
637 f1, f2, fa, move, anc = args 636 f1, f2, fa, move, anc = args
638 if f == '.hgsubstate': # merged internally 637 if f == '.hgsubstate': # merged internally
639 continue 638 continue
640 repo.ui.debug(" preserving %s for resolve of %s\n" % (f1, f)) 639 repo.ui.debug(" preserving %s for resolve of %s\n" % (f1, f))
641 fcl = wctx[f1] 640 fcl = wctx[f1]
642 fco = mctx[f2] 641 fco = mctx[f2]
643 actx = repo[anc] 642 actx = repo[anc]
644 if fa in actx: 643 if fa in actx:
645 fca = actx[fa] 644 fca = actx[fa]
665 workeractions = [a for a in actions if a[1] in 'gr'] 664 workeractions = [a for a in actions if a[1] in 'gr']
666 updateactions = [a for a in workeractions if a[1] == 'g'] 665 updateactions = [a for a in workeractions if a[1] == 'g']
667 updated = len(updateactions) 666 updated = len(updateactions)
668 removeactions = [a for a in workeractions if a[1] == 'r'] 667 removeactions = [a for a in workeractions if a[1] == 'r']
669 removed = len(removeactions) 668 removed = len(removeactions)
670 actions = [a for a in actions if a[1] not in 'grk'] 669 actions = [a for a in actions if a[1] not in 'gr']
671 670
672 hgsub = [a[1] for a in workeractions if a[0] == '.hgsubstate'] 671 hgsub = [a[1] for a in workeractions if a[0] == '.hgsubstate']
673 if hgsub and hgsub[0] == 'r': 672 if hgsub and hgsub[0] == 'r':
674 subrepo.submerge(repo, wctx, mctx, wctx, overwrite) 673 subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
675 674
689 progress(_updating, z, item=item, total=numupdates, unit=_files) 688 progress(_updating, z, item=item, total=numupdates, unit=_files)
690 689
691 if hgsub and hgsub[0] == 'g': 690 if hgsub and hgsub[0] == 'g':
692 subrepo.submerge(repo, wctx, mctx, wctx, overwrite) 691 subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
693 692
694 for i, a in enumerate(actions): 693 for f, m, args, msg in actions:
695 f, m, args, msg = a 694
696 progress(_updating, z + i + 1, item=f, total=numupdates, unit=_files) 695 # forget (manifest only, just log it) (must come first)
697 if m == "m": # merge 696 if m == "f":
697 repo.ui.debug(" %s: %s -> f\n" % (f, msg))
698 z += 1
699 progress(_updating, z, item=f, total=numupdates, unit=_files)
700
701 # re-add (manifest only, just log it)
702 elif m == "a":
703 repo.ui.debug(" %s: %s -> a\n" % (f, msg))
704 z += 1
705 progress(_updating, z, item=f, total=numupdates, unit=_files)
706
707 # keep (noop, just log it)
708 elif m == "k":
709 repo.ui.debug(" %s: %s -> k\n" % (f, msg))
710 # no progress
711
712 # merge
713 elif m == "m":
714 repo.ui.debug(" %s: %s -> m\n" % (f, msg))
715 z += 1
716 progress(_updating, z, item=f, total=numupdates, unit=_files)
698 f1, f2, fa, move, anc = args 717 f1, f2, fa, move, anc = args
699 if f == '.hgsubstate': # subrepo states need updating 718 if f == '.hgsubstate': # subrepo states need updating
700 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx), 719 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
701 overwrite) 720 overwrite)
702 continue 721 continue
707 else: 726 else:
708 if r is None: 727 if r is None:
709 updated += 1 728 updated += 1
710 else: 729 else:
711 merged += 1 730 merged += 1
712 elif m == "dm": # directory rename, move local 731
732 # directory rename, move local
733 elif m == "dm":
734 repo.ui.debug(" %s: %s -> dm\n" % (f, msg))
735 z += 1
736 progress(_updating, z, item=f, total=numupdates, unit=_files)
713 f0, flags = args 737 f0, flags = args
714 repo.ui.note(_("moving %s to %s\n") % (f0, f)) 738 repo.ui.note(_("moving %s to %s\n") % (f0, f))
715 audit(f) 739 audit(f)
716 repo.wwrite(f, wctx.filectx(f0).data(), flags) 740 repo.wwrite(f, wctx.filectx(f0).data(), flags)
717 util.unlinkpath(repo.wjoin(f0)) 741 util.unlinkpath(repo.wjoin(f0))
718 updated += 1 742 updated += 1
719 elif m == "dg": # local directory rename, get 743
744 # local directory rename, get
745 elif m == "dg":
746 repo.ui.debug(" %s: %s -> dg\n" % (f, msg))
747 z += 1
748 progress(_updating, z, item=f, total=numupdates, unit=_files)
720 f0, flags = args 749 f0, flags = args
721 repo.ui.note(_("getting %s to %s\n") % (f0, f)) 750 repo.ui.note(_("getting %s to %s\n") % (f0, f))
722 repo.wwrite(f, mctx.filectx(f0).data(), flags) 751 repo.wwrite(f, mctx.filectx(f0).data(), flags)
723 updated += 1 752 updated += 1
724 elif m == "dr": # divergent renames 753
754 # divergent renames
755 elif m == "dr":
756 repo.ui.debug(" %s: %s -> dr\n" % (f, msg))
757 z += 1
758 progress(_updating, z, item=f, total=numupdates, unit=_files)
725 fl, = args 759 fl, = args
726 repo.ui.warn(_("note: possible conflict - %s was renamed " 760 repo.ui.warn(_("note: possible conflict - %s was renamed "
727 "multiple times to:\n") % f) 761 "multiple times to:\n") % f)
728 for nf in fl: 762 for nf in fl:
729 repo.ui.warn(" %s\n" % nf) 763 repo.ui.warn(" %s\n" % nf)
730 elif m == "rd": # rename and delete 764
765 # rename and delete
766 elif m == "rd":
767 repo.ui.debug(" %s: %s -> rd\n" % (f, msg))
768 z += 1
769 progress(_updating, z, item=f, total=numupdates, unit=_files)
731 fl, = args 770 fl, = args
732 repo.ui.warn(_("note: possible conflict - %s was deleted " 771 repo.ui.warn(_("note: possible conflict - %s was deleted "
733 "and renamed to:\n") % f) 772 "and renamed to:\n") % f)
734 for nf in fl: 773 for nf in fl:
735 repo.ui.warn(" %s\n" % nf) 774 repo.ui.warn(" %s\n" % nf)
736 elif m == "e": # exec 775
776 # exec
777 elif m == "e":
778 repo.ui.debug(" %s: %s -> e\n" % (f, msg))
779 z += 1
780 progress(_updating, z, item=f, total=numupdates, unit=_files)
737 flags, = args 781 flags, = args
738 audit(f) 782 audit(f)
739 util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags) 783 util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags)
740 updated += 1 784 updated += 1
785
741 ms.commit() 786 ms.commit()
742 progress(_updating, None, total=numupdates, unit=_files) 787 progress(_updating, None, total=numupdates, unit=_files)
743 788
744 return updated, merged, removed, unresolved 789 return updated, merged, removed, unresolved
745 790
762 for ancestor in ancestors: 807 for ancestor in ancestors:
763 repo.ui.note(_('\ncalculating bids for ancestor %s\n') % ancestor) 808 repo.ui.note(_('\ncalculating bids for ancestor %s\n') % ancestor)
764 actions = manifestmerge(repo, wctx, mctx, ancestor, 809 actions = manifestmerge(repo, wctx, mctx, ancestor,
765 branchmerge, force, 810 branchmerge, force,
766 partial, acceptremote, followcopies) 811 partial, acceptremote, followcopies)
767 for a in sorted(actions): 812 for a in sorted(actions, key=lambda a: (a[1], a)):
768 f, m, args, msg = a 813 f, m, args, msg = a
769 repo.ui.debug(' %s: %s -> %s\n' % (f, msg, m)) 814 repo.ui.debug(' %s: %s -> %s\n' % (f, msg, m))
770 if f in fbids: 815 if f in fbids:
771 fbids[f].append(a) 816 fbids[f].append(a)
772 else: 817 else:
847 return newactions 892 return newactions
848 893
849 def recordupdates(repo, actions, branchmerge): 894 def recordupdates(repo, actions, branchmerge):
850 "record merge actions to the dirstate" 895 "record merge actions to the dirstate"
851 896
852 for a in actions: 897 for f, m, args, msg in actions:
853 f, m, args, msg = a 898
854 if m == "r": # remove (must come first) 899 # remove (must come first)
900 if m == "r": # remove
855 if branchmerge: 901 if branchmerge:
856 repo.dirstate.remove(f) 902 repo.dirstate.remove(f)
857 else: 903 else:
858 repo.dirstate.drop(f) 904 repo.dirstate.drop(f)
859 elif m == "f": # forget (must come first) 905
906 # forget (must come first)
907 elif m == "f":
860 repo.dirstate.drop(f) 908 repo.dirstate.drop(f)
861 elif m == "a": # re-add 909
910 # re-add
911 elif m == "a":
862 if not branchmerge: 912 if not branchmerge:
863 repo.dirstate.add(f) 913 repo.dirstate.add(f)
864 elif m == "e": # exec change 914
915 # exec change
916 elif m == "e":
865 repo.dirstate.normallookup(f) 917 repo.dirstate.normallookup(f)
866 elif m == "k": # keep 918
919 # keep
920 elif m == "k":
867 pass 921 pass
868 elif m == "g": # get 922
923 # get
924 elif m == "g":
869 if branchmerge: 925 if branchmerge:
870 repo.dirstate.otherparent(f) 926 repo.dirstate.otherparent(f)
871 else: 927 else:
872 repo.dirstate.normal(f) 928 repo.dirstate.normal(f)
873 elif m == "m": # merge 929
930 # merge
931 elif m == "m":
874 f1, f2, fa, move, anc = args 932 f1, f2, fa, move, anc = args
875 if branchmerge: 933 if branchmerge:
876 # We've done a branch merge, mark this file as merged 934 # We've done a branch merge, mark this file as merged
877 # so that we properly record the merger later 935 # so that we properly record the merger later
878 repo.dirstate.merge(f) 936 repo.dirstate.merge(f)
891 # modification. 949 # modification.
892 if f2 == f: # file not locally copied/moved 950 if f2 == f: # file not locally copied/moved
893 repo.dirstate.normallookup(f) 951 repo.dirstate.normallookup(f)
894 if move: 952 if move:
895 repo.dirstate.drop(f1) 953 repo.dirstate.drop(f1)
896 elif m == "dm": # directory rename, move local 954
955 # directory rename, move local
956 elif m == "dm":
897 f0, flag = args 957 f0, flag = args
898 if f0 not in repo.dirstate: 958 if f0 not in repo.dirstate:
899 # untracked file moved 959 # untracked file moved
900 continue 960 continue
901 if branchmerge: 961 if branchmerge:
903 repo.dirstate.remove(f0) 963 repo.dirstate.remove(f0)
904 repo.dirstate.copy(f0, f) 964 repo.dirstate.copy(f0, f)
905 else: 965 else:
906 repo.dirstate.normal(f) 966 repo.dirstate.normal(f)
907 repo.dirstate.drop(f0) 967 repo.dirstate.drop(f0)
908 elif m == "dg": # directory rename, get 968
969 # directory rename, get
970 elif m == "dg":
909 f0, flag = args 971 f0, flag = args
910 if branchmerge: 972 if branchmerge:
911 repo.dirstate.add(f) 973 repo.dirstate.add(f)
912 repo.dirstate.copy(f0, f) 974 repo.dirstate.copy(f0, f)
913 else: 975 else: