2008-08-18 23:16:31 +04:00
|
|
|
# rebase.py - rebasing feature for mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2008 Stefano Tortarolo <stefano.tortarolo at gmail dot com>
|
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2009-06-24 15:42:02 +04:00
|
|
|
'''command to move sets of revisions to a different ancestor
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2009-07-26 03:59:59 +04:00
|
|
|
This extension lets you rebase changesets in an existing Mercurial
|
|
|
|
repository.
|
2008-08-18 23:16:31 +04:00
|
|
|
|
|
|
|
For more information:
|
2015-09-30 23:43:49 +03:00
|
|
|
https://mercurial-scm.org/wiki/RebaseExtension
|
2008-08-18 23:16:31 +04:00
|
|
|
'''
|
|
|
|
|
2016-05-06 19:51:32 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import os
|
2016-05-14 08:03:12 +03:00
|
|
|
|
|
|
|
from mercurial.i18n import _
|
|
|
|
from mercurial.node import (
|
|
|
|
hex,
|
|
|
|
nullid,
|
|
|
|
nullrev,
|
|
|
|
short,
|
|
|
|
)
|
2016-05-06 19:51:32 +03:00
|
|
|
from mercurial import (
|
|
|
|
bookmarks,
|
|
|
|
cmdutil,
|
|
|
|
commands,
|
|
|
|
copies,
|
|
|
|
destutil,
|
2016-11-22 05:27:12 +03:00
|
|
|
dirstateguard,
|
2016-05-06 19:51:32 +03:00
|
|
|
error,
|
|
|
|
extensions,
|
|
|
|
hg,
|
|
|
|
lock,
|
2016-11-02 21:56:07 +03:00
|
|
|
merge as mergemod,
|
2016-11-22 05:32:39 +03:00
|
|
|
mergeutil,
|
2016-05-06 19:51:32 +03:00
|
|
|
obsolete,
|
|
|
|
patch,
|
|
|
|
phases,
|
|
|
|
registrar,
|
|
|
|
repair,
|
|
|
|
repoview,
|
|
|
|
revset,
|
|
|
|
scmutil,
|
2017-02-19 12:16:09 +03:00
|
|
|
smartset,
|
2016-05-06 19:51:32 +03:00
|
|
|
util,
|
|
|
|
)
|
|
|
|
|
|
|
|
release = lock.release
|
2017-05-14 10:19:47 +03:00
|
|
|
templateopts = cmdutil.templateopts
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2015-10-14 00:17:15 +03:00
|
|
|
# The following constants are used throughout the rebase module. The ordering of
|
|
|
|
# their values must be maintained.
|
|
|
|
|
|
|
|
# Indicates that a revision needs to be rebased
|
2014-12-02 20:46:20 +03:00
|
|
|
revtodo = -1
|
2010-02-06 12:51:50 +03:00
|
|
|
nullmerge = -2
|
2013-01-19 02:41:48 +04:00
|
|
|
revignored = -3
|
2015-11-19 03:06:00 +03:00
|
|
|
# successor in rebase destination
|
2015-09-15 03:31:48 +03:00
|
|
|
revprecursor = -4
|
2015-11-19 03:06:00 +03:00
|
|
|
# plain prune (no successor)
|
2015-11-19 00:44:29 +03:00
|
|
|
revpruned = -5
|
2015-11-19 02:58:06 +03:00
|
|
|
revskipped = (revignored, revprecursor, revpruned)
|
2010-02-06 12:51:50 +03:00
|
|
|
|
2011-05-12 19:09:56 +04:00
|
|
|
cmdtable = {}
|
2016-01-09 17:07:20 +03:00
|
|
|
command = registrar.command(cmdtable)
|
2016-08-23 18:26:08 +03:00
|
|
|
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
|
2015-04-28 23:44:37 +03:00
|
|
|
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
|
|
|
|
# be specifying the version(s) of Mercurial they are tested with, or
|
|
|
|
# leave the attribute unspecified.
|
2016-08-23 18:26:08 +03:00
|
|
|
testedwith = 'ships-with-hg-core'
|
2011-05-12 19:09:56 +04:00
|
|
|
|
2015-10-13 13:20:05 +03:00
|
|
|
def _nothingtorebase():
|
|
|
|
return 1
|
|
|
|
|
2016-02-03 20:24:47 +03:00
|
|
|
def _savegraft(ctx, extra):
|
|
|
|
s = ctx.extra().get('source', None)
|
|
|
|
if s is not None:
|
|
|
|
extra['source'] = s
|
|
|
|
s = ctx.extra().get('intermediate-source', None)
|
|
|
|
if s is not None:
|
|
|
|
extra['intermediate-source'] = s
|
|
|
|
|
|
|
|
def _savebranch(ctx, extra):
|
|
|
|
extra['branch'] = ctx.branch()
|
|
|
|
|
2013-10-01 22:28:18 +04:00
|
|
|
def _makeextrafn(copiers):
|
|
|
|
"""make an extrafn out of the given copy-functions.
|
|
|
|
|
|
|
|
A copy function takes a context and an extra dict, and mutates the
|
|
|
|
extra dict as needed based on the given context.
|
|
|
|
"""
|
|
|
|
def extrafn(ctx, extra):
|
|
|
|
for c in copiers:
|
|
|
|
c(ctx, extra)
|
|
|
|
return extrafn
|
|
|
|
|
2016-04-30 19:41:08 +03:00
|
|
|
def _destrebase(repo, sourceset, destspace=None):
|
2016-02-14 16:25:59 +03:00
|
|
|
"""small wrapper around destmerge to pass the right extra args
|
|
|
|
|
|
|
|
Please wrap destutil.destmerge instead."""
|
|
|
|
return destutil.destmerge(repo, action='rebase', sourceset=sourceset,
|
2016-04-30 19:41:08 +03:00
|
|
|
onheadcheck=False, destspace=destspace)
|
2015-10-15 03:50:31 +03:00
|
|
|
|
2016-03-08 17:04:53 +03:00
|
|
|
revsetpredicate = registrar.revsetpredicate()
|
2015-12-29 17:58:30 +03:00
|
|
|
|
|
|
|
@revsetpredicate('_destrebase')
|
2015-10-15 03:56:03 +03:00
|
|
|
def _revsetdestrebase(repo, subset, x):
|
2015-09-17 20:59:52 +03:00
|
|
|
# ``_rebasedefaultdest()``
|
|
|
|
|
|
|
|
# default destination for rebase.
|
|
|
|
# # XXX: Currently private because I expect the signature to change.
|
|
|
|
# # XXX: - bailing out in case of ambiguity vs returning all data.
|
|
|
|
# i18n: "_rebasedefaultdest" is a keyword
|
2016-02-14 16:25:59 +03:00
|
|
|
sourceset = None
|
|
|
|
if x is not None:
|
2017-02-19 12:16:09 +03:00
|
|
|
sourceset = revset.getset(repo, smartset.fullreposet(repo), x)
|
|
|
|
return subset & smartset.baseset([_destrebase(repo, sourceset)])
|
2015-09-17 20:59:52 +03:00
|
|
|
|
2016-06-14 00:36:13 +03:00
|
|
|
class rebaseruntime(object):
|
|
|
|
"""This class is a container for rebase runtime state"""
|
2016-06-21 17:22:49 +03:00
|
|
|
def __init__(self, repo, ui, opts=None):
|
|
|
|
if opts is None:
|
|
|
|
opts = {}
|
|
|
|
|
|
|
|
self.repo = repo
|
|
|
|
self.ui = ui
|
|
|
|
self.opts = opts
|
2016-06-14 00:36:13 +03:00
|
|
|
self.originalwd = None
|
|
|
|
self.external = nullrev
|
|
|
|
# Mapping between the old revision id and either what is the new rebased
|
|
|
|
# revision or what needs to be done with the old revision. The state
|
|
|
|
# dict will be what contains most of the rebase progress state.
|
|
|
|
self.state = {}
|
|
|
|
self.activebookmark = None
|
2016-07-01 15:09:53 +03:00
|
|
|
self.currentbookmarks = None
|
2017-05-12 08:38:03 +03:00
|
|
|
self.dest = None
|
2016-06-14 00:40:59 +03:00
|
|
|
self.skipped = set()
|
2017-05-12 08:38:03 +03:00
|
|
|
self.destancestors = set()
|
2016-06-14 00:36:13 +03:00
|
|
|
|
2016-06-21 16:29:23 +03:00
|
|
|
self.collapsef = opts.get('collapse', False)
|
|
|
|
self.collapsemsg = cmdutil.logmessage(ui, opts)
|
2016-06-21 16:29:23 +03:00
|
|
|
self.date = opts.get('date', None)
|
|
|
|
|
|
|
|
e = opts.get('extrafn') # internal, used by e.g. hgsubversion
|
|
|
|
self.extrafns = [_savegraft]
|
|
|
|
if e:
|
|
|
|
self.extrafns = [e]
|
2016-06-21 16:29:23 +03:00
|
|
|
|
2016-06-21 16:29:23 +03:00
|
|
|
self.keepf = opts.get('keep', False)
|
|
|
|
self.keepbranchesf = opts.get('keepbranches', False)
|
|
|
|
# keepopen is not meant for use on the command line, but by
|
|
|
|
# other extensions
|
|
|
|
self.keepopen = opts.get('keepopen', False)
|
2016-06-21 16:29:23 +03:00
|
|
|
self.obsoletenotrebased = {}
|
2016-06-21 16:29:23 +03:00
|
|
|
|
2017-03-08 01:04:29 +03:00
|
|
|
def storestatus(self, tr=None):
|
2017-03-08 01:11:44 +03:00
|
|
|
"""Store the current status to allow recovery"""
|
2017-03-08 01:04:29 +03:00
|
|
|
if tr:
|
|
|
|
tr.addfilegenerator('rebasestate', ('rebasestate',),
|
|
|
|
self._writestatus, location='plain')
|
|
|
|
else:
|
|
|
|
with self.repo.vfs("rebasestate", "w") as f:
|
|
|
|
self._writestatus(f)
|
|
|
|
|
|
|
|
def _writestatus(self, f):
|
2017-03-12 22:33:35 +03:00
|
|
|
repo = self.repo.unfiltered()
|
2017-03-08 01:11:44 +03:00
|
|
|
f.write(repo[self.originalwd].hex() + '\n')
|
2017-05-12 08:38:03 +03:00
|
|
|
f.write(repo[self.dest].hex() + '\n')
|
2017-03-08 01:11:44 +03:00
|
|
|
f.write(repo[self.external].hex() + '\n')
|
|
|
|
f.write('%d\n' % int(self.collapsef))
|
|
|
|
f.write('%d\n' % int(self.keepf))
|
|
|
|
f.write('%d\n' % int(self.keepbranchesf))
|
|
|
|
f.write('%s\n' % (self.activebookmark or ''))
|
|
|
|
for d, v in self.state.iteritems():
|
|
|
|
oldrev = repo[d].hex()
|
|
|
|
if v >= 0:
|
|
|
|
newrev = repo[v].hex()
|
|
|
|
elif v == revtodo:
|
|
|
|
# To maintain format compatibility, we have to use nullid.
|
|
|
|
# Please do remove this special case when upgrading the format.
|
|
|
|
newrev = hex(nullid)
|
|
|
|
else:
|
|
|
|
newrev = v
|
|
|
|
f.write("%s:%s\n" % (oldrev, newrev))
|
|
|
|
repo.ui.debug('rebase status stored\n')
|
|
|
|
|
2016-06-21 16:29:23 +03:00
|
|
|
def restorestatus(self):
|
|
|
|
"""Restore a previously stored status"""
|
|
|
|
repo = self.repo
|
|
|
|
keepbranches = None
|
2017-05-12 08:38:03 +03:00
|
|
|
dest = None
|
2016-06-21 16:29:23 +03:00
|
|
|
collapse = False
|
|
|
|
external = nullrev
|
|
|
|
activebookmark = None
|
|
|
|
state = {}
|
|
|
|
|
|
|
|
try:
|
|
|
|
f = repo.vfs("rebasestate")
|
|
|
|
for i, l in enumerate(f.read().splitlines()):
|
|
|
|
if i == 0:
|
|
|
|
originalwd = repo[l].rev()
|
|
|
|
elif i == 1:
|
2017-05-12 08:38:03 +03:00
|
|
|
dest = repo[l].rev()
|
2016-06-21 16:29:23 +03:00
|
|
|
elif i == 2:
|
|
|
|
external = repo[l].rev()
|
|
|
|
elif i == 3:
|
|
|
|
collapse = bool(int(l))
|
|
|
|
elif i == 4:
|
|
|
|
keep = bool(int(l))
|
|
|
|
elif i == 5:
|
|
|
|
keepbranches = bool(int(l))
|
|
|
|
elif i == 6 and not (len(l) == 81 and ':' in l):
|
|
|
|
# line 6 is a recent addition, so for backwards
|
|
|
|
# compatibility check that the line doesn't look like the
|
|
|
|
# oldrev:newrev lines
|
|
|
|
activebookmark = l
|
|
|
|
else:
|
|
|
|
oldrev, newrev = l.split(':')
|
|
|
|
if newrev in (str(nullmerge), str(revignored),
|
|
|
|
str(revprecursor), str(revpruned)):
|
|
|
|
state[repo[oldrev].rev()] = int(newrev)
|
|
|
|
elif newrev == nullid:
|
|
|
|
state[repo[oldrev].rev()] = revtodo
|
|
|
|
# Legacy compat special case
|
|
|
|
else:
|
|
|
|
state[repo[oldrev].rev()] = repo[newrev].rev()
|
|
|
|
|
|
|
|
except IOError as err:
|
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
cmdutil.wrongtooltocontinue(repo, _('rebase'))
|
|
|
|
|
|
|
|
if keepbranches is None:
|
|
|
|
raise error.Abort(_('.hg/rebasestate is incomplete'))
|
|
|
|
|
|
|
|
skipped = set()
|
|
|
|
# recompute the set of skipped revs
|
|
|
|
if not collapse:
|
2017-02-11 03:56:29 +03:00
|
|
|
seen = {dest}
|
2016-06-21 16:29:23 +03:00
|
|
|
for old, new in sorted(state.items()):
|
|
|
|
if new != revtodo and new in seen:
|
|
|
|
skipped.add(old)
|
|
|
|
seen.add(new)
|
|
|
|
repo.ui.debug('computed skipped revs: %s\n' %
|
|
|
|
(' '.join(str(r) for r in sorted(skipped)) or None))
|
|
|
|
repo.ui.debug('rebase status resumed\n')
|
2017-02-11 03:56:29 +03:00
|
|
|
_setrebasesetvisibility(repo, set(state.keys()) | {originalwd})
|
2016-06-21 16:29:23 +03:00
|
|
|
|
|
|
|
self.originalwd = originalwd
|
2017-05-12 08:38:03 +03:00
|
|
|
self.dest = dest
|
2016-06-21 16:29:23 +03:00
|
|
|
self.state = state
|
|
|
|
self.skipped = skipped
|
|
|
|
self.collapsef = collapse
|
|
|
|
self.keepf = keep
|
|
|
|
self.keepbranchesf = keepbranches
|
|
|
|
self.external = external
|
|
|
|
self.activebookmark = activebookmark
|
|
|
|
|
2017-05-12 08:38:03 +03:00
|
|
|
def _handleskippingobsolete(self, rebaserevs, obsoleterevs, dest):
|
2016-07-01 15:09:53 +03:00
|
|
|
"""Compute structures necessary for skipping obsolete revisions
|
|
|
|
|
|
|
|
rebaserevs: iterable of all revisions that are to be rebased
|
|
|
|
obsoleterevs: iterable of all obsolete revisions in rebaseset
|
2017-05-12 08:38:03 +03:00
|
|
|
dest: a destination revision for the rebase operation
|
2016-07-01 15:09:53 +03:00
|
|
|
"""
|
|
|
|
self.obsoletenotrebased = {}
|
|
|
|
if not self.ui.configbool('experimental', 'rebaseskipobsolete',
|
|
|
|
default=True):
|
|
|
|
return
|
|
|
|
rebaseset = set(rebaserevs)
|
|
|
|
obsoleteset = set(obsoleterevs)
|
|
|
|
self.obsoletenotrebased = _computeobsoletenotrebased(self.repo,
|
2017-05-12 08:38:03 +03:00
|
|
|
obsoleteset, dest)
|
2016-07-01 15:09:53 +03:00
|
|
|
skippedset = set(self.obsoletenotrebased)
|
|
|
|
_checkobsrebase(self.repo, self.ui, obsoleteset, rebaseset, skippedset)
|
|
|
|
|
2016-07-01 15:09:53 +03:00
|
|
|
def _prepareabortorcontinue(self, isabort):
|
|
|
|
try:
|
|
|
|
self.restorestatus()
|
2017-03-08 03:30:31 +03:00
|
|
|
self.collapsemsg = restorecollapsemsg(self.repo, isabort)
|
2016-07-01 15:09:53 +03:00
|
|
|
except error.RepoLookupError:
|
|
|
|
if isabort:
|
|
|
|
clearstatus(self.repo)
|
|
|
|
clearcollapsemsg(self.repo)
|
|
|
|
self.repo.ui.warn(_('rebase aborted (no revision is removed,'
|
|
|
|
' only broken state is cleared)\n'))
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
msg = _('cannot continue inconsistent rebase')
|
|
|
|
hint = _('use "hg rebase --abort" to clear broken state')
|
|
|
|
raise error.Abort(msg, hint=hint)
|
|
|
|
if isabort:
|
2017-05-12 08:38:03 +03:00
|
|
|
return abort(self.repo, self.originalwd, self.dest,
|
2016-07-01 15:09:53 +03:00
|
|
|
self.state, activebookmark=self.activebookmark)
|
|
|
|
|
2016-07-01 15:09:53 +03:00
|
|
|
obsrevs = (r for r, st in self.state.items() if st == revprecursor)
|
2017-05-12 08:38:03 +03:00
|
|
|
self._handleskippingobsolete(self.state.keys(), obsrevs, self.dest)
|
2016-07-01 15:09:53 +03:00
|
|
|
|
2016-07-01 15:09:53 +03:00
|
|
|
def _preparenewrebase(self, dest, rebaseset):
|
|
|
|
if dest is None:
|
|
|
|
return _nothingtorebase()
|
|
|
|
|
|
|
|
allowunstable = obsolete.isenabled(self.repo, obsolete.allowunstableopt)
|
|
|
|
if (not (self.keepf or allowunstable)
|
|
|
|
and self.repo.revs('first(children(%ld) - %ld)',
|
|
|
|
rebaseset, rebaseset)):
|
|
|
|
raise error.Abort(
|
|
|
|
_("can't remove original changesets with"
|
|
|
|
" unrebased descendants"),
|
|
|
|
hint=_('use --keep to keep original changesets'))
|
|
|
|
|
rebase: turn rebase revs into set before filtering obsolete
When the inhibit extension from mutable-history is enabled, it attempts to
iterate over the rebaseset to prevent the nodes being rebased from being
marked obsolete. This happens at the same time as rebase's
_filterobsoleterevs function trying to iterate over the rebaseset to figure
out which ones are obsolete. The two of these iterating over the same
revset generatorset cause a 'generator already executing' exception. This is
probably a flaw in the revset implementation, since iterating over the same
set twice should be supported.
This regression was introduced in 5d16ebe7b14, since it changed
_filterobsoleterevs to be called before the rebaseset was turned into a
set(). For now let’s just make the rebaseset an actual set again before
calling that function. This was caught by the inhibit tests.
The relevant call stack from test-inhibit.t:
File "/tmp/hgtests.jgjrN5/install/lib/python/hgext/rebase.py", line 285, in _preparenewrebase
obsrevs = _filterobsoleterevs(self.repo, rebaseset)
File "/data/hgbuild/facebook-hg-rpms/mutable-history/hgext/inhibit.py", line 197, in _filterobsoleterevswrap
r = orig(repo, rebasesetrevs, *args, **kwargs)
File "/tmp/hgtests.jgjrN5/install/lib/python/hgext/rebase.py", line 1380, in _filterobsoleterevs
return set(r for r in revs if repo[r].obsolete())
File "/tmp/hgtests.jgjrN5/install/lib/python/hgext/rebase.py", line 1380, in <genexpr>
return set(r for r in revs if repo[r].obsolete())
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/revset.py", line 3079, in _iterordered
val2 = next(iter2)
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/revset.py", line 3417, in gen
yield nextrev()
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/revset.py", line 3424, in _consumegen
for item in self._gen:
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/revset.py", line 71, in iterate
cl = repo.changelog
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/repoview.py", line 319, in changelog
revs = filterrevs(unfi, self.filtername)
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/repoview.py", line 261, in filterrevs
repo.filteredrevcache[filtername] = func(repo.unfiltered())
File "/data/hgbuild/facebook-hg-rpms/mutable-history/hgext/directaccess.py", line 65, in _computehidden
hidden = repoview.filterrevs(repo, 'visible')
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/repoview.py", line 261, in filterrevs
repo.filteredrevcache[filtername] = func(repo.unfiltered())
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/repoview.py", line 175, in computehidden
hideable = hideablerevs(repo)
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/repoview.py", line 33, in hideablerevs
return obsolete.getrevs(repo, 'obsolete')
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/obsolete.py", line 1097, in getrevs
repo.obsstore.caches[name] = cachefuncs[name](repo)
File "/data/hgbuild/facebook-hg-rpms/mutable-history/hgext/inhibit.py", line 255, in _computeobsoleteset
if getrev(n) not in blacklist:
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/revset.py", line 3264, in __contains__
return x in self._r1 or x in self._r2
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/revset.py", line 3348, in __contains__
for l in self._consumegen():
File "/tmp/hgtests.jgjrN5/install/lib/python/mercurial/revset.py", line 3424, in _consumegen
for item in self._gen:
ValueError: generator already executing
2016-07-19 13:29:53 +03:00
|
|
|
obsrevs = _filterobsoleterevs(self.repo, set(rebaseset))
|
2016-07-01 15:09:53 +03:00
|
|
|
self._handleskippingobsolete(rebaseset, obsrevs, dest)
|
2016-07-01 15:09:53 +03:00
|
|
|
|
|
|
|
result = buildstate(self.repo, dest, rebaseset, self.collapsef,
|
|
|
|
self.obsoletenotrebased)
|
|
|
|
|
|
|
|
if not result:
|
|
|
|
# Empty state built, nothing to rebase
|
|
|
|
self.ui.status(_('nothing to rebase\n'))
|
|
|
|
return _nothingtorebase()
|
|
|
|
|
2017-03-11 21:35:44 +03:00
|
|
|
for root in self.repo.set('roots(%ld)', rebaseset):
|
|
|
|
if not self.keepf and not root.mutable():
|
|
|
|
raise error.Abort(_("can't rebase public changeset %s")
|
|
|
|
% root,
|
|
|
|
hint=_("see 'hg help phases' for details"))
|
2016-07-01 15:09:53 +03:00
|
|
|
|
2017-05-12 08:38:03 +03:00
|
|
|
(self.originalwd, self.dest, self.state) = result
|
2016-07-01 15:09:53 +03:00
|
|
|
if self.collapsef:
|
2017-05-12 08:38:03 +03:00
|
|
|
self.destancestors = self.repo.changelog.ancestors(
|
|
|
|
[self.dest],
|
2016-07-01 15:09:53 +03:00
|
|
|
inclusive=True)
|
|
|
|
self.external = externalparent(self.repo, self.state,
|
2017-05-12 08:38:03 +03:00
|
|
|
self.destancestors)
|
2016-07-01 15:09:53 +03:00
|
|
|
|
|
|
|
if dest.closesbranch() and not self.keepbranchesf:
|
|
|
|
self.ui.status(_('reopening closed branch head %s\n') % dest)
|
|
|
|
|
2017-03-08 03:27:32 +03:00
|
|
|
def _performrebase(self, tr):
|
2016-07-01 15:09:53 +03:00
|
|
|
repo, ui, opts = self.repo, self.ui, self.opts
|
|
|
|
if self.keepbranchesf:
|
|
|
|
# insert _savebranch at the start of extrafns so if
|
|
|
|
# there's a user-provided extrafn it can clobber branch if
|
|
|
|
# desired
|
|
|
|
self.extrafns.insert(0, _savebranch)
|
|
|
|
if self.collapsef:
|
|
|
|
branches = set()
|
|
|
|
for rev in self.state:
|
|
|
|
branches.add(repo[rev].branch())
|
|
|
|
if len(branches) > 1:
|
|
|
|
raise error.Abort(_('cannot collapse multiple named '
|
|
|
|
'branches'))
|
|
|
|
|
|
|
|
# Rebase
|
2017-05-12 08:38:03 +03:00
|
|
|
if not self.destancestors:
|
|
|
|
self.destancestors = repo.changelog.ancestors([self.dest],
|
|
|
|
inclusive=True)
|
2016-07-01 15:09:53 +03:00
|
|
|
|
|
|
|
# Keep track of the current bookmarks in order to reset them later
|
|
|
|
self.currentbookmarks = repo._bookmarks.copy()
|
|
|
|
self.activebookmark = self.activebookmark or repo._activebookmark
|
|
|
|
if self.activebookmark:
|
|
|
|
bookmarks.deactivate(repo)
|
|
|
|
|
2017-03-08 03:30:31 +03:00
|
|
|
# Store the state before we begin so users can run 'hg rebase --abort'
|
|
|
|
# if we fail before the transaction closes.
|
|
|
|
self.storestatus()
|
|
|
|
|
2016-09-17 10:02:56 +03:00
|
|
|
sortedrevs = repo.revs('sort(%ld, -topo)', self.state)
|
2016-08-26 03:16:51 +03:00
|
|
|
cands = [k for k, v in self.state.iteritems() if v == revtodo]
|
|
|
|
total = len(cands)
|
2016-07-01 15:09:53 +03:00
|
|
|
pos = 0
|
2016-07-14 13:12:09 +03:00
|
|
|
for rev in sortedrevs:
|
2016-07-01 15:09:53 +03:00
|
|
|
ctx = repo[rev]
|
|
|
|
desc = '%d:%s "%s"' % (ctx.rev(), ctx,
|
|
|
|
ctx.description().split('\n', 1)[0])
|
|
|
|
names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node())
|
|
|
|
if names:
|
|
|
|
desc += ' (%s)' % ' '.join(names)
|
2017-05-11 21:37:18 +03:00
|
|
|
if self.state[rev] == rev:
|
|
|
|
ui.status(_('already rebased %s\n') % desc)
|
|
|
|
elif self.state[rev] == revtodo:
|
2016-08-26 03:16:51 +03:00
|
|
|
pos += 1
|
2016-07-01 15:09:53 +03:00
|
|
|
ui.status(_('rebasing %s\n') % desc)
|
|
|
|
ui.progress(_("rebasing"), pos, ("%d:%s" % (rev, ctx)),
|
|
|
|
_('changesets'), total)
|
2017-05-12 08:38:03 +03:00
|
|
|
p1, p2, base = defineparents(repo, rev, self.dest,
|
2016-07-01 15:09:53 +03:00
|
|
|
self.state,
|
2017-05-12 08:38:03 +03:00
|
|
|
self.destancestors,
|
2016-07-01 15:09:53 +03:00
|
|
|
self.obsoletenotrebased)
|
2017-03-08 03:27:32 +03:00
|
|
|
self.storestatus(tr=tr)
|
2016-07-01 15:09:53 +03:00
|
|
|
storecollapsemsg(repo, self.collapsemsg)
|
|
|
|
if len(repo[None].parents()) == 2:
|
|
|
|
repo.ui.debug('resuming interrupted rebase\n')
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
|
|
|
|
'rebase')
|
|
|
|
stats = rebasenode(repo, rev, p1, base, self.state,
|
2017-05-12 08:38:03 +03:00
|
|
|
self.collapsef, self.dest)
|
2016-07-01 15:09:53 +03:00
|
|
|
if stats and stats[3] > 0:
|
|
|
|
raise error.InterventionRequired(
|
|
|
|
_('unresolved conflicts (see hg '
|
|
|
|
'resolve, then hg rebase --continue)'))
|
|
|
|
finally:
|
|
|
|
ui.setconfig('ui', 'forcemerge', '', 'rebase')
|
|
|
|
if not self.collapsef:
|
|
|
|
merging = p2 != nullrev
|
|
|
|
editform = cmdutil.mergeeditform(merging, 'rebase')
|
|
|
|
editor = cmdutil.getcommiteditor(editform=editform, **opts)
|
|
|
|
newnode = concludenode(repo, rev, p1, p2,
|
2016-07-14 12:59:27 +03:00
|
|
|
extrafn=_makeextrafn(self.extrafns),
|
2016-07-01 15:09:53 +03:00
|
|
|
editor=editor,
|
|
|
|
keepbranches=self.keepbranchesf,
|
|
|
|
date=self.date)
|
2017-05-18 23:18:05 +03:00
|
|
|
if newnode is None:
|
|
|
|
# If it ended up being a no-op commit, then the normal
|
|
|
|
# merge state clean-up path doesn't happen, so do it
|
|
|
|
# here. Fix issue5494
|
|
|
|
mergemod.mergestate.clean(repo)
|
2016-07-01 15:09:53 +03:00
|
|
|
else:
|
|
|
|
# Skip commit if we are collapsing
|
2017-06-01 05:46:04 +03:00
|
|
|
repo.setparents(repo[p1].node())
|
2016-07-01 15:09:53 +03:00
|
|
|
newnode = None
|
|
|
|
# Update the state
|
|
|
|
if newnode is not None:
|
|
|
|
self.state[rev] = repo[newnode].rev()
|
|
|
|
ui.debug('rebased as %s\n' % short(newnode))
|
|
|
|
else:
|
|
|
|
if not self.collapsef:
|
|
|
|
ui.warn(_('note: rebase of %d:%s created no changes '
|
|
|
|
'to commit\n') % (rev, ctx))
|
|
|
|
self.skipped.add(rev)
|
|
|
|
self.state[rev] = p1
|
|
|
|
ui.debug('next revision set to %s\n' % p1)
|
|
|
|
elif self.state[rev] == nullmerge:
|
|
|
|
ui.debug('ignoring null merge rebase of %s\n' % rev)
|
|
|
|
elif self.state[rev] == revignored:
|
|
|
|
ui.status(_('not rebasing ignored %s\n') % desc)
|
|
|
|
elif self.state[rev] == revprecursor:
|
2017-05-12 08:38:03 +03:00
|
|
|
destctx = repo[self.obsoletenotrebased[rev]]
|
|
|
|
descdest = '%d:%s "%s"' % (destctx.rev(), destctx,
|
|
|
|
destctx.description().split('\n', 1)[0])
|
2016-07-01 15:09:53 +03:00
|
|
|
msg = _('note: not rebasing %s, already in destination as %s\n')
|
2017-05-12 08:38:03 +03:00
|
|
|
ui.status(msg % (desc, descdest))
|
2016-07-01 15:09:53 +03:00
|
|
|
elif self.state[rev] == revpruned:
|
|
|
|
msg = _('note: not rebasing %s, it has no successor\n')
|
|
|
|
ui.status(msg % desc)
|
|
|
|
else:
|
|
|
|
ui.status(_('already rebased %s as %s\n') %
|
|
|
|
(desc, repo[self.state[rev]]))
|
|
|
|
|
|
|
|
ui.progress(_('rebasing'), None)
|
|
|
|
ui.note(_('rebase merging completed\n'))
|
|
|
|
|
2016-07-01 15:09:53 +03:00
|
|
|
def _finishrebase(self):
|
|
|
|
repo, ui, opts = self.repo, self.ui, self.opts
|
|
|
|
if self.collapsef and not self.keepopen:
|
|
|
|
p1, p2, _base = defineparents(repo, min(self.state),
|
2017-05-12 08:38:03 +03:00
|
|
|
self.dest, self.state,
|
|
|
|
self.destancestors,
|
2016-07-01 15:09:53 +03:00
|
|
|
self.obsoletenotrebased)
|
|
|
|
editopt = opts.get('edit')
|
|
|
|
editform = 'rebase.collapse'
|
|
|
|
if self.collapsemsg:
|
|
|
|
commitmsg = self.collapsemsg
|
|
|
|
else:
|
|
|
|
commitmsg = 'Collapsed revision'
|
|
|
|
for rebased in self.state:
|
|
|
|
if rebased not in self.skipped and\
|
|
|
|
self.state[rebased] > nullmerge:
|
|
|
|
commitmsg += '\n* %s' % repo[rebased].description()
|
|
|
|
editopt = True
|
|
|
|
editor = cmdutil.getcommiteditor(edit=editopt, editform=editform)
|
2016-07-14 13:12:09 +03:00
|
|
|
revtoreuse = max(self.state)
|
2017-03-19 21:54:15 +03:00
|
|
|
dsguard = dirstateguard.dirstateguard(repo, 'rebase')
|
|
|
|
try:
|
|
|
|
newnode = concludenode(repo, revtoreuse, p1, self.external,
|
|
|
|
commitmsg=commitmsg,
|
|
|
|
extrafn=_makeextrafn(self.extrafns),
|
|
|
|
editor=editor,
|
|
|
|
keepbranches=self.keepbranchesf,
|
|
|
|
date=self.date)
|
|
|
|
dsguard.close()
|
|
|
|
release(dsguard)
|
|
|
|
except error.InterventionRequired:
|
|
|
|
dsguard.close()
|
|
|
|
release(dsguard)
|
|
|
|
raise
|
|
|
|
except Exception:
|
|
|
|
release(dsguard)
|
|
|
|
raise
|
|
|
|
|
2016-07-01 15:09:53 +03:00
|
|
|
if newnode is None:
|
2017-05-12 08:38:03 +03:00
|
|
|
newrev = self.dest
|
2016-07-01 15:09:53 +03:00
|
|
|
else:
|
|
|
|
newrev = repo[newnode].rev()
|
|
|
|
for oldrev in self.state.iterkeys():
|
|
|
|
if self.state[oldrev] > nullmerge:
|
|
|
|
self.state[oldrev] = newrev
|
|
|
|
|
|
|
|
if 'qtip' in repo.tags():
|
|
|
|
updatemq(repo, self.state, self.skipped, **opts)
|
|
|
|
|
|
|
|
if self.currentbookmarks:
|
|
|
|
# Nodeids are needed to reset bookmarks
|
|
|
|
nstate = {}
|
|
|
|
for k, v in self.state.iteritems():
|
2017-05-11 21:37:18 +03:00
|
|
|
if v > nullmerge and v != k:
|
2016-07-01 15:09:53 +03:00
|
|
|
nstate[repo[k].node()] = repo[v].node()
|
|
|
|
elif v == revprecursor:
|
|
|
|
succ = self.obsoletenotrebased[k]
|
|
|
|
nstate[repo[k].node()] = repo[succ].node()
|
|
|
|
# XXX this is the same as dest.node() for the non-continue path --
|
|
|
|
# this should probably be cleaned up
|
2017-05-12 08:38:03 +03:00
|
|
|
destnode = repo[self.dest].node()
|
2016-07-01 15:09:53 +03:00
|
|
|
|
|
|
|
# restore original working directory
|
|
|
|
# (we do this before stripping)
|
|
|
|
newwd = self.state.get(self.originalwd, self.originalwd)
|
|
|
|
if newwd == revprecursor:
|
|
|
|
newwd = self.obsoletenotrebased[self.originalwd]
|
|
|
|
elif newwd < 0:
|
|
|
|
# original directory is a parent of rebase set root or ignored
|
|
|
|
newwd = self.originalwd
|
|
|
|
if newwd not in [c.rev() for c in repo[None].parents()]:
|
|
|
|
ui.note(_("update back to initial working directory parent\n"))
|
|
|
|
hg.updaterepo(repo, newwd, False)
|
|
|
|
|
2016-11-10 20:21:41 +03:00
|
|
|
if self.currentbookmarks:
|
|
|
|
with repo.transaction('bookmark') as tr:
|
2017-05-12 08:38:03 +03:00
|
|
|
updatebookmarks(repo, destnode, nstate,
|
2016-11-10 20:21:41 +03:00
|
|
|
self.currentbookmarks, tr)
|
|
|
|
if self.activebookmark not in repo._bookmarks:
|
|
|
|
# active bookmark was divergent one and has been deleted
|
|
|
|
self.activebookmark = None
|
|
|
|
|
2016-07-01 15:09:53 +03:00
|
|
|
if not self.keepf:
|
|
|
|
collapsedas = None
|
|
|
|
if self.collapsef:
|
|
|
|
collapsedas = newnode
|
|
|
|
clearrebased(ui, repo, self.state, self.skipped, collapsedas)
|
|
|
|
|
|
|
|
clearstatus(repo)
|
|
|
|
clearcollapsemsg(repo)
|
|
|
|
|
|
|
|
ui.note(_("rebase completed\n"))
|
|
|
|
util.unlinkpath(repo.sjoin('undo'), ignoremissing=True)
|
|
|
|
if self.skipped:
|
|
|
|
skippedlen = len(self.skipped)
|
|
|
|
ui.note(_("%d revisions have been skipped\n") % skippedlen)
|
|
|
|
|
|
|
|
if (self.activebookmark and
|
|
|
|
repo['.'].node() == repo._bookmarks[self.activebookmark]):
|
|
|
|
bookmarks.activate(repo, self.activebookmark)
|
|
|
|
|
2011-05-12 19:09:56 +04:00
|
|
|
@command('rebase',
|
|
|
|
[('s', 'source', '',
|
2014-10-08 22:40:50 +04:00
|
|
|
_('rebase the specified changeset and descendants'), _('REV')),
|
2011-05-12 19:09:56 +04:00
|
|
|
('b', 'base', '',
|
2014-10-08 22:40:50 +04:00
|
|
|
_('rebase everything from branching point of specified changeset'),
|
2011-05-12 19:09:56 +04:00
|
|
|
_('REV')),
|
2011-10-15 22:12:32 +04:00
|
|
|
('r', 'rev', [],
|
|
|
|
_('rebase these revisions'),
|
|
|
|
_('REV')),
|
2011-05-12 19:09:56 +04:00
|
|
|
('d', 'dest', '',
|
|
|
|
_('rebase onto the specified changeset'), _('REV')),
|
|
|
|
('', 'collapse', False, _('collapse the rebased changesets')),
|
|
|
|
('m', 'message', '',
|
|
|
|
_('use text as collapse commit message'), _('TEXT')),
|
2011-10-11 08:01:25 +04:00
|
|
|
('e', 'edit', False, _('invoke editor on commit messages')),
|
2011-05-12 19:09:56 +04:00
|
|
|
('l', 'logfile', '',
|
|
|
|
_('read collapse commit message from file'), _('FILE')),
|
2015-05-13 01:04:19 +03:00
|
|
|
('k', 'keep', False, _('keep original changesets')),
|
2011-05-12 19:09:56 +04:00
|
|
|
('', 'keepbranches', False, _('keep original branch names')),
|
2012-06-20 22:08:57 +04:00
|
|
|
('D', 'detach', False, _('(DEPRECATED)')),
|
2014-09-01 13:48:55 +04:00
|
|
|
('i', 'interactive', False, _('(DEPRECATED)')),
|
2011-05-12 19:09:56 +04:00
|
|
|
('t', 'tool', '', _('specify merge tool')),
|
|
|
|
('c', 'continue', False, _('continue an interrupted rebase')),
|
|
|
|
('a', 'abort', False, _('abort an interrupted rebase'))] +
|
|
|
|
templateopts,
|
2012-07-31 20:18:26 +04:00
|
|
|
_('[-s REV | -b REV] [-d REV] [OPTION]'))
|
2008-08-18 23:16:31 +04:00
|
|
|
def rebase(ui, repo, **opts):
|
|
|
|
"""move changeset (and descendants) to a different branch
|
|
|
|
|
2009-07-26 03:59:59 +04:00
|
|
|
Rebase uses repeated merging to graft changesets from one part of
|
2010-03-10 05:53:16 +03:00
|
|
|
history (the source) onto another (the destination). This can be
|
2010-05-17 23:16:35 +04:00
|
|
|
useful for linearizing *local* changes relative to a master
|
2010-03-10 05:53:16 +03:00
|
|
|
development tree.
|
|
|
|
|
2015-12-18 21:06:43 +03:00
|
|
|
Published commits cannot be rebased (see :hg:`help phases`).
|
|
|
|
To copy commits, see :hg:`help graft`.
|
2013-02-01 06:01:26 +04:00
|
|
|
|
2016-02-14 16:25:59 +03:00
|
|
|
If you don't specify a destination changeset (``-d/--dest``), rebase
|
|
|
|
will use the same logic as :hg:`merge` to pick a destination. if
|
|
|
|
the current branch contains exactly one other head, the other head
|
|
|
|
is merged with by default. Otherwise, an explicit revision with
|
|
|
|
which to merge with must be provided. (destination changeset is not
|
|
|
|
modified by rebasing, but new changesets are added as its
|
|
|
|
descendants.)
|
2010-03-10 05:53:16 +03:00
|
|
|
|
2016-02-01 16:06:35 +03:00
|
|
|
Here are the ways to select changesets:
|
2015-12-18 21:24:41 +03:00
|
|
|
|
|
|
|
1. Explicitly select them using ``--rev``.
|
|
|
|
|
|
|
|
2. Use ``--source`` to select a root changeset and include all of its
|
2016-02-01 16:14:06 +03:00
|
|
|
descendants.
|
2015-12-18 21:24:41 +03:00
|
|
|
|
|
|
|
3. Use ``--base`` to select a changeset; rebase will find ancestors
|
2016-02-01 16:14:06 +03:00
|
|
|
and their descendants which are not also ancestors of the destination.
|
2013-02-01 05:01:11 +04:00
|
|
|
|
2016-01-22 23:32:47 +03:00
|
|
|
4. If you do not specify any of ``--rev``, ``source``, or ``--base``,
|
2016-02-01 16:14:06 +03:00
|
|
|
rebase will use ``--base .`` as above.
|
2016-01-22 23:32:47 +03:00
|
|
|
|
2015-12-18 21:22:03 +03:00
|
|
|
Rebase will destroy original changesets unless you use ``--keep``.
|
|
|
|
It will also move your bookmarks (even if you do).
|
|
|
|
|
|
|
|
Some changesets may be dropped if they do not contribute changes
|
|
|
|
(e.g. merges from the destination branch).
|
2010-03-10 05:53:16 +03:00
|
|
|
|
2015-12-18 21:31:45 +03:00
|
|
|
Unlike ``merge``, rebase will do nothing if you are at the branch tip of
|
|
|
|
a named branch with two heads. You will need to explicitly specify source
|
|
|
|
and/or destination.
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2016-02-05 01:14:53 +03:00
|
|
|
If you need to use a tool to automate merge/conflict decisions, you
|
|
|
|
can specify one with ``--tool``, see :hg:`help merge-tools`.
|
2016-02-05 02:29:32 +03:00
|
|
|
As a caveat: the tool will not be used to mediate when a file was
|
|
|
|
deleted, there is no hook presently available for this.
|
2016-02-05 01:14:53 +03:00
|
|
|
|
2015-12-18 21:32:15 +03:00
|
|
|
If a rebase is interrupted to manually resolve a conflict, it can be
|
2009-04-18 16:40:21 +04:00
|
|
|
continued with --continue/-c or aborted with --abort/-a.
|
2010-05-21 00:58:16 +04:00
|
|
|
|
2014-10-08 23:03:07 +04:00
|
|
|
.. container:: verbose
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
- move "local changes" (current commit back to branching point)
|
|
|
|
to the current branch tip after a pull::
|
|
|
|
|
|
|
|
hg rebase
|
|
|
|
|
|
|
|
- move a single changeset to the stable branch::
|
|
|
|
|
|
|
|
hg rebase -r 5f493448 -d stable
|
|
|
|
|
|
|
|
- splice a commit and all its descendants onto another part of history::
|
|
|
|
|
|
|
|
hg rebase --source c0c3 --dest 4cf9
|
|
|
|
|
|
|
|
- rebase everything on a branch marked by a bookmark onto the
|
|
|
|
default branch::
|
|
|
|
|
|
|
|
hg rebase --base myfeature --dest default
|
|
|
|
|
|
|
|
- collapse a sequence of changes into a single commit::
|
|
|
|
|
|
|
|
hg rebase --collapse -r 1520:1525 -d .
|
|
|
|
|
|
|
|
- move a named branch while preserving its name::
|
|
|
|
|
|
|
|
hg rebase -r "branch(featureX)" -d 1.3 --keepbranches
|
|
|
|
|
2017-03-15 03:43:44 +03:00
|
|
|
Configuration Options:
|
|
|
|
|
|
|
|
You can make rebase require a destination if you set the following config
|
2017-04-30 23:52:32 +03:00
|
|
|
option::
|
2017-03-15 03:43:44 +03:00
|
|
|
|
|
|
|
[commands]
|
2017-04-30 23:38:52 +03:00
|
|
|
rebase.requiredest = True
|
2017-03-15 03:43:44 +03:00
|
|
|
|
|
|
|
Return Values:
|
|
|
|
|
2013-10-26 19:24:25 +04:00
|
|
|
Returns 0 on success, 1 if nothing to rebase or there are
|
|
|
|
unresolved conflicts.
|
2014-10-08 23:03:07 +04:00
|
|
|
|
2008-08-18 23:16:31 +04:00
|
|
|
"""
|
2016-06-21 17:22:49 +03:00
|
|
|
rbsrt = rebaseruntime(repo, ui, opts)
|
2011-10-11 08:01:25 +04:00
|
|
|
|
2008-08-18 23:16:31 +04:00
|
|
|
lock = wlock = None
|
|
|
|
try:
|
|
|
|
wlock = repo.wlock()
|
2012-01-13 04:19:07 +04:00
|
|
|
lock = repo.lock()
|
2008-08-18 23:16:31 +04:00
|
|
|
|
|
|
|
# Validate input and define rebasing points
|
|
|
|
destf = opts.get('dest', None)
|
|
|
|
srcf = opts.get('source', None)
|
|
|
|
basef = opts.get('base', None)
|
2011-10-15 22:12:32 +04:00
|
|
|
revf = opts.get('rev', [])
|
2016-04-30 19:41:08 +03:00
|
|
|
# search default destination in this space
|
|
|
|
# used in the 'hg pull --rebase' case, see issue 5214.
|
|
|
|
destspace = opts.get('_destspace')
|
2008-08-18 23:16:31 +04:00
|
|
|
contf = opts.get('continue')
|
|
|
|
abortf = opts.get('abort')
|
2014-09-01 13:48:55 +04:00
|
|
|
if opts.get('interactive'):
|
2015-10-06 22:07:00 +03:00
|
|
|
try:
|
|
|
|
if extensions.find('histedit'):
|
|
|
|
enablehistedit = ''
|
|
|
|
except KeyError:
|
|
|
|
enablehistedit = " --config extensions.histedit="
|
|
|
|
help = "hg%s help -e histedit" % enablehistedit
|
2014-09-01 13:48:55 +04:00
|
|
|
msg = _("interactive history editing is supported by the "
|
2015-10-06 22:05:40 +03:00
|
|
|
"'histedit' extension (see \"%s\")") % help
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg)
|
2014-09-01 13:48:55 +04:00
|
|
|
|
2016-06-21 16:29:23 +03:00
|
|
|
if rbsrt.collapsemsg and not rbsrt.collapsef:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
2011-03-15 20:33:36 +03:00
|
|
|
_('message can only be specified with collapse'))
|
|
|
|
|
2008-08-18 23:16:31 +04:00
|
|
|
if contf or abortf:
|
|
|
|
if contf and abortf:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot use both abort and continue'))
|
2016-06-21 16:29:23 +03:00
|
|
|
if rbsrt.collapsef:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
2010-06-05 02:22:33 +04:00
|
|
|
_('cannot use collapse with continue or abort'))
|
2009-04-22 03:39:47 +04:00
|
|
|
if srcf or basef or destf:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
2008-08-18 23:16:31 +04:00
|
|
|
_('abort and continue do not allow specifying revisions'))
|
2015-09-01 22:37:51 +03:00
|
|
|
if abortf and opts.get('tool', False):
|
2011-04-02 13:07:05 +04:00
|
|
|
ui.warn(_('tool option will be ignored\n'))
|
2016-11-02 21:59:29 +03:00
|
|
|
if contf:
|
|
|
|
ms = mergemod.mergestate.read(repo)
|
2016-11-22 05:32:39 +03:00
|
|
|
mergeutil.checkunresolved(ms)
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2016-07-01 15:09:53 +03:00
|
|
|
retcode = rbsrt._prepareabortorcontinue(abortf)
|
|
|
|
if retcode is not None:
|
|
|
|
return retcode
|
2008-08-18 23:16:31 +04:00
|
|
|
else:
|
2016-04-30 19:41:08 +03:00
|
|
|
dest, rebaseset = _definesets(ui, repo, destf, srcf, basef, revf,
|
|
|
|
destspace=destspace)
|
2016-07-01 15:09:53 +03:00
|
|
|
retcode = rbsrt._preparenewrebase(dest, rebaseset)
|
|
|
|
if retcode is not None:
|
|
|
|
return retcode
|
2013-11-26 06:18:56 +04:00
|
|
|
|
2017-03-08 03:27:32 +03:00
|
|
|
with repo.transaction('rebase') as tr:
|
2017-03-19 21:54:15 +03:00
|
|
|
dsguard = dirstateguard.dirstateguard(repo, 'rebase')
|
2017-03-08 03:27:32 +03:00
|
|
|
try:
|
|
|
|
rbsrt._performrebase(tr)
|
2017-03-19 21:54:15 +03:00
|
|
|
dsguard.close()
|
|
|
|
release(dsguard)
|
2017-03-08 03:27:32 +03:00
|
|
|
except error.InterventionRequired:
|
2017-03-19 21:54:15 +03:00
|
|
|
dsguard.close()
|
|
|
|
release(dsguard)
|
2017-03-08 03:27:32 +03:00
|
|
|
tr.close()
|
|
|
|
raise
|
2017-03-19 21:54:15 +03:00
|
|
|
except Exception:
|
|
|
|
release(dsguard)
|
|
|
|
raise
|
2016-07-01 15:09:53 +03:00
|
|
|
rbsrt._finishrebase()
|
2008-08-18 23:16:31 +04:00
|
|
|
finally:
|
2009-04-22 04:01:22 +04:00
|
|
|
release(lock, wlock)
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2017-03-13 07:56:39 +03:00
|
|
|
def _definesets(ui, repo, destf=None, srcf=None, basef=None, revf=None,
|
2016-04-30 19:41:08 +03:00
|
|
|
destspace=None):
|
2016-02-10 02:49:55 +03:00
|
|
|
"""use revisions argument to define destination and rebase set
|
|
|
|
"""
|
2017-03-16 01:03:43 +03:00
|
|
|
if revf is None:
|
|
|
|
revf = []
|
2017-03-13 07:56:39 +03:00
|
|
|
|
2016-04-30 19:41:08 +03:00
|
|
|
# destspace is here to work around issues with `hg pull --rebase` see
|
|
|
|
# issue5214 for details
|
2016-02-10 02:49:55 +03:00
|
|
|
if srcf and basef:
|
|
|
|
raise error.Abort(_('cannot specify both a source and a base'))
|
|
|
|
if revf and basef:
|
|
|
|
raise error.Abort(_('cannot specify both a revision and a base'))
|
|
|
|
if revf and srcf:
|
|
|
|
raise error.Abort(_('cannot specify both a revision and a source'))
|
|
|
|
|
|
|
|
cmdutil.checkunfinished(repo)
|
|
|
|
cmdutil.bailifchanged(repo)
|
|
|
|
|
2017-03-30 13:50:10 +03:00
|
|
|
if ui.configbool('commands', 'rebase.requiredest') and not destf:
|
|
|
|
raise error.Abort(_('you must specify a destination'),
|
|
|
|
hint=_('use: hg rebase -d REV'))
|
|
|
|
|
2016-02-10 02:49:55 +03:00
|
|
|
if destf:
|
|
|
|
dest = scmutil.revsingle(repo, destf)
|
|
|
|
|
|
|
|
if revf:
|
|
|
|
rebaseset = scmutil.revrange(repo, revf)
|
|
|
|
if not rebaseset:
|
|
|
|
ui.status(_('empty "rev" revision set - nothing to rebase\n'))
|
|
|
|
return None, None
|
|
|
|
elif srcf:
|
|
|
|
src = scmutil.revrange(repo, [srcf])
|
|
|
|
if not src:
|
|
|
|
ui.status(_('empty "source" revision set - nothing to rebase\n'))
|
|
|
|
return None, None
|
|
|
|
rebaseset = repo.revs('(%ld)::', src)
|
|
|
|
assert rebaseset
|
|
|
|
else:
|
|
|
|
base = scmutil.revrange(repo, [basef or '.'])
|
|
|
|
if not base:
|
|
|
|
ui.status(_('empty "base" revision set - '
|
|
|
|
"can't compute rebase set\n"))
|
|
|
|
return None, None
|
2016-02-14 16:25:59 +03:00
|
|
|
if not destf:
|
2016-04-30 19:41:08 +03:00
|
|
|
dest = repo[_destrebase(repo, base, destspace=destspace)]
|
2016-02-14 16:25:59 +03:00
|
|
|
destf = str(dest)
|
|
|
|
|
2016-11-28 08:45:22 +03:00
|
|
|
roots = [] # selected children of branching points
|
|
|
|
bpbase = {} # {branchingpoint: [origbase]}
|
|
|
|
for b in base: # group bases by branching points
|
|
|
|
bp = repo.revs('ancestor(%d, %d)', b, dest).first()
|
|
|
|
bpbase[bp] = bpbase.get(bp, []) + [b]
|
|
|
|
if None in bpbase:
|
|
|
|
# emulate the old behavior, showing "nothing to rebase" (a better
|
|
|
|
# behavior may be abort with "cannot find branching point" error)
|
|
|
|
bpbase.clear()
|
|
|
|
for bp, bs in bpbase.iteritems(): # calculate roots
|
|
|
|
roots += list(repo.revs('children(%d) & ancestors(%ld)', bp, bs))
|
|
|
|
|
|
|
|
rebaseset = repo.revs('%ld::', roots)
|
2016-02-10 02:49:55 +03:00
|
|
|
|
|
|
|
if not rebaseset:
|
|
|
|
# transform to list because smartsets are not comparable to
|
|
|
|
# lists. This should be improved to honor laziness of
|
|
|
|
# smartset.
|
|
|
|
if list(base) == [dest.rev()]:
|
|
|
|
if basef:
|
|
|
|
ui.status(_('nothing to rebase - %s is both "base"'
|
|
|
|
' and destination\n') % dest)
|
|
|
|
else:
|
|
|
|
ui.status(_('nothing to rebase - working directory '
|
|
|
|
'parent is also destination\n'))
|
|
|
|
elif not repo.revs('%ld - ::%d', base, dest):
|
|
|
|
if basef:
|
|
|
|
ui.status(_('nothing to rebase - "base" %s is '
|
|
|
|
'already an ancestor of destination '
|
|
|
|
'%s\n') %
|
|
|
|
('+'.join(str(repo[r]) for r in base),
|
|
|
|
dest))
|
|
|
|
else:
|
|
|
|
ui.status(_('nothing to rebase - working '
|
|
|
|
'directory parent is already an '
|
|
|
|
'ancestor of destination %s\n') % dest)
|
|
|
|
else: # can it happen?
|
|
|
|
ui.status(_('nothing to rebase from %s to %s\n') %
|
|
|
|
('+'.join(str(repo[r]) for r in base), dest))
|
|
|
|
return None, None
|
2016-02-14 16:25:59 +03:00
|
|
|
|
|
|
|
if not destf:
|
2016-04-30 19:41:08 +03:00
|
|
|
dest = repo[_destrebase(repo, rebaseset, destspace=destspace)]
|
2016-02-14 16:25:59 +03:00
|
|
|
destf = str(dest)
|
|
|
|
|
2016-02-10 02:49:55 +03:00
|
|
|
return dest, rebaseset
|
|
|
|
|
2017-05-12 08:38:03 +03:00
|
|
|
def externalparent(repo, state, destancestors):
|
2013-10-24 08:05:22 +04:00
|
|
|
"""Return the revision that should be used as the second parent
|
2017-05-12 08:38:03 +03:00
|
|
|
when the revisions in state is collapsed on top of destancestors.
|
2013-10-24 08:05:22 +04:00
|
|
|
Abort if there is more than one parent.
|
2010-01-31 15:30:17 +03:00
|
|
|
"""
|
2013-10-24 08:05:22 +04:00
|
|
|
parents = set()
|
2010-01-31 15:30:17 +03:00
|
|
|
source = min(state)
|
|
|
|
for rev in state:
|
|
|
|
if rev == source:
|
|
|
|
continue
|
|
|
|
for p in repo[rev].parents():
|
|
|
|
if (p.rev() not in state
|
2017-05-12 08:38:03 +03:00
|
|
|
and p.rev() not in destancestors):
|
2013-10-24 08:05:22 +04:00
|
|
|
parents.add(p.rev())
|
|
|
|
if not parents:
|
|
|
|
return nullrev
|
|
|
|
if len(parents) == 1:
|
|
|
|
return parents.pop()
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('unable to collapse on top of %s, there is more '
|
2013-10-23 19:42:13 +04:00
|
|
|
'than one external parent: %s') %
|
2017-05-12 08:38:03 +03:00
|
|
|
(max(destancestors),
|
2013-10-23 19:42:13 +04:00
|
|
|
', '.join(str(p) for p in sorted(parents))))
|
2010-01-31 15:30:17 +03:00
|
|
|
|
2015-09-25 00:51:05 +03:00
|
|
|
def concludenode(repo, rev, p1, p2, commitmsg=None, editor=None, extrafn=None,
|
2015-10-26 12:22:26 +03:00
|
|
|
keepbranches=False, date=None):
|
2014-11-19 05:38:51 +03:00
|
|
|
'''Commit the wd changes with parents p1 and p2. Reuse commit info from rev
|
|
|
|
but also store useful information in extra.
|
2014-12-02 07:12:53 +03:00
|
|
|
Return node of committed revision.'''
|
2017-03-19 21:54:15 +03:00
|
|
|
repo.setparents(repo[p1].node(), repo[p2].node())
|
|
|
|
ctx = repo[rev]
|
|
|
|
if commitmsg is None:
|
|
|
|
commitmsg = ctx.description()
|
|
|
|
keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
|
|
|
|
extra = {'rebase_source': ctx.hex()}
|
|
|
|
if extrafn:
|
|
|
|
extrafn(ctx, extra)
|
|
|
|
|
2017-05-12 08:38:03 +03:00
|
|
|
destphase = max(ctx.phase(), phases.draft)
|
|
|
|
overrides = {('phases', 'new-commit'): destphase}
|
2017-03-19 21:54:15 +03:00
|
|
|
with repo.ui.configoverride(overrides, 'rebase'):
|
|
|
|
if keepbranch:
|
|
|
|
repo.ui.setconfig('ui', 'allowemptycommit', True)
|
|
|
|
# Commit might fail if unresolved files exist
|
|
|
|
if date is None:
|
|
|
|
date = ctx.date()
|
|
|
|
newnode = repo.commit(text=commitmsg, user=ctx.user(),
|
|
|
|
date=date, extra=extra, editor=editor)
|
|
|
|
|
|
|
|
repo.dirstate.setbranch(repo[newnode].branch())
|
|
|
|
return newnode
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2017-05-12 08:38:03 +03:00
|
|
|
def rebasenode(repo, rev, p1, base, state, collapse, dest):
|
2014-11-19 05:38:51 +03:00
|
|
|
'Rebase a single revision rev on top of p1 using base as merge ancestor'
|
2008-08-18 23:16:31 +04:00
|
|
|
# Merge phase
|
2017-05-12 08:38:03 +03:00
|
|
|
# Update to destination and merge it with local
|
2014-12-02 07:12:59 +03:00
|
|
|
if repo['.'].rev() != p1:
|
|
|
|
repo.ui.debug(" update to %d:%s\n" % (p1, repo[p1]))
|
2016-11-02 21:56:07 +03:00
|
|
|
mergemod.update(repo, p1, False, True)
|
2008-08-18 23:16:31 +04:00
|
|
|
else:
|
2017-05-12 08:38:15 +03:00
|
|
|
repo.ui.debug(" already in destination\n")
|
2015-10-16 19:15:34 +03:00
|
|
|
repo.dirstate.write(repo.currenttransaction())
|
2014-12-02 07:12:59 +03:00
|
|
|
repo.ui.debug(" merge against %d:%s\n" % (rev, repo[rev]))
|
2013-10-30 22:45:14 +04:00
|
|
|
if base is not None:
|
2014-12-02 07:12:59 +03:00
|
|
|
repo.ui.debug(" detach base %d:%s\n" % (base, repo[base]))
|
rebase: allow collapsing branches in place (issue3111)
We allow rebase plus collapse, but not collapse only? I imagine people would
rebase first then collapse once they are sure the rebase is correct and it is
the right time to finish it.
I was reluctant to submit this patch for reasons detailed below, but it
improves rebase --collapse usefulness so much it is worth the ugliness.
The fix is ugly because we should be fixing the collapse code path rather than
the merge. Collapsing by merging changesets repeatedly is inefficient compared
to what commit --amend does: commitctx(), update, strip. The problem with the
latter is, to generate the synthetic changeset, copy records are gathered with
copies.pathcopies(). copies.pathcopies() is still implemented with merging in
mind and discards information like file replaced by the copy of another,
criss-cross copies and so forth. I believe this information should not be lost,
even if we decide not to interpret it fully later, at merge time.
The second issue with improving rebase --collapse is the option should not be
there to begin with. Rebasing and collapsing are orthogonal and a dedicated
command would probably enable a better, simpler ui. We should avoid advertizing
rebase --collapse, but with this fix it becomes the best shipped solution to
collapse changesets.
And for the record, available techniques are:
- revert + commit + strip: lose copies
- mq/qfold: repeated patching() (mostly correct, fragile)
- rebase: repeated merges (mostly correct, fragile)
- collapse: revert + tag rewriting wizardry, lose copies
- histedit: repeated patching() (mostly correct, fragile)
- amend: copies.pathcopies() + commitctx() + update + strip
2012-05-03 17:14:58 +04:00
|
|
|
# When collapsing in-place, the parent is the common ancestor, we
|
|
|
|
# have to allow merging with it.
|
2016-11-02 21:56:07 +03:00
|
|
|
stats = mergemod.update(repo, rev, True, True, base, collapse,
|
|
|
|
labels=['dest', 'source'])
|
2014-10-14 02:55:45 +04:00
|
|
|
if collapse:
|
2017-05-12 08:38:03 +03:00
|
|
|
copies.duplicatecopies(repo, rev, dest)
|
2014-10-14 02:55:45 +04:00
|
|
|
else:
|
|
|
|
# If we're not using --collapse, we need to
|
|
|
|
# duplicate copies between the revision we're
|
|
|
|
# rebasing and its first parent, but *not*
|
|
|
|
# duplicate any copies that have already been
|
|
|
|
# performed in the destination.
|
|
|
|
p1rev = repo[rev].p1().rev()
|
2017-05-12 08:38:03 +03:00
|
|
|
copies.duplicatecopies(repo, rev, p1rev, skiprev=dest)
|
2014-10-14 02:55:45 +04:00
|
|
|
return stats
|
2008-08-21 13:35:17 +04:00
|
|
|
|
2013-01-19 02:41:48 +04:00
|
|
|
def nearestrebased(repo, rev, state):
|
|
|
|
"""return the nearest ancestors of rev in the rebase result"""
|
|
|
|
rebased = [r for r in state if state[r] > nullmerge]
|
|
|
|
candidates = repo.revs('max(%ld and (::%d))', rebased, rev)
|
|
|
|
if candidates:
|
2014-10-07 11:16:59 +04:00
|
|
|
return state[candidates.first()]
|
2013-01-19 02:41:48 +04:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2016-12-24 23:38:27 +03:00
|
|
|
def _checkobsrebase(repo, ui, rebaseobsrevs, rebasesetrevs, rebaseobsskipped):
|
2016-03-29 21:49:45 +03:00
|
|
|
"""
|
|
|
|
Abort if rebase will create divergence or rebase is noop because of markers
|
|
|
|
|
|
|
|
`rebaseobsrevs`: set of obsolete revision in source
|
|
|
|
`rebasesetrevs`: set of revisions to be rebased from source
|
|
|
|
`rebaseobsskipped`: set of revisions from source skipped because they have
|
|
|
|
successors in destination
|
|
|
|
"""
|
|
|
|
# Obsolete node with successors not in dest leads to divergence
|
|
|
|
divergenceok = ui.configbool('experimental',
|
|
|
|
'allowdivergence')
|
|
|
|
divergencebasecandidates = rebaseobsrevs - rebaseobsskipped
|
|
|
|
|
|
|
|
if divergencebasecandidates and not divergenceok:
|
|
|
|
divhashes = (str(repo[r])
|
|
|
|
for r in divergencebasecandidates)
|
|
|
|
msg = _("this rebase will cause "
|
|
|
|
"divergences from: %s")
|
|
|
|
h = _("to force the rebase please set "
|
|
|
|
"experimental.allowdivergence=True")
|
|
|
|
raise error.Abort(msg % (",".join(divhashes),), hint=h)
|
|
|
|
|
2017-05-12 08:38:03 +03:00
|
|
|
def defineparents(repo, rev, dest, state, destancestors,
|
2016-04-12 00:33:07 +03:00
|
|
|
obsoletenotrebased):
|
2008-08-18 23:16:31 +04:00
|
|
|
'Return the new parent relationship of the revision that will be rebased'
|
|
|
|
parents = repo[rev].parents()
|
|
|
|
p1 = p2 = nullrev
|
2016-04-12 00:33:07 +03:00
|
|
|
rp1 = None
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2014-10-14 03:00:39 +04:00
|
|
|
p1n = parents[0].rev()
|
2017-05-12 08:38:03 +03:00
|
|
|
if p1n in destancestors:
|
|
|
|
p1 = dest
|
2014-10-14 03:00:39 +04:00
|
|
|
elif p1n in state:
|
|
|
|
if state[p1n] == nullmerge:
|
2017-05-12 08:38:03 +03:00
|
|
|
p1 = dest
|
2015-11-19 02:58:06 +03:00
|
|
|
elif state[p1n] in revskipped:
|
2014-10-14 03:00:39 +04:00
|
|
|
p1 = nearestrebased(repo, p1n, state)
|
2013-01-19 02:41:48 +04:00
|
|
|
if p1 is None:
|
2017-05-12 08:38:03 +03:00
|
|
|
p1 = dest
|
2010-02-06 12:51:50 +03:00
|
|
|
else:
|
2014-10-14 03:00:39 +04:00
|
|
|
p1 = state[p1n]
|
|
|
|
else: # p1n external
|
2017-05-12 08:38:03 +03:00
|
|
|
p1 = dest
|
2014-10-14 03:00:39 +04:00
|
|
|
p2 = p1n
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2017-05-12 08:38:03 +03:00
|
|
|
if len(parents) == 2 and parents[1].rev() not in destancestors:
|
2014-10-14 03:00:39 +04:00
|
|
|
p2n = parents[1].rev()
|
2008-08-18 23:16:31 +04:00
|
|
|
# interesting second parent
|
2014-10-14 03:00:39 +04:00
|
|
|
if p2n in state:
|
2017-05-12 08:38:03 +03:00
|
|
|
if p1 == dest: # p1n in destancestors or external
|
2014-10-14 03:00:39 +04:00
|
|
|
p1 = state[p2n]
|
2016-04-12 00:33:07 +03:00
|
|
|
if p1 == revprecursor:
|
|
|
|
rp1 = obsoletenotrebased[p2n]
|
2015-11-19 02:58:06 +03:00
|
|
|
elif state[p2n] in revskipped:
|
2014-10-14 03:00:39 +04:00
|
|
|
p2 = nearestrebased(repo, p2n, state)
|
2013-01-19 02:41:48 +04:00
|
|
|
if p2 is None:
|
|
|
|
# no ancestors rebased yet, detach
|
2017-05-12 08:38:03 +03:00
|
|
|
p2 = dest
|
2008-08-18 23:16:31 +04:00
|
|
|
else:
|
2014-10-14 03:00:39 +04:00
|
|
|
p2 = state[p2n]
|
|
|
|
else: # p2n external
|
|
|
|
if p2 != nullrev: # p1n external too => rev is a merged revision
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot use revision %d as base, result '
|
2008-08-18 23:16:31 +04:00
|
|
|
'would have 3 parents') % rev)
|
2014-10-14 03:00:39 +04:00
|
|
|
p2 = p2n
|
2010-01-31 15:30:17 +03:00
|
|
|
repo.ui.debug(" future parents are %d and %d\n" %
|
2016-04-12 00:33:07 +03:00
|
|
|
(repo[rp1 or p1].rev(), repo[p2].rev()))
|
2014-11-19 05:38:51 +03:00
|
|
|
|
2016-02-01 18:41:43 +03:00
|
|
|
if not any(p.rev() in state for p in parents):
|
|
|
|
# Case (1) root changeset of a non-detaching rebase set.
|
2014-11-19 05:38:51 +03:00
|
|
|
# Let the merge mechanism find the base itself.
|
|
|
|
base = None
|
|
|
|
elif not repo[rev].p2():
|
|
|
|
# Case (2) detaching the node with a single parent, use this parent
|
|
|
|
base = repo[rev].p1().rev()
|
|
|
|
else:
|
2015-01-04 03:29:07 +03:00
|
|
|
# Assuming there is a p1, this is the case where there also is a p2.
|
|
|
|
# We are thus rebasing a merge and need to pick the right merge base.
|
2014-11-19 05:38:51 +03:00
|
|
|
#
|
|
|
|
# Imagine we have:
|
2015-01-04 03:29:07 +03:00
|
|
|
# - M: current rebase revision in this step
|
2014-11-19 05:38:51 +03:00
|
|
|
# - A: one parent of M
|
2015-01-04 03:29:07 +03:00
|
|
|
# - B: other parent of M
|
2014-11-19 05:38:51 +03:00
|
|
|
# - D: destination of this merge step (p1 var)
|
|
|
|
#
|
2015-01-04 03:29:07 +03:00
|
|
|
# Consider the case where D is a descendant of A or B and the other is
|
|
|
|
# 'outside'. In this case, the right merge base is the D ancestor.
|
|
|
|
#
|
|
|
|
# An informal proof, assuming A is 'outside' and B is the D ancestor:
|
2014-11-19 05:38:51 +03:00
|
|
|
#
|
|
|
|
# If we pick B as the base, the merge involves:
|
|
|
|
# - changes from B to M (actual changeset payload)
|
|
|
|
# - changes from B to D (induced by rebase) as D is a rebased
|
|
|
|
# version of B)
|
|
|
|
# Which exactly represent the rebase operation.
|
|
|
|
#
|
2015-01-04 03:29:07 +03:00
|
|
|
# If we pick A as the base, the merge involves:
|
2014-11-19 05:38:51 +03:00
|
|
|
# - changes from A to M (actual changeset payload)
|
|
|
|
# - changes from A to D (with include changes between unrelated A and B
|
|
|
|
# plus changes induced by rebase)
|
|
|
|
# Which does not represent anything sensible and creates a lot of
|
2015-01-04 03:29:07 +03:00
|
|
|
# conflicts. A is thus not the right choice - B is.
|
|
|
|
#
|
|
|
|
# Note: The base found in this 'proof' is only correct in the specified
|
|
|
|
# case. This base does not make sense if is not D a descendant of A or B
|
|
|
|
# or if the other is not parent 'outside' (especially not if the other
|
|
|
|
# parent has been rebased). The current implementation does not
|
|
|
|
# make it feasible to consider different cases separately. In these
|
|
|
|
# other cases we currently just leave it to the user to correctly
|
|
|
|
# resolve an impossible merge using a wrong ancestor.
|
2016-04-12 00:33:07 +03:00
|
|
|
#
|
|
|
|
# xx, p1 could be -4, and both parents could probably be -4...
|
2014-11-19 05:38:51 +03:00
|
|
|
for p in repo[rev].parents():
|
|
|
|
if state.get(p.rev()) == p1:
|
|
|
|
base = p.rev()
|
|
|
|
break
|
|
|
|
else: # fallback when base not found
|
|
|
|
base = None
|
|
|
|
|
|
|
|
# Raise because this function is called wrong (see issue 4106)
|
|
|
|
raise AssertionError('no base found to rebase on '
|
|
|
|
'(defineparents called wrong)')
|
2016-04-12 00:33:07 +03:00
|
|
|
return rp1 or p1, p2, base
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2009-03-26 17:58:50 +03:00
|
|
|
def isagitpatch(repo, patchname):
|
|
|
|
'Return true if the given patch is in git format'
|
|
|
|
mqpatch = os.path.join(repo.mq.path, patchname)
|
|
|
|
for line in patch.linereader(file(mqpatch, 'rb')):
|
|
|
|
if line.startswith('diff --git'):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2008-08-18 23:16:31 +04:00
|
|
|
def updatemq(repo, state, skipped, **opts):
|
|
|
|
'Update rebased mq patches - finalize and then import them'
|
|
|
|
mqrebase = {}
|
2010-07-12 14:04:07 +04:00
|
|
|
mq = repo.mq
|
2011-06-13 13:06:11 +04:00
|
|
|
original_series = mq.fullseries[:]
|
2012-04-25 19:04:18 +04:00
|
|
|
skippedpatches = set()
|
2011-03-26 15:05:17 +03:00
|
|
|
|
2010-07-12 14:04:07 +04:00
|
|
|
for p in mq.applied:
|
|
|
|
rev = repo[p.node].rev()
|
|
|
|
if rev in state:
|
2009-09-19 03:15:38 +04:00
|
|
|
repo.ui.debug('revision %d is an mq patch (%s), finalize it.\n' %
|
2010-07-12 14:04:07 +04:00
|
|
|
(rev, p.name))
|
|
|
|
mqrebase[rev] = (p.name, isagitpatch(repo, p.name))
|
2012-04-25 19:04:18 +04:00
|
|
|
else:
|
|
|
|
# Applied but not rebased, not sure this should happen
|
|
|
|
skippedpatches.add(p.name)
|
2008-08-18 23:16:31 +04:00
|
|
|
|
|
|
|
if mqrebase:
|
2010-07-12 14:04:07 +04:00
|
|
|
mq.finish(repo, mqrebase.keys())
|
2008-08-18 23:16:31 +04:00
|
|
|
|
|
|
|
# We must start import from the newest revision
|
2009-04-27 01:50:44 +04:00
|
|
|
for rev in sorted(mqrebase, reverse=True):
|
2008-08-18 23:16:31 +04:00
|
|
|
if rev not in skipped:
|
2010-07-12 14:04:07 +04:00
|
|
|
name, isgit = mqrebase[rev]
|
2012-10-12 01:22:02 +04:00
|
|
|
repo.ui.note(_('updating mq patch %s to %s:%s\n') %
|
|
|
|
(name, state[rev], repo[state[rev]]))
|
2010-07-12 14:04:07 +04:00
|
|
|
mq.qimport(repo, (), patchname=name, git=isgit,
|
|
|
|
rev=[str(state[rev])])
|
2012-04-25 19:04:18 +04:00
|
|
|
else:
|
|
|
|
# Rebased and skipped
|
|
|
|
skippedpatches.add(mqrebase[rev][0])
|
|
|
|
|
|
|
|
# Patches were either applied and rebased and imported in
|
|
|
|
# order, applied and removed or unapplied. Discard the removed
|
|
|
|
# ones while preserving the original series order and guards.
|
|
|
|
newseries = [s for s in original_series
|
|
|
|
if mq.guard_re.split(s, 1)[0] not in skippedpatches]
|
|
|
|
mq.fullseries[:] = newseries
|
|
|
|
mq.seriesdirty = True
|
2011-06-13 14:02:14 +04:00
|
|
|
mq.savedirty()
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2017-05-12 08:38:03 +03:00
|
|
|
def updatebookmarks(repo, destnode, nstate, originalbookmarks, tr):
|
2013-01-31 04:08:32 +04:00
|
|
|
'Move bookmarks to their correct changesets, and delete divergent ones'
|
2012-11-08 02:21:39 +04:00
|
|
|
marks = repo._bookmarks
|
2011-07-15 22:07:19 +04:00
|
|
|
for k, v in originalbookmarks.iteritems():
|
|
|
|
if v in nstate:
|
2013-01-31 05:49:54 +04:00
|
|
|
# update the bookmarks for revs that have moved
|
|
|
|
marks[k] = nstate[v]
|
2017-05-12 08:38:03 +03:00
|
|
|
bookmarks.deletedivergent(repo, [destnode], k)
|
2015-11-21 01:06:31 +03:00
|
|
|
marks.recordchange(tr)
|
2011-07-15 22:07:19 +04:00
|
|
|
|
2016-02-18 00:45:01 +03:00
|
|
|
def storecollapsemsg(repo, collapsemsg):
|
|
|
|
'Store the collapse message to allow recovery'
|
|
|
|
collapsemsg = collapsemsg or ''
|
|
|
|
f = repo.vfs("last-message.txt", "w")
|
|
|
|
f.write("%s\n" % collapsemsg)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def clearcollapsemsg(repo):
|
|
|
|
'Remove collapse message file'
|
2017-03-11 22:02:25 +03:00
|
|
|
repo.vfs.unlinkpath("last-message.txt", ignoremissing=True)
|
2016-02-18 00:45:01 +03:00
|
|
|
|
2017-03-08 03:30:31 +03:00
|
|
|
def restorecollapsemsg(repo, isabort):
|
2016-02-18 00:45:01 +03:00
|
|
|
'Restore previously stored collapse message'
|
|
|
|
try:
|
|
|
|
f = repo.vfs("last-message.txt")
|
|
|
|
collapsemsg = f.readline().strip()
|
|
|
|
f.close()
|
|
|
|
except IOError as err:
|
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
2017-03-08 03:30:31 +03:00
|
|
|
if isabort:
|
|
|
|
# Oh well, just abort like normal
|
|
|
|
collapsemsg = ''
|
|
|
|
else:
|
|
|
|
raise error.Abort(_('missing .hg/last-message.txt for rebase'))
|
2016-02-18 00:45:01 +03:00
|
|
|
return collapsemsg
|
|
|
|
|
2008-08-18 23:16:31 +04:00
|
|
|
def clearstatus(repo):
|
|
|
|
'Remove the status files'
|
2015-01-27 15:33:56 +03:00
|
|
|
_clearrebasesetvisibiliy(repo)
|
2017-03-11 22:02:25 +03:00
|
|
|
repo.vfs.unlinkpath("rebasestate", ignoremissing=True)
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2015-05-10 17:57:24 +03:00
|
|
|
def needupdate(repo, state):
|
|
|
|
'''check whether we should `update --clean` away from a merge, or if
|
|
|
|
somehow the working dir got forcibly updated, e.g. by older hg'''
|
2015-11-12 04:07:15 +03:00
|
|
|
parents = [p.rev() for p in repo[None].parents()]
|
2013-08-02 02:33:09 +04:00
|
|
|
|
2015-05-10 17:57:24 +03:00
|
|
|
# Are we in a merge state at all?
|
|
|
|
if len(parents) < 2:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# We should be standing on the first as-of-yet unrebased commit.
|
|
|
|
firstunrebased = min([old for old, new in state.iteritems()
|
|
|
|
if new == nullrev])
|
|
|
|
if firstunrebased in parents:
|
|
|
|
return True
|
2013-08-02 02:33:09 +04:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
2017-05-12 08:38:03 +03:00
|
|
|
def abort(repo, originalwd, dest, state, activebookmark=None):
|
2015-04-13 21:54:02 +03:00
|
|
|
'''Restore the repository to its original state. Additional args:
|
|
|
|
|
|
|
|
activebookmark: the name of the bookmark that should be active after the
|
|
|
|
restore'''
|
2015-10-14 00:06:51 +03:00
|
|
|
|
2015-10-15 22:13:46 +03:00
|
|
|
try:
|
|
|
|
# If the first commits in the rebased set get skipped during the rebase,
|
2017-05-12 08:38:03 +03:00
|
|
|
# their values within the state mapping will be the dest rev id. The
|
|
|
|
# dstates list must must not contain the dest rev (issue4896)
|
|
|
|
dstates = [s for s in state.values() if s >= 0 and s != dest]
|
2015-10-15 22:13:46 +03:00
|
|
|
immutable = [d for d in dstates if not repo[d].mutable()]
|
|
|
|
cleanup = True
|
|
|
|
if immutable:
|
|
|
|
repo.ui.warn(_("warning: can't clean up public changesets %s\n")
|
|
|
|
% ', '.join(str(repo[r]) for r in immutable),
|
2016-09-21 02:44:28 +03:00
|
|
|
hint=_("see 'hg help phases' for details"))
|
2015-10-15 22:13:46 +03:00
|
|
|
cleanup = False
|
|
|
|
|
|
|
|
descendants = set()
|
|
|
|
if dstates:
|
|
|
|
descendants = set(repo.changelog.descendants(dstates))
|
|
|
|
if descendants - set(dstates):
|
2017-05-12 08:38:15 +03:00
|
|
|
repo.ui.warn(_("warning: new changesets detected on destination "
|
|
|
|
"branch, can't strip\n"))
|
2015-10-15 22:13:46 +03:00
|
|
|
cleanup = False
|
|
|
|
|
|
|
|
if cleanup:
|
2016-02-05 04:56:46 +03:00
|
|
|
shouldupdate = False
|
2017-05-12 08:38:03 +03:00
|
|
|
rebased = filter(lambda x: x >= 0 and x != dest, state.values())
|
2016-02-05 04:56:46 +03:00
|
|
|
if rebased:
|
|
|
|
strippoints = [
|
|
|
|
c.node() for c in repo.set('roots(%ld)', rebased)]
|
2017-03-08 01:19:08 +03:00
|
|
|
|
|
|
|
updateifonnodes = set(rebased)
|
2017-05-12 08:38:03 +03:00
|
|
|
updateifonnodes.add(dest)
|
2017-03-08 01:19:08 +03:00
|
|
|
updateifonnodes.add(originalwd)
|
|
|
|
shouldupdate = repo['.'].rev() in updateifonnodes
|
2016-02-05 04:56:46 +03:00
|
|
|
|
2015-10-15 22:13:46 +03:00
|
|
|
# Update away from the rebase if necessary
|
2016-02-05 04:56:46 +03:00
|
|
|
if shouldupdate or needupdate(repo, state):
|
2016-11-02 21:56:07 +03:00
|
|
|
mergemod.update(repo, originalwd, False, True)
|
2015-10-15 22:13:46 +03:00
|
|
|
|
|
|
|
# Strip from the first rebased revision
|
|
|
|
if rebased:
|
|
|
|
# no backup of rebased cset versions needed
|
|
|
|
repair.strip(repo.ui, repo, strippoints)
|
|
|
|
|
|
|
|
if activebookmark and activebookmark in repo._bookmarks:
|
|
|
|
bookmarks.activate(repo, activebookmark)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
clearstatus(repo)
|
2016-02-18 00:45:01 +03:00
|
|
|
clearcollapsemsg(repo)
|
2015-10-15 22:13:46 +03:00
|
|
|
repo.ui.warn(_('rebase aborted\n'))
|
2013-08-02 02:54:12 +04:00
|
|
|
return 0
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2015-09-15 03:31:48 +03:00
|
|
|
def buildstate(repo, dest, rebaseset, collapse, obsoletenotrebased):
|
2011-10-15 21:07:51 +04:00
|
|
|
'''Define which revisions are going to be rebased and where
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2011-10-15 21:07:51 +04:00
|
|
|
repo: repo
|
|
|
|
dest: context
|
|
|
|
rebaseset: set of rev
|
2012-06-20 22:08:57 +04:00
|
|
|
'''
|
2017-03-11 10:07:20 +03:00
|
|
|
originalwd = repo['.'].rev()
|
2017-02-11 03:56:29 +03:00
|
|
|
_setrebasesetvisibility(repo, set(rebaseset) | {originalwd})
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2010-03-02 23:08:43 +03:00
|
|
|
# This check isn't strictly necessary, since mq detects commits over an
|
|
|
|
# applied patch. But it prevents messing up the working directory when
|
|
|
|
# a partially completed rebase is blocked by mq.
|
2011-10-15 21:07:51 +04:00
|
|
|
if 'qtip' in repo.tags() and (dest.node() in
|
2010-03-14 02:36:10 +03:00
|
|
|
[s.node for s in repo.mq.applied]):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot rebase onto an applied mq patch'))
|
2010-03-02 23:08:43 +03:00
|
|
|
|
2011-10-15 21:07:51 +04:00
|
|
|
roots = list(repo.set('roots(%ld)', rebaseset))
|
|
|
|
if not roots:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('no matching revisions'))
|
2013-01-17 03:35:01 +04:00
|
|
|
roots.sort()
|
2017-03-11 23:25:56 +03:00
|
|
|
state = dict.fromkeys(rebaseset, revtodo)
|
2013-01-17 03:35:01 +04:00
|
|
|
detachset = set()
|
2017-05-11 21:37:18 +03:00
|
|
|
emptyrebase = True
|
2013-01-17 03:35:01 +04:00
|
|
|
for root in roots:
|
|
|
|
commonbase = root.ancestor(dest)
|
|
|
|
if commonbase == root:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('source is ancestor of destination'))
|
2013-01-17 03:35:01 +04:00
|
|
|
if commonbase == dest:
|
2017-03-13 02:44:01 +03:00
|
|
|
wctx = repo[None]
|
|
|
|
if dest == wctx.p1():
|
|
|
|
# when rebasing to '.', it will use the current wd branch name
|
|
|
|
samebranch = root.branch() == wctx.branch()
|
|
|
|
else:
|
|
|
|
samebranch = root.branch() == dest.branch()
|
2013-01-17 03:35:01 +04:00
|
|
|
if not collapse and samebranch and root in dest.children():
|
2017-05-11 21:37:18 +03:00
|
|
|
# mark the revision as done by setting its new revision
|
|
|
|
# equal to its old (current) revisions
|
|
|
|
state[root.rev()] = root.rev()
|
2013-01-17 03:35:01 +04:00
|
|
|
repo.ui.debug('source is a child of destination\n')
|
2017-05-11 21:37:18 +03:00
|
|
|
continue
|
2013-01-17 03:35:01 +04:00
|
|
|
|
2017-05-11 21:37:18 +03:00
|
|
|
emptyrebase = False
|
2016-09-13 23:49:42 +03:00
|
|
|
repo.ui.debug('rebase onto %s starting from %s\n' % (dest, root))
|
2013-01-17 03:35:01 +04:00
|
|
|
# Rebase tries to turn <dest> into a parent of <root> while
|
|
|
|
# preserving the number of parents of rebased changesets:
|
|
|
|
#
|
|
|
|
# - A changeset with a single parent will always be rebased as a
|
|
|
|
# changeset with a single parent.
|
|
|
|
#
|
|
|
|
# - A merge will be rebased as merge unless its parents are both
|
|
|
|
# ancestors of <dest> or are themselves in the rebased set and
|
|
|
|
# pruned while rebased.
|
|
|
|
#
|
|
|
|
# If one parent of <root> is an ancestor of <dest>, the rebased
|
|
|
|
# version of this parent will be <dest>. This is always true with
|
|
|
|
# --base option.
|
|
|
|
#
|
|
|
|
# Otherwise, we need to *replace* the original parents with
|
|
|
|
# <dest>. This "detaches" the rebased set from its former location
|
|
|
|
# and rebases it onto <dest>. Changes introduced by ancestors of
|
|
|
|
# <root> not common with <dest> (the detachset, marked as
|
|
|
|
# nullmerge) are "removed" from the rebased changesets.
|
|
|
|
#
|
|
|
|
# - If <root> has a single parent, set it to <dest>.
|
|
|
|
#
|
|
|
|
# - If <root> is a merge, we cannot decide which parent to
|
|
|
|
# replace, the rebase operation is not clearly defined.
|
|
|
|
#
|
|
|
|
# The table below sums up this behavior:
|
|
|
|
#
|
|
|
|
# +------------------+----------------------+-------------------------+
|
|
|
|
# | | one parent | merge |
|
|
|
|
# +------------------+----------------------+-------------------------+
|
|
|
|
# | parent in | new parent is <dest> | parents in ::<dest> are |
|
|
|
|
# | ::<dest> | | remapped to <dest> |
|
|
|
|
# +------------------+----------------------+-------------------------+
|
|
|
|
# | unrelated source | new parent is <dest> | ambiguous, abort |
|
|
|
|
# +------------------+----------------------+-------------------------+
|
|
|
|
#
|
|
|
|
# The actual abort is handled by `defineparents`
|
|
|
|
if len(root.parents()) <= 1:
|
|
|
|
# ancestors of <root> not ancestors of <dest>
|
|
|
|
detachset.update(repo.changelog.findmissingrevs([commonbase.rev()],
|
|
|
|
[root.rev()]))
|
2017-05-11 21:37:18 +03:00
|
|
|
if emptyrebase:
|
|
|
|
return None
|
|
|
|
for rev in sorted(state):
|
|
|
|
parents = [p for p in repo.changelog.parentrevs(rev) if p != nullrev]
|
|
|
|
# if all parents of this revision are done, then so is this revision
|
|
|
|
if parents and all((state.get(p) == p for p in parents)):
|
|
|
|
state[rev] = rev
|
2013-01-17 03:35:01 +04:00
|
|
|
for r in detachset:
|
|
|
|
if r not in state:
|
|
|
|
state[r] = nullmerge
|
2013-01-19 02:41:48 +04:00
|
|
|
if len(roots) > 1:
|
|
|
|
# If we have multiple roots, we may have "hole" in the rebase set.
|
|
|
|
# Rebase roots that descend from those "hole" should not be detached as
|
|
|
|
# other root are. We use the special `revignored` to inform rebase that
|
2013-02-10 21:24:29 +04:00
|
|
|
# the revision should be ignored but that `defineparents` should search
|
|
|
|
# a rebase destination that make sense regarding rebased topology.
|
2013-01-19 02:41:48 +04:00
|
|
|
rebasedomain = set(repo.revs('%ld::%ld', rebaseset, rebaseset))
|
|
|
|
for ignored in set(rebasedomain) - set(rebaseset):
|
|
|
|
state[ignored] = revignored
|
2015-09-15 03:31:48 +03:00
|
|
|
for r in obsoletenotrebased:
|
2015-11-19 00:44:29 +03:00
|
|
|
if obsoletenotrebased[r] is None:
|
|
|
|
state[r] = revpruned
|
|
|
|
else:
|
|
|
|
state[r] = revprecursor
|
2017-03-11 10:07:20 +03:00
|
|
|
return originalwd, dest.rev(), state
|
2008-08-18 23:16:31 +04:00
|
|
|
|
rebase: do not invent successor to skipped changeset
When rebase results in an empty a changeset it is "skipped" and no related
changeset is created at all. When we added obsolescence support to rebase (in
cee0a253a56c) it seemed a good idea to use its parent successor as the
successors for such dropped changesets. (see old version of the altered test).
This option was chosen because it seems a good way to hint about were the
dropped changeset "intended" to be. Such hint would have been used by automatic
evolution mechanism to rebase potential unstable children.
However, field testing of this version are not conclusive. It very often leads
to the creation of (totally unfounded) evolution divergence. This changeset
changes this behavior and mark skipped changesets as pruned (obsolete without
successors). This prevents the issue and seems semantically better probably a
win for obsolescence reading tool.
See example bellow for details:
User Babar has five changesets of interest:
- O, its current base of development.
- U, the new upstream
- A and C, some development changesets
- B another development changeset independent from A
O - A - B - C
\
U
Babar decides that B is more critical than the A and C and rebase it first
$ hg rebase --rev B --dest U
B is now obsolete (in lower case bellow). Rebase result, B', is its
successors.(note, C is unstable)
O - A - b - C
\
U - B'
Babar is now done with B', and want to rebase the rest of its history:
$ hg rebase --source A --dest B'
hg rebase process A, B and C. B is skipped as all its changes are already contained
in B'.
O - U - B' - A' - C'
Babar have the expected result graph wise, obsolescence marker are as follow:
B -> B' (from first rebase)
A -> A' (from second rebase)
C -> C' (from second rebase)
B -> ?? (from second rebase)
Before this changeset, the last marker is `B -> A'`. This cause two issues:
- This is semantically wrong. B have nothing to do with A'
- B has now two successors sets: (B',) and (A',). We detect a divergent
rewriting. The B' and A' are reported as "divergent" to Babar, confusion
ensues. In addition such divergent situation (divergent changeset are children
to each other) is tricky to solve.
With this changeset the last marker is `B -> ø`:
- This is semantically better.
- B has a single successors set (B',)
This scenario is added to the tests suite.
2013-01-18 17:15:32 +04:00
|
|
|
def clearrebased(ui, repo, state, skipped, collapsedas=None):
|
2012-09-19 01:42:27 +04:00
|
|
|
"""dispose of rebased revision at the end of the rebase
|
|
|
|
|
|
|
|
If `collapsedas` is not None, the rebase was a collapse whose result if the
|
|
|
|
`collapsedas` node."""
|
2014-10-15 00:23:52 +04:00
|
|
|
if obsolete.isenabled(repo, obsolete.createmarkersopt):
|
2012-09-19 01:13:31 +04:00
|
|
|
markers = []
|
|
|
|
for rev, newrev in sorted(state.items()):
|
2017-05-11 21:37:18 +03:00
|
|
|
if newrev >= 0 and newrev != rev:
|
rebase: do not invent successor to skipped changeset
When rebase results in an empty a changeset it is "skipped" and no related
changeset is created at all. When we added obsolescence support to rebase (in
cee0a253a56c) it seemed a good idea to use its parent successor as the
successors for such dropped changesets. (see old version of the altered test).
This option was chosen because it seems a good way to hint about were the
dropped changeset "intended" to be. Such hint would have been used by automatic
evolution mechanism to rebase potential unstable children.
However, field testing of this version are not conclusive. It very often leads
to the creation of (totally unfounded) evolution divergence. This changeset
changes this behavior and mark skipped changesets as pruned (obsolete without
successors). This prevents the issue and seems semantically better probably a
win for obsolescence reading tool.
See example bellow for details:
User Babar has five changesets of interest:
- O, its current base of development.
- U, the new upstream
- A and C, some development changesets
- B another development changeset independent from A
O - A - B - C
\
U
Babar decides that B is more critical than the A and C and rebase it first
$ hg rebase --rev B --dest U
B is now obsolete (in lower case bellow). Rebase result, B', is its
successors.(note, C is unstable)
O - A - b - C
\
U - B'
Babar is now done with B', and want to rebase the rest of its history:
$ hg rebase --source A --dest B'
hg rebase process A, B and C. B is skipped as all its changes are already contained
in B'.
O - U - B' - A' - C'
Babar have the expected result graph wise, obsolescence marker are as follow:
B -> B' (from first rebase)
A -> A' (from second rebase)
C -> C' (from second rebase)
B -> ?? (from second rebase)
Before this changeset, the last marker is `B -> A'`. This cause two issues:
- This is semantically wrong. B have nothing to do with A'
- B has now two successors sets: (B',) and (A',). We detect a divergent
rewriting. The B' and A' are reported as "divergent" to Babar, confusion
ensues. In addition such divergent situation (divergent changeset are children
to each other) is tricky to solve.
With this changeset the last marker is `B -> ø`:
- This is semantically better.
- B has a single successors set (B',)
This scenario is added to the tests suite.
2013-01-18 17:15:32 +04:00
|
|
|
if rev in skipped:
|
|
|
|
succs = ()
|
|
|
|
elif collapsedas is not None:
|
|
|
|
succs = (repo[collapsedas],)
|
|
|
|
else:
|
|
|
|
succs = (repo[newrev],)
|
|
|
|
markers.append((repo[rev], succs))
|
2012-09-19 01:13:31 +04:00
|
|
|
if markers:
|
2017-05-10 02:29:31 +03:00
|
|
|
obsolete.createmarkers(repo, markers, operation='rebase')
|
2012-09-19 01:13:31 +04:00
|
|
|
else:
|
2017-05-11 21:37:18 +03:00
|
|
|
rebased = [rev for rev in state
|
|
|
|
if state[rev] > nullmerge and state[rev] != rev]
|
2012-09-19 01:13:31 +04:00
|
|
|
if rebased:
|
2013-01-17 03:35:01 +04:00
|
|
|
stripped = []
|
|
|
|
for root in repo.set('roots(%ld)', rebased):
|
|
|
|
if set(repo.changelog.descendants([root.rev()])) - set(state):
|
|
|
|
ui.warn(_("warning: new changesets detected "
|
|
|
|
"on source branch, not stripping\n"))
|
|
|
|
else:
|
|
|
|
stripped.append(root.node())
|
|
|
|
if stripped:
|
2012-09-19 01:13:31 +04:00
|
|
|
# backup the old csets by default
|
2013-01-17 03:35:01 +04:00
|
|
|
repair.strip(ui, repo, stripped, "all")
|
2012-09-19 00:58:12 +04:00
|
|
|
|
|
|
|
|
2008-10-23 02:34:52 +04:00
|
|
|
def pullrebase(orig, ui, repo, *args, **opts):
|
2008-08-18 23:16:31 +04:00
|
|
|
'Call rebase after pull if the latter has been invoked with --rebase'
|
2015-11-16 00:18:48 +03:00
|
|
|
ret = None
|
2008-08-18 23:16:31 +04:00
|
|
|
if opts.get('rebase'):
|
2017-03-30 13:50:10 +03:00
|
|
|
if ui.configbool('commands', 'rebase.requiredest'):
|
|
|
|
msg = _('rebase destination required by configuration')
|
|
|
|
hint = _('use hg pull followed by hg rebase -d DEST')
|
|
|
|
raise error.Abort(msg, hint=hint)
|
|
|
|
|
2015-08-12 02:45:11 +03:00
|
|
|
wlock = lock = None
|
2010-03-10 14:38:33 +03:00
|
|
|
try:
|
2015-08-12 02:45:11 +03:00
|
|
|
wlock = repo.wlock()
|
|
|
|
lock = repo.lock()
|
|
|
|
if opts.get('update'):
|
|
|
|
del opts['update']
|
|
|
|
ui.debug('--update and --rebase are not compatible, ignoring '
|
|
|
|
'the update flag\n')
|
|
|
|
|
2017-01-01 15:16:29 +03:00
|
|
|
cmdutil.checkunfinished(repo)
|
2017-01-10 11:32:27 +03:00
|
|
|
cmdutil.bailifchanged(repo, hint=_('cannot pull with rebase: '
|
|
|
|
'please commit or shelve your changes first'))
|
2017-01-01 15:16:29 +03:00
|
|
|
|
2015-08-12 02:45:11 +03:00
|
|
|
revsprepull = len(repo)
|
|
|
|
origpostincoming = commands.postincoming
|
|
|
|
def _dummy(*args, **kwargs):
|
|
|
|
pass
|
|
|
|
commands.postincoming = _dummy
|
|
|
|
try:
|
2015-11-16 00:18:48 +03:00
|
|
|
ret = orig(ui, repo, *args, **opts)
|
2015-08-12 02:45:11 +03:00
|
|
|
finally:
|
|
|
|
commands.postincoming = origpostincoming
|
|
|
|
revspostpull = len(repo)
|
|
|
|
if revspostpull > revsprepull:
|
|
|
|
# --rev option from pull conflict with rebase own --rev
|
|
|
|
# dropping it
|
|
|
|
if 'rev' in opts:
|
|
|
|
del opts['rev']
|
|
|
|
# positional argument from pull conflicts with rebase's own
|
|
|
|
# --source.
|
|
|
|
if 'source' in opts:
|
|
|
|
del opts['source']
|
2016-04-30 19:39:39 +03:00
|
|
|
# revsprepull is the len of the repo, not revnum of tip.
|
|
|
|
destspace = list(repo.changelog.revs(start=revsprepull))
|
|
|
|
opts['_destspace'] = destspace
|
2016-02-14 16:25:59 +03:00
|
|
|
try:
|
|
|
|
rebase(ui, repo, **opts)
|
|
|
|
except error.NoMergeDestAbort:
|
|
|
|
# we can maybe update instead
|
2016-02-14 03:45:17 +03:00
|
|
|
rev, _a, _b = destutil.destupdate(repo)
|
2016-02-14 16:25:59 +03:00
|
|
|
if rev == repo['.'].rev():
|
|
|
|
ui.status(_('nothing to rebase\n'))
|
|
|
|
else:
|
|
|
|
ui.status(_('nothing to rebase - updating instead\n'))
|
2016-02-14 03:45:17 +03:00
|
|
|
# not passing argument to get the bare update behavior
|
|
|
|
# with warning and trumpets
|
|
|
|
commands.update(ui, repo)
|
2010-03-10 14:38:33 +03:00
|
|
|
finally:
|
2015-08-12 02:45:11 +03:00
|
|
|
release(lock, wlock)
|
2008-08-18 23:16:31 +04:00
|
|
|
else:
|
2011-05-27 12:03:29 +04:00
|
|
|
if opts.get('tool'):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('--tool can only be used with --rebase'))
|
2015-11-16 00:18:48 +03:00
|
|
|
ret = orig(ui, repo, *args, **opts)
|
|
|
|
|
|
|
|
return ret
|
2008-08-18 23:16:31 +04:00
|
|
|
|
2015-01-27 15:33:56 +03:00
|
|
|
def _setrebasesetvisibility(repo, revs):
|
|
|
|
"""store the currently rebased set on the repo object
|
|
|
|
|
|
|
|
This is used by another function to prevent rebased revision to because
|
2017-02-01 19:47:27 +03:00
|
|
|
hidden (see issue4504)"""
|
2015-01-27 15:33:56 +03:00
|
|
|
repo = repo.unfiltered()
|
|
|
|
repo._rebaseset = revs
|
|
|
|
# invalidate cache if visibility changes
|
|
|
|
hiddens = repo.filteredrevcache.get('visible', set())
|
|
|
|
if revs & hiddens:
|
|
|
|
repo.invalidatevolatilesets()
|
|
|
|
|
|
|
|
def _clearrebasesetvisibiliy(repo):
|
|
|
|
"""remove rebaseset data from the repo"""
|
|
|
|
repo = repo.unfiltered()
|
|
|
|
if '_rebaseset' in vars(repo):
|
|
|
|
del repo._rebaseset
|
|
|
|
|
|
|
|
def _rebasedvisible(orig, repo):
|
2017-02-01 19:47:27 +03:00
|
|
|
"""ensure rebased revs stay visible (see issue4504)"""
|
2015-01-27 15:33:56 +03:00
|
|
|
blockers = orig(repo)
|
|
|
|
blockers.update(getattr(repo, '_rebaseset', ()))
|
|
|
|
return blockers
|
|
|
|
|
2016-01-14 22:50:28 +03:00
|
|
|
def _filterobsoleterevs(repo, revs):
|
|
|
|
"""returns a set of the obsolete revisions in revs"""
|
|
|
|
return set(r for r in revs if repo[r].obsolete())
|
|
|
|
|
2016-01-06 23:55:56 +03:00
|
|
|
def _computeobsoletenotrebased(repo, rebaseobsrevs, dest):
|
2015-09-15 03:31:48 +03:00
|
|
|
"""return a mapping obsolete => successor for all obsolete nodes to be
|
2015-11-19 00:44:29 +03:00
|
|
|
rebased that have a successors in the destination
|
|
|
|
|
2016-10-18 00:16:55 +03:00
|
|
|
obsolete => None entries in the mapping indicate nodes with no successor"""
|
2015-09-15 03:31:48 +03:00
|
|
|
obsoletenotrebased = {}
|
|
|
|
|
2015-10-17 01:58:46 +03:00
|
|
|
# Build a mapping successor => obsolete nodes for the obsolete
|
2015-09-15 03:31:48 +03:00
|
|
|
# nodes to be rebased
|
|
|
|
allsuccessors = {}
|
2015-10-15 01:42:15 +03:00
|
|
|
cl = repo.changelog
|
2016-01-06 23:55:56 +03:00
|
|
|
for r in rebaseobsrevs:
|
|
|
|
node = cl.node(r)
|
|
|
|
for s in obsolete.allsuccessors(repo.obsstore, [node]):
|
|
|
|
try:
|
|
|
|
allsuccessors[cl.rev(s)] = cl.rev(node)
|
|
|
|
except LookupError:
|
|
|
|
pass
|
2015-09-15 03:31:48 +03:00
|
|
|
|
|
|
|
if allsuccessors:
|
|
|
|
# Look for successors of obsolete nodes to be rebased among
|
|
|
|
# the ancestors of dest
|
2015-10-15 01:42:15 +03:00
|
|
|
ancs = cl.ancestors([repo[dest].rev()],
|
|
|
|
stoprev=min(allsuccessors),
|
|
|
|
inclusive=True)
|
2015-09-15 03:31:48 +03:00
|
|
|
for s in allsuccessors:
|
|
|
|
if s in ancs:
|
|
|
|
obsoletenotrebased[allsuccessors[s]] = s
|
2015-11-19 00:44:29 +03:00
|
|
|
elif (s == allsuccessors[s] and
|
|
|
|
allsuccessors.values().count(s) == 1):
|
|
|
|
# plain prune
|
|
|
|
obsoletenotrebased[s] = None
|
|
|
|
|
2015-09-15 03:31:48 +03:00
|
|
|
return obsoletenotrebased
|
|
|
|
|
2013-05-14 22:23:17 +04:00
|
|
|
def summaryhook(ui, repo):
|
2017-01-06 11:58:41 +03:00
|
|
|
if not repo.vfs.exists('rebasestate'):
|
2013-05-14 22:23:17 +04:00
|
|
|
return
|
2013-09-30 19:35:07 +04:00
|
|
|
try:
|
2016-06-21 16:29:23 +03:00
|
|
|
rbsrt = rebaseruntime(repo, ui, {})
|
|
|
|
rbsrt.restorestatus()
|
|
|
|
state = rbsrt.state
|
2013-09-30 19:35:07 +04:00
|
|
|
except error.RepoLookupError:
|
|
|
|
# i18n: column positioning for "hg summary"
|
|
|
|
msg = _('rebase: (use "hg rebase --abort" to clear broken state)\n')
|
|
|
|
ui.write(msg)
|
|
|
|
return
|
2014-12-04 18:03:02 +03:00
|
|
|
numrebased = len([i for i in state.itervalues() if i >= 0])
|
2013-05-14 22:23:17 +04:00
|
|
|
# i18n: column positioning for "hg summary"
|
|
|
|
ui.write(_('rebase: %s, %s (rebase --continue)\n') %
|
|
|
|
(ui.label(_('%d rebased'), 'rebase.rebased') % numrebased,
|
|
|
|
ui.label(_('%d remaining'), 'rebase.remaining') %
|
|
|
|
(len(state) - numrebased)))
|
|
|
|
|
2008-08-18 23:16:31 +04:00
|
|
|
def uisetup(ui):
|
2015-01-27 15:33:56 +03:00
|
|
|
#Replace pull with a decorator to provide --rebase option
|
2008-10-23 02:34:52 +04:00
|
|
|
entry = extensions.wrapcommand(commands.table, 'pull', pullrebase)
|
|
|
|
entry[1].append(('', 'rebase', None,
|
2011-05-27 12:03:29 +04:00
|
|
|
_("rebase working directory to branch head")))
|
|
|
|
entry[1].append(('t', 'tool', '',
|
|
|
|
_("specify merge tool for rebase")))
|
2013-05-14 22:23:17 +04:00
|
|
|
cmdutil.summaryhooks.add('rebase', summaryhook)
|
2013-07-25 08:51:44 +04:00
|
|
|
cmdutil.unfinishedstates.append(
|
2013-07-25 11:17:52 +04:00
|
|
|
['rebasestate', False, False, _('rebase in progress'),
|
2013-07-25 08:51:44 +04:00
|
|
|
_("use 'hg rebase --continue' or 'hg rebase --abort'")])
|
2015-12-24 23:41:40 +03:00
|
|
|
cmdutil.afterresolvedstates.append(
|
|
|
|
['rebasestate', _('hg rebase --continue')])
|
2015-01-27 15:33:56 +03:00
|
|
|
# ensure rebased rev are not hidden
|
2017-05-28 07:08:51 +03:00
|
|
|
extensions.wrapfunction(repoview, 'pinnedrevs', _rebasedvisible)
|