##// END OF EJS Templates
chgserver: add fastannotate config section to sensitive list...
chgserver: add fastannotate config section to sensitive list Depending on the config value of `fastannotate.modes`, the fastannotate extension can do different things in uisetup. Depending on value of `fastannotate.server`, it can register new wireprotocol capabilities. This fixes test-fastannotate-hg.t, test-fastannotate-protocol.t and test-fastannotate.t with chg.

File last commit:

r45092:d06e748c default
r45102:bc592059 default
Show More
histedit.py
2644 lines | 84.2 KiB | text/x-python | PythonLexer
Augie Fackler
histedit: new extension for interactive history editing
r17064 # histedit.py - interactive history editing for mercurial
#
# Copyright 2009 Augie Fackler <raf@durin42.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
Augie Fackler
histedit: add extension docstring from external README...
r17131 """interactive history editing
With this extension installed, Mercurial gains one new command: histedit. Usage
is as follows, assuming the following history::
@ 3[tip] 7c2fd3b9020c 2009-04-27 18:04 -0500 durin42
| Add delta
|
o 2 030b686bedc4 2009-04-27 18:04 -0500 durin42
| Add gamma
|
o 1 c561b4e977df 2009-04-27 18:04 -0500 durin42
| Add beta
|
o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
Add alpha
If you were to run ``hg histedit c561b4e977df``, you would see the following
file open in your editor::
pick c561b4e977df Add beta
pick 030b686bedc4 Add gamma
pick 7c2fd3b9020c Add delta
FUJIWARA Katsunori
histedit: correct changeset IDs in online help...
r18322 # Edit history between c561b4e977df and 7c2fd3b9020c
Augie Fackler
histedit: add extension docstring from external README...
r17131 #
Adrian Zgorzałek
histedit: clarify description of fold command...
r20503 # Commits are listed from least to most recent
#
Augie Fackler
histedit: add extension docstring from external README...
r17131 # Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
Matt Mackall
histedit: shorten new fold message...
r20511 # f, fold = use commit, but combine it with the one above
Ben Schmidt
histedit: modify rollup to discard date from the rollup commit (issue4820)...
r31056 # r, roll = like fold, but discard this commit's description and date
Augie Fackler
histedit: add extension docstring from external README...
r17131 # d, drop = remove commit from history
timeless@mozdev.org
histedit: improve discoverability of edit commit message
r26100 # m, mess = edit commit message without changing commit content
Saurabh Singh
histedit: removing the experimental config 'histeditng'...
r34490 # b, base = checkout changeset and apply further changesets from there
Augie Fackler
histedit: add extension docstring from external README...
r17131 #
In this file, lines beginning with ``#`` are ignored. You must specify a rule
for each revision in your history. For example, if you had meant to add gamma
before beta, and then wanted to add delta in the same revision as beta, you
would reorganize the file to look like this::
pick 030b686bedc4 Add gamma
pick c561b4e977df Add beta
fold 7c2fd3b9020c Add delta
FUJIWARA Katsunori
histedit: correct changeset IDs in online help...
r18322 # Edit history between c561b4e977df and 7c2fd3b9020c
Augie Fackler
histedit: add extension docstring from external README...
r17131 #
Adrian Zgorzałek
histedit: clarify description of fold command...
r20503 # Commits are listed from least to most recent
#
Augie Fackler
histedit: add extension docstring from external README...
r17131 # Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
Matt Mackall
histedit: shorten new fold message...
r20511 # f, fold = use commit, but combine it with the one above
Ben Schmidt
histedit: modify rollup to discard date from the rollup commit (issue4820)...
r31056 # r, roll = like fold, but discard this commit's description and date
Augie Fackler
histedit: add extension docstring from external README...
r17131 # d, drop = remove commit from history
timeless@mozdev.org
histedit: improve discoverability of edit commit message
r26100 # m, mess = edit commit message without changing commit content
Saurabh Singh
histedit: removing the experimental config 'histeditng'...
r34490 # b, base = checkout changeset and apply further changesets from there
Augie Fackler
histedit: add extension docstring from external README...
r17131 #
At which point you close the editor and ``histedit`` starts working. When you
specify a ``fold`` operation, ``histedit`` will open an editor when it folds
those revisions together, offering you a chance to clean up the commit message::
Add beta
***
Add delta
Augie Fackler
histedit: new extension for interactive history editing
r17064
Ben Schmidt
histedit: improve documentation and behaviour of dates...
r31055 Edit the commit message to your liking, then close the editor. The date used
for the commit will be the later of the two commits' dates. For this example,
let's assume that the commit message was changed to ``Add beta and delta.``
After histedit has run and had a chance to remove any old or temporary
revisions it needed, the history looks like this::
Augie Fackler
histedit: add extension docstring from external README...
r17131
@ 2[tip] 989b4d060121 2009-04-27 18:04 -0500 durin42
| Add beta and delta.
|
o 1 081603921c3f 2009-04-27 18:04 -0500 durin42
| Add gamma
|
o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
Add alpha
Note that ``histedit`` does *not* remove any revisions (even its own temporary
ones) until after it has completed all the editing operations, so it will
probably perform several strip operations when it's done. For the above example,
it had to run strip twice. Strip can be slow depending on a variety of factors,
so you might need to be a little patient. You can choose to keep the original
revisions by passing the ``--keep`` flag.
The ``edit`` operation will drop you back to a command prompt,
allowing you to edit files freely, or even use ``hg record`` to commit
some changes as a separate commit. When you're done, any remaining
uncommitted changes will be committed as well. When done, run ``hg
Ben Schmidt
histedit: improve documentation and behaviour of dates...
r31055 histedit --continue`` to finish this step. If there are uncommitted
changes, you'll be prompted for a new commit message, but the default
commit message will be the original message for the ``edit`` ed
revision, and the date of the original commit will be preserved.
Augie Fackler
histedit: add extension docstring from external README...
r17131
The ``message`` operation will give you a chance to revise a commit
message without changing the contents. It's a shortcut for doing
``edit`` immediately followed by `hg histedit --continue``.
If ``histedit`` encounters a conflict when moving a revision (while
handling ``pick`` or ``fold``), it'll stop in a similar manner to
``edit`` with the difference that it won't prompt you for a commit
message when done. If you decide at this point that you don't like how
much work it will be to rearrange history, or that you made a mistake,
you can use ``hg histedit --abort`` to abandon the new changes you
have made and return to the state before you attempted to edit your
history.
FUJIWARA Katsunori
histedit: correct the number of added revisions in online help...
r18323 If we clone the histedit-ed example repository above and add four more
changes, such that we have the following history::
Augie Fackler
histedit: add extension docstring from external README...
r17131
@ 6[tip] 038383181893 2009-04-27 18:04 -0500 stefan
| Add theta
|
o 5 140988835471 2009-04-27 18:04 -0500 stefan
| Add eta
|
o 4 122930637314 2009-04-27 18:04 -0500 stefan
| Add zeta
|
o 3 836302820282 2009-04-27 18:04 -0500 stefan
| Add epsilon
|
o 2 989b4d060121 2009-04-27 18:04 -0500 durin42
| Add beta and delta.
|
o 1 081603921c3f 2009-04-27 18:04 -0500 durin42
| Add gamma
|
o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42
Add alpha
If you run ``hg histedit --outgoing`` on the clone then it is the same
as running ``hg histedit 836302820282``. If you need plan to push to a
repository that Mercurial does not detect to be related to the source
repo, you can add a ``--force`` option.
Mateusz Kwapich
histedit: add a config allowing changing histedit rule line length limit...
r24199
Mateusz Kwapich
histedit: delete to drop...
r27414 Config
------
Mateusz Kwapich
histedit: add a config allowing changing histedit rule line length limit...
r24199 Histedit rule lines are truncated to 80 characters by default. You
timeless@mozdev.org
histedit: fix English (en-US)
r26171 can customize this behavior by setting a different length in your
FUJIWARA Katsunori
histedit: fix reST syntax problem of example code in help document...
r24869 configuration file::
Mateusz Kwapich
histedit: add a config allowing changing histedit rule line length limit...
r24199
FUJIWARA Katsunori
histedit: fix reST syntax problem of example code in help document...
r24869 [histedit]
linelen = 120 # truncate rule lines at 120 characters
Gregory Szorc
histedit: pick an appropriate base changeset by default (BC)...
r27262
Augie Fackler
histedit: add templating support to histedit's rule file generation...
r41650 The summary of a change can be customized as well::
[histedit]
summary-template = '{rev} {bookmarks} {desc|firstline}'
The customized summary should be kept short enough that rule lines
will fit in the configured line length. See above if that requires
customization.
Gregory Szorc
histedit: pick an appropriate base changeset by default (BC)...
r27262 ``hg histedit`` attempts to automatically choose an appropriate base
revision to use. To change which base revision is used, define a
revset in your configuration file::
[histedit]
defaultrev = only(.) & draft()
Mateusz Kwapich
histedit: delete to drop...
r27414
By default each edited revision needs to be present in histedit commands.
To remove revision you need to use ``drop`` operation. You can configure
FUJIWARA Katsunori
doc: prevent literal text block from being treated as non-literal one...
r27957 the drop to be implicit for missing commits by adding::
Mateusz Kwapich
histedit: delete to drop...
r27414
[histedit]
dropmissing = True
Durham Goode
histedit: add histedit.singletransaction config option...
r31513 By default, histedit will close the transaction after each action. For
performance purposes, you can configure histedit to use a single transaction
across the entire histedit. WARNING: This setting introduces a significant risk
of losing the work you've done in a histedit if the histedit aborts
unexpectedly::
[histedit]
singletransaction = True
Augie Fackler
histedit: new extension for interactive history editing
r17064 """
Augie Fackler
histedit: add extension docstring from external README...
r17131
Pulkit Goyal
py3: make hgext/hisedit.py use absolute_import
r29126 from __future__ import absolute_import
Matt Harbison
histedit: conditionalize the imports of 'fcntl' and 'termios'...
r40688 # chistedit dependencies that are not available everywhere
try:
import fcntl
import termios
except ImportError:
fcntl = None
termios = None
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 import functools
Yuya Nishihara
curses: do not setlocale() at import time (issue5261)...
r42883 import locale
Augie Fackler
histedit: new extension for interactive history editing
r17064 import os
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 import struct
Yuya Nishihara
py3: move up symbol imports to enforce import-checker rules...
r29205
from mercurial.i18n import _
Gregory Szorc
py3: manually import getattr where it is needed...
r43359 from mercurial.pycompat import (
getattr,
open,
)
Pulkit Goyal
py3: make hgext/hisedit.py use absolute_import
r29126 from mercurial import (
bundle2,
cmdutil,
context,
copies,
destutil,
discovery,
Martin von Zweigbergk
py3: make chistedit render...
r43685 encoding,
Pulkit Goyal
py3: make hgext/hisedit.py use absolute_import
r29126 error,
exchange,
extensions,
hg,
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 logcmdutil,
Pulkit Goyal
py3: make hgext/hisedit.py use absolute_import
r29126 merge as mergemod,
Siddharth Agarwal
histedit: make check for unresolved conflicts explicit (issue5545)...
r32057 mergeutil,
Pulkit Goyal
py3: make hgext/hisedit.py use absolute_import
r29126 node,
obsolete,
Pulkit Goyal
py3: handle keyword arguments in hgext/histedit.py...
r35000 pycompat,
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 registrar,
Pulkit Goyal
py3: make hgext/hisedit.py use absolute_import
r29126 repair,
Martin von Zweigbergk
histedit: use rewriteutil.precheck() instead of reimplementing it...
r44385 rewriteutil,
Pulkit Goyal
py3: make hgext/hisedit.py use absolute_import
r29126 scmutil,
Pulkit Goyal
histedit: add a stateobj variable to histeditstate class...
r38525 state as statemod,
Pulkit Goyal
py3: make hgext/hisedit.py use absolute_import
r29126 util,
)
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 from mercurial.utils import (
Taapas Agrawal
histedit: add rewrite.update-timestamp support to fold and mess...
r41249 dateutil,
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 stringutil,
)
Augie Fackler
histedit: new extension for interactive history editing
r17064
Pulkit Goyal
py3: conditionalize cPickle import by adding in util...
r29324 pickle = util.pickle
Adrian Buehlmann
histedit: use cmdutil.command decorator
r17147 cmdtable = {}
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 command = registrar.command(cmdtable)
Adrian Buehlmann
histedit: use cmdutil.command decorator
r17147
Boris Feld
configitems: register the 'histedit.defaultrev' config
r34472 configtable = {}
configitem = registrar.configitem(configtable)
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'experimental', b'histedit.autoverb', default=False,
Boris Feld
configitems: register the 'experimental.histedit.autoverb' config
r34476 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'histedit', b'defaultrev', default=None,
Boris Feld
configitems: register the 'histedit.defaultrev' config
r34472 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'histedit', b'dropmissing', default=False,
Boris Feld
configitems: register the 'histedit.dropmissing' config
r34473 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'histedit', b'linelen', default=80,
Boris Feld
configitems: register the 'histedit.singletransaction' config
r34475 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'histedit', b'singletransaction', default=False,
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 )
Augie Fackler
formatting: blacken the codebase...
r43346 configitem(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'ui', b'interface.histedit', default=None,
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 configitem(b'histedit', b'summary-template', default=b'{rev} {desc|firstline}')
Boris Feld
configitems: register the 'histedit.defaultrev' config
r34472
Augie Fackler
extensions: change magic "shipped with hg" string...
r29841 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
Augie Fackler
extensions: document that `testedwith = 'internal'` is special...
r25186 # 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.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 testedwith = b'ships-with-hg-core'
Augie Fackler
histedit: new extension for interactive history editing
r17064
timeless
histedit: replace @addhisteditaction with @action...
r27675 actiontable = {}
primaryactions = set()
secondaryactions = set()
tertiaryactions = set()
internalactions = set()
Augie Fackler
formatting: blacken the codebase...
r43346
Mateusz Kwapich
histedit: add a hint about enabled dropmissing to histedit edit comment...
r28592 def geteditcomment(ui, first, last):
timeless
histedit: replace editcomment with a function
r27673 """ construct the editor comment
The comment includes::
- an intro
timeless
histedit: prefer edit commit, edit message, use commit...
r27674 - sorted primary commands
- sorted short commands
timeless
histedit: replace @addhisteditaction with @action...
r27675 - sorted long commands
Mateusz Kwapich
histedit: add a hint about enabled dropmissing to histedit edit comment...
r28592 - additional hints
timeless
histedit: replace editcomment with a function
r27673
Commands are only included once.
"""
Augie Fackler
formatting: blacken the codebase...
r43346 intro = _(
"""Edit history between %s and %s
timeless
histedit: replace editcomment with a function
r27673
Commits are listed from least to most recent
liscju
histedit: adds hint how to reorder changesets at editor (issue3766)
r28396 You can reorder changesets by reordering the lines
timeless
histedit: replace @addhisteditaction with @action...
r27675 Commands:
Augie Fackler
formatting: blacken the codebase...
r43346 """
)
timeless
histedit: replace @addhisteditaction with @action...
r27675 actions = []
Augie Fackler
formatting: blacken the codebase...
r43346
timeless
histedit: replace @addhisteditaction with @action...
r27675 def addverb(v):
a = actiontable[v]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lines = a.message.split(b"\n")
timeless
histedit: replace @addhisteditaction with @action...
r27675 if len(a.verbs):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 v = b', '.join(sorted(a.verbs, key=lambda v: len(v)))
actions.append(b" %s = %s" % (v, lines[0]))
Matt Harbison
histedit: avoid using a list comprehension to fill a list with fixed values...
r44447 actions.extend([b' %s'] * (len(lines) - 1))
timeless
histedit: replace @addhisteditaction with @action...
r27675
for v in (
Augie Fackler
formatting: blacken the codebase...
r43346 sorted(primaryactions)
+ sorted(secondaryactions)
+ sorted(tertiaryactions)
):
timeless
histedit: replace @addhisteditaction with @action...
r27675 addverb(v)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 actions.append(b'')
Augie Fackler
histedit: new extension for interactive history editing
r17064
Mateusz Kwapich
histedit: add a hint about enabled dropmissing to histedit edit comment...
r28592 hints = []
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if ui.configbool(b'histedit', b'dropmissing'):
Augie Fackler
formatting: blacken the codebase...
r43346 hints.append(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"Deleting a changeset from the list "
b"will DISCARD it from the edited history!"
Augie Fackler
formatting: blacken the codebase...
r43346 )
Mateusz Kwapich
histedit: add a hint about enabled dropmissing to histedit edit comment...
r28592
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lines = (intro % (first, last)).split(b'\n') + actions + hints
return b''.join([b'# %s\n' % l if l else b'#\n' for l in lines])
timeless
histedit: replace editcomment with a function
r27673
Augie Fackler
formatting: blacken the codebase...
r43346
David Soria Parra
histedit: add histedit state class...
r22976 class histeditstate(object):
Martin von Zweigbergk
histedit: drop unused constructor arguments (API)...
r41200 def __init__(self, repo):
David Soria Parra
histedit: add histedit state class...
r22976 self.repo = repo
Martin von Zweigbergk
histedit: drop unused constructor arguments (API)...
r41200 self.actions = None
self.keep = None
self.topmost = None
self.parentctxnode = None
self.lock = None
self.wlock = None
Durham Goode
histedit: store backup file before histedit...
r24757 self.backupfile = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.stateobj = statemod.cmdstate(repo, b'histedit-state')
Martin von Zweigbergk
histedit: drop unused constructor arguments (API)...
r41200 self.replacements = []
David Soria Parra
histedit: add histedit state class...
r22976
David Soria Parra
histedit: read state from histeditstate...
r22983 def read(self):
Augie Fackler
histedit: update docstring on histeditstate.read()...
r22986 """Load histedit state from disk and set fields appropriately."""
Pulkit Goyal
histedit: use self.stateobj to check whether interrupted histedit exists...
r38526 if not self.stateobj.exists():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cmdutil.wrongtooltocontinue(self.repo, _(b'histedit'))
David Soria Parra
histedit: read state from histeditstate...
r22983
Pulkit Goyal
histedit: use self.stateobj to check whether interrupted histedit exists...
r38526 data = self._read()
Pulkit Goyal
histedit: factor out logic of processing state data in separate fn...
r38524
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.parentctxnode = data[b'parentctxnode']
actions = parserules(data[b'rules'], self)
Pulkit Goyal
histedit: factor out logic of processing state data in separate fn...
r38524 self.actions = actions
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.keep = data[b'keep']
self.topmost = data[b'topmost']
self.replacements = data[b'replacements']
self.backupfile = data[b'backupfile']
Pulkit Goyal
histedit: factor out logic of processing state data in separate fn...
r38524
Pulkit Goyal
histedit: use self.stateobj to check whether interrupted histedit exists...
r38526 def _read(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fp = self.repo.vfs.read(b'histedit-state')
if fp.startswith(b'v1\n'):
Bryan O'Sullivan
histedit: only use pickle if not using the modern save format...
r27527 data = self._load()
parentctxnode, rules, keep, topmost, replacements, backupfile = data
else:
Pulkit Goyal
histedit: factor out logic of processing state data in separate fn...
r38524 data = pickle.loads(fp)
Durham Goode
histedit: replace pickle with custom serialization...
r24756 parentctxnode, rules, keep, topmost, replacements = data
Durham Goode
histedit: store backup file before histedit...
r24757 backupfile = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rules = b"\n".join([b"%s %s" % (verb, rest) for [verb, rest] in rules])
David Soria Parra
histedit: read state from histeditstate...
r22983
Augie Fackler
formatting: blacken the codebase...
r43346 return {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'parentctxnode': parentctxnode,
b"rules": rules,
b"keep": keep,
b"topmost": topmost,
b"replacements": replacements,
b"backupfile": backupfile,
Augie Fackler
formatting: blacken the codebase...
r43346 }
David Soria Parra
histedit: read state from histeditstate...
r22983
Durham Goode
histedit: add transaction support to writing the state file...
r31511 def write(self, tr=None):
if tr:
Augie Fackler
formatting: blacken the codebase...
r43346 tr.addfilegenerator(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'histedit-state',
(b'histedit-state',),
Augie Fackler
formatting: blacken the codebase...
r43346 self._write,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 location=b'plain',
Augie Fackler
formatting: blacken the codebase...
r43346 )
Durham Goode
histedit: add transaction support to writing the state file...
r31511 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with self.repo.vfs(b"histedit-state", b"w") as f:
Durham Goode
histedit: add transaction support to writing the state file...
r31511 self._write(f)
def _write(self, fp):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fp.write(b'v1\n')
fp.write(b'%s\n' % node.hex(self.parentctxnode))
fp.write(b'%s\n' % node.hex(self.topmost))
fp.write(b'%s\n' % (b'True' if self.keep else b'False'))
fp.write(b'%d\n' % len(self.actions))
Mateusz Kwapich
histedit: get rid of state.rules...
r27208 for action in self.actions:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fp.write(b'%s\n' % action.tostate())
fp.write(b'%d\n' % len(self.replacements))
Durham Goode
histedit: replace pickle with custom serialization...
r24756 for replacement in self.replacements:
Augie Fackler
formatting: blacken the codebase...
r43346 fp.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'%s%s\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % (
node.hex(replacement[0]),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b''.join(node.hex(r) for r in replacement[1]),
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Durham Goode
histedit: fix serializing of None backupfile...
r24958 backupfile = self.backupfile
if not backupfile:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 backupfile = b''
fp.write(b'%s\n' % backupfile)
David Soria Parra
histedit: add histedit state class...
r22976
Durham Goode
histedit: replace pickle with custom serialization...
r24756 def _load(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fp = self.repo.vfs(b'histedit-state', b'r')
Durham Goode
histedit: replace pickle with custom serialization...
r24756 lines = [l[:-1] for l in fp.readlines()]
index = 0
Augie Fackler
formatting: blacken the codebase...
r43346 lines[index] # version number
Durham Goode
histedit: replace pickle with custom serialization...
r24756 index += 1
parentctxnode = node.bin(lines[index])
index += 1
topmost = node.bin(lines[index])
index += 1
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 keep = lines[index] == b'True'
Durham Goode
histedit: replace pickle with custom serialization...
r24756 index += 1
# Rules
rules = []
rulelen = int(lines[index])
index += 1
Gregory Szorc
global: use pycompat.xrange()...
r38806 for i in pycompat.xrange(rulelen):
Durham Goode
histedit: change state format to allow non-hash lines...
r24810 ruleaction = lines[index]
index += 1
Durham Goode
histedit: replace pickle with custom serialization...
r24756 rule = lines[index]
index += 1
Durham Goode
histedit: change state format to allow non-hash lines...
r24810 rules.append((ruleaction, rule))
Durham Goode
histedit: replace pickle with custom serialization...
r24756
# Replacements
replacements = []
replacementlen = int(lines[index])
index += 1
Gregory Szorc
global: use pycompat.xrange()...
r38806 for i in pycompat.xrange(replacementlen):
Durham Goode
histedit: replace pickle with custom serialization...
r24756 replacement = lines[index]
original = node.bin(replacement[:40])
Augie Fackler
formatting: blacken the codebase...
r43346 succ = [
node.bin(replacement[i : i + 40])
for i in range(40, len(replacement), 40)
]
Durham Goode
histedit: replace pickle with custom serialization...
r24756 replacements.append((original, succ))
index += 1
Durham Goode
histedit: store backup file before histedit...
r24757 backupfile = lines[index]
index += 1
Durham Goode
histedit: replace pickle with custom serialization...
r24756 fp.close()
Durham Goode
histedit: store backup file before histedit...
r24757 return parentctxnode, rules, keep, topmost, replacements, backupfile
Durham Goode
histedit: replace pickle with custom serialization...
r24756
David Soria Parra
histedit: add clear method to remove state...
r22978 def clear(self):
Christian Delahousse
histedit: check presence of statefile before deleting it...
r26583 if self.inprogress():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.repo.vfs.unlink(b'histedit-state')
David Soria Parra
histedit: add clear method to remove state...
r22978
Christian Delahousse
histedit: add inprogress method to state class...
r26582 def inprogress(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return self.repo.vfs.exists(b'histedit-state')
Christian Delahousse
histedit: add inprogress method to state class...
r26582
Mateusz Kwapich
histedit: add actions property to histedit state...
r27200
Durham Goode
histedit: add a new histeditaction class...
r24765 class histeditaction(object):
def __init__(self, state, node):
self.state = state
self.repo = state.repo
self.node = node
@classmethod
def fromrule(cls, state, rule):
"""Parses the given rule, returning an instance of the histeditaction.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ruleid = rule.strip().split(b' ', 1)[0]
Sangeet Kumar Mishra
histedit: make histedit's commands accept revsets (issue5746)...
r37124 # ruleid can be anything from rev numbers, hashes, "bookmarks" etc
# Check for validation of rule ids and get the rulehash
timeless
histedit: handle exceptions from node.bin in fromrule
r27547 try:
Sangeet Kumar Mishra
histedit: make histedit's commands accept revsets (issue5746)...
r37124 rev = node.bin(ruleid)
Augie Fackler
node: make bin() be a wrapper instead of just an alias...
r36256 except TypeError:
Sangeet Kumar Mishra
histedit: make histedit's commands accept revsets (issue5746)...
r37124 try:
_ctx = scmutil.revsingle(state.repo, ruleid)
rulehash = _ctx.hex()
rev = node.bin(rulehash)
except error.RepoLookupError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.ParseError(_(b"invalid changeset %s") % ruleid)
timeless
histedit: handle exceptions from node.bin in fromrule
r27547 return cls(state, rev)
Mateusz Kwapich
histedit: add verify() to histeditaction...
r27202
Pierre-Yves David
histedit: move constraint verification to the 'action.verify' method...
r29879 def verify(self, prev, expected, seen):
Mateusz Kwapich
histedit: add verify() to histeditaction...
r27202 """ Verifies semantic correctness of the rule"""
repo = self.repo
ha = node.hex(self.node)
Martin von Zweigbergk
scmutil: rename resolvepartialhexnodeid() to resolvehexnodeidprefix()...
r37696 self.node = scmutil.resolvehexnodeidprefix(repo, ha)
Martin von Zweigbergk
histedit: look up partial nodeid as partial nodeid...
r37524 if self.node is None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.ParseError(_(b'unknown changeset %s listed') % ha[:12])
Martin von Zweigbergk
histedit: drop unnecessary check for "self.node is not None"...
r37523 self._verifynodeconstraints(prev, expected, seen)
Pierre-Yves David
histedit: move constraint verification to the 'action.verify' method...
r29879
Pierre-Yves David
histedt: use inheritance to override the constraints in 'base'...
r29880 def _verifynodeconstraints(self, prev, expected, seen):
# by default command need a node in the edited list
if self.node not in expected:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.ParseError(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'%s "%s" changeset was not a candidate')
Augie Fackler
formatting: blacken the codebase...
r43346 % (self.verb, node.short(self.node)),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hint=_(b'only use listed changesets'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
histedt: use inheritance to override the constraints in 'base'...
r29880 # and only one command per node
if self.node in seen:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.ParseError(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'duplicated command for changeset %s')
% node.short(self.node)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Durham Goode
histedit: add a new histeditaction class...
r24765
Sean Farley
histedit: remove unneeded initial parameter...
r29466 def torule(self):
Mateusz Kwapich
histedit: add torule method to histedit action objects...
r27203 """build a histedit rule line for an action
by default lines are in the form:
<hash> <rev> <summary>
"""
ctx = self.repo[self.node]
Augie Fackler
histedit: add templating support to histedit's rule file generation...
r41650 ui = self.repo.ui
Augie Fackler
formatting: blacken the codebase...
r43346 summary = (
cmdutil.rendertemplate(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx, ui.config(b'histedit', b'summary-template')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 or b''
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
histedit: add templating support to histedit's rule file generation...
r41650 summary = summary.splitlines()[0]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 line = b'%s %s %s' % (self.verb, ctx, summary)
Mateusz Kwapich
histedit: add torule method to histedit action objects...
r27203 # trim to 75 columns by default so it's not stupidly wide in my editor
# (the 5 more are left for verb)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 maxlen = self.repo.ui.configint(b'histedit', b'linelen')
Augie Fackler
formatting: blacken the codebase...
r43346 maxlen = max(maxlen, 22) # avoid truncating hash
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 return stringutil.ellipsis(line, maxlen)
Mateusz Kwapich
histedit: add torule method to histedit action objects...
r27203
Mateusz Kwapich
histedit: add tostate method to histedit action...
r27206 def tostate(self):
"""Print an action in format used by histedit state files
(the first line is a verb, the remainder is the second)
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b"%s\n%s" % (self.verb, node.hex(self.node))
Mateusz Kwapich
histedit: add tostate method to histedit action...
r27206
Durham Goode
histedit: add a new histeditaction class...
r24765 def run(self):
"""Runs the action. The default behavior is simply apply the action's
rulectx onto the current parentctx."""
self.applychange()
self.continuedirty()
return self.continueclean()
def applychange(self):
"""Applies the changes from this action's rulectx onto the current
parentctx, but does not commit them."""
repo = self.repo
rulectx = repo[self.node]
timeless
histedit: limit updated and merging output to important updates...
r28004 repo.ui.pushbuffer(error=True, labeled=True)
timeless
histedit: omit useless message from update (histeditaction)...
r27405 hg.update(repo, self.state.parentctxnode, quietempty=True)
Rodrigo Damazio Bovendorp
histedit: narrow the scope of discarded ui output...
r42219 repo.ui.popbuffer()
Durham Goode
histedit: add a new histeditaction class...
r24765 stats = applychanges(repo.ui, repo, rulectx, {})
Boris Feld
histedit: preserve active branch while histediting...
r35391 repo.dirstate.setbranch(rulectx.branch())
Gregory Szorc
merge: deprecate accessing update results by index...
r37143 if stats.unresolvedcount:
timeless
histedit: list action when intervention is required
r27629 raise error.InterventionRequired(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'Fix up the change (%s %s)')
Augie Fackler
formatting: blacken the codebase...
r43346 % (self.verb, node.short(self.node)),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hint=_(b'hg histedit --continue to resume'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Durham Goode
histedit: add a new histeditaction class...
r24765
def continuedirty(self):
"""Continues the action when changes have been applied to the working
copy. The default behavior is to commit the dirty changes."""
repo = self.repo
rulectx = repo[self.node]
editor = self.commiteditor()
commit = commitfuncfor(repo, rulectx)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if repo.ui.configbool(b'rewrite', b'update-timestamp'):
Taapas Agrawal
histedit: add rewrite.update-timestamp support to fold and mess...
r41249 date = dateutil.makedate()
else:
date = rulectx.date()
Augie Fackler
formatting: blacken the codebase...
r43346 commit(
text=rulectx.description(),
user=rulectx.user(),
date=date,
extra=rulectx.extra(),
editor=editor,
)
Durham Goode
histedit: add a new histeditaction class...
r24765
def commiteditor(self):
"""The editor to be used to edit the commit message."""
return False
def continueclean(self):
"""Continues the action when the working copy is clean. The default
behavior is to accept the current commit as the new version of the
rulectx."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = self.repo[b'.']
Durham Goode
histedit: add a new histeditaction class...
r24765 if ctx.node() == self.state.parentctxnode:
Augie Fackler
formatting: blacken the codebase...
r43346 self.repo.ui.warn(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'%s: skipping changeset (no changes)\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % node.short(self.node)
)
Durham Goode
histedit: add a new histeditaction class...
r24765 return ctx, [(self.node, tuple())]
if ctx.node() == self.node:
# Nothing changed
return ctx, []
return ctx, [(self.node, (ctx.node(),))]
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 def commitfuncfor(repo, src):
"""Build a commit function for the replacement of <src>
Mads Kiilerich
spelling: fix some minor issues found by spell checker
r18644 This function ensure we apply the same treatment to all changesets.
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436
Pierre-Yves David
histedit: record histedit source (issue3681)...
r18437 - Add a 'histedit_source' entry in extra.
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436
Augie Fackler
histedit: copyedit docstring wording problem I noticed while here
r25450 Note that fold has its own separated logic because its handling is a bit
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 different and not easily factored out of the fold method.
"""
Pierre-Yves David
histedit: proper phase conservation (issue3724)...
r18440 phasemin = src.phase()
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 def commitfunc(**kwargs):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 overrides = {(b'phases', b'new-commit'): phasemin}
with repo.ui.configoverride(overrides, b'histedit'):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra = kwargs.get('extra', {}).copy()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 extra[b'histedit_source'] = src.hex()
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 kwargs['extra'] = extra
Pierre-Yves David
histedit: proper phase conservation (issue3724)...
r18440 return repo.commit(**kwargs)
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
histedit: factor most commit creation in a function...
r18436 return commitfunc
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 def applychanges(ui, repo, ctx, opts):
"""Merge changeset from ctx (only) in the current working directory"""
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 wcpar = repo.dirstate.p1()
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 if ctx.p1().node() == wcpar:
timeless@mozdev.org
histedit: fix English (en-US)
r26171 # edits are "in place" we do not need to make any merge,
timeless
histedit: fix comment in applychanges
r27603 # just applies changes on parent for editing
Rodrigo Damazio Bovendorp
histedit: narrow the scope of discarded ui output...
r42219 ui.pushbuffer()
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 cmdutil.revert(ui, repo, ctx, (wcpar, node.nullid), all=True)
Gregory Szorc
histedit: always define update results...
r37126 stats = mergemod.updateresult(0, 0, 0, 0)
Rodrigo Damazio Bovendorp
histedit: narrow the scope of discarded ui output...
r42219 ui.popbuffer()
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 else:
try:
# ui.forcemerge is an internal variable, do not document
Augie Fackler
formatting: blacken the codebase...
r43346 repo.ui.setconfig(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'ui', b'forcemerge', opts.get(b'tool', b''), b'histedit'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martin von Zweigbergk
graft: default `base` argument to common case of `ctx.p1()`...
r44693 stats = mergemod.graft(repo, ctx, labels=[b'local', b'histedit'])
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 finally:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo.ui.setconfig(b'ui', b'forcemerge', b'', b'histedit')
Pierre-Yves David
histedit: replaces patching logic by merges...
r17647 return stats
Leah Xue
histedit: factored out diff/patch logic...
r17407
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
histedit: rename variables so they have "ctx" in them...
r36421 def collapse(repo, firstctx, lastctx, commitopts, skipprompt=False):
Pierre-Yves David
histedit: fold in memory...
r17644 """collapse the set of revisions from first to last as new one.
Expected commit options are:
- message
- date
- username
Mads Kiilerich
spelling: fix minor spell checker issues
r17738 Commit message is edited in all cases.
Pierre-Yves David
histedit: fold in memory...
r17644
This function works in memory."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctxs = list(repo.set(b'%d::%d', firstctx.rev(), lastctx.rev()))
Pierre-Yves David
histedit: fold in memory...
r17644 if not ctxs:
return None
Augie Fackler
histedit: abort rather than edit a public changeset (issue4704)...
r25452 for c in ctxs:
if not c.mutable():
timeless
histedit: use parse-error exception for parsing
r27545 raise error.ParseError(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"cannot fold into public change %s") % node.short(c.node())
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 base = firstctx.p1()
Pierre-Yves David
histedit: fold in memory...
r17644
# commit a new version of the old changeset, including the update
# collect all files which might be affected
files = set()
for ctx in ctxs:
files.update(ctx.files())
# Recompute copies (avoid recording a -> b -> a)
Gregory Szorc
histedit: rename variables so they have "ctx" in them...
r36421 copied = copies.pathcopies(base, lastctx)
Pierre-Yves David
histedit: fold in memory...
r17644
# prune files which were reverted by the updates
Gregory Szorc
histedit: rename variables so they have "ctx" in them...
r36421 files = [f for f in files if not cmdutil.samefile(f, lastctx, base)]
Pierre-Yves David
histedit: fold in memory...
r17644 # commit version of these files as defined by head
Gregory Szorc
histedit: rename variables so they have "ctx" in them...
r36421 headmf = lastctx.manifest()
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
histedit: fold in memory...
r17644 def filectxfn(repo, ctx, path):
if path in headmf:
Gregory Szorc
histedit: rename variables so they have "ctx" in them...
r36421 fctx = lastctx[path]
Pierre-Yves David
histedit: fold in memory...
r17644 flags = fctx.flags()
Augie Fackler
formatting: blacken the codebase...
r43346 mctx = context.memfilectx(
repo,
ctx,
fctx.path(),
fctx.data(),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 islink=b'l' in flags,
isexec=b'x' in flags,
Augie Fackler
formatting: blacken the codebase...
r43346 copysource=copied.get(path),
)
Pierre-Yves David
histedit: fold in memory...
r17644 return mctx
Mads Kiilerich
convert: use None value for missing files instead of overloading IOError...
r22296 return None
Pierre-Yves David
histedit: fold in memory...
r17644
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if commitopts.get(b'message'):
message = commitopts[b'message']
Pierre-Yves David
histedit: fold in memory...
r17644 else:
Gregory Szorc
histedit: rename variables so they have "ctx" in them...
r36421 message = firstctx.description()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 user = commitopts.get(b'user')
date = commitopts.get(b'date')
extra = commitopts.get(b'extra')
Pierre-Yves David
histedit: fold in memory...
r17644
Gregory Szorc
histedit: rename variables so they have "ctx" in them...
r36421 parents = (firstctx.p1().node(), firstctx.p2().node())
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152 editor = None
Durham Goode
histedit: fix rollup prompting for a commit message (issue4606)...
r24828 if not skipprompt:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 editor = cmdutil.getcommiteditor(edit=True, editform=b'histedit.fold')
Augie Fackler
formatting: blacken the codebase...
r43346 new = context.memctx(
repo,
parents=parents,
text=message,
files=files,
filectxfn=filectxfn,
user=user,
date=date,
extra=extra,
editor=editor,
)
Pierre-Yves David
histedit: fold in memory...
r17644 return repo.commitctx(new)
Augie Fackler
formatting: blacken the codebase...
r43346
liscju
histedit: extracts _isdirtywc function...
r26981 def _isdirtywc(repo):
return repo[None].dirty(missing=True)
Augie Fackler
formatting: blacken the codebase...
r43346
Mateusz Kwapich
histedit: add abortdirty function...
r27084 def abortdirty():
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'working copy has pending changes'),
Augie Fackler
formatting: blacken the codebase...
r43346 hint=_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'amend, commit, or revert them and run histedit '
b'--continue, or abort with histedit --abort'
Augie Fackler
formatting: blacken the codebase...
r43346 ),
)
Mateusz Kwapich
histedit: add abortdirty function...
r27084
timeless
histedit: replace @addhisteditaction with @action...
r27675 def action(verbs, message, priority=False, internal=False):
def wrap(cls):
assert not priority or not internal
verb = verbs[0]
if priority:
primaryactions.add(verb)
elif internal:
internalactions.add(verb)
elif len(verbs) > 1:
secondaryactions.add(verb)
else:
tertiaryactions.add(verb)
Mateusz Kwapich
histedit: add addhisteditaction decorator...
r27201
timeless
histedit: replace @addhisteditaction with @action...
r27675 cls.verb = verb
cls.verbs = verbs
cls.message = message
Mateusz Kwapich
histedit: add addhisteditaction decorator...
r27201 for verb in verbs:
actiontable[verb] = cls
return cls
Augie Fackler
formatting: blacken the codebase...
r43346
Mateusz Kwapich
histedit: add addhisteditaction decorator...
r27201 return wrap
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @action([b'pick', b'p'], _(b'use commit'), priority=True)
Durham Goode
histedit: convert pick action into a class...
r24767 class pick(histeditaction):
def run(self):
rulectx = self.repo[self.node]
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 if rulectx.p1().node() == self.state.parentctxnode:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.repo.ui.debug(b'node %s unchanged\n' % node.short(self.node))
Durham Goode
histedit: convert pick action into a class...
r24767 return rulectx, []
Augie Fackler
histedit: new extension for interactive history editing
r17064
Durham Goode
histedit: convert pick action into a class...
r24767 return super(pick, self).run()
Augie Fackler
histedit: new extension for interactive history editing
r17064
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @action([b'edit', b'e'], _(b'use commit, but stop for amending'), priority=True)
Durham Goode
histedit: convert edit action into a class...
r24770 class edit(histeditaction):
def run(self):
repo = self.repo
rulectx = repo[self.node]
timeless
histedit: omit useless message from update (edit)...
r27407 hg.update(repo, self.state.parentctxnode, quietempty=True)
Durham Goode
histedit: convert edit action into a class...
r24770 applychanges(repo.ui, repo, rulectx, {})
raise error.InterventionRequired(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'Editing (%s), you may commit or record as needed now.')
timeless
histedit: list action when intervention is required
r27629 % node.short(self.node),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hint=_(b'hg histedit --continue to resume'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Durham Goode
histedit: convert edit action into a class...
r24770
def commiteditor(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return cmdutil.getcommiteditor(edit=True, editform=b'histedit.edit')
@action([b'fold', b'f'], _(b'use commit, but combine it with the one above'))
Durham Goode
histedit: convert fold/roll actions into a class...
r24771 class fold(histeditaction):
Pierre-Yves David
histedit: move constraint verification to the 'action.verify' method...
r29879 def verify(self, prev, expected, seen):
timeless
histedit: check fold of public change during verify
r27542 """ Verifies semantic correctness of the fold rule"""
Pierre-Yves David
histedit: move constraint verification to the 'action.verify' method...
r29879 super(fold, self).verify(prev, expected, seen)
timeless
histedit: check fold of public change during verify
r27542 repo = self.repo
if not prev:
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 c = repo[self.node].p1()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif not prev.verb in (b'pick', b'base'):
timeless
histedit: check fold of public change during verify
r27542 return
else:
c = repo[prev.node]
if not c.mutable():
timeless
histedit: use parse-error exception for parsing
r27545 raise error.ParseError(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"cannot fold into public change %s") % node.short(c.node())
Augie Fackler
formatting: blacken the codebase...
r43346 )
timeless
histedit: check fold of public change during verify
r27542
Durham Goode
histedit: convert fold/roll actions into a class...
r24771 def continuedirty(self):
repo = self.repo
rulectx = repo[self.node]
commit = commitfuncfor(repo, rulectx)
Augie Fackler
formatting: blacken the codebase...
r43346 commit(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 text=b'fold-temp-revision %s' % node.short(self.node),
Augie Fackler
formatting: blacken the codebase...
r43346 user=rulectx.user(),
date=rulectx.date(),
extra=rulectx.extra(),
)
Durham Goode
histedit: convert fold/roll actions into a class...
r24771
def continueclean(self):
repo = self.repo
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = repo[b'.']
Durham Goode
histedit: convert fold/roll actions into a class...
r24771 rulectx = repo[self.node]
parentctxnode = self.state.parentctxnode
if ctx.node() == parentctxnode:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo.ui.warn(_(b'%s: empty changeset\n') % node.short(self.node))
Durham Goode
histedit: convert fold/roll actions into a class...
r24771 return ctx, [(self.node, (parentctxnode,))]
Mike Edgar
histedit: add "roll" command to fold commit data and drop message (issue4256)...
r22152
Durham Goode
histedit: convert fold/roll actions into a class...
r24771 parentctx = repo[parentctxnode]
Augie Fackler
cleanup: run pyupgrade on our source tree to clean up varying things...
r44937 newcommits = {
Augie Fackler
formatting: blacken the codebase...
r43346 c.node()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for c in repo.set(b'(%d::. - %d)', parentctx.rev(), parentctx.rev())
Augie Fackler
cleanup: run pyupgrade on our source tree to clean up varying things...
r44937 }
Durham Goode
histedit: convert fold/roll actions into a class...
r24771 if not newcommits:
Augie Fackler
formatting: blacken the codebase...
r43346 repo.ui.warn(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'%s: cannot fold - working copy is not a '
b'descendant of previous commit %s\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
% (node.short(self.node), node.short(parentctxnode))
)
Durham Goode
histedit: convert fold/roll actions into a class...
r24771 return ctx, [(self.node, (ctx.node(),))]
middlecommits = newcommits.copy()
middlecommits.discard(ctx.node())
Augie Fackler
formatting: blacken the codebase...
r43346 return self.finishfold(
repo.ui, repo, parentctx, rulectx, ctx.node(), middlecommits
)
Durham Goode
histedit: convert fold/roll actions into a class...
r24771
Durham Goode
histedit: improve roll action integration with fold...
r24773 def skipprompt(self):
Augie Fackler
histedit: use one editor when multiple folds happen in a row (issue3524) (BC)...
r26246 """Returns true if the rule should skip the message editor.
For example, 'fold' wants to show an editor, but 'rollup'
doesn't want to.
"""
Durham Goode
histedit: improve roll action integration with fold...
r24773 return False
Durham Goode
histedit: move finishfold into fold class...
r24772
Augie Fackler
histedit: use one editor when multiple folds happen in a row (issue3524) (BC)...
r26246 def mergedescs(self):
"""Returns true if the rule should merge messages of multiple changes.
This exists mainly so that 'rollup' rules can be a subclass of
'fold'.
"""
return True
Ben Schmidt
histedit: modify rollup to discard date from the rollup commit (issue4820)...
r31056 def firstdate(self):
"""Returns true if the rule should preserve the date of the first
change.
This exists mainly so that 'rollup' rules can be a subclass of
'fold'.
"""
return False
Durham Goode
histedit: improve roll action integration with fold...
r24773 def finishfold(self, ui, repo, ctx, oldctx, newnode, internalchanges):
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 parent = ctx.p1().node()
Yuya Nishihara
cleanup: pass in overwrite flag to hg.updaterepo() as named argument...
r38527 hg.updaterepo(repo, parent, overwrite=False)
Durham Goode
histedit: move finishfold into fold class...
r24772 ### prepare new commit data
Durham Goode
histedit: improve roll action integration with fold...
r24773 commitopts = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 commitopts[b'user'] = ctx.user()
Durham Goode
histedit: move finishfold into fold class...
r24772 # commit message
Augie Fackler
histedit: use one editor when multiple folds happen in a row (issue3524) (BC)...
r26246 if not self.mergedescs():
Durham Goode
histedit: move finishfold into fold class...
r24772 newmessage = ctx.description()
else:
Augie Fackler
formatting: blacken the codebase...
r43346 newmessage = (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'\n***\n'.join(
Augie Fackler
formatting: blacken the codebase...
r43346 [ctx.description()]
+ [repo[r].description() for r in internalchanges]
+ [oldctx.description()]
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 + b'\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 commitopts[b'message'] = newmessage
Durham Goode
histedit: move finishfold into fold class...
r24772 # date
Ben Schmidt
histedit: modify rollup to discard date from the rollup commit (issue4820)...
r31056 if self.firstdate():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 commitopts[b'date'] = ctx.date()
Ben Schmidt
histedit: modify rollup to discard date from the rollup commit (issue4820)...
r31056 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 commitopts[b'date'] = max(ctx.date(), oldctx.date())
Taapas Agrawal
histedit: add rewrite.update-timestamp support to fold and mess...
r41249 # if date is to be updated to current
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if ui.configbool(b'rewrite', b'update-timestamp'):
commitopts[b'date'] = dateutil.makedate()
Taapas Agrawal
histedit: add rewrite.update-timestamp support to fold and mess...
r41249
Durham Goode
histedit: move finishfold into fold class...
r24772 extra = ctx.extra().copy()
# histedit_source
# note: ctx is likely a temporary commit but that the best we can do
# here. This is sufficient to solve issue3681 anyway.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 extra[b'histedit_source'] = b'%s,%s' % (ctx.hex(), oldctx.hex())
commitopts[b'extra'] = extra
Jun Wu
histedit: get rid of ui.backupconfig
r31459 phasemin = max(ctx.phase(), oldctx.phase())
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 overrides = {(b'phases', b'new-commit'): phasemin}
with repo.ui.configoverride(overrides, b'histedit'):
Augie Fackler
formatting: blacken the codebase...
r43346 n = collapse(
repo,
ctx,
repo[newnode],
commitopts,
skipprompt=self.skipprompt(),
)
Durham Goode
histedit: move finishfold into fold class...
r24772 if n is None:
return ctx, []
Yuya Nishihara
cleanup: pass in overwrite flag to hg.updaterepo() as named argument...
r38527 hg.updaterepo(repo, n, overwrite=False)
Augie Fackler
formatting: blacken the codebase...
r43346 replacements = [
(oldctx.node(), (newnode,)),
(ctx.node(), (n,)),
(newnode, (n,)),
]
Durham Goode
histedit: move finishfold into fold class...
r24772 for ich in internalchanges:
replacements.append((ich, (n,)))
return repo[n], replacements
Durham Goode
histedit: convert fold/roll actions into a class...
r24771
Augie Fackler
formatting: blacken the codebase...
r43346
@action(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'base', b'b'],
_(b'checkout changeset and apply further changesets from there'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Mateusz Kwapich
histedit: add an experimental base action...
r27085 class base(histeditaction):
def run(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if self.repo[b'.'].node() != self.node:
Martin von Zweigbergk
merge: introduce a clean_update() for that use-case...
r44743 mergemod.clean_update(self.repo[self.node])
Mateusz Kwapich
histedit: add an experimental base action...
r27085 return self.continueclean()
def continuedirty(self):
abortdirty()
def continueclean(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 basectx = self.repo[b'.']
Mateusz Kwapich
histedit: add an experimental base action...
r27085 return basectx, []
Pierre-Yves David
histedt: use inheritance to override the constraints in 'base'...
r29880 def _verifynodeconstraints(self, prev, expected, seen):
# base can only be use with a node not in the edited set
if self.node in expected:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = _(b'%s "%s" changeset was an edited list candidate')
Augie Fackler
histedit: correct output of error when 'base' is from the edit list...
r29887 raise error.ParseError(
msg % (self.verb, node.short(self.node)),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hint=_(b'base must only use unlisted changesets'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
@action(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'_multifold'],
Augie Fackler
formatting: blacken the codebase...
r43346 _(
"""fold subclass used for when multiple folds happen in a row
Augie Fackler
histedit: use one editor when multiple folds happen in a row (issue3524) (BC)...
r26246
We only want to fire the editor for the folded message once when
(say) four changes are folded down into a single change. This is
similar to rollup, but we should preserve both messages so that
when the last fold operation runs we can show the user all the
commit messages in their editor.
Augie Fackler
formatting: blacken the codebase...
r43346 """
),
internal=True,
)
timeless
histedit: replace @addhisteditaction with @action...
r27675 class _multifold(fold):
Augie Fackler
histedit: use one editor when multiple folds happen in a row (issue3524) (BC)...
r26246 def skipprompt(self):
return True
Augie Fackler
formatting: blacken the codebase...
r43346
@action(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"roll", b"r"],
_(b"like fold, but discard this commit's description and date"),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Durham Goode
histedit: convert fold/roll actions into a class...
r24771 class rollup(fold):
Augie Fackler
histedit: use one editor when multiple folds happen in a row (issue3524) (BC)...
r26246 def mergedescs(self):
return False
Durham Goode
histedit: improve roll action integration with fold...
r24773 def skipprompt(self):
return True
Augie Fackler
histedit: new extension for interactive history editing
r17064
Ben Schmidt
histedit: modify rollup to discard date from the rollup commit (issue4820)...
r31056 def firstdate(self):
return True
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @action([b"drop", b"d"], _(b'remove commit from history'))
Durham Goode
histedit: convert drop action into a class...
r24768 class drop(histeditaction):
def run(self):
parentctx = self.repo[self.state.parentctxnode]
return parentctx, [(self.node, tuple())]
Augie Fackler
histedit: new extension for interactive history editing
r17064
Augie Fackler
formatting: blacken the codebase...
r43346
@action(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"mess", b"m"],
_(b'edit commit message without changing commit content'),
Augie Fackler
formatting: blacken the codebase...
r43346 priority=True,
)
Durham Goode
histedit: convert message action into a class...
r24769 class message(histeditaction):
def commiteditor(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return cmdutil.getcommiteditor(edit=True, editform=b'histedit.mess')
Augie Fackler
histedit: new extension for interactive history editing
r17064
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
histedit: remove a mutable default argument...
r26335 def findoutgoing(ui, repo, remote=None, force=False, opts=None):
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 """utility function to find the first outgoing changeset
timeless@mozdev.org
histedit: fix English (en-US)
r26171 Used by initialization code"""
Pierre-Yves David
histedit: remove a mutable default argument...
r26335 if opts is None:
opts = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 dest = ui.expandpath(remote or b'default-push', remote or b'default')
Martin von Zweigbergk
parseurl: consistently call second output "branches"...
r37278 dest, branches = hg.parseurl(dest, None)[:2]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b'comparing with %s\n') % util.hidepassword(dest))
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021
Martin von Zweigbergk
parseurl: consistently call second output "branches"...
r37278 revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 other = hg.peer(repo, opts, dest)
if revs:
revs = [repo.lookup(rev) for rev in revs]
outgoing = discovery.findcommonoutgoing(repo, other, revs, force=force)
if not outgoing.missing:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'no outgoing ancestors'))
roots = list(repo.revs(b"roots(%ln)", outgoing.missing))
Martin von Zweigbergk
cleanup: some Yoda conditions, this patch removes...
r40065 if len(roots) > 1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = _(b'there are ambiguous outgoing revisions')
hint = _(b"see 'hg help histedit' for more detail")
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(msg, hint=hint)
Martin von Zweigbergk
histedit: avoid repo.lookup() for converting revnum to nodeid...
r37330 return repo[roots[0]].node()
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 # Curses Support
try:
import curses
except ImportError:
curses = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 KEY_LIST = [b'pick', b'edit', b'fold', b'drop', b'mess', b'roll']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 ACTION_LABELS = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'fold': b'^fold',
b'roll': b'^roll',
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 }
Augie Fackler
formatting: blacken the codebase...
r43346 COLOR_HELP, COLOR_SELECTED, COLOR_OK, COLOR_WARN, COLOR_CURRENT = 1, 2, 3, 4, 5
Jordi Gutiérrez Hermoso
chistedit: add basic colours to diff view...
r42258 COLOR_DIFF_ADD_LINE, COLOR_DIFF_DEL_LINE, COLOR_DIFF_OFFSET = 6, 7, 8
Jordi Gutiérrez Hermoso
histedit: define new colour pairs for roll action...
r44062 COLOR_ROLL, COLOR_ROLL_CURRENT, COLOR_ROLL_SELECTED = 9, 10, 11
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
E_QUIT, E_HISTEDIT = 1, 2
E_PAGEDOWN, E_PAGEUP, E_LINEUP, E_LINEDOWN, E_RESIZE = 3, 4, 5, 6, 7
MODE_INIT, MODE_PATCH, MODE_RULES, MODE_HELP = 0, 1, 2, 3
KEYTABLE = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'global': {
b'h': b'next-action',
b'KEY_RIGHT': b'next-action',
b'l': b'prev-action',
b'KEY_LEFT': b'prev-action',
b'q': b'quit',
b'c': b'histedit',
b'C': b'histedit',
b'v': b'showpatch',
b'?': b'help',
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 },
MODE_RULES: {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'd': b'action-drop',
b'e': b'action-edit',
b'f': b'action-fold',
b'm': b'action-mess',
b'p': b'action-pick',
b'r': b'action-roll',
b' ': b'select',
b'j': b'down',
b'k': b'up',
b'KEY_DOWN': b'down',
b'KEY_UP': b'up',
b'J': b'move-down',
b'K': b'move-up',
b'KEY_NPAGE': b'move-down',
b'KEY_PPAGE': b'move-up',
b'0': b'goto', # Used for 0..9
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 },
MODE_PATCH: {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' ': b'page-down',
b'KEY_NPAGE': b'page-down',
b'KEY_PPAGE': b'page-up',
b'j': b'line-down',
b'k': b'line-up',
b'KEY_DOWN': b'line-down',
b'KEY_UP': b'line-up',
b'J': b'down',
b'K': b'up',
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 },
Augie Fackler
formatting: blacken the codebase...
r43346 MODE_HELP: {},
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 }
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def screen_size():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return struct.unpack(b'hh', fcntl.ioctl(1, termios.TIOCGWINSZ, b' '))
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 class histeditrule(object):
Kyle Lippincott
chistedit: support histedit.summary-template in curses histedit plan...
r45057 def __init__(self, ui, ctx, pos, action=b'pick'):
self.ui = ui
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 self.ctx = ctx
self.action = action
self.origpos = pos
self.pos = pos
self.conflicts = []
Martin von Zweigbergk
py3: make chistedit render...
r43685 def __bytes__(self):
Jordi Gutiérrez Hermoso
histeditrule: split __bytes__ property into prefix and desc...
r44061 # Example display of several histeditrules:
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 #
# #10 pick 316392:06a16c25c053 add option to skip tests
Jordi Gutiérrez Hermoso
histeditrule: split __bytes__ property into prefix and desc...
r44061 # #11 ^roll 316393:71313c964cc5 <RED>oops a fixup commit</RED>
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 # #12 pick 316394:ab31f3973b0d include mfbt for mozilla-config.h
# #13 ^fold 316395:14ce5803f4c3 fix warnings
#
# The carets point to the changeset being folded into ("roll this
# changeset into the changeset above").
Jordi Gutiérrez Hermoso
histeditrule: split __bytes__ property into prefix and desc...
r44061 return b'%s%s' % (self.prefix, self.desc)
__str__ = encoding.strmethod(__bytes__)
@property
def prefix(self):
# Some actions ('fold' and 'roll') combine a patch with a
# previous one. Add a marker showing which patch they apply
# to.
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 action = ACTION_LABELS.get(self.action, self.action)
Jordi Gutiérrez Hermoso
histeditrule: split __bytes__ property into prefix and desc...
r44061
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 h = self.ctx.hex()[0:12]
r = self.ctx.rev()
Jordi Gutiérrez Hermoso
histeditrule: split __bytes__ property into prefix and desc...
r44061
return b"#%s %s %d:%s " % (
Martin von Zweigbergk
py3: make chistedit render...
r43685 (b'%d' % self.origpos).ljust(2),
action.ljust(6),
r,
h,
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
Jordi Gutiérrez Hermoso
histeditrule: split __bytes__ property into prefix and desc...
r44061 @property
def desc(self):
Kyle Lippincott
chistedit: support histedit.summary-template in curses histedit plan...
r45057 summary = (
cmdutil.rendertemplate(
self.ctx, self.ui.config(b'histedit', b'summary-template')
)
or b''
)
if summary:
return summary
Jordi Gutiérrez Hermoso
histeditrule: split __bytes__ property into prefix and desc...
r44061 # This is split off from the prefix property so that we can
# separately make the description for 'roll' red (since it
# will get discarded).
return self.ctx.description().splitlines()[0].strip()
Martin von Zweigbergk
py3: make chistedit render...
r43685
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def checkconflicts(self, other):
if other.pos > self.pos and other.origpos <= self.origpos:
if set(other.ctx.files()) & set(self.ctx.files()) != set():
self.conflicts.append(other)
return self.conflicts
if other in self.conflicts:
self.conflicts.remove(other)
return self.conflicts
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 # ============ EVENTS ===============
def movecursor(state, oldpos, newpos):
'''Change the rule/changeset that the cursor is pointing to, regardless of
current mode (you can switch between patches from the view patch window).'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 state[b'pos'] = newpos
mode, _ = state[b'mode']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 if mode == MODE_RULES:
# Scroll through the list by updating the view for MODE_RULES, so that
# even if we are not currently viewing the rules, switching back will
# result in the cursor's rule being visible.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 modestate = state[b'modes'][MODE_RULES]
if newpos < modestate[b'line_offset']:
modestate[b'line_offset'] = newpos
elif newpos > modestate[b'line_offset'] + state[b'page_height'] - 1:
modestate[b'line_offset'] = newpos - state[b'page_height'] + 1
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
# Reset the patch view region to the top of the new patch.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 state[b'modes'][MODE_PATCH][b'line_offset'] = 0
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def changemode(state, mode):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 curmode, _ = state[b'mode']
state[b'mode'] = (mode, curmode)
feyu@google.com
histedit: Speed up scrolling in patch view mode...
r42419 if mode == MODE_PATCH:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 state[b'modes'][MODE_PATCH][b'patchcontents'] = patchcontents(state)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def makeselection(state, pos):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 state[b'selected'] = pos
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def swap(state, oldpos, newpos):
"""Swap two positions and calculate necessary conflicts in
O(|newpos-oldpos|) time"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rules = state[b'rules']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 assert 0 <= oldpos < len(rules) and 0 <= newpos < len(rules)
rules[oldpos], rules[newpos] = rules[newpos], rules[oldpos]
# TODO: swap should not know about histeditrule's internals
rules[newpos].pos = newpos
rules[oldpos].pos = oldpos
start = min(oldpos, newpos)
end = max(oldpos, newpos)
for r in pycompat.xrange(start, end + 1):
rules[newpos].checkconflicts(rules[r])
rules[oldpos].checkconflicts(rules[r])
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if state[b'selected']:
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 makeselection(state, newpos)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def changeaction(state, pos, action):
"""Change the action state on the given position to the new action"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rules = state[b'rules']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 assert 0 <= pos < len(rules)
rules[pos].action = action
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def cycleaction(state, pos, next=False):
"""Changes the action state the next or the previous action from
the action list"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rules = state[b'rules']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 assert 0 <= pos < len(rules)
current = rules[pos].action
assert current in KEY_LIST
index = KEY_LIST.index(current)
if next:
index += 1
else:
index -= 1
changeaction(state, pos, KEY_LIST[index % len(KEY_LIST)])
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def changeview(state, delta, unit):
'''Change the region of whatever is being viewed (a patch or the list of
changesets). 'delta' is an amount (+/- 1) and 'unit' is 'page' or 'line'.'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mode, _ = state[b'mode']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 if mode != MODE_PATCH:
return
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mode_state = state[b'modes'][mode]
num_lines = len(mode_state[b'patchcontents'])
page_height = state[b'page_height']
unit = page_height if unit == b'page' else 1
Martin von Zweigbergk
py3: use integer division in histedit...
r45092 num_pages = 1 + (num_lines - 1) // page_height
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 max_offset = (num_pages - 1) * page_height
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 newline = mode_state[b'line_offset'] + delta * unit
mode_state[b'line_offset'] = max(0, min(max_offset, newline))
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def event(state, ch):
"""Change state based on the current character input
This takes the current state and based on the current character input from
the user we change the state.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 selected = state[b'selected']
oldpos = state[b'pos']
rules = state[b'rules']
if ch in (curses.KEY_RESIZE, b"KEY_RESIZE"):
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return E_RESIZE
lookup_ch = ch
Denis Laxalde
py3: prevent comparison with None in curses histedit (issue6196)
r43502 if ch is not None and b'0' <= ch <= b'9':
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lookup_ch = b'0'
curmode, prevmode = state[b'mode']
action = KEYTABLE[curmode].get(
lookup_ch, KEYTABLE[b'global'].get(lookup_ch)
)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 if action is None:
return
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if action in (b'down', b'move-down'):
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 newpos = min(oldpos + 1, len(rules) - 1)
movecursor(state, oldpos, newpos)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if selected is not None or action == b'move-down':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 swap(state, oldpos, newpos)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action in (b'up', b'move-up'):
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 newpos = max(0, oldpos - 1)
movecursor(state, oldpos, newpos)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if selected is not None or action == b'move-up':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 swap(state, oldpos, newpos)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'next-action':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 cycleaction(state, oldpos, next=True)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'prev-action':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 cycleaction(state, oldpos, next=False)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'select':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 selected = oldpos if selected is None else None
makeselection(state, selected)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10:
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 newrule = next((r for r in rules if r.origpos == int(ch)))
movecursor(state, oldpos, newrule.pos)
if selected is not None:
swap(state, oldpos, newrule.pos)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action.startswith(b'action-'):
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 changeaction(state, oldpos, action[7:])
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'showpatch':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 changemode(state, MODE_PATCH if curmode != MODE_PATCH else prevmode)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'help':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 changemode(state, MODE_HELP if curmode != MODE_HELP else prevmode)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'quit':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return E_QUIT
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'histedit':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return E_HISTEDIT
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'page-down':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return E_PAGEDOWN
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'page-up':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return E_PAGEUP
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'line-down':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return E_LINEDOWN
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'line-up':
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return E_LINEUP
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def makecommands(rules):
"""Returns a list of commands consumable by histedit --commands based on
our list of rules"""
commands = []
for rules in rules:
Martin von Zweigbergk
py3: avoid another b''.format() in chistedit...
r43688 commands.append(b'%s %s\n' % (rules.action, rules.ctx))
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return commands
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def addln(win, y, x, line, color=None):
"""Add a line to the given window left padding but 100% filled with
whitespace characters, so that the color appears on the whole line"""
maxy, maxx = win.getmaxyx()
length = maxx - 1 - x
Martin von Zweigbergk
py3: make chistedit render...
r43685 line = bytes(line).ljust(length)[:length]
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 if y < 0:
y = maxy + y
if x < 0:
x = maxx + x
if color:
win.addstr(y, x, line, color)
else:
win.addstr(y, x, line)
Augie Fackler
formatting: blacken the codebase...
r43346
Yu Feng
histedit: Show file names in multiple line format
r42418 def _trunc_head(line, n):
if len(line) <= n:
return line
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'> ' + line[-(n - 2) :]
Augie Fackler
formatting: blacken the codebase...
r43346
Yu Feng
histedit: Show file names in multiple line format
r42418 def _trunc_tail(line, n):
if len(line) <= n:
return line
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return line[: n - 2] + b' >'
Augie Fackler
formatting: blacken the codebase...
r43346
Yu Feng
histedit: Show file names in multiple line format
r42418
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def patchcontents(state):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = state[b'repo']
rule = state[b'rules'][state[b'pos']]
Augie Fackler
formatting: blacken the codebase...
r43346 displayer = logcmdutil.changesetdisplayer(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo.ui, repo, {b"patch": True, b"template": b"status"}, buffered=True
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 overrides = {(b'ui', b'verbose'): True}
with repo.ui.configoverride(overrides, source=b'histedit'):
Jordi Gutiérrez Hermoso
chistedit: use context manager to set verbose ui...
r42336 displayer.show(rule.ctx)
displayer.close()
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return displayer.hunk[rule.ctx.rev()].splitlines()
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 def _chisteditmain(repo, rules, stdscr):
Jordi Gutiérrez Hermoso
chistedit: use default curses colours...
r42257 try:
curses.use_default_colors()
except curses.error:
pass
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 # initialize color pattern
curses.init_pair(COLOR_HELP, curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(COLOR_SELECTED, curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(COLOR_WARN, curses.COLOR_BLACK, curses.COLOR_YELLOW)
curses.init_pair(COLOR_OK, curses.COLOR_BLACK, curses.COLOR_GREEN)
Jordi Gutiérrez Hermoso
chistedit: use magenta for current line as in crecord (issue6071)...
r41851 curses.init_pair(COLOR_CURRENT, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
Jordi Gutiérrez Hermoso
chistedit: add basic colours to diff view...
r42258 curses.init_pair(COLOR_DIFF_ADD_LINE, curses.COLOR_GREEN, -1)
curses.init_pair(COLOR_DIFF_DEL_LINE, curses.COLOR_RED, -1)
curses.init_pair(COLOR_DIFF_OFFSET, curses.COLOR_MAGENTA, -1)
Jordi Gutiérrez Hermoso
histedit: define new colour pairs for roll action...
r44062 curses.init_pair(COLOR_ROLL, curses.COLOR_RED, -1)
curses.init_pair(
COLOR_ROLL_CURRENT, curses.COLOR_BLACK, curses.COLOR_MAGENTA
)
curses.init_pair(COLOR_ROLL_SELECTED, curses.COLOR_RED, curses.COLOR_WHITE)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
# don't display the cursor
try:
curses.curs_set(0)
except curses.error:
pass
def rendercommit(win, state):
"""Renders the commit window that shows the log of the current selected
commit"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 pos = state[b'pos']
rules = state[b'rules']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 rule = rules[pos]
ctx = rule.ctx
win.box()
maxy, maxx = win.getmaxyx()
length = maxx - 3
Martin von Zweigbergk
histedit: restore hex nodeids to be 12 digits long...
r43693 line = b"changeset: %d:%s" % (ctx.rev(), ctx.hex()[:12])
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 win.addstr(1, 1, line[:length])
Martin von Zweigbergk
py3: make chistedit render...
r43685 line = b"user: %s" % ctx.user()
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 win.addstr(2, 1, line[:length])
bms = repo.nodebookmarks(ctx.node())
Martin von Zweigbergk
py3: make chistedit render...
r43685 line = b"bookmark: %s" % b' '.join(bms)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 win.addstr(3, 1, line[:length])
Martin von Zweigbergk
py3: make chistedit render...
r43685 line = b"summary: %s" % (ctx.description().splitlines()[0])
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 win.addstr(4, 1, line[:length])
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 line = b"files: "
Yu Feng
histedit: Show file names in multiple line format
r42418 win.addstr(5, 1, line)
fnx = 1 + len(line)
fnmaxx = length - fnx + 1
y = 5
fnmaxn = maxy - (1 + y) - 1
files = ctx.files()
for i, line1 in enumerate(files):
if len(files) > fnmaxn and i == fnmaxn - 1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 win.addstr(y, fnx, _trunc_tail(b','.join(files[i:]), fnmaxx))
Yu Feng
histedit: Show file names in multiple line format
r42418 y = y + 1
break
win.addstr(y, fnx, _trunc_head(line1, fnmaxx))
y = y + 1
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
conflicts = rule.conflicts
if len(conflicts) > 0:
Martin von Zweigbergk
histedit: restore hex nodeids to be 12 digits long...
r43693 conflictstr = b','.join(map(lambda r: r.ctx.hex()[:12], conflicts))
Martin von Zweigbergk
py3: make chistedit render...
r43685 conflictstr = b"changed files overlap with %s" % conflictstr
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 conflictstr = b'no overlap'
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
Yu Feng
histedit: Show file names in multiple line format
r42418 win.addstr(y, 1, conflictstr[:length])
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 win.noutrefresh()
def helplines(mode):
if mode == MODE_PATCH:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 help = b"""\
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 ?: help, k/up: line up, j/down: line down, v: stop viewing patch
pgup: prev page, space/pgdn: next page, c: commit, q: abort
"""
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 help = b"""\
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 ?: help, k/up: move up, j/down: move down, space: select, v: view patch
d: drop, e: edit, f: fold, m: mess, p: pick, r: roll
pgup/K: move patch up, pgdn/J: move patch down, c: commit, q: abort
"""
return help.splitlines()
def renderhelp(win, state):
maxy, maxx = win.getmaxyx()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mode, _ = state[b'mode']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 for y, line in enumerate(helplines(mode)):
if y >= maxy:
break
addln(win, y, 0, line, curses.color_pair(COLOR_HELP))
win.noutrefresh()
def renderrules(rulesscr, state):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rules = state[b'rules']
pos = state[b'pos']
selected = state[b'selected']
start = state[b'modes'][MODE_RULES][b'line_offset']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
conflicts = [r.ctx for r in rules if r.conflicts]
if len(conflicts) > 0:
Martin von Zweigbergk
py3: render message about conflicts in chistedit code...
r43687 line = b"potential conflict in %s" % b','.join(
map(pycompat.bytestr, conflicts)
)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 addln(rulesscr, -1, 0, line, curses.color_pair(COLOR_WARN))
for y, rule in enumerate(rules[start:]):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if y >= state[b'page_height']:
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 break
if len(rule.conflicts) > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rulesscr.addstr(y, 0, b" ", curses.color_pair(COLOR_WARN))
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rulesscr.addstr(y, 0, b" ", curses.COLOR_BLACK)
Jordi Gutiérrez Hermoso
histedit: render a rolled up description using the proper roll colours...
r44063
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 if y + start == selected:
Jordi Gutiérrez Hermoso
histedit: render a rolled up description using the proper roll colours...
r44063 rollcolor = COLOR_ROLL_SELECTED
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 addln(rulesscr, y, 2, rule, curses.color_pair(COLOR_SELECTED))
elif y + start == pos:
Jordi Gutiérrez Hermoso
histedit: render a rolled up description using the proper roll colours...
r44063 rollcolor = COLOR_ROLL_CURRENT
Augie Fackler
formatting: blacken the codebase...
r43346 addln(
rulesscr,
y,
2,
rule,
curses.color_pair(COLOR_CURRENT) | curses.A_BOLD,
)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 else:
Jordi Gutiérrez Hermoso
histedit: render a rolled up description using the proper roll colours...
r44063 rollcolor = COLOR_ROLL
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 addln(rulesscr, y, 2, rule)
Jordi Gutiérrez Hermoso
histedit: render a rolled up description using the proper roll colours...
r44063
if rule.action == b'roll':
rulesscr.addstr(
y,
2 + len(rule.prefix),
rule.desc,
curses.color_pair(rollcolor),
)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 rulesscr.noutrefresh()
Jordi Gutiérrez Hermoso
chistedit: add basic colours to diff view...
r42258 def renderstring(win, state, output, diffcolors=False):
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 maxy, maxx = win.getmaxyx()
length = min(maxy - 1, len(output))
for y in range(0, length):
Jordi Gutiérrez Hermoso
chistedit: add basic colours to diff view...
r42258 line = output[y]
if diffcolors:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if line and line[0] == b'+':
Jordi Gutiérrez Hermoso
chistedit: add basic colours to diff view...
r42258 win.addstr(
Augie Fackler
formatting: blacken the codebase...
r43346 y, 0, line, curses.color_pair(COLOR_DIFF_ADD_LINE)
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif line and line[0] == b'-':
Jordi Gutiérrez Hermoso
chistedit: add basic colours to diff view...
r42258 win.addstr(
Augie Fackler
formatting: blacken the codebase...
r43346 y, 0, line, curses.color_pair(COLOR_DIFF_DEL_LINE)
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif line.startswith(b'@@ '):
Augie Fackler
formatting: blacken the codebase...
r43346 win.addstr(y, 0, line, curses.color_pair(COLOR_DIFF_OFFSET))
Jordi Gutiérrez Hermoso
chistedit: add basic colours to diff view...
r42258 else:
win.addstr(y, 0, line)
else:
win.addstr(y, 0, line)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 win.noutrefresh()
def renderpatch(win, state):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 start = state[b'modes'][MODE_PATCH][b'line_offset']
content = state[b'modes'][MODE_PATCH][b'patchcontents']
feyu@google.com
histedit: Speed up scrolling in patch view mode...
r42419 renderstring(win, state, content[start:], diffcolors=True)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
def layout(mode):
maxy, maxx = stdscr.getmaxyx()
helplen = len(helplines(mode))
return {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'commit': (12, maxx),
b'help': (helplen, maxx),
b'main': (maxy - helplen - 12, maxx),
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 }
def drawvertwin(size, y, x):
win = curses.newwin(size[0], size[1], y, x)
y += size[0]
return win, y, x
state = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'pos': 0,
b'rules': rules,
b'selected': None,
b'mode': (MODE_INIT, MODE_INIT),
b'page_height': None,
b'modes': {
MODE_RULES: {b'line_offset': 0,},
MODE_PATCH: {b'line_offset': 0,},
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 },
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'repo': repo,
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 }
# eventloop
ch = None
stdscr.clear()
stdscr.refresh()
while True:
try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 oldmode, _ = state[b'mode']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 if oldmode == MODE_INIT:
changemode(state, MODE_RULES)
e = event(state, ch)
if e == E_QUIT:
return False
if e == E_HISTEDIT:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return state[b'rules']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 else:
if e == E_RESIZE:
size = screen_size()
if size != stdscr.getmaxyx():
curses.resizeterm(*size)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 curmode, _ = state[b'mode']
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 sizes = layout(curmode)
if curmode != oldmode:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 state[b'page_height'] = sizes[b'main'][0]
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 # Adjust the view to fit the current screen size.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 movecursor(state, state[b'pos'], state[b'pos'])
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
# Pack the windows against the top, each pane spread across the
# full width of the screen.
y, x = (0, 0)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 helpwin, y, x = drawvertwin(sizes[b'help'], y, x)
mainwin, y, x = drawvertwin(sizes[b'main'], y, x)
commitwin, y, x = drawvertwin(sizes[b'commit'], y, x)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
if e in (E_PAGEDOWN, E_PAGEUP, E_LINEDOWN, E_LINEUP):
if e == E_PAGEDOWN:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 changeview(state, +1, b'page')
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 elif e == E_PAGEUP:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 changeview(state, -1, b'page')
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 elif e == E_LINEDOWN:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 changeview(state, +1, b'line')
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 elif e == E_LINEUP:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 changeview(state, -1, b'line')
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
# start rendering
commitwin.erase()
helpwin.erase()
mainwin.erase()
if curmode == MODE_PATCH:
renderpatch(mainwin, state)
elif curmode == MODE_HELP:
renderstring(mainwin, state, __doc__.strip().splitlines())
else:
renderrules(mainwin, state)
rendercommit(commitwin, state)
renderhelp(helpwin, state)
curses.doupdate()
# done rendering
Martin von Zweigbergk
py3: handle keypresses in chistedit...
r43686 ch = encoding.strtolocal(stdscr.getkey())
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 except curses.error:
pass
Augie Fackler
formatting: blacken the codebase...
r43346
Steve Fink
histedit: py3 fixes for curses mode...
r44892 def _chistedit(ui, repo, freeargs, opts):
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 """interactively edit changeset history via a curses interface
Provides a ncurses interface to histedit. Press ? in chistedit mode
to see an extensive help. Requires python-curses to be installed."""
if curses is None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b"Python curses library required"))
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
# disable color
ui._colormode = None
try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 keep = opts.get(b'keep')
revs = opts.get(b'rev', [])[:]
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 cmdutil.checkunfinished(repo)
cmdutil.bailifchanged(repo)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if os.path.exists(os.path.join(repo.path, b'histedit-state')):
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'history edit already in progress, try '
b'--continue or --abort'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 revs.extend(freeargs)
if not revs:
defaultrev = destutil.desthistedit(ui, repo)
if defaultrev is not None:
revs.append(defaultrev)
if len(revs) != 1:
raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'histedit requires exactly one ancestor revision')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rr = list(repo.set(b'roots(%ld)', scmutil.revrange(repo, revs)))
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 if len(rr) != 1:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'The specified revisions must have '
b'exactly one common root'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 root = rr[0].node()
Martin von Zweigbergk
cleanup: use p1() instead of parents() when we only need the first parent...
r41444 topmost = repo.dirstate.p1()
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 revs = between(repo, root, topmost, keep)
if not revs:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'%s is not an ancestor of working directory')
Augie Fackler
formatting: blacken the codebase...
r43346 % node.short(root)
)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638
ctxs = []
for i, r in enumerate(revs):
Kyle Lippincott
chistedit: support histedit.summary-template in curses histedit plan...
r45057 ctxs.append(histeditrule(ui, repo[r], i))
Yuya Nishihara
curses: do not setlocale() at import time (issue5261)...
r42883 # Curses requires setting the locale or it will default to the C
# locale. This sets the locale to the user's default system
# locale.
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 locale.setlocale(locale.LC_ALL, '')
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 rc = curses.wrapper(functools.partial(_chisteditmain, repo, ctxs))
curses.echo()
curses.endwin()
if rc is False:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b"histedit aborted\n"))
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 return 0
if type(rc) is list:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b"performing changes\n"))
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 rules = makecommands(rc)
Martin von Zweigbergk
py3: open chistedit file in binary mode using vfs...
r43689 with repo.vfs(b'chistedit', b'w+') as fp:
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 for r in rules:
fp.write(r)
Steve Fink
histedit: py3 fixes for curses mode...
r44892 opts[b'commands'] = fp.name
return _texthistedit(ui, repo, freeargs, opts)
Augie Fackler
histedit: import chistedit curses UI from hg-experimental...
r40638 except KeyboardInterrupt:
pass
return -1
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'histedit',
Augie Fackler
formatting: blacken the codebase...
r43346 [
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'commands',
b'',
_(b'read history edits from the specified file'),
_(b'FILE'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'c', b'continue', False, _(b'continue an edit already in progress')),
(b'', b'edit-plan', False, _(b'edit remaining actions list')),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'k',
b'keep',
Augie Fackler
formatting: blacken the codebase...
r43346 False,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"don't strip old nodes after edit is complete"),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'', b'abort', False, _(b'abort an edit in progress')),
(b'o', b'outgoing', False, _(b'changesets not found in destination')),
(
b'f',
b'force',
False,
_(b'force outgoing even for unrelated repositories'),
),
(b'r', b'rev', [], _(b'first revision to be edited'), _(b'REV')),
Augie Fackler
formatting: blacken the codebase...
r43346 ]
+ cmdutil.formatteropts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"[OPTIONS] ([ANCESTOR] | --outgoing [URL])"),
Augie Fackler
formatting: blacken the codebase...
r43346 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
)
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 def histedit(ui, repo, *freeargs, **opts):
Augie Fackler
histedit: add extension docstring from external README...
r17131 """interactively edit changeset history
FUJIWARA Katsunori
histedit: add description about basic histedit function to command help...
r19621
timeless
histedit: explain basics of histedit commands...
r27713 This command lets you edit a linear series of changesets (up to
and including the working directory, which should be clean).
FUJIWARA Katsunori
doc: prevent non-literal text block from being treated as literal one...
r27956 You can:
timeless
histedit: explain basics of histedit commands...
r27713
- `pick` to [re]order a changeset
- `drop` to omit changeset
- `mess` to reword the changeset commit message
Ben Schmidt
histedit: improve documentation and behaviour of dates...
r31055 - `fold` to combine it with the preceding changeset (using the later date)
timeless
histedit: explain basics of histedit commands...
r27713
Ben Schmidt
histedit: modify rollup to discard date from the rollup commit (issue4820)...
r31056 - `roll` like fold, but discarding this commit's description and date
timeless
histedit: explain basics of histedit commands...
r27713
Ben Schmidt
histedit: improve documentation and behaviour of dates...
r31055 - `edit` to edit this changeset (preserving date)
FUJIWARA Katsunori
histedit: add description about "histedit --outgoing" to command help...
r19622
Saurabh Singh
histedit: removing the experimental config 'histeditng'...
r34490 - `base` to checkout changeset and apply further changesets from there
Wagner Bruna
histedit: fix typo in documentation
r27972 There are a number of ways to select the root changeset:
timeless
histedit: clarify modes...
r27714
- Specify ANCESTOR directly
Gregory Szorc
histedit: pick an appropriate base changeset by default (BC)...
r27262
timeless
histedit: clarify modes...
r27714 - Use --outgoing -- it will be the first linear changeset not
FUJIWARA Katsunori
doc: describe full help document hierarchy to create a valid link in HTML...
r28077 included in destination. (See :hg:`help config.paths.default-push`)
timeless
histedit: clarify modes...
r27714
- Otherwise, the value from the "histedit.defaultrev" config option
is used as a revset to select the base revision when ANCESTOR is not
specified. The first revision returned by the revset is used. By
default, this selects the editable history that is unique to the
ancestry of the working directory.
FUJIWARA Katsunori
histedit: add more detailed help about "--outgoing"
r19842
timeless
histedit: hide --outgoing warnings
r27630 .. container:: verbose
FUJIWARA Katsunori
histedit: add more detailed help about "--outgoing"
r19842
timeless
histedit: hide --outgoing warnings
r27630 If you use --outgoing, this command will abort if there are ambiguous
outgoing revisions. For example, if there are multiple branches
containing outgoing revisions.
Use "min(outgoing() and ::.)" or similar revset specification
instead of --outgoing to specify edit target revision exactly in
such ambiguous situation. See :hg:`help revsets` for detail about
selecting revisions.
FUJIWARA Katsunori
histedit: add description about exit code
r19972
Mathias De Maré
histedit: add examples
r27145 .. container:: verbose
Examples:
- A number of changes have been made.
Revision 3 is no longer needed.
Start history editing from revision 3::
hg histedit -r 3
An editor opens, containing the list of revisions,
with specific actions specified::
pick 5339bf82f0ca 3 Zworgle the foobar
pick 8ef592ce7cc4 4 Bedazzle the zerlog
pick 0a9639fcda9d 5 Morgify the cromulancy
Additional information about the possible actions
to take appears below the list of revisions.
To remove revision 3 from the history,
its action (at the beginning of the relevant line)
is changed to 'drop'::
drop 5339bf82f0ca 3 Zworgle the foobar
pick 8ef592ce7cc4 4 Bedazzle the zerlog
pick 0a9639fcda9d 5 Morgify the cromulancy
- A number of changes have been made.
Revision 2 and 4 need to be swapped.
Start history editing from revision 2::
hg histedit -r 2
An editor opens, containing the list of revisions,
with specific actions specified::
pick 252a1af424ad 2 Blorb a morgwazzle
pick 5339bf82f0ca 3 Zworgle the foobar
pick 8ef592ce7cc4 4 Bedazzle the zerlog
To swap revision 2 and 4, its lines are swapped
in the editor::
pick 8ef592ce7cc4 4 Bedazzle the zerlog
pick 5339bf82f0ca 3 Zworgle the foobar
pick 252a1af424ad 2 Blorb a morgwazzle
FUJIWARA Katsunori
histedit: add description about exit code
r19972 Returns 0 on success, 1 if user intervention is required (not only
for intentional "edit" command, but also for resolving unexpected
conflicts).
Augie Fackler
histedit: new extension for interactive history editing
r17064 """
Steve Fink
histedit: py3 fixes for curses mode...
r44892 opts = pycompat.byteskwargs(opts)
Augie Fackler
histedit: fix --continue and --abort when curses is enabled...
r41211 # kludge: _chistedit only works for starting an edit, not aborting
# or continuing, so fall back to regular _texthistedit for those
# operations.
Martin von Zweigbergk
histedit: fix formatting after D8150...
r44925 if ui.interface(b'histedit') == b'curses' and _getgoal(opts) == goalnew:
Steve Fink
histedit: py3 fixes for curses mode...
r44892 return _chistedit(ui, repo, freeargs, opts)
return _texthistedit(ui, repo, freeargs, opts)
def _texthistedit(ui, repo, freeargs, opts):
David Soria Parra
histedit: move locks into state...
r22984 state = histeditstate(repo)
Martin von Zweigbergk
histedit: use context manager for locks...
r41201 with repo.wlock() as wlock, repo.lock() as lock:
state.wlock = wlock
state.lock = lock
Steve Fink
histedit: py3 fixes for curses mode...
r44892 _histedit(ui, repo, state, freeargs, opts)
Siddharth Agarwal
histedit: hold wlock and lock while in progress...
r20071
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 goalcontinue = b'continue'
goalabort = b'abort'
goaleditplan = b'edit-plan'
goalnew = b'new'
Kostia Balytskyi
histedit: change string literals to constants in goal naming...
r28144
Augie Fackler
formatting: blacken the codebase...
r43346
Kostia Balytskyi
histedit: break _histedit function into smaller pieces...
r28134 def _getgoal(opts):
Augie Fackler
histedit: fix call to _getgoal() by adding a byteskwargs() wrapper...
r41259 if opts.get(b'continue'):
Kostia Balytskyi
histedit: change string literals to constants in goal naming...
r28144 return goalcontinue
Augie Fackler
histedit: fix call to _getgoal() by adding a byteskwargs() wrapper...
r41259 if opts.get(b'abort'):
Kostia Balytskyi
histedit: change string literals to constants in goal naming...
r28144 return goalabort
Augie Fackler
histedit: fix call to _getgoal() by adding a byteskwargs() wrapper...
r41259 if opts.get(b'edit_plan'):
Kostia Balytskyi
histedit: change string literals to constants in goal naming...
r28144 return goaleditplan
return goalnew
Kostia Balytskyi
histedit: break _histedit function into smaller pieces...
r28134
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
histedit: use ui.fin to read commands from stdin...
r30262 def _readfile(ui, path):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if path == b'-':
with ui.timeblockedsection(b'histedit'):
Simon Farnsworth
histedit: log the time taken to read in the commands list...
r30983 return ui.fin.read()
Jun Wu
histedit: do not close stdin...
r28550 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with open(path, b'rb') as f:
Jun Wu
histedit: do not close stdin...
r28550 return f.read()
Augie Fackler
formatting: blacken the codebase...
r43346
Kostia Balytskyi
histedit: break _histedit function into smaller pieces...
r28134 def _validateargs(ui, repo, state, freeargs, opts, goal, rules, revs):
timeless
histedit: improve grammar for _histedit comment
r27169 # TODO only abort if we try to histedit mq patches, not just
Augie Fackler
histedit: new extension for interactive history editing
r17064 # blanket if mq patches are applied somewhere
mq = getattr(repo, 'mq', None)
if mq and mq.applied:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'source has mq patches applied'))
Augie Fackler
histedit: new extension for interactive history editing
r17064
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 # basic argument incompatibility processing
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 outg = opts.get(b'outgoing')
editplan = opts.get(b'edit_plan')
abort = opts.get(b'abort')
force = opts.get(b'force')
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 if force and not outg:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'--force only allowed with --outgoing'))
if goal == b'continue':
Augie Fackler
cleanup: use __builtins__.any instead of util.any...
r25149 if any((outg, abort, revs, freeargs, rules, editplan)):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'no arguments allowed with --continue'))
elif goal == b'abort':
Augie Fackler
cleanup: use __builtins__.any instead of util.any...
r25149 if any((outg, revs, freeargs, rules, editplan)):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'no arguments allowed with --abort'))
elif goal == b'edit-plan':
Augie Fackler
cleanup: use __builtins__.any instead of util.any...
r25149 if any((outg, revs, freeargs)):
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'only --commands argument allowed with --edit-plan')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 else:
Martin von Zweigbergk
histedit: avoid repeating name of state file in a few places...
r38822 if state.inprogress():
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'history edit already in progress, try '
b'--continue or --abort'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 if outg:
if revs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'no revisions allowed with --outgoing'))
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 if len(freeargs) > 1:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'only one repo argument allowed with --outgoing')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020 else:
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 revs.extend(freeargs)
Durham Goode
histedit: allow configuring default behavior...
r24009 if len(revs) == 0:
Gregory Szorc
histedit: pick an appropriate base changeset by default (BC)...
r27262 defaultrev = destutil.desthistedit(ui, repo)
if defaultrev is not None:
revs.append(defaultrev)
Pierre-Yves David
histedit: move outgoing processing to its own function...
r19021 if len(revs) != 1:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'histedit requires exactly one ancestor revision')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
histedit: move all arguments checks to the beginning of the command...
r19020
Steve Fink
histedit: py3 fixes for curses mode...
r44892 def _histedit(ui, repo, state, freeargs, opts):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm = ui.formatter(b'histedit', opts)
Pulkit Goyal
histedit: add support to output nodechanges using formatter...
r35124 fm.startitem()
Kostia Balytskyi
histedit: break _histedit function into smaller pieces...
r28134 goal = _getgoal(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revs = opts.get(b'rev', [])
nobackup = not ui.configbool(b'rewrite', b'backup-bundle')
rules = opts.get(b'commands', b'')
state.keep = opts.get(b'keep', False)
Augie Fackler
histedit: new extension for interactive history editing
r17064
Kostia Balytskyi
histedit: break _histedit function into smaller pieces...
r28134 _validateargs(ui, repo, state, freeargs, opts, goal, rules, revs)
David Soria Parra
histedit: use state object where necessary...
r22977
Navaneeth Suresh
histedit: add warning message on editing tagged commits (issue4017)...
r41136 hastags = False
if revs:
revs = scmutil.revrange(repo, revs)
ctxs = [repo[rev] for rev in revs]
for ctx in ctxs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 tags = [tag for tag in ctx.tags() if tag != b'tip']
Navaneeth Suresh
histedit: add warning message on editing tagged commits (issue4017)...
r41136 if not hastags:
hastags = len(tags)
if hastags:
Augie Fackler
formatting: blacken the codebase...
r43346 if ui.promptchoice(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'warning: tags associated with the given'
b' changeset will be lost after histedit.\n'
b'do you want to continue (yN)? $$ &Yes $$ &No'
Augie Fackler
formatting: blacken the codebase...
r43346 ),
default=1,
):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'histedit cancelled\n'))
David Soria Parra
histedit: use state object where necessary...
r22977 # rebuild state
Kostia Balytskyi
histedit: change string literals to constants in goal naming...
r28144 if goal == goalcontinue:
David Soria Parra
histedit: read state from histeditstate...
r22983 state.read()
David Soria Parra
histedit: pass state to boostrapcontinue...
r22980 state = bootstrapcontinue(ui, state, opts)
Kostia Balytskyi
histedit: change string literals to constants in goal naming...
r28144 elif goal == goaleditplan:
Kostia Balytskyi
histedit: renaming parts to which _histedit was split...
r28154 _edithisteditplan(ui, repo, state, rules)
Mateusz Kwapich
histedit: add --edit-plan option to histedit...
r24142 return
Kostia Balytskyi
histedit: change string literals to constants in goal naming...
r28144 elif goal == goalabort:
Sushil khanchi
histedit: add --no-backup option (issue5825)...
r38566 _aborthistedit(ui, repo, state, nobackup=nobackup)
Augie Fackler
histedit: new extension for interactive history editing
r17064 return
else:
Kostia Balytskyi
histedit: change string literals to constants in goal naming...
r28144 # goal == goalnew
Kostia Balytskyi
histedit: renaming parts to which _histedit was split...
r28154 _newhistedit(ui, repo, state, revs, freeargs, opts)
Durham Goode
histedit: store backup file before histedit...
r24757
Kostia Balytskyi
histedit: renaming parts to which _histedit was split...
r28154 _continuehistedit(ui, repo, state)
Pulkit Goyal
histedit: add support to output nodechanges using formatter...
r35124 _finishhistedit(ui, repo, state, fm)
fm.end()
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _continueaction)...
r28133
Augie Fackler
formatting: blacken the codebase...
r43346
Kostia Balytskyi
histedit: renaming parts to which _histedit was split...
r28154 def _continuehistedit(ui, repo, state):
"""This function runs after either:
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _continueaction)...
r28133 - bootstrapcontinue (if the goal is 'continue')
Kostia Balytskyi
histedit: renaming parts to which _histedit was split...
r28154 - _newhistedit (if the goal is 'new')
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _continueaction)...
r28133 """
Augie Fackler
histedit: use one editor when multiple folds happen in a row (issue3524) (BC)...
r26246 # preprocess rules so that we can hide inner folds from the user
# and only show one editor
Mateusz Kwapich
histedit: change state.rules uses to state.actions...
r27207 actions = state.actions[:]
Augie Fackler
formatting: blacken the codebase...
r43346 for idx, (action, nextact) in enumerate(zip(actions, actions[1:] + [None])):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if action.verb == b'fold' and nextact and nextact.verb == b'fold':
Mateusz Kwapich
histedit: change state.rules uses to state.actions...
r27207 state.actions[idx].__class__ = _multifold
Augie Fackler
histedit: use one editor when multiple folds happen in a row (issue3524) (BC)...
r26246
Durham Goode
histedit: add histedit.singletransaction config option...
r31513 # Force an initial state file write, so the user can run --abort/continue
# even if there's an exception before the first transaction serialize.
state.write()
Martin von Zweigbergk
histedit: create transaction outside of try...
r33445
tr = None
# Don't use singletransaction by default since it rolls the entire
# transaction back if an unexpected exception happens (like a
# pretxncommit hook throws, or the user aborts the commit msg editor).
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if ui.configbool(b"histedit", b"singletransaction"):
Martin von Zweigbergk
histedit: create transaction outside of try...
r33445 # Don't use a 'with' for the transaction, since actions may close
# and reopen a transaction. For example, if the action executes an
# external process it may choose to commit the transaction first.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 tr = repo.transaction(b'histedit')
Augie Fackler
formatting: blacken the codebase...
r43346 progress = ui.makeprogress(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"editing"), unit=_(b'changes'), total=len(state.actions)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martin von Zweigbergk
histedit: use progress helper...
r38397 with progress, util.acceptintervention(tr):
Durham Goode
histedit: add histedit.singletransaction config option...
r31513 while state.actions:
Martin von Zweigbergk
histedit: remove transaction from state object...
r33444 state.write(tr=tr)
Durham Goode
histedit: add histedit.singletransaction config option...
r31513 actobj = state.actions[0]
Martin von Zweigbergk
histedit: use progress helper...
r38397 progress.increment(item=actobj.torule())
Augie Fackler
formatting: blacken the codebase...
r43346 ui.debug(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'histedit: processing %s %s\n' % (actobj.verb, actobj.torule())
Augie Fackler
formatting: blacken the codebase...
r43346 )
Durham Goode
histedit: add histedit.singletransaction config option...
r31513 parentctx, replacement_ = actobj.run()
state.parentctxnode = parentctx.node()
state.replacements.extend(replacement_)
state.actions.pop(0)
Mateusz Kwapich
histedit: don't allow to strip nodes which are necessary to continue histedit...
r24111 state.write()
Augie Fackler
histedit: new extension for interactive history editing
r17064
Augie Fackler
formatting: blacken the codebase...
r43346
Pulkit Goyal
histedit: add support to output nodechanges using formatter...
r35124 def _finishhistedit(ui, repo, state, fm):
Kostia Balytskyi
histedit: break _histedit into smaller pieces (add _finishaction)...
r28153 """This action runs when histedit is finishing its session"""
Yuya Nishihara
cleanup: pass in overwrite flag to hg.updaterepo() as named argument...
r38527 hg.updaterepo(repo, state.parentctxnode, overwrite=False)
Augie Fackler
histedit: new extension for interactive history editing
r17064
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 mapping, tmpnodes, created, ntm = processreplacement(state)
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 if mapping:
Gregory Szorc
py3: define and use pycompat.iteritems() for hgext/...
r43375 for prec, succs in pycompat.iteritems(mapping):
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 if not succs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.debug(b'histedit: %s is dropped\n' % node.short(prec))
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 else:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.debug(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'histedit: %s is replaced by %s\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % (node.short(prec), node.short(succs[0]))
)
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 if len(succs) > 1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 m = b'histedit: %s'
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 for n in succs[1:]:
ui.debug(m % node.short(n))
Durham Goode
histedit: fix keep during --continue...
r25330 if not state.keep:
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 if mapping:
Jun Wu
histedit: use scmutil.cleanupnodes (BC)...
r33351 movetopmostbookmarks(repo, state.topmost, ntm)
Pierre-Yves David
histedit: extract bookmark logic in a dedicated function...
r17663 # TODO update mq state
Jun Wu
histedit: unify strip backup files on success (BC)...
r33350 else:
mapping = {}
for n in tmpnodes:
Boris Feld
histedit: don't cleanup nodes already disposed of...
r39950 if n in repo:
mapping[n] = ()
Jun Wu
histedit: unify strip backup files on success (BC)...
r33350
Jun Wu
histedit: use scmutil.cleanupnodes (BC)...
r33351 # remove entries about unknown nodes
index: use `index.has_node` in `histedit._finishhistedit...
r43947 has_node = repo.unfiltered().changelog.index.has_node
Augie Fackler
formatting: blacken the codebase...
r43346 mapping = {
k: v
for k, v in mapping.items()
index: use `index.has_node` in `histedit._finishhistedit...
r43947 if has_node(k) and all(has_node(n) for n in v)
Augie Fackler
formatting: blacken the codebase...
r43346 }
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 scmutil.cleanupnodes(repo, mapping, b'histedit')
Pulkit Goyal
histedit: add support to output nodechanges using formatter...
r35124 hf = fm.hexfunc
fl = fm.formatlist
fd = fm.formatdict
Augie Fackler
formatting: blacken the codebase...
r43346 nodechanges = fd(
{
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hf(oldn): fl([hf(n) for n in newn], name=b'node')
Gregory Szorc
py3: define and use pycompat.iteritems() for hgext/...
r43375 for oldn, newn in pycompat.iteritems(mapping)
Augie Fackler
formatting: blacken the codebase...
r43346 },
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 key=b"oldnode",
value=b"newnodes",
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pulkit Goyal
histedit: add support to output nodechanges using formatter...
r35124 fm.data(nodechanges=nodechanges)
Pierre-Yves David
histedit: backout ebb5bb9bc32e...
r25894
David Soria Parra
histedit: add clear method to remove state...
r22978 state.clear()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if os.path.exists(repo.sjoin(b'undo')):
os.unlink(repo.sjoin(b'undo'))
if repo.vfs.exists(b'histedit-last-edit.txt'):
repo.vfs.unlink(b'histedit-last-edit.txt')
Augie Fackler
histedit: new extension for interactive history editing
r17064
Augie Fackler
formatting: blacken the codebase...
r43346
Sushil khanchi
histedit: add --no-backup option (issue5825)...
r38566 def _aborthistedit(ui, repo, state, nobackup=False):
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _abortaction)...
r28130 try:
state.read()
Kostia Balytskyi
histedit: unifying the way replacements are computed for abort and success...
r28179 __, leafs, tmpnodes, __ = processreplacement(state)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.debug(b'restore wc to old parent %s\n' % node.short(state.topmost))
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _abortaction)...
r28130
# Recover our old commits if necessary
if not state.topmost in repo and state.backupfile:
Pierre-Yves David
histedit: directly use repo.vfs.join...
r31329 backupfile = repo.vfs.join(state.backupfile)
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _abortaction)...
r28130 f = hg.openpath(ui, backupfile)
gen = exchange.readbundle(ui, f, backupfile)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with repo.transaction(b'histedit.abort') as tr:
Augie Fackler
formatting: blacken the codebase...
r43346 bundle2.applybundle(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo,
gen,
tr,
source=b'histedit',
url=b'bundle:' + backupfile,
Augie Fackler
formatting: blacken the codebase...
r43346 )
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _abortaction)...
r28130
os.remove(backupfile)
# check whether we should update away
Augie Fackler
formatting: blacken the codebase...
r43346 if repo.unfiltered().revs(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'parents() and (%n or %ln::)',
Augie Fackler
formatting: blacken the codebase...
r43346 state.parentctxnode,
leafs | tmpnodes,
):
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _abortaction)...
r28130 hg.clean(repo, state.topmost, show_stats=True, quietempty=True)
Sushil khanchi
histedit: add --no-backup option (issue5825)...
r38566 cleanupnode(ui, repo, tmpnodes, nobackup=nobackup)
cleanupnode(ui, repo, leafs, nobackup=nobackup)
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _abortaction)...
r28130 except Exception:
if state.inprogress():
Augie Fackler
formatting: blacken the codebase...
r43346 ui.warn(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'warning: encountered an exception during histedit '
b'--abort; the repository may not have been completely '
b'cleaned up\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _abortaction)...
r28130 raise
finally:
Augie Fackler
formatting: blacken the codebase...
r43346 state.clear()
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _abortaction)...
r28130
Taapas Agrawal
abort: added support for histedit...
r42787 def hgaborthistedit(ui, repo):
state = histeditstate(repo)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 nobackup = not ui.configbool(b'rewrite', b'backup-bundle')
Taapas Agrawal
abort: added support for histedit...
r42787 with repo.wlock() as wlock, repo.lock() as lock:
state.wlock = wlock
state.lock = lock
_aborthistedit(ui, repo, state, nobackup=nobackup)
Augie Fackler
formatting: blacken the codebase...
r43346
Kostia Balytskyi
histedit: renaming parts to which _histedit was split...
r28154 def _edithisteditplan(ui, repo, state, rules):
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _editplanaction)...
r28131 state.read()
if not rules:
Augie Fackler
formatting: blacken the codebase...
r43346 comment = geteditcomment(
ui, node.short(state.parentctxnode), node.short(state.topmost)
)
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _editplanaction)...
r28131 rules = ruleeditor(repo, ui, state.actions, comment)
else:
Yuya Nishihara
histedit: use ui.fin to read commands from stdin...
r30262 rules = _readfile(ui, rules)
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _editplanaction)...
r28131 actions = parserules(rules, state)
Augie Fackler
formatting: blacken the codebase...
r43346 ctxs = [repo[act.node] for act in state.actions if act.node]
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _editplanaction)...
r28131 warnverifyactions(ui, repo, actions, state, ctxs)
state.actions = actions
state.write()
Augie Fackler
formatting: blacken the codebase...
r43346
Kostia Balytskyi
histedit: renaming parts to which _histedit was split...
r28154 def _newhistedit(ui, repo, state, revs, freeargs, opts):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 outg = opts.get(b'outgoing')
rules = opts.get(b'commands', b'')
force = opts.get(b'force')
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132
cmdutil.checkunfinished(repo)
cmdutil.bailifchanged(repo)
Martin von Zweigbergk
cleanup: use p1() instead of parents() when we only need the first parent...
r41444 topmost = repo.dirstate.p1()
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132 if outg:
if freeargs:
remote = freeargs[0]
else:
remote = None
root = findoutgoing(ui, repo, remote, force, opts)
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rr = list(repo.set(b'roots(%ld)', scmutil.revrange(repo, revs)))
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132 if len(rr) != 1:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'The specified revisions must have '
b'exactly one common root'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132 root = rr[0].node()
revs = between(repo, root, topmost, state.keep)
if not revs:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'%s is not an ancestor of working directory') % node.short(root)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132
ctxs = [repo[r] for r in revs]
Augie Fackler
histedit: sniff-test for untracked file conflicts before prompting for rules...
r43247
wctx = repo[None]
# Please don't ask me why `ancestors` is this value. I figured it
# out with print-debugging, not by actually understanding what the
# merge code is doing. :(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ancs = [repo[b'.']]
Augie Fackler
histedit: sniff-test for untracked file conflicts before prompting for rules...
r43247 # Sniff-test to make sure we won't collide with untracked files in
# the working directory. If we don't do this, we can get a
# collision after we've started histedit and backing out gets ugly
# for everyone, especially the user.
for c in [ctxs[0].p1()] + ctxs:
try:
mergemod.calculateupdates(
Augie Fackler
formatting: blacken the codebase...
r43346 repo,
wctx,
c,
ancs,
Augie Fackler
histedit: sniff-test for untracked file conflicts before prompting for rules...
r43247 # These parameters were determined by print-debugging
# what happens later on inside histedit.
Augie Fackler
formatting: blacken the codebase...
r43346 branchmerge=False,
force=False,
acceptremote=False,
followcopies=False,
)
Augie Fackler
histedit: sniff-test for untracked file conflicts before prompting for rules...
r43247 except error.Abort:
raise error.Abort(
Augie Fackler
formatting: blacken the codebase...
r43346 _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"untracked files in working directory conflict with files in %s"
Augie Fackler
formatting: blacken the codebase...
r43346 )
% c
)
Augie Fackler
histedit: sniff-test for untracked file conflicts before prompting for rules...
r43247
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132 if not rules:
Mateusz Kwapich
histedit: add a hint about enabled dropmissing to histedit edit comment...
r28592 comment = geteditcomment(ui, node.short(root), node.short(topmost))
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132 actions = [pick(state, r) for r in revs]
rules = ruleeditor(repo, ui, actions, comment)
else:
Yuya Nishihara
histedit: use ui.fin to read commands from stdin...
r30262 rules = _readfile(ui, rules)
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132 actions = parserules(rules, state)
warnverifyactions(ui, repo, actions, state, ctxs)
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 parentctxnode = repo[root].p1().node()
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132
state.parentctxnode = parentctxnode
state.actions = actions
state.topmost = topmost
state.replacements = []
Augie Fackler
formatting: blacken the codebase...
r43346 ui.log(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"histedit",
b"%d actions to histedit\n",
Augie Fackler
formatting: blacken the codebase...
r43346 len(actions),
histedit_num_actions=len(actions),
)
Phil Cohen
histedit: add ui.log for action count...
r35506
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132 # Create a backup so we can always abort completely.
backupfile = None
if not obsolete.isenabled(repo, obsolete.createmarkersopt):
Augie Fackler
formatting: blacken the codebase...
r43346 backupfile = repair.backupbundle(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo, [parentctxnode], [topmost], root, b'histedit'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Kostia Balytskyi
histedit: break _histedit function into smaller pieces (add _newaction)...
r28132 state.backupfile = backupfile
Augie Fackler
formatting: blacken the codebase...
r43346
Sean Farley
histedit: extract common summary code into method...
r29467 def _getsummary(ctx):
# a common pattern is to extract the summary but default to the empty
# string
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 summary = ctx.description() or b''
Sean Farley
histedit: extract common summary code into method...
r29467 if summary:
summary = summary.splitlines()[0]
return summary
Augie Fackler
formatting: blacken the codebase...
r43346
Durham Goode
histedit: delete all non-actionclass related code...
r24774 def bootstrapcontinue(ui, state, opts):
repo = state.repo
Siddharth Agarwal
histedit: make check for unresolved conflicts explicit (issue5545)...
r32057
ms = mergemod.mergestate.read(repo)
mergeutil.checkunresolved(ms)
Mateusz Kwapich
histedit: change state.rules uses to state.actions...
r27207 if state.actions:
actobj = state.actions.pop(0)
Durham Goode
histedit: fix --continue when rules are finished...
r24959
liscju
histedit: extracts _isdirtywc function...
r26981 if _isdirtywc(repo):
Durham Goode
histedit: fix --continue when rules are finished...
r24959 actobj.continuedirty()
liscju
histedit: extracts _isdirtywc function...
r26981 if _isdirtywc(repo):
Mateusz Kwapich
histedit: add abortdirty function...
r27084 abortdirty()
Durham Goode
histedit: integrate action class into flow...
r24766
Durham Goode
histedit: fix --continue when rules are finished...
r24959 parentctx, replacements = actobj.continueclean()
Pierre-Yves David
histedit: move `continue` logic into a dedicated function...
r17666
Durham Goode
histedit: fix --continue when rules are finished...
r24959 state.parentctxnode = parentctx.node()
state.replacements.extend(replacements)
David Soria Parra
histedit: pass state to boostrapcontinue...
r22980
return state
Pierre-Yves David
histedit: move `continue` logic into a dedicated function...
r17666
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
histedit: move `between function` outside the action logic...
r17642 def between(repo, old, new, keep):
"""select and validate the set of revision to edit
When keep is false, the specified set can't have children."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revs = repo.revs(b'%n::%n', old, new)
Yuya Nishihara
histedit: use repo.revs() instead of repo.set() where revisions are needed...
r36431 if revs and not keep:
Martin von Zweigbergk
histedit: use rewriteutil.precheck() instead of reimplementing it...
r44385 rewriteutil.precheck(repo, revs, b'edit')
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if repo.revs(b'(%ld) and merge()', revs):
raise error.Abort(_(b'cannot edit history that contains merges'))
Yuya Nishihara
histedit: use repo.revs() instead of repo.set() where revisions are needed...
r36431 return pycompat.maplist(repo.changelog.node, revs)
Pierre-Yves David
histedit: move `between function` outside the action logic...
r17642
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 def ruleeditor(repo, ui, actions, editcomment=b""):
Mateusz Kwapich
histedit: extract method ruleeditor...
r24140 """open an editor to edit rules
rules are in the format [ [act, ctx], ...] like in state.rules
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if repo.ui.configbool(b"experimental", b"histedit.autoverb"):
Sean Farley
histedit: move autoverb rule to the commit it matches...
r29470 newact = util.sortdict()
Sean Farley
histedit: move autoverb logic from torule to ruleeditor...
r29465 for act in actions:
ctx = repo[act.node]
Sean Farley
histedit: use _getsummary in ruleeditor...
r29469 summary = _getsummary(ctx)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fword = summary.split(b' ', 1)[0].lower()
Sean Farley
histedit: move autoverb rule to the commit it matches...
r29470 added = False
Sean Farley
histedit: move autoverb logic from torule to ruleeditor...
r29465 # if it doesn't end with the special character '!' just skip this
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if fword.endswith(b'!'):
Sean Farley
histedit: move autoverb logic from torule to ruleeditor...
r29465 fword = fword[:-1]
if fword in primaryactions | secondaryactions | tertiaryactions:
act.verb = fword
Sean Farley
histedit: move autoverb rule to the commit it matches...
r29470 # get the target summary
Augie Fackler
formatting: blacken the codebase...
r43346 tsum = summary[len(fword) + 1 :].lstrip()
Sean Farley
histedit: move autoverb rule to the commit it matches...
r29470 # safe but slow: reverse iterate over the actions so we
# don't clash on two commits having the same summary
Gregory Szorc
py3: define and use pycompat.iteritems() for hgext/...
r43375 for na, l in reversed(list(pycompat.iteritems(newact))):
Sean Farley
histedit: move autoverb rule to the commit it matches...
r29470 actx = repo[na.node]
asum = _getsummary(actx)
if asum == tsum:
added = True
l.append(act)
break
if not added:
newact[act] = []
# copy over and flatten the new list
actions = []
Gregory Szorc
py3: define and use pycompat.iteritems() for hgext/...
r43375 for na, l in pycompat.iteritems(newact):
Sean Farley
histedit: move autoverb rule to the commit it matches...
r29470 actions.append(na)
actions += l
Sean Farley
histedit: move autoverb logic from torule to ruleeditor...
r29465
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rules = b'\n'.join([act.torule() for act in actions])
rules += b'\n\n'
Mateusz Kwapich
histedit: extract method ruleeditor...
r24140 rules += editcomment
Augie Fackler
formatting: blacken the codebase...
r43346 rules = ui.edit(
rules,
ui.username(),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 {b'prefix': b'histedit'},
Augie Fackler
formatting: blacken the codebase...
r43346 repopath=repo.path,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 action=b'histedit',
Augie Fackler
formatting: blacken the codebase...
r43346 )
Mateusz Kwapich
histedit: extract method ruleeditor...
r24140
# Save edit rules in .hg/histedit-last-edit.txt in case
# the user needs to ask for help after something
# surprising happens.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with repo.vfs(b'histedit-last-edit.txt', b'wb') as f:
Augie Fackler
histedit: modernize write of histedit-last-edit file...
r36186 f.write(rules)
Mateusz Kwapich
histedit: extract method ruleeditor...
r24140
return rules
Augie Fackler
formatting: blacken the codebase...
r43346
Mateusz Kwapich
histedit: get rid of state.rules...
r27208 def parserules(rules, state):
"""Read the histedit rules string and return list of action objects """
Augie Fackler
formatting: blacken the codebase...
r43346 rules = [
l
for l in (r.strip() for r in rules.splitlines())
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if l and not l.startswith(b'#')
Augie Fackler
formatting: blacken the codebase...
r43346 ]
Mateusz Kwapich
histedit: get rid of state.rules...
r27208 actions = []
Augie Fackler
histedit: new extension for interactive history editing
r17064 for r in rules:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b' ' not in r:
raise error.ParseError(_(b'malformed line "%s"') % r)
verb, rest = r.split(b' ', 1)
Mateusz Kwapich
histedit: make verification configurable...
r27082
Mateusz Kwapich
histedit: get rid of state.rules...
r27208 if verb not in actiontable:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.ParseError(_(b'unknown action "%s"') % verb)
Mateusz Kwapich
histedit: get rid of state.rules...
r27208
Mateusz Kwapich
histedit: make verification configurable...
r27082 action = actiontable[verb].fromrule(state, rest)
Mateusz Kwapich
histedit: get rid of state.rules...
r27208 actions.append(action)
return actions
Augie Fackler
formatting: blacken the codebase...
r43346
timeless
histedit: limit mentioning histedit-last-edit.txt...
r27543 def warnverifyactions(ui, repo, actions, state, ctxs):
try:
verifyactions(actions, state, ctxs)
timeless
histedit: use parse-error exception for parsing
r27545 except error.ParseError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if repo.vfs.exists(b'histedit-last-edit.txt'):
Augie Fackler
formatting: blacken the codebase...
r43346 ui.warn(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'warning: histedit rules saved '
b'to: .hg/histedit-last-edit.txt\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
timeless
histedit: limit mentioning histedit-last-edit.txt...
r27543 raise
Augie Fackler
formatting: blacken the codebase...
r43346
Mateusz Kwapich
histedit: get rid of state.rules...
r27208 def verifyactions(actions, state, ctxs):
"""Verify that there exists exactly one action per given changeset and
other constraints.
Will abort if there are to many or too few rules, a malformed rule,
or a rule on a changeset outside of the user-given range.
"""
Augie Fackler
cleanup: run pyupgrade on our source tree to clean up varying things...
r44937 expected = {c.node() for c in ctxs}
Mateusz Kwapich
histedit: get rid of state.rules...
r27208 seen = set()
timeless
histedit: pass previous action to verify
r27541 prev = None
André Klitzing
histedit: check first changeset for verb "roll" or "fold" (issue5498)...
r33757
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if actions and actions[0].verb in [b'roll', b'fold']:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.ParseError(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'first changeset cannot use verb "%s"') % actions[0].verb
Augie Fackler
formatting: blacken the codebase...
r43346 )
André Klitzing
histedit: check first changeset for verb "roll" or "fold" (issue5498)...
r33757
Mateusz Kwapich
histedit: get rid of state.rules...
r27208 for action in actions:
Pierre-Yves David
histedit: move constraint verification to the 'action.verify' method...
r29879 action.verify(prev, expected, seen)
timeless
histedit: pass previous action to verify
r27541 prev = action
Pierre-Yves David
histedit: drop the 'nodetoverify' local variable...
r29876 if action.node is not None:
Pierre-Yves David
histedit: directly use node in 'verifyactions'...
r29878 seen.add(action.node)
Pierre-Yves David
histedit: more precise user message when changeset is missing...
r19048 missing = sorted(expected - seen) # sort to stabilize output
Mateusz Kwapich
histedit: delete to drop...
r27414
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if state.repo.ui.configbool(b'histedit', b'dropmissing'):
Mateusz Kwapich
histedit: have dropmissing abort on empty plan...
r28519 if len(actions) == 0:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.ParseError(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'no rules provided'),
hint=_(b'use strip extension to remove commits'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Mateusz Kwapich
histedit: have dropmissing abort on empty plan...
r28519
Pierre-Yves David
histedit: directly use node in 'verifyactions'...
r29878 drops = [drop(state, n) for n in missing]
Mateusz Kwapich
histedit: delete to drop...
r27414 # put the in the beginning so they execute immediately and
# don't show in the edit-plan in the future
actions[:0] = drops
elif missing:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.ParseError(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'missing rules for changeset %s') % node.short(missing[0]),
Augie Fackler
formatting: blacken the codebase...
r43346 hint=_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'use "drop %s" to discard, see also: '
b"'hg help -e histedit.config'"
Augie Fackler
formatting: blacken the codebase...
r43346 )
% node.short(missing[0]),
)
Pierre-Yves David
histedit: extract bookmark logic in a dedicated function...
r17663
Kostia Balytskyi
histedit: make histedit aware of obsolescense not stored in state (issue4800)...
r28216 def adjustreplacementsfrommarkers(repo, oldreplacements):
Mads Kiilerich
spelling: fixes of non-dictionary words
r30332 """Adjust replacements from obsolescence markers
Kostia Balytskyi
histedit: make histedit aware of obsolescense not stored in state (issue4800)...
r28216
Replacements structure is originally generated based on
histedit's state and does not account for changes that are
not recorded there. This function fixes that by adding
Mads Kiilerich
spelling: fixes of non-dictionary words
r30332 data read from obsolescence markers"""
Kostia Balytskyi
histedit: make histedit aware of obsolescense not stored in state (issue4800)...
r28216 if not obsolete.isenabled(repo, obsolete.createmarkersopt):
return oldreplacements
unfi = repo.unfiltered()
index: use `index.get_rev` in `histedit.adjustreplacementsfrommarkers`...
r43968 get_rev = unfi.changelog.index.get_rev
Pierre-Yves David
histedit: also handle locally missing nodes when reading obsolescence...
r28224 obsstore = repo.obsstore
Kostia Balytskyi
histedit: make histedit aware of obsolescense not stored in state (issue4800)...
r28216 newreplacements = list(oldreplacements)
oldsuccs = [r[1] for r in oldreplacements]
# successors that have already been added to succstocheck once
Augie Fackler
formatting: blacken the codebase...
r43346 seensuccs = set().union(
*oldsuccs
) # create a set from an iterable of tuples
Kostia Balytskyi
histedit: make histedit aware of obsolescense not stored in state (issue4800)...
r28216 succstocheck = list(seensuccs)
while succstocheck:
n = succstocheck.pop()
index: use `index.get_rev` in `histedit.adjustreplacementsfrommarkers`...
r43968 missing = get_rev(n) is None
Pierre-Yves David
histedit: also handle locally missing nodes when reading obsolescence...
r28224 markers = obsstore.successors.get(n, ())
if missing and not markers:
# dead end, mark it as such
Kostia Balytskyi
histedit: make histedit aware of obsolescense not stored in state (issue4800)...
r28216 newreplacements.append((n, ()))
Pierre-Yves David
histedit: also handle locally missing nodes when reading obsolescence...
r28224 for marker in markers:
nsuccs = marker[1]
Kostia Balytskyi
histedit: make histedit aware of obsolescense not stored in state (issue4800)...
r28216 newreplacements.append((n, nsuccs))
for nsucc in nsuccs:
if nsucc not in seensuccs:
seensuccs.add(nsucc)
succstocheck.append(nsucc)
return newreplacements
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 def processreplacement(state):
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 """process the list of replacements to return
1) the final mapping between original and created nodes
2) the list of temporary node created by histedit
3) the list of new commit created by histedit"""
Kostia Balytskyi
histedit: make histedit aware of obsolescense not stored in state (issue4800)...
r28216 replacements = adjustreplacementsfrommarkers(state.repo, state.replacements)
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 allsuccs = set()
replaced = set()
fullmapping = {}
Augie Fackler
histedit: correct spelling etc in more comments...
r26039 # initialize basic set
# fullmapping records all operations recorded in replacement
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 for rep in replacements:
allsuccs.update(rep[1])
replaced.add(rep[0])
fullmapping.setdefault(rep[0], set()).update(rep[1])
new = allsuccs - replaced
tmpnodes = allsuccs & replaced
Augie Fackler
histedit: correct spelling etc in more comments...
r26039 # Reduce content fullmapping into direct relation between original nodes
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 # and final node created during history edition
# Dropped changeset are replaced by an empty list
toproceed = set(fullmapping)
final = {}
while toproceed:
for x in list(toproceed):
succs = fullmapping[x]
for s in list(succs):
if s in toproceed:
# non final node with unknown closure
# We can't process this now
break
elif s in final:
# non final node, replace with closure
succs.remove(s)
succs.update(final[s])
else:
final[x] = succs
toproceed.remove(x)
# remove tmpnodes from final mapping
for n in tmpnodes:
del final[n]
# we expect all changes involved in final to exist in the repo
# turn `final` into list (topologically sorted)
index: use `index.get_rev` in `histedit.processreplacement`...
r43969 get_rev = state.repo.changelog.index.get_rev
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 for prec, succs in final.items():
index: use `index.get_rev` in `histedit.processreplacement`...
r43969 final[prec] = sorted(succs, key=get_rev)
Pierre-Yves David
histedit: extract bookmark logic in a dedicated function...
r17663
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 # computed topmost element (necessary for bookmark)
if new:
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 newtopmost = sorted(new, key=state.repo.changelog.rev)[-1]
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758 elif not final:
# Nothing rewritten at all. we won't need `newtopmost`
# It is the same as `oldtopmost` and `processreplacement` know it
newtopmost = None
else:
# every body died. The newtopmost is the parent of the root.
Augie Fackler
histedit: remove now-superfluous repo argument from processreplacement...
r22985 r = state.repo.changelog.rev
newtopmost = state.repo[sorted(final, key=r)[0]].p1().node()
Pierre-Yves David
histedit: replace various nodes lists with replacement graph (and issue3582)...
r17758
return final, tmpnodes, new, newtopmost
Pierre-Yves David
histedit: extract bookmark logic in a dedicated function...
r17663
Augie Fackler
formatting: blacken the codebase...
r43346
Jun Wu
histedit: move topmost bookmark movement to a separate function...
r33346 def movetopmostbookmarks(repo, oldtopmost, newtopmost):
"""Move bookmark from oldtopmost to newly created topmost
This is arguably a feature and we may only want that for the active
bookmark. But the behavior is kept compatible with the old version for now.
"""
if not oldtopmost or not newtopmost:
return
oldbmarks = repo.nodebookmarks(oldtopmost)
if oldbmarks:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with repo.lock(), repo.transaction(b'histedit') as tr:
Jun Wu
histedit: move topmost bookmark movement to a separate function...
r33346 marks = repo._bookmarks
Boris Feld
bookmark: use 'applychanges' when updating bookmark in histedit
r33486 changes = []
Jun Wu
histedit: move topmost bookmark movement to a separate function...
r33346 for name in oldbmarks:
Boris Feld
bookmark: use 'applychanges' when updating bookmark in histedit
r33486 changes.append((name, newtopmost))
marks.applychanges(repo, tr, changes)
Jun Wu
histedit: move topmost bookmark movement to a separate function...
r33346
Augie Fackler
formatting: blacken the codebase...
r43346
Sushil khanchi
histedit: add --no-backup option (issue5825)...
r38566 def cleanupnode(ui, repo, nodes, nobackup=False):
Pierre-Yves David
histedit: backout changeset 2b599f5468a4...
r31637 """strip a group of nodes from the repository
The set of node to strip may contains unknown nodes."""
with repo.lock():
# do not let filtering get in the way of the cleanse
# we should probably get rid of obsolescence marker created during the
# histedit, but we currently do not have such information.
repo = repo.unfiltered()
# Find all nodes that need to be stripped
# (we use %lr instead of %ln to silently ignore unknown items)
index: use `index.has_node` in `histedit.cleanupnode`...
r43948 has_node = repo.changelog.index.has_node
nodes = sorted(n for n in nodes if has_node(n))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 roots = [c.node() for c in repo.set(b"roots(%ln)", nodes)]
Jun Wu
histedit: pass multiple nodes to strip (BC)...
r33349 if roots:
Sushil khanchi
histedit: add --no-backup option (issue5825)...
r38566 backup = not nobackup
repair.strip(ui, repo, roots, backup=backup)
Pierre-Yves David
histedit: backout changeset 2b599f5468a4...
r31637
Augie Fackler
formatting: blacken the codebase...
r43346
Mateusz Kwapich
histedit: don't allow to strip nodes which are necessary to continue histedit...
r24111 def stripwrapper(orig, ui, repo, nodelist, *args, **kwargs):
Matt Harbison
histedit: fix an `isinstance(nodelist, str)` check for py3...
r44182 if isinstance(nodelist, bytes):
Mateusz Kwapich
histedit: don't allow to strip nodes which are necessary to continue histedit...
r24111 nodelist = [nodelist]
Martin von Zweigbergk
histedit: avoid repeating name of state file in a few places...
r38822 state = histeditstate(repo)
if state.inprogress():
Mateusz Kwapich
histedit: don't allow to strip nodes which are necessary to continue histedit...
r24111 state.read()
Augie Fackler
formatting: blacken the codebase...
r43346 histedit_nodes = {
action.node for action in state.actions if action.node
}
Martin von Zweigbergk
histedit: avoid converting nodeid to context and back again...
r30025 common_nodes = histedit_nodes & set(nodelist)
Mateusz Kwapich
histedit: don't allow to strip nodes which are necessary to continue histedit...
r24111 if common_nodes:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"histedit in progress, can't strip %s")
% b', '.join(node.short(x) for x in common_nodes)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Mateusz Kwapich
histedit: don't allow to strip nodes which are necessary to continue histedit...
r24111 return orig(ui, repo, nodelist, *args, **kwargs)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 extensions.wrapfunction(repair, b'strip', stripwrapper)
Mateusz Kwapich
histedit: don't allow to strip nodes which are necessary to continue histedit...
r24111
Augie Fackler
formatting: blacken the codebase...
r43346
Bryan O'Sullivan
summary: add a histedit hook
r19215 def summaryhook(ui, repo):
Martin von Zweigbergk
histedit: avoid repeating name of state file in a few places...
r38822 state = histeditstate(repo)
if not state.inprogress():
Bryan O'Sullivan
summary: add a histedit hook
r19215 return
David Soria Parra
histedit: read state from histeditstate...
r22983 state.read()
Mateusz Kwapich
histedit: change state.rules uses to state.actions...
r27207 if state.actions:
Bryan O'Sullivan
summary: add a histedit hook
r19215 # i18n: column positioning for "hg summary"
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'hist: %s (histedit --continue)\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.label(_(b'%d remaining'), b'histedit.remaining')
Augie Fackler
formatting: blacken the codebase...
r43346 % len(state.actions)
)
)
Bryan O'Sullivan
summary: add a histedit hook
r19215
def extsetup(ui):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cmdutil.summaryhooks.add(b'histedit', summaryhook)
Augie Fackler
formatting: blacken the codebase...
r43346 statemod.addunfinished(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'histedit',
fname=b'histedit-state',
Augie Fackler
formatting: blacken the codebase...
r43346 allowcommit=True,
continueflag=True,
abortfunc=hgaborthistedit,
)