2014-06-02 23:54:54 +04:00
|
|
|
# fbamend.py - improved amend functionality
|
|
|
|
#
|
|
|
|
# Copyright 2013 Facebook, Inc.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
|
|
|
|
"""extends the existing commit amend functionality
|
|
|
|
|
2016-09-21 17:45:25 +03:00
|
|
|
Adds an hg amend command that amends the current parent changeset with the
|
2018-02-14 00:36:51 +03:00
|
|
|
changes in the working copy. Similar to the existing hg commit --amend
|
2014-06-02 23:54:54 +04:00
|
|
|
except it doesn't prompt for the commit message unless --edit is provided.
|
|
|
|
|
2016-09-21 17:45:25 +03:00
|
|
|
Allows amending changesets that have children and can automatically rebase
|
|
|
|
the children onto the new version of the changeset.
|
2014-06-02 23:54:54 +04:00
|
|
|
|
2014-06-12 09:34:21 +04:00
|
|
|
This extension is incompatible with changeset evolution. The command will
|
|
|
|
automatically disable itself if changeset evolution is enabled.
|
2016-10-25 21:10:47 +03:00
|
|
|
|
|
|
|
To disable the creation of preamend bookmarks and use obsolescence
|
2016-11-16 05:46:56 +03:00
|
|
|
markers instead to fix up amends, enable the userestack option::
|
2016-10-25 21:10:47 +03:00
|
|
|
|
|
|
|
[fbamend]
|
2016-11-16 05:46:56 +03:00
|
|
|
userestack = true
|
|
|
|
|
|
|
|
To make `hg previous` and `hg next` always pick the newest commit at
|
|
|
|
each step of walking up or down the stack instead of aborting when
|
2017-01-20 11:24:45 +03:00
|
|
|
encountering non-linearity (equivalent to the --newest flag), enable
|
2016-11-16 05:46:56 +03:00
|
|
|
the following config option::
|
|
|
|
|
|
|
|
[fbamend]
|
|
|
|
alwaysnewest = true
|
2016-10-25 21:10:47 +03:00
|
|
|
|
2017-06-19 19:50:32 +03:00
|
|
|
To automatically update the commit date, enable the following config option::
|
|
|
|
|
|
|
|
[fbamend]
|
|
|
|
date = implicitupdate
|
|
|
|
|
2018-02-14 00:36:51 +03:00
|
|
|
To stop fbamend from automatically rebasing stacked changes::
|
|
|
|
|
|
|
|
[commands]
|
|
|
|
amend.autorebase = false
|
|
|
|
|
2017-06-19 19:50:32 +03:00
|
|
|
Note that if --date is specified on the command line, it takes precedence.
|
|
|
|
|
2014-06-02 23:54:54 +04:00
|
|
|
"""
|
|
|
|
|
2017-06-14 03:08:50 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2018-02-20 23:27:34 +03:00
|
|
|
import tempfile
|
|
|
|
|
|
|
|
from mercurial.node import hex
|
|
|
|
from mercurial.i18n import _
|
|
|
|
|
Make hg next --rebase intelligently obsolete/inhibit changesets
Summary:
This change updates the behavior hg next --rebase. Specifically:
- Only one changeset can be rebased at a time. If there are multiple candidate changesets, the command aborts.
- Each time a changeset is rebased, its precursor is marked as obsolete, inhibition markers are stripped from it and its ancestors, and its preamend bookmark is deleted, if one exists.
- The result of this is that if no non-obsolete changesets depend on the existence of the pre-rebased changeset, that changeset and its ancestors will be stripped, resulting in a cleaner user experience.
- This change also adds back the --evolve flag, but makes it show in error instead of working. It turns out that removing the flag outright breaks the evolve extension.
Test Plan:
See updated unit tests for the exact commands to run to test this, as well as an overview of all of the new situations where behavior was changed.
A basic test plan would be:
1. Initialize a new repository, and create a stack of 4 commits.
2. Amend the second commit in the stack.
3. Do `hg next --rebase`. It should work as before.
4. Do `hg next --rebase` again. This time, the entire old stack should "disappear" from hg sl.
Additionally, attempting to run `hg next --rebase` when there are multiple possible child changesets should fail.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3941922
Tasks: 13570554
Signature: t1:3941922:1475205056:58a8d1726cfcccbf14a38727be0220a09532ec97
2016-09-30 20:40:58 +03:00
|
|
|
from mercurial import (
|
|
|
|
bookmarks,
|
|
|
|
cmdutil,
|
|
|
|
commands,
|
2016-10-04 20:29:55 +03:00
|
|
|
error,
|
|
|
|
extensions,
|
2018-02-20 23:27:34 +03:00
|
|
|
lock as lockmod,
|
Make hg next --rebase intelligently obsolete/inhibit changesets
Summary:
This change updates the behavior hg next --rebase. Specifically:
- Only one changeset can be rebased at a time. If there are multiple candidate changesets, the command aborts.
- Each time a changeset is rebased, its precursor is marked as obsolete, inhibition markers are stripped from it and its ancestors, and its preamend bookmark is deleted, if one exists.
- The result of this is that if no non-obsolete changesets depend on the existence of the pre-rebased changeset, that changeset and its ancestors will be stripped, resulting in a cleaner user experience.
- This change also adds back the --evolve flag, but makes it show in error instead of working. It turns out that removing the flag outright breaks the evolve extension.
Test Plan:
See updated unit tests for the exact commands to run to test this, as well as an overview of all of the new situations where behavior was changed.
A basic test plan would be:
1. Initialize a new repository, and create a stack of 4 commits.
2. Amend the second commit in the stack.
3. Do `hg next --rebase`. It should work as before.
4. Do `hg next --rebase` again. This time, the entire old stack should "disappear" from hg sl.
Additionally, attempting to run `hg next --rebase` when there are multiple possible child changesets should fail.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3941922
Tasks: 13570554
Signature: t1:3941922:1475205056:58a8d1726cfcccbf14a38727be0220a09532ec97
2016-09-30 20:40:58 +03:00
|
|
|
phases,
|
2017-05-22 23:38:37 +03:00
|
|
|
registrar,
|
2017-11-25 20:19:09 +03:00
|
|
|
scmutil,
|
Make hg next --rebase intelligently obsolete/inhibit changesets
Summary:
This change updates the behavior hg next --rebase. Specifically:
- Only one changeset can be rebased at a time. If there are multiple candidate changesets, the command aborts.
- Each time a changeset is rebased, its precursor is marked as obsolete, inhibition markers are stripped from it and its ancestors, and its preamend bookmark is deleted, if one exists.
- The result of this is that if no non-obsolete changesets depend on the existence of the pre-rebased changeset, that changeset and its ancestors will be stripped, resulting in a cleaner user experience.
- This change also adds back the --evolve flag, but makes it show in error instead of working. It turns out that removing the flag outright breaks the evolve extension.
Test Plan:
See updated unit tests for the exact commands to run to test this, as well as an overview of all of the new situations where behavior was changed.
A basic test plan would be:
1. Initialize a new repository, and create a stack of 4 commits.
2. Amend the second commit in the stack.
3. Do `hg next --rebase`. It should work as before.
4. Do `hg next --rebase` again. This time, the entire old stack should "disappear" from hg sl.
Additionally, attempting to run `hg next --rebase` when there are multiple possible child changesets should fail.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3941922
Tasks: 13570554
Signature: t1:3941922:1475205056:58a8d1726cfcccbf14a38727be0220a09532ec97
2016-09-30 20:40:58 +03:00
|
|
|
)
|
2014-06-02 23:54:54 +04:00
|
|
|
|
2018-02-20 23:27:34 +03:00
|
|
|
from .. import (
|
2017-07-14 22:06:22 +03:00
|
|
|
histedit,
|
|
|
|
rebase as rebasemod,
|
|
|
|
)
|
2017-06-17 01:50:01 +03:00
|
|
|
|
2017-06-14 03:08:50 +03:00
|
|
|
from . import (
|
2017-06-14 03:09:16 +03:00
|
|
|
common,
|
2017-06-17 00:06:24 +03:00
|
|
|
fold,
|
2017-07-13 21:04:56 +03:00
|
|
|
hiddenoverride,
|
2017-07-27 13:39:01 +03:00
|
|
|
hide,
|
2017-06-17 00:11:43 +03:00
|
|
|
metaedit,
|
2017-06-14 03:09:16 +03:00
|
|
|
movement,
|
2017-06-17 00:39:04 +03:00
|
|
|
prune,
|
2017-06-14 03:09:34 +03:00
|
|
|
restack,
|
2017-06-16 23:48:14 +03:00
|
|
|
revsets,
|
2017-06-16 23:59:12 +03:00
|
|
|
split,
|
2017-06-14 03:08:50 +03:00
|
|
|
unamend,
|
|
|
|
)
|
|
|
|
|
2017-06-16 23:48:14 +03:00
|
|
|
revsetpredicate = revsets.revsetpredicate
|
|
|
|
|
2014-06-02 23:54:54 +04:00
|
|
|
cmdtable = {}
|
2017-05-22 23:38:37 +03:00
|
|
|
command = registrar.command(cmdtable)
|
2017-06-14 03:08:50 +03:00
|
|
|
|
2017-06-17 00:06:24 +03:00
|
|
|
cmdtable.update(fold.cmdtable)
|
2017-07-27 13:39:01 +03:00
|
|
|
cmdtable.update(hide.cmdtable)
|
2017-06-17 00:11:43 +03:00
|
|
|
cmdtable.update(metaedit.cmdtable)
|
2017-06-14 03:09:16 +03:00
|
|
|
cmdtable.update(movement.cmdtable)
|
2017-06-17 00:39:04 +03:00
|
|
|
cmdtable.update(prune.cmdtable)
|
2017-06-16 23:59:12 +03:00
|
|
|
cmdtable.update(split.cmdtable)
|
|
|
|
cmdtable.update(unamend.cmdtable)
|
2017-06-14 03:08:50 +03:00
|
|
|
|
2017-10-24 06:02:57 +03:00
|
|
|
configtable = {}
|
|
|
|
configitem = registrar.configitem(configtable)
|
|
|
|
|
|
|
|
configitem('fbamend', 'alwaysnewest', default=False)
|
|
|
|
configitem('fbamend', 'date', default=None)
|
|
|
|
configitem('fbamend', 'education', default=None)
|
|
|
|
configitem('fbamend', 'safestrip', default=True)
|
2018-02-14 00:36:51 +03:00
|
|
|
configitem('commands', 'amend.autorebase', default=True)
|
2017-10-24 06:02:57 +03:00
|
|
|
|
2016-11-29 16:24:07 +03:00
|
|
|
testedwith = 'ships-with-fb-hgext'
|
2014-06-02 23:54:54 +04:00
|
|
|
|
2015-02-12 22:02:34 +03:00
|
|
|
amendopts = [
|
2016-09-21 17:45:25 +03:00
|
|
|
('', 'rebase', None, _('rebases children after the amend')),
|
|
|
|
('', 'fixup', None, _('rebase children from a previous amend')),
|
2017-11-25 20:19:09 +03:00
|
|
|
('', 'to', '', _('amend to a specific commit in the current stack')),
|
2014-06-02 23:54:54 +04:00
|
|
|
]
|
|
|
|
|
|
|
|
def uisetup(ui):
|
2017-07-13 21:04:56 +03:00
|
|
|
hiddenoverride.uisetup(ui)
|
2017-06-17 00:39:04 +03:00
|
|
|
prune.uisetup(ui)
|
2014-06-02 23:54:54 +04:00
|
|
|
entry = extensions.wrapcommand(commands.table, 'commit', commit)
|
|
|
|
for opt in amendopts:
|
|
|
|
opt = (opt[0], opt[1], opt[2], "(with --amend) " + opt[3])
|
|
|
|
entry[1].append(opt)
|
2016-09-23 20:39:36 +03:00
|
|
|
|
2014-06-12 09:34:21 +04:00
|
|
|
# manual call of the decorator
|
|
|
|
command('^amend', [
|
2015-04-15 19:29:09 +03:00
|
|
|
('A', 'addremove', None,
|
|
|
|
_('mark new/missing files as added/removed before committing')),
|
2014-06-12 09:34:21 +04:00
|
|
|
('e', 'edit', None, _('prompt to edit the commit message')),
|
2015-10-24 03:00:56 +03:00
|
|
|
('i', 'interactive', None, _('use interactive mode')),
|
2017-06-19 23:24:41 +03:00
|
|
|
] + amendopts + commands.walkopts + commands.commitopts
|
|
|
|
+ commands.commitopts2,
|
2014-06-12 09:34:21 +04:00
|
|
|
_('hg amend [OPTION]...'))(amend)
|
|
|
|
|
2016-02-04 14:03:31 +03:00
|
|
|
def has_automv(loaded):
|
|
|
|
if not loaded:
|
|
|
|
return
|
|
|
|
automv = extensions.find('automv')
|
|
|
|
entry = extensions.wrapcommand(cmdtable, 'amend', automv.mvcheck)
|
|
|
|
entry[1].append(
|
|
|
|
('', 'no-move-detection', None,
|
|
|
|
_('disable automatic file move detection')))
|
|
|
|
extensions.afterloaded('automv', has_automv)
|
|
|
|
|
2016-11-03 21:11:39 +03:00
|
|
|
def evolveloaded(loaded):
|
2016-09-23 20:39:36 +03:00
|
|
|
if not loaded:
|
|
|
|
return
|
Make hg next --rebase intelligently obsolete/inhibit changesets
Summary:
This change updates the behavior hg next --rebase. Specifically:
- Only one changeset can be rebased at a time. If there are multiple candidate changesets, the command aborts.
- Each time a changeset is rebased, its precursor is marked as obsolete, inhibition markers are stripped from it and its ancestors, and its preamend bookmark is deleted, if one exists.
- The result of this is that if no non-obsolete changesets depend on the existence of the pre-rebased changeset, that changeset and its ancestors will be stripped, resulting in a cleaner user experience.
- This change also adds back the --evolve flag, but makes it show in error instead of working. It turns out that removing the flag outright breaks the evolve extension.
Test Plan:
See updated unit tests for the exact commands to run to test this, as well as an overview of all of the new situations where behavior was changed.
A basic test plan would be:
1. Initialize a new repository, and create a stack of 4 commits.
2. Amend the second commit in the stack.
3. Do `hg next --rebase`. It should work as before.
4. Do `hg next --rebase` again. This time, the entire old stack should "disappear" from hg sl.
Additionally, attempting to run `hg next --rebase` when there are multiple possible child changesets should fail.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3941922
Tasks: 13570554
Signature: t1:3941922:1475205056:58a8d1726cfcccbf14a38727be0220a09532ec97
2016-09-30 20:40:58 +03:00
|
|
|
|
2016-09-23 20:39:36 +03:00
|
|
|
evolvemod = extensions.find('evolve')
|
2016-11-16 05:46:56 +03:00
|
|
|
|
2017-06-16 23:59:12 +03:00
|
|
|
# Remove conflicted commands from evolve.
|
2017-06-14 03:09:16 +03:00
|
|
|
table = evolvemod.cmdtable
|
2017-06-17 00:39:04 +03:00
|
|
|
for name in ['prev', 'next', 'split', 'fold', 'metaedit', 'prune']:
|
2017-06-15 20:35:28 +03:00
|
|
|
todelete = [k for k in table if name in k]
|
|
|
|
for k in todelete:
|
|
|
|
oldentry = table[k]
|
|
|
|
table['debugevolve%s' % name] = oldentry
|
|
|
|
del table[k]
|
2017-01-20 11:24:45 +03:00
|
|
|
|
2016-11-03 21:11:39 +03:00
|
|
|
extensions.afterloaded('evolve', evolveloaded)
|
2016-02-04 14:03:31 +03:00
|
|
|
|
2016-11-03 21:11:39 +03:00
|
|
|
def rebaseloaded(loaded):
|
Add hg rebase --restack
Summary:
This change adds a `--restack` option to `hg rebase`. When invoked, the command will rebase all descendants of precursors of the current changeset onto the current changeset. This is similar to the behavior of `hg evolve --all`, except it only handles unstable changesets, and not other issues that can arise from shared mutable history such as divergence or bumping.
I've been playing around with some of the more advanced features (such as allowing the command to be run from anywhere in the old stack or new stack, as well as allowing the user to specify the number of changesets to rebase), but I wanted to upload the most simple iteration of this command for feedback.
Test Plan:
See unit tests for complete commands.
1. Create a stack of commits.
2. Somewhere in the middle of the stack, amend a commit, potentially several times.
3. Run `hg rebase --restack`.
4. The top half of the stack should be rebased onto the amended commit, and the preamend bookmark should be gone.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: rmcelroy, quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3972103
Tasks: 13651947
Signature: t1:3972103:1476230834:8f77eac4e8d8681dd9f8125747c1ff75c8da1ad8
2016-10-12 03:41:07 +03:00
|
|
|
if not loaded:
|
|
|
|
return
|
|
|
|
entry = extensions.wrapcommand(rebasemod.cmdtable, 'rebase',
|
2016-11-03 21:11:39 +03:00
|
|
|
wraprebase)
|
Add hg rebase --restack
Summary:
This change adds a `--restack` option to `hg rebase`. When invoked, the command will rebase all descendants of precursors of the current changeset onto the current changeset. This is similar to the behavior of `hg evolve --all`, except it only handles unstable changesets, and not other issues that can arise from shared mutable history such as divergence or bumping.
I've been playing around with some of the more advanced features (such as allowing the command to be run from anywhere in the old stack or new stack, as well as allowing the user to specify the number of changesets to rebase), but I wanted to upload the most simple iteration of this command for feedback.
Test Plan:
See unit tests for complete commands.
1. Create a stack of commits.
2. Somewhere in the middle of the stack, amend a commit, potentially several times.
3. Run `hg rebase --restack`.
4. The top half of the stack should be rebased onto the amended commit, and the preamend bookmark should be gone.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: rmcelroy, quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3972103
Tasks: 13651947
Signature: t1:3972103:1476230834:8f77eac4e8d8681dd9f8125747c1ff75c8da1ad8
2016-10-12 03:41:07 +03:00
|
|
|
entry[1].append((
|
|
|
|
'', 'restack', False, _('rebase all changesets in the current '
|
|
|
|
'stack onto the latest version of their '
|
|
|
|
'respective parents')
|
|
|
|
))
|
2016-11-03 21:11:39 +03:00
|
|
|
extensions.afterloaded('rebase', rebaseloaded)
|
Add hg rebase --restack
Summary:
This change adds a `--restack` option to `hg rebase`. When invoked, the command will rebase all descendants of precursors of the current changeset onto the current changeset. This is similar to the behavior of `hg evolve --all`, except it only handles unstable changesets, and not other issues that can arise from shared mutable history such as divergence or bumping.
I've been playing around with some of the more advanced features (such as allowing the command to be run from anywhere in the old stack or new stack, as well as allowing the user to specify the number of changesets to rebase), but I wanted to upload the most simple iteration of this command for feedback.
Test Plan:
See unit tests for complete commands.
1. Create a stack of commits.
2. Somewhere in the middle of the stack, amend a commit, potentially several times.
3. Run `hg rebase --restack`.
4. The top half of the stack should be rebased onto the amended commit, and the preamend bookmark should be gone.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: rmcelroy, quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3972103
Tasks: 13651947
Signature: t1:3972103:1476230834:8f77eac4e8d8681dd9f8125747c1ff75c8da1ad8
2016-10-12 03:41:07 +03:00
|
|
|
|
2014-06-02 23:54:54 +04:00
|
|
|
def commit(orig, ui, repo, *pats, **opts):
|
|
|
|
if opts.get("amend"):
|
|
|
|
# commit --amend default behavior is to prompt for edit
|
2015-04-07 23:31:44 +03:00
|
|
|
opts['noeditmessage'] = True
|
2014-06-02 23:54:54 +04:00
|
|
|
return amend(ui, repo, *pats, **opts)
|
|
|
|
else:
|
2015-10-27 02:19:40 +03:00
|
|
|
badflags = [flag for flag in
|
|
|
|
['rebase', 'fixup'] if opts.get(flag, None)]
|
|
|
|
if badflags:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort(_('--%s must be called with --amend') %
|
2015-10-27 02:19:40 +03:00
|
|
|
badflags[0])
|
|
|
|
|
2014-06-02 23:54:54 +04:00
|
|
|
return orig(ui, repo, *pats, **opts)
|
|
|
|
|
|
|
|
def amend(ui, repo, *pats, **opts):
|
2016-09-21 17:45:25 +03:00
|
|
|
'''amend the current changeset with more changes
|
2014-06-02 23:54:54 +04:00
|
|
|
'''
|
2017-12-28 09:54:03 +03:00
|
|
|
# 'rebase' is a tristate option: None=auto, True=force, False=disable
|
2014-06-02 23:54:54 +04:00
|
|
|
rebase = opts.get('rebase')
|
2017-11-25 20:19:09 +03:00
|
|
|
to = opts.get('to')
|
2014-06-02 23:54:54 +04:00
|
|
|
|
2015-02-12 22:02:34 +03:00
|
|
|
if rebase and _histediting(repo):
|
|
|
|
# if a histedit is in flight, it's dangerous to remove old commits
|
|
|
|
hint = _('during histedit, use amend without --rebase')
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort('histedit in progress', hint=hint)
|
2015-02-12 22:02:34 +03:00
|
|
|
|
2015-10-24 03:00:56 +03:00
|
|
|
badflags = [flag for flag in
|
|
|
|
['rebase', 'fixup'] if opts.get(flag, None)]
|
|
|
|
if opts.get('interactive') and badflags:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort(_('--interactive and --%s are mutually exclusive') %
|
2015-10-24 03:00:56 +03:00
|
|
|
badflags[0])
|
|
|
|
|
2015-02-12 22:02:34 +03:00
|
|
|
fixup = opts.get('fixup')
|
2017-07-14 22:06:22 +03:00
|
|
|
|
|
|
|
badtoflags = [
|
|
|
|
'rebase', 'fixup', 'addremove', 'edit', 'interactive', 'include',
|
|
|
|
'exclude', 'message', 'logfile', 'date', 'user',
|
|
|
|
'no-move-detection', 'stack'
|
|
|
|
]
|
|
|
|
|
|
|
|
if to and any(opts.get(flag, None) for flag in badtoflags):
|
|
|
|
raise error.Abort(_('--to cannot be used with any other options'))
|
|
|
|
|
2014-06-02 23:54:54 +04:00
|
|
|
if fixup:
|
|
|
|
fixupamend(ui, repo)
|
|
|
|
return
|
|
|
|
|
2017-07-14 22:06:22 +03:00
|
|
|
if to:
|
|
|
|
amendtocommit(ui, repo, to)
|
|
|
|
return
|
|
|
|
|
2014-06-02 23:54:54 +04:00
|
|
|
old = repo['.']
|
|
|
|
if old.phase() == phases.public:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort(_('cannot amend public changesets'))
|
2014-06-02 23:54:54 +04:00
|
|
|
if len(repo[None].parents()) > 1:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort(_('cannot amend while merging'))
|
2014-06-02 23:54:54 +04:00
|
|
|
|
|
|
|
haschildren = len(old.children()) > 0
|
|
|
|
|
2015-10-28 00:37:20 +03:00
|
|
|
opts['message'] = cmdutil.logmessage(ui, opts)
|
|
|
|
# Avoid further processing of any logfile. If such a file existed, its
|
|
|
|
# contents have been copied into opts['message'] by logmessage
|
|
|
|
opts['logfile'] = ''
|
|
|
|
|
2015-04-07 23:31:44 +03:00
|
|
|
if not opts.get('noeditmessage') and not opts.get('message'):
|
2014-06-02 23:54:54 +04:00
|
|
|
opts['message'] = old.description()
|
|
|
|
|
2017-06-19 19:50:32 +03:00
|
|
|
commitdate = opts.get('date')
|
|
|
|
if not commitdate:
|
|
|
|
if ui.config('fbamend', 'date') == 'implicitupdate':
|
|
|
|
commitdate = 'now'
|
|
|
|
else:
|
|
|
|
commitdate = old.date()
|
2014-06-02 23:54:54 +04:00
|
|
|
|
|
|
|
oldbookmarks = old.bookmarks()
|
2015-12-14 22:30:33 +03:00
|
|
|
tr = None
|
2015-08-04 19:10:50 +03:00
|
|
|
wlock = None
|
|
|
|
lock = None
|
|
|
|
try:
|
|
|
|
wlock = repo.wlock()
|
|
|
|
lock = repo.lock()
|
2015-10-24 03:00:56 +03:00
|
|
|
|
|
|
|
if opts.get('interactive'):
|
|
|
|
# Strip the interactive flag to avoid infinite recursive loop
|
|
|
|
opts.pop('interactive')
|
|
|
|
cmdutil.dorecord(ui, repo, amend, None, False,
|
|
|
|
cmdutil.recordfilter, *pats, **opts)
|
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
2017-09-08 20:07:41 +03:00
|
|
|
node = cmdutil.amend(ui, repo, old, {}, pats, opts)
|
2015-08-04 19:10:50 +03:00
|
|
|
|
|
|
|
if node == old.node():
|
|
|
|
ui.status(_("nothing changed\n"))
|
2017-06-17 01:50:01 +03:00
|
|
|
return 1
|
2015-08-04 19:10:50 +03:00
|
|
|
|
2017-12-28 09:54:03 +03:00
|
|
|
if haschildren and rebase is None and not _histediting(repo):
|
|
|
|
# If the user has chosen the default behaviour for the
|
|
|
|
# rebase, then see if we can apply any heuristics. This
|
|
|
|
# will not performed if a histedit is in flight.
|
|
|
|
|
|
|
|
newcommit = repo[node]
|
|
|
|
# If the rebase did not change the manifest and the
|
|
|
|
# working copy is clean, force the children to be
|
|
|
|
# restacked.
|
|
|
|
if (old.manifestnode() == newcommit.manifestnode() and
|
|
|
|
not repo[None].dirty()):
|
2018-02-14 00:36:51 +03:00
|
|
|
if ui.configbool('commands', 'amend.autorebase'):
|
|
|
|
ui.status(_('(auto-rebasing descendants, use --no-rebase'
|
|
|
|
' or set [commands] amend.autorebase=False in hgrc'
|
|
|
|
' to disable this)\n'))
|
|
|
|
|
|
|
|
rebase = True
|
|
|
|
else :
|
|
|
|
rebase = False
|
2017-12-28 09:54:03 +03:00
|
|
|
|
2015-08-04 19:10:50 +03:00
|
|
|
if haschildren and not rebase:
|
2016-09-21 17:45:25 +03:00
|
|
|
msg = _("warning: the changeset's children were left behind\n")
|
2015-08-04 19:10:50 +03:00
|
|
|
if _histediting(repo):
|
|
|
|
ui.warn(msg)
|
|
|
|
ui.status(_('(this is okay since a histedit is in progress)\n'))
|
|
|
|
else:
|
|
|
|
_usereducation(ui)
|
|
|
|
ui.warn(msg)
|
2017-06-26 17:31:28 +03:00
|
|
|
ui.status(_("(use 'hg restack' to rebase them)\n"))
|
2015-08-04 19:10:50 +03:00
|
|
|
|
2017-07-18 20:09:28 +03:00
|
|
|
changes = []
|
2015-08-04 19:10:50 +03:00
|
|
|
# move old bookmarks to new node
|
|
|
|
for bm in oldbookmarks:
|
2017-07-18 20:09:28 +03:00
|
|
|
changes.append((bm, node))
|
2015-08-04 19:10:50 +03:00
|
|
|
|
2015-12-14 22:30:33 +03:00
|
|
|
tr = repo.transaction('fixupamend')
|
2017-07-18 20:09:28 +03:00
|
|
|
repo._bookmarks.applychanges(repo, tr, changes)
|
2015-12-14 22:30:33 +03:00
|
|
|
tr.close()
|
2015-08-04 19:10:50 +03:00
|
|
|
|
|
|
|
if rebase and haschildren:
|
|
|
|
fixupamend(ui, repo)
|
|
|
|
finally:
|
2015-12-14 22:30:33 +03:00
|
|
|
lockmod.release(wlock, lock, tr)
|
2014-06-02 23:54:54 +04:00
|
|
|
|
|
|
|
def fixupamend(ui, repo):
|
2016-09-21 17:45:25 +03:00
|
|
|
"""rebases any children found on the preamend changset and strips the
|
|
|
|
preamend changset
|
2014-06-02 23:54:54 +04:00
|
|
|
"""
|
2015-08-04 19:10:50 +03:00
|
|
|
wlock = None
|
|
|
|
lock = None
|
2015-12-14 22:30:33 +03:00
|
|
|
tr = None
|
2015-08-04 19:10:50 +03:00
|
|
|
try:
|
|
|
|
wlock = repo.wlock()
|
|
|
|
lock = repo.lock()
|
|
|
|
current = repo['.']
|
2014-06-02 23:54:54 +04:00
|
|
|
|
2018-02-20 23:27:34 +03:00
|
|
|
# Use obsolescence information to fix up the amend.
|
|
|
|
common.restackonce(ui, repo, current.rev())
|
2015-08-04 19:10:50 +03:00
|
|
|
finally:
|
2015-12-14 22:30:33 +03:00
|
|
|
lockmod.release(wlock, lock, tr)
|
2015-02-12 12:26:20 +03:00
|
|
|
|
2017-11-25 20:19:09 +03:00
|
|
|
def amendtocommit(ui, repo, commitspec):
|
2017-07-14 22:06:22 +03:00
|
|
|
"""amend to a specific commit
|
|
|
|
"""
|
|
|
|
with repo.wlock(), repo.lock():
|
|
|
|
originalcommits = list(repo.set("::. - public()"))
|
2017-11-25 20:19:09 +03:00
|
|
|
try:
|
|
|
|
revs = scmutil.revrange(repo, [commitspec])
|
|
|
|
except error.RepoLookupError:
|
|
|
|
raise error.Abort(_("revision '%s' cannot be found")
|
|
|
|
% commitspec)
|
|
|
|
if len(revs) > 1:
|
|
|
|
raise error.Abort(_("'%s' refers to multiple changesets")
|
|
|
|
% commitspec)
|
|
|
|
targetcommit = repo[revs.first()]
|
|
|
|
if targetcommit not in originalcommits:
|
|
|
|
raise error.Abort(_("revision '%s' is not a parent of "
|
|
|
|
'the working copy' % commitspec))
|
|
|
|
|
2017-07-14 22:06:22 +03:00
|
|
|
tempcommit = repo.commit(text="tempCommit")
|
|
|
|
|
|
|
|
if not tempcommit:
|
2017-11-25 20:19:09 +03:00
|
|
|
raise error.Abort(_('no pending changes to amend'))
|
2017-07-14 22:06:22 +03:00
|
|
|
|
|
|
|
tempcommithex = hex(tempcommit)
|
|
|
|
|
|
|
|
fp = tempfile.NamedTemporaryFile()
|
|
|
|
try:
|
|
|
|
found = False
|
2017-11-25 20:19:09 +03:00
|
|
|
for curcommit in originalcommits:
|
|
|
|
fp.write("pick " + str(curcommit) + "\n")
|
|
|
|
if curcommit == targetcommit:
|
2017-07-14 22:06:22 +03:00
|
|
|
fp.write("roll " + tempcommithex[:12] + "\n")
|
|
|
|
found = True
|
|
|
|
if not found:
|
2017-11-25 20:19:09 +03:00
|
|
|
raise error.Abort(_("revision '%s' cannot be found")
|
|
|
|
% commitspec)
|
2017-07-14 22:06:22 +03:00
|
|
|
fp.flush()
|
|
|
|
try:
|
|
|
|
histedit.histedit(ui, repo, commands=fp.name)
|
|
|
|
except error.InterventionRequired:
|
|
|
|
ui.warn(_('amend --to encountered an issue - '
|
|
|
|
'use hg histedit to continue or abort'))
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
fp.close()
|
|
|
|
|
2016-11-03 21:11:39 +03:00
|
|
|
def wraprebase(orig, ui, repo, **opts):
|
Add hg rebase --restack
Summary:
This change adds a `--restack` option to `hg rebase`. When invoked, the command will rebase all descendants of precursors of the current changeset onto the current changeset. This is similar to the behavior of `hg evolve --all`, except it only handles unstable changesets, and not other issues that can arise from shared mutable history such as divergence or bumping.
I've been playing around with some of the more advanced features (such as allowing the command to be run from anywhere in the old stack or new stack, as well as allowing the user to specify the number of changesets to rebase), but I wanted to upload the most simple iteration of this command for feedback.
Test Plan:
See unit tests for complete commands.
1. Create a stack of commits.
2. Somewhere in the middle of the stack, amend a commit, potentially several times.
3. Run `hg rebase --restack`.
4. The top half of the stack should be rebased onto the amended commit, and the preamend bookmark should be gone.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: rmcelroy, quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3972103
Tasks: 13651947
Signature: t1:3972103:1476230834:8f77eac4e8d8681dd9f8125747c1ff75c8da1ad8
2016-10-12 03:41:07 +03:00
|
|
|
"""Wrapper around `hg rebase` adding the `--restack` option, which rebases
|
2016-10-14 21:05:53 +03:00
|
|
|
all "unstable" descendants of an obsolete changeset onto the latest
|
|
|
|
version of that changeset. This is similar to (and intended as a
|
|
|
|
replacement for) the `hg evolve --all` command.
|
Add hg rebase --restack
Summary:
This change adds a `--restack` option to `hg rebase`. When invoked, the command will rebase all descendants of precursors of the current changeset onto the current changeset. This is similar to the behavior of `hg evolve --all`, except it only handles unstable changesets, and not other issues that can arise from shared mutable history such as divergence or bumping.
I've been playing around with some of the more advanced features (such as allowing the command to be run from anywhere in the old stack or new stack, as well as allowing the user to specify the number of changesets to rebase), but I wanted to upload the most simple iteration of this command for feedback.
Test Plan:
See unit tests for complete commands.
1. Create a stack of commits.
2. Somewhere in the middle of the stack, amend a commit, potentially several times.
3. Run `hg rebase --restack`.
4. The top half of the stack should be rebased onto the amended commit, and the preamend bookmark should be gone.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: rmcelroy, quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3972103
Tasks: 13651947
Signature: t1:3972103:1476230834:8f77eac4e8d8681dd9f8125747c1ff75c8da1ad8
2016-10-12 03:41:07 +03:00
|
|
|
"""
|
2016-11-03 21:11:39 +03:00
|
|
|
if opts['restack']:
|
2017-01-11 00:53:43 +03:00
|
|
|
# We can't abort if --dest is passed because some extensions
|
|
|
|
# (namely remotenames) will automatically add this flag.
|
|
|
|
# So just silently drop it instead.
|
|
|
|
opts.pop('dest', None)
|
|
|
|
|
2016-11-03 21:11:39 +03:00
|
|
|
if opts['rev']:
|
|
|
|
raise error.Abort(_("cannot use both --rev and --restack"))
|
|
|
|
if opts['source']:
|
|
|
|
raise error.Abort(_("cannot use both --source and --restack"))
|
|
|
|
if opts['base']:
|
|
|
|
raise error.Abort(_("cannot use both --base and --restack"))
|
|
|
|
if opts['abort']:
|
|
|
|
raise error.Abort(_("cannot use both --abort and --restack"))
|
|
|
|
if opts['continue']:
|
|
|
|
raise error.Abort(_("cannot use both --continue and --restack"))
|
2017-01-26 02:48:12 +03:00
|
|
|
|
|
|
|
# The --hidden option is handled at a higher level, so instead of
|
|
|
|
# checking for it directly we have to check whether the repo
|
|
|
|
# is unfiltered.
|
|
|
|
if repo == repo.unfiltered():
|
|
|
|
raise error.Abort(_("cannot use both --hidden and --restack"))
|
|
|
|
|
2017-06-14 03:09:34 +03:00
|
|
|
return restack.restack(ui, repo, opts)
|
Add hg rebase --restack
Summary:
This change adds a `--restack` option to `hg rebase`. When invoked, the command will rebase all descendants of precursors of the current changeset onto the current changeset. This is similar to the behavior of `hg evolve --all`, except it only handles unstable changesets, and not other issues that can arise from shared mutable history such as divergence or bumping.
I've been playing around with some of the more advanced features (such as allowing the command to be run from anywhere in the old stack or new stack, as well as allowing the user to specify the number of changesets to rebase), but I wanted to upload the most simple iteration of this command for feedback.
Test Plan:
See unit tests for complete commands.
1. Create a stack of commits.
2. Somewhere in the middle of the stack, amend a commit, potentially several times.
3. Run `hg rebase --restack`.
4. The top half of the stack should be rebased onto the amended commit, and the preamend bookmark should be gone.
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: rmcelroy, quark, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3972103
Tasks: 13651947
Signature: t1:3972103:1476230834:8f77eac4e8d8681dd9f8125747c1ff75c8da1ad8
2016-10-12 03:41:07 +03:00
|
|
|
|
2016-11-03 21:11:39 +03:00
|
|
|
return orig(ui, repo, **opts)
|
2016-10-25 21:10:47 +03:00
|
|
|
|
2015-02-12 13:16:28 +03:00
|
|
|
def _preamendname(repo, node):
|
|
|
|
suffix = '.preamend'
|
2015-05-10 06:22:31 +03:00
|
|
|
name = bmactive(repo)
|
2015-02-12 13:16:28 +03:00
|
|
|
if not name:
|
2015-02-13 07:43:29 +03:00
|
|
|
name = hex(node)[:12]
|
2015-02-12 13:16:28 +03:00
|
|
|
return name + suffix
|
|
|
|
|
2015-02-12 22:02:34 +03:00
|
|
|
def _histediting(repo):
|
|
|
|
return repo.vfs.exists('histedit-state')
|
|
|
|
|
2015-02-12 12:26:20 +03:00
|
|
|
def _usereducation(ui):
|
|
|
|
"""
|
|
|
|
You can print out a message to the user here
|
|
|
|
"""
|
2015-04-17 20:17:23 +03:00
|
|
|
education = ui.config('fbamend', 'education')
|
|
|
|
if education:
|
|
|
|
ui.warn(education + "\n")
|
2015-05-10 06:22:31 +03:00
|
|
|
|
2017-02-02 02:14:17 +03:00
|
|
|
def _fixbookmarks(repo, revs):
|
|
|
|
"""Make any bookmarks pointing to the given revisions point to the
|
|
|
|
latest version of each respective revision.
|
|
|
|
"""
|
|
|
|
repo = repo.unfiltered()
|
|
|
|
cl = repo.changelog
|
2017-07-17 22:02:08 +03:00
|
|
|
with repo.wlock(), repo.lock(), repo.transaction('movebookmarks') as tr:
|
2017-07-18 20:09:28 +03:00
|
|
|
changes = []
|
2017-07-17 22:02:08 +03:00
|
|
|
for rev in revs:
|
|
|
|
latest = cl.node(common.latest(repo, rev))
|
|
|
|
for bm in repo.nodebookmarks(cl.node(rev)):
|
2017-07-18 20:09:28 +03:00
|
|
|
changes.append((bm, latest))
|
|
|
|
repo._bookmarks.applychanges(repo, tr, changes)
|
2017-02-02 02:14:17 +03:00
|
|
|
|
2015-05-10 06:22:31 +03:00
|
|
|
### bookmarks api compatibility layer ###
|
|
|
|
def bmactivate(repo, mark):
|
|
|
|
try:
|
|
|
|
return bookmarks.activate(repo, mark)
|
|
|
|
except AttributeError:
|
|
|
|
return bookmarks.setcurrent(repo, mark)
|
|
|
|
|
|
|
|
def bmactive(repo):
|
|
|
|
try:
|
|
|
|
return repo._activebookmark
|
|
|
|
except AttributeError:
|
|
|
|
return repo._bookmarkcurrent
|