D3849: rebase: refactor dryrun implementation
khanchi97 (Sushil khanchi)
phabricator at mercurial-scm.org
Wed Jun 27 07:09:14 UTC 2018
khanchi97 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This patch refactor dry-run code to make it easy to add additional
functionality in dryrun. Otherwise we had to add every functionality
through _origrebase() which does not seem a good implementation.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D3849
AFFECTED FILES
hgext/rebase.py
CHANGE DETAILS
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -644,6 +644,12 @@
repo['.'].node() == repo._bookmarks[self.activebookmark]):
bookmarks.activate(repo, self.activebookmark)
+ def _abortunfinishedrebase(self, backup=False, suppwarns=True):
+ repo = self.repo
+ with repo.wlock(), repo.lock():
+ retcode = self._prepareabortorcontinue(isabort=True)
+ return retcode
+
@command('rebase',
[('s', 'source', '',
_('rebase the specified changeset and descendants'), _('REV')),
@@ -818,19 +824,7 @@
opts[r'dest'] = '_destautoorphanrebase(SRC)'
if dryrun:
- try:
- overrides = {('rebase', 'singletransaction'): True}
- with ui.configoverride(overrides, 'rebase'):
- _origrebase(ui, repo, inmemory=True, leaveunfinished=True,
- **opts)
- except error.InMemoryMergeConflictsError:
- ui.status(_('hit a merge conflict\n'))
- return 1
- else:
- ui.status(_('there will be no conflict, you can rebase\n'))
- return 0
- finally:
- _origrebase(ui, repo, abort=True)
+ return _dryrunrebase(ui, repo, **opts)
elif inmemory:
try:
# in-memory merge doesn't support conflicts, so if we hit any, abort
@@ -846,6 +840,24 @@
else:
return _origrebase(ui, repo, **opts)
+def _dryrunrebase(ui, repo, **opts):
+ leaveunfinished = True
+ inmemory = True
+ rbsrt = rebaseruntime(repo, ui, inmemory, opts)
+ try:
+ overrides = {('rebase', 'singletransaction'): True}
+ with ui.configoverride(overrides, 'rebase'):
+ _origrebase(ui, repo, inmemory=True,
+ leaveunfinished=leaveunfinished, **opts)
+ except error.InMemoryMergeConflictsError:
+ ui.status(_('hit a merge conflict\n'))
+ return 1
+ else:
+ ui.status(_('there will be no conflict, you can rebase\n'))
+ return 0
+ finally:
+ rbsrt._abortunfinishedrebase()
+
def _origrebase(ui, repo, inmemory=False, leaveunfinished=False, **opts):
opts = pycompat.byteskwargs(opts)
rbsrt = rebaseruntime(repo, ui, inmemory, opts)
To: khanchi97, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list