792 |
792 |
793 Returns 0 on success, 1 if nothing to rebase or there are |
793 Returns 0 on success, 1 if nothing to rebase or there are |
794 unresolved conflicts. |
794 unresolved conflicts. |
795 |
795 |
796 """ |
796 """ |
|
797 opts = pycompat.byteskwargs(opts) |
797 inmemory = ui.configbool('rebase', 'experimental.inmemory') |
798 inmemory = ui.configbool('rebase', 'experimental.inmemory') |
798 dryrun = opts.get(r'dry_run') |
799 dryrun = opts.get('dry_run') |
799 if dryrun: |
800 if dryrun: |
800 if opts.get(r'abort'): |
801 if opts.get('abort'): |
801 raise error.Abort(_('cannot specify both --dry-run and --abort')) |
802 raise error.Abort(_('cannot specify both --dry-run and --abort')) |
802 if opts.get(r'continue'): |
803 if opts.get('continue'): |
803 raise error.Abort(_('cannot specify both --dry-run and --continue')) |
804 raise error.Abort(_('cannot specify both --dry-run and --continue')) |
804 |
805 |
805 if (opts.get(r'continue') or opts.get(r'abort') or |
806 if (opts.get('continue') or opts.get('abort') or |
806 repo.currenttransaction() is not None): |
807 repo.currenttransaction() is not None): |
807 # in-memory rebase is not compatible with resuming rebases. |
808 # in-memory rebase is not compatible with resuming rebases. |
808 # (Or if it is run within a transaction, since the restart logic can |
809 # (Or if it is run within a transaction, since the restart logic can |
809 # fail the entire transaction.) |
810 # fail the entire transaction.) |
810 inmemory = False |
811 inmemory = False |
811 |
812 |
812 if opts.get(r'auto_orphans'): |
813 if opts.get('auto_orphans'): |
813 for key in opts: |
814 for key in opts: |
814 if key != r'auto_orphans' and opts.get(key): |
815 if key != 'auto_orphans' and opts.get(key): |
815 raise error.Abort(_('--auto-orphans is incompatible with %s') % |
816 raise error.Abort(_('--auto-orphans is incompatible with %s') % |
816 ('--' + pycompat.bytestr(key))) |
817 ('--' + key)) |
817 userrevs = list(repo.revs(opts.get(r'auto_orphans'))) |
818 userrevs = list(repo.revs(opts.get('auto_orphans'))) |
818 opts[r'rev'] = [revsetlang.formatspec('%ld and orphan()', userrevs)] |
819 opts['rev'] = [revsetlang.formatspec('%ld and orphan()', userrevs)] |
819 opts[r'dest'] = '_destautoorphanrebase(SRC)' |
820 opts['dest'] = '_destautoorphanrebase(SRC)' |
820 |
821 |
821 if dryrun: |
822 if dryrun: |
822 return _dryrunrebase(ui, repo, opts) |
823 return _dryrunrebase(ui, repo, opts) |
823 elif inmemory: |
824 elif inmemory: |
824 try: |
825 try: |
828 with ui.configoverride(overrides, 'rebase'): |
829 with ui.configoverride(overrides, 'rebase'): |
829 return _dorebase(ui, repo, opts, inmemory=inmemory) |
830 return _dorebase(ui, repo, opts, inmemory=inmemory) |
830 except error.InMemoryMergeConflictsError: |
831 except error.InMemoryMergeConflictsError: |
831 ui.warn(_('hit merge conflicts; re-running rebase without in-memory' |
832 ui.warn(_('hit merge conflicts; re-running rebase without in-memory' |
832 ' merge\n')) |
833 ' merge\n')) |
833 _dorebase(ui, repo, {r'abort': True}) |
834 _dorebase(ui, repo, {'abort': True}) |
834 return _dorebase(ui, repo, opts, inmemory=False) |
835 return _dorebase(ui, repo, opts, inmemory=False) |
835 else: |
836 else: |
836 return _dorebase(ui, repo, opts) |
837 return _dorebase(ui, repo, opts) |
837 |
838 |
838 def _dryrunrebase(ui, repo, opts): |
839 def _dryrunrebase(ui, repo, opts): |
839 rbsrt = rebaseruntime(repo, ui, inmemory=True, |
840 rbsrt = rebaseruntime(repo, ui, inmemory=True, opts=opts) |
840 opts=pycompat.byteskwargs(opts)) |
|
841 with repo.wlock(), repo.lock(): |
841 with repo.wlock(), repo.lock(): |
842 try: |
842 try: |
843 overrides = {('rebase', 'singletransaction'): True} |
843 overrides = {('rebase', 'singletransaction'): True} |
844 with ui.configoverride(overrides, 'rebase'): |
844 with ui.configoverride(overrides, 'rebase'): |
845 _origrebase(ui, repo, opts, rbsrt, inmemory=True, |
845 _origrebase(ui, repo, opts, rbsrt, inmemory=True, |
854 # no need to store backup in case of dryrun |
854 # no need to store backup in case of dryrun |
855 rbsrt._prepareabortorcontinue(isabort=True, backup=False, |
855 rbsrt._prepareabortorcontinue(isabort=True, backup=False, |
856 suppwarns=True) |
856 suppwarns=True) |
857 |
857 |
858 def _dorebase(ui, repo, opts, inmemory=False): |
858 def _dorebase(ui, repo, opts, inmemory=False): |
859 rbsrt = rebaseruntime(repo, ui, inmemory, pycompat.byteskwargs(opts)) |
859 rbsrt = rebaseruntime(repo, ui, inmemory, opts) |
860 return _origrebase(ui, repo, opts, rbsrt, inmemory=inmemory) |
860 return _origrebase(ui, repo, opts, rbsrt, inmemory=inmemory) |
861 |
861 |
862 def _origrebase(ui, repo, opts, rbsrt, inmemory=False, leaveunfinished=False): |
862 def _origrebase(ui, repo, opts, rbsrt, inmemory=False, leaveunfinished=False): |
863 opts = pycompat.byteskwargs(opts) |
|
864 with repo.wlock(), repo.lock(): |
863 with repo.wlock(), repo.lock(): |
865 # Validate input and define rebasing points |
864 # Validate input and define rebasing points |
866 destf = opts.get('dest', None) |
865 destf = opts.get('dest', None) |
867 srcf = opts.get('source', None) |
866 srcf = opts.get('source', None) |
868 basef = opts.get('base', None) |
867 basef = opts.get('base', None) |