Mercurial > hg
comparison hgext/rebase.py @ 39100:e9e742bd0501
rebase: use action variable to select things to do
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 15 Aug 2018 10:47:07 +0900 |
parents | 3f9a5d746cf6 |
children | 18cbe2d872d3 |
comparison
equal
deleted
inserted
replaced
39099:3f9a5d746cf6 | 39100:e9e742bd0501 |
---|---|
804 """ | 804 """ |
805 opts = pycompat.byteskwargs(opts) | 805 opts = pycompat.byteskwargs(opts) |
806 inmemory = ui.configbool('rebase', 'experimental.inmemory') | 806 inmemory = ui.configbool('rebase', 'experimental.inmemory') |
807 dryrun = opts.get('dry_run') | 807 dryrun = opts.get('dry_run') |
808 confirm = opts.get('confirm') | 808 confirm = opts.get('confirm') |
809 stop = opts.get('stop') | |
810 selactions = [k for k in ['abort', 'stop', 'continue'] if opts.get(k)] | 809 selactions = [k for k in ['abort', 'stop', 'continue'] if opts.get(k)] |
811 if len(selactions) > 1: | 810 if len(selactions) > 1: |
812 raise error.Abort(_('cannot use --%s with --%s') | 811 raise error.Abort(_('cannot use --%s with --%s') |
813 % tuple(selactions[:2])) | 812 % tuple(selactions[:2])) |
814 action = selactions[0] if selactions else None | 813 action = selactions[0] if selactions else None |
817 if confirm and action: | 816 if confirm and action: |
818 raise error.Abort(_('cannot specify both --confirm and --%s') % action) | 817 raise error.Abort(_('cannot specify both --confirm and --%s') % action) |
819 if dryrun and confirm: | 818 if dryrun and confirm: |
820 raise error.Abort(_('cannot specify both --confirm and --dry-run')) | 819 raise error.Abort(_('cannot specify both --confirm and --dry-run')) |
821 | 820 |
822 if (opts.get('continue') or opts.get('abort') or | 821 if action in {'abort', 'continue'} or repo.currenttransaction() is not None: |
823 repo.currenttransaction() is not None): | |
824 # in-memory rebase is not compatible with resuming rebases. | 822 # in-memory rebase is not compatible with resuming rebases. |
825 # (Or if it is run within a transaction, since the restart logic can | 823 # (Or if it is run within a transaction, since the restart logic can |
826 # fail the entire transaction.) | 824 # fail the entire transaction.) |
827 inmemory = False | 825 inmemory = False |
828 | 826 |
834 userrevs = list(repo.revs(opts.get('auto_orphans'))) | 832 userrevs = list(repo.revs(opts.get('auto_orphans'))) |
835 opts['rev'] = [revsetlang.formatspec('%ld and orphan()', userrevs)] | 833 opts['rev'] = [revsetlang.formatspec('%ld and orphan()', userrevs)] |
836 opts['dest'] = '_destautoorphanrebase(SRC)' | 834 opts['dest'] = '_destautoorphanrebase(SRC)' |
837 | 835 |
838 if dryrun or confirm: | 836 if dryrun or confirm: |
839 return _dryrunrebase(ui, repo, opts) | 837 return _dryrunrebase(ui, repo, action, opts) |
840 elif stop: | 838 elif action == 'stop': |
841 rbsrt = rebaseruntime(repo, ui) | 839 rbsrt = rebaseruntime(repo, ui) |
842 rbsrt.restorestatus() | 840 rbsrt.restorestatus() |
843 | 841 |
844 if rbsrt.collapsef: | 842 if rbsrt.collapsef: |
845 raise error.Abort(_("cannot stop in --collapse session")) | 843 raise error.Abort(_("cannot stop in --collapse session")) |
861 try: | 859 try: |
862 # in-memory merge doesn't support conflicts, so if we hit any, abort | 860 # in-memory merge doesn't support conflicts, so if we hit any, abort |
863 # and re-run as an on-disk merge. | 861 # and re-run as an on-disk merge. |
864 overrides = {('rebase', 'singletransaction'): True} | 862 overrides = {('rebase', 'singletransaction'): True} |
865 with ui.configoverride(overrides, 'rebase'): | 863 with ui.configoverride(overrides, 'rebase'): |
866 return _dorebase(ui, repo, opts, inmemory=inmemory) | 864 return _dorebase(ui, repo, action, opts, inmemory=inmemory) |
867 except error.InMemoryMergeConflictsError: | 865 except error.InMemoryMergeConflictsError: |
868 ui.warn(_('hit merge conflicts; re-running rebase without in-memory' | 866 ui.warn(_('hit merge conflicts; re-running rebase without in-memory' |
869 ' merge\n')) | 867 ' merge\n')) |
870 _dorebase(ui, repo, {'abort': True}) | 868 _dorebase(ui, repo, action='abort') |
871 return _dorebase(ui, repo, opts, inmemory=False) | 869 return _dorebase(ui, repo, action, opts, inmemory=False) |
872 else: | 870 else: |
873 return _dorebase(ui, repo, opts) | 871 return _dorebase(ui, repo, action, opts) |
874 | 872 |
875 def _dryrunrebase(ui, repo, opts): | 873 def _dryrunrebase(ui, repo, action, opts): |
876 rbsrt = rebaseruntime(repo, ui, inmemory=True, opts=opts) | 874 rbsrt = rebaseruntime(repo, ui, inmemory=True, opts=opts) |
877 confirm = opts.get('confirm') | 875 confirm = opts.get('confirm') |
878 if confirm: | 876 if confirm: |
879 ui.status(_('starting in-memory rebase\n')) | 877 ui.status(_('starting in-memory rebase\n')) |
880 else: | 878 else: |
883 with repo.wlock(), repo.lock(): | 881 with repo.wlock(), repo.lock(): |
884 needsabort = True | 882 needsabort = True |
885 try: | 883 try: |
886 overrides = {('rebase', 'singletransaction'): True} | 884 overrides = {('rebase', 'singletransaction'): True} |
887 with ui.configoverride(overrides, 'rebase'): | 885 with ui.configoverride(overrides, 'rebase'): |
888 _origrebase(ui, repo, opts, rbsrt, inmemory=True, | 886 _origrebase(ui, repo, action, opts, rbsrt, inmemory=True, |
889 leaveunfinished=True) | 887 leaveunfinished=True) |
890 except error.InMemoryMergeConflictsError: | 888 except error.InMemoryMergeConflictsError: |
891 ui.status(_('hit a merge conflict\n')) | 889 ui.status(_('hit a merge conflict\n')) |
892 return 1 | 890 return 1 |
893 else: | 891 else: |
909 if needsabort: | 907 if needsabort: |
910 # no need to store backup in case of dryrun | 908 # no need to store backup in case of dryrun |
911 rbsrt._prepareabortorcontinue(isabort=True, backup=False, | 909 rbsrt._prepareabortorcontinue(isabort=True, backup=False, |
912 suppwarns=True) | 910 suppwarns=True) |
913 | 911 |
914 def _dorebase(ui, repo, opts, inmemory=False): | 912 def _dorebase(ui, repo, action, opts, inmemory=False): |
915 rbsrt = rebaseruntime(repo, ui, inmemory, opts) | 913 rbsrt = rebaseruntime(repo, ui, inmemory, opts) |
916 return _origrebase(ui, repo, opts, rbsrt, inmemory=inmemory) | 914 return _origrebase(ui, repo, action, opts, rbsrt, inmemory=inmemory) |
917 | 915 |
918 def _origrebase(ui, repo, opts, rbsrt, inmemory=False, leaveunfinished=False): | 916 def _origrebase(ui, repo, action, opts, rbsrt, inmemory=False, |
917 leaveunfinished=False): | |
918 assert action != 'stop' | |
919 with repo.wlock(), repo.lock(): | 919 with repo.wlock(), repo.lock(): |
920 # Validate input and define rebasing points | 920 # Validate input and define rebasing points |
921 destf = opts.get('dest', None) | 921 destf = opts.get('dest', None) |
922 srcf = opts.get('source', None) | 922 srcf = opts.get('source', None) |
923 basef = opts.get('base', None) | 923 basef = opts.get('base', None) |
924 revf = opts.get('rev', []) | 924 revf = opts.get('rev', []) |
925 # search default destination in this space | 925 # search default destination in this space |
926 # used in the 'hg pull --rebase' case, see issue 5214. | 926 # used in the 'hg pull --rebase' case, see issue 5214. |
927 destspace = opts.get('_destspace') | 927 destspace = opts.get('_destspace') |
928 contf = opts.get('continue') | |
929 abortf = opts.get('abort') | |
930 if opts.get('interactive'): | 928 if opts.get('interactive'): |
931 try: | 929 try: |
932 if extensions.find('histedit'): | 930 if extensions.find('histedit'): |
933 enablehistedit = '' | 931 enablehistedit = '' |
934 except KeyError: | 932 except KeyError: |
940 | 938 |
941 if rbsrt.collapsemsg and not rbsrt.collapsef: | 939 if rbsrt.collapsemsg and not rbsrt.collapsef: |
942 raise error.Abort( | 940 raise error.Abort( |
943 _('message can only be specified with collapse')) | 941 _('message can only be specified with collapse')) |
944 | 942 |
945 if contf or abortf: | 943 if action: |
946 if rbsrt.collapsef: | 944 if rbsrt.collapsef: |
947 raise error.Abort( | 945 raise error.Abort( |
948 _('cannot use collapse with continue or abort')) | 946 _('cannot use collapse with continue or abort')) |
949 if srcf or basef or destf: | 947 if srcf or basef or destf: |
950 raise error.Abort( | 948 raise error.Abort( |
951 _('abort and continue do not allow specifying revisions')) | 949 _('abort and continue do not allow specifying revisions')) |
952 if abortf and opts.get('tool', False): | 950 if action == 'abort' and opts.get('tool', False): |
953 ui.warn(_('tool option will be ignored\n')) | 951 ui.warn(_('tool option will be ignored\n')) |
954 if contf: | 952 if action == 'continue': |
955 ms = mergemod.mergestate.read(repo) | 953 ms = mergemod.mergestate.read(repo) |
956 mergeutil.checkunresolved(ms) | 954 mergeutil.checkunresolved(ms) |
957 | 955 |
958 retcode = rbsrt._prepareabortorcontinue(abortf) | 956 retcode = rbsrt._prepareabortorcontinue(isabort=(action == 'abort')) |
959 if retcode is not None: | 957 if retcode is not None: |
960 return retcode | 958 return retcode |
961 else: | 959 else: |
962 destmap = _definedestmap(ui, repo, inmemory, destf, srcf, basef, | 960 destmap = _definedestmap(ui, repo, inmemory, destf, srcf, basef, |
963 revf, destspace=destspace) | 961 revf, destspace=destspace) |