mq.py
3701 lines
| 136.4 KiB
| text/x-python
|
PythonLexer
/ hgext / mq.py
Marti Raudsepp
|
r6187 | # mq.py - patch queues for mercurial | ||
mason@suse.com
|
r1808 | # | ||
Vadim Gelfer
|
r2859 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> | ||
mason@suse.com
|
r1808 | # | ||
Martin Geisler
|
r8225 | # This software may be used and distributed according to the terms of the | ||
Matt Mackall
|
r10263 | # GNU General Public License version 2 or any later version. | ||
mason@suse.com
|
r1808 | |||
Dirkjan Ochtman
|
r8932 | '''manage a stack of patches | ||
Vadim Gelfer
|
r2554 | |||
This extension lets you work with a stack of patches in a Mercurial | ||||
Martin Geisler
|
r7983 | repository. It manages two stacks of patches - all known patches, and | ||
Vadim Gelfer
|
r2554 | applied patches (subset of known patches). | ||
Known patches are represented as patch files in the .hg/patches | ||||
Martin Geisler
|
r7983 | directory. Applied patches are both patch files and changesets. | ||
Vadim Gelfer
|
r2554 | |||
Yuya Nishihara
|
r30879 | Common tasks (use :hg:`help COMMAND` for more details):: | ||
Vadim Gelfer
|
r2554 | |||
Martin Geisler
|
r9157 | create new patch qnew | ||
import existing patch qimport | ||||
Vadim Gelfer
|
r2554 | |||
Martin Geisler
|
r9157 | print patch series qseries | ||
print applied patches qapplied | ||||
Vadim Gelfer
|
r2554 | |||
Martin Geisler
|
r9157 | add known patch to applied stack qpush | ||
remove patch from applied stack qpop | ||||
refresh contents of top applied patch qrefresh | ||||
Patrick Mezard
|
r10190 | |||
By default, mq will automatically use git patches when required to | ||||
avoid losing file mode changes, copy records, binary files or empty | ||||
timeless@mozdev.org
|
r26098 | files creations or deletions. This behavior can be configured with:: | ||
Patrick Mezard
|
r10190 | |||
[mq] | ||||
git = auto/keep/yes/no | ||||
If set to 'keep', mq will obey the [diff] section configuration while | ||||
preserving existing git patches upon qrefresh. If set to 'yes' or | ||||
'no', mq will override the [diff] section and always generate git or | ||||
regular patches, possibly losing data in the second case. | ||||
Martin Geisler
|
r11234 | |||
Matt Mackall
|
r16040 | It may be desirable for mq changesets to be kept in the secret phase (see | ||
Matt Mackall
|
r16017 | :hg:`help phases`), which can be enabled with the following setting:: | ||
[mq] | ||||
secret = True | ||||
Martin Geisler
|
r11234 | You will by default be managing a patch queue named "patches". You can | ||
create other, independent patch queues with the :hg:`qqueue` command. | ||||
Patrick Mezard
|
r16656 | |||
If the working directory contains uncommitted files, qpush, qpop and | ||||
qgoto abort immediately. If -f/--force is used, the changes are | ||||
Patrick Mezard
|
r16733 | discarded. Setting:: | ||
Patrick Mezard
|
r16656 | |||
[mq] | ||||
Patrick Mezard
|
r16733 | keepchanges = True | ||
make them behave as if --keep-changes were passed, and non-conflicting | ||||
Patrick Mezard
|
r16656 | local changes will be tolerated and preserved. If incompatible options | ||
such as -f/--force or --exact are passed, this setting is ignored. | ||||
Pierre-Yves David
|
r19826 | |||
This extension used to provide a strip command. This command now lives | ||||
in the strip extension. | ||||
Vadim Gelfer
|
r2554 | ''' | ||
Yuya Nishihara
|
r34139 | from __future__ import absolute_import, print_function | ||
Pulkit Goyal
|
r29127 | |||
import errno | ||||
import os | ||||
import re | ||||
import shutil | ||||
Matt Mackall
|
r3891 | from mercurial.i18n import _ | ||
Pulkit Goyal
|
r29127 | from mercurial.node import ( | ||
bin, | ||||
hex, | ||||
nullid, | ||||
nullrev, | ||||
short, | ||||
) | ||||
from mercurial import ( | ||||
cmdutil, | ||||
commands, | ||||
Augie Fackler
|
r30489 | dirstateguard, | ||
Augie Fackler
|
r34024 | encoding, | ||
Pulkit Goyal
|
r29127 | error, | ||
extensions, | ||||
hg, | ||||
localrepo, | ||||
lock as lockmod, | ||||
Yuya Nishihara
|
r35906 | logcmdutil, | ||
Pulkit Goyal
|
r29127 | patch as patchmod, | ||
phases, | ||||
Pulkit Goyal
|
r30519 | pycompat, | ||
Pulkit Goyal
|
r29127 | registrar, | ||
Yuya Nishihara
|
r31024 | revsetlang, | ||
Pulkit Goyal
|
r29127 | scmutil, | ||
Yuya Nishihara
|
r31023 | smartset, | ||
Yuya Nishihara
|
r36026 | subrepoutil, | ||
Pulkit Goyal
|
r29127 | util, | ||
Pierre-Yves David
|
r31243 | vfs as vfsmod, | ||
Pulkit Goyal
|
r29127 | ) | ||
Yuya Nishihara
|
r37102 | from mercurial.utils import ( | ||
dateutil, | ||||
stringutil, | ||||
) | ||||
Pulkit Goyal
|
r29127 | |||
release = lockmod.release | ||||
Martin Geisler
|
r14298 | seriesopts = [('s', 'summary', None, _('print first line of patch header'))] | ||
cmdtable = {} | ||||
Yuya Nishihara
|
r32337 | command = registrar.command(cmdtable) | ||
Augie Fackler
|
r29841 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | ||
Augie Fackler
|
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
|
r29841 | testedwith = 'ships-with-hg-core' | ||
Martin Geisler
|
r14298 | |||
Boris Feld
|
r34182 | configtable = {} | ||
configitem = registrar.configitem(configtable) | ||||
configitem('mq', 'git', | ||||
default='auto', | ||||
) | ||||
Boris Feld
|
r34183 | configitem('mq', 'keepchanges', | ||
default=False, | ||||
) | ||||
Boris Feld
|
r34184 | configitem('mq', 'plain', | ||
default=False, | ||||
) | ||||
Boris Feld
|
r34185 | configitem('mq', 'secret', | ||
default=False, | ||||
) | ||||
Boris Feld
|
r34182 | |||
Mads Kiilerich
|
r19951 | # force load strip extension formerly included in mq and import some utility | ||
Pierre-Yves David
|
r19822 | try: | ||
stripext = extensions.find('strip') | ||||
except KeyError: | ||||
# note: load is lazy so we could avoid the try-except, | ||||
Mads Kiilerich
|
r19951 | # but I (marmoute) prefer this explicit code. | ||
Pierre-Yves David
|
r19822 | class dummyui(object): | ||
def debug(self, msg): | ||||
pass | ||||
Yuya Nishihara
|
r41031 | def log(self, event, msgfmt, *msgargs, **opts): | ||
pass | ||||
Pierre-Yves David
|
r19822 | stripext = extensions.load(dummyui(), 'strip', '') | ||
Pierre-Yves David
|
r19825 | strip = stripext.strip | ||
Pierre-Yves David
|
r19823 | checksubstate = stripext.checksubstate | ||
Pierre-Yves David
|
r19824 | checklocalchanges = stripext.checklocalchanges | ||
Pierre-Yves David
|
r19823 | |||
Patrick Mezard
|
r4037 | # Patch names looks like unix-file names. | ||
# They must be joinable with queue directory and result in the patch path. | ||||
normname = util.normpath | ||||
Benoit Boissinot
|
r8778 | class statusentry(object): | ||
Benoit Boissinot
|
r10682 | def __init__(self, node, name): | ||
self.node, self.name = node, name | ||||
Augie Fackler
|
r35860 | |||
def __bytes__(self): | ||||
Benoit Boissinot
|
r10678 | return hex(self.node) + ':' + self.name | ||
Brendan Cully
|
r2780 | |||
Augie Fackler
|
r35860 | __str__ = encoding.strmethod(__bytes__) | ||
__repr__ = encoding.strmethod(__bytes__) | ||||
Mads Kiilerich
|
r22546 | # The order of the headers in 'hg export' HG patches: | ||
HGHEADERS = [ | ||||
# '# HG changeset patch', | ||||
'# User ', | ||||
'# Date ', | ||||
'# ', | ||||
'# Branch ', | ||||
'# Node ID ', | ||||
'# Parent ', # can occur twice for merges - but that is not relevant for mq | ||||
] | ||||
Mads Kiilerich
|
r23442 | # The order of headers in plain 'mail style' patches: | ||
PLAINHEADERS = { | ||||
'from': 0, | ||||
'date': 1, | ||||
'subject': 2, | ||||
} | ||||
Mads Kiilerich
|
r22546 | |||
def inserthgheader(lines, header, value): | ||||
"""Assuming lines contains a HG patch header, add a header line with value. | ||||
Yuya Nishihara
|
r34133 | >>> try: inserthgheader([], b'# Date ', b'z') | ||
Yuya Nishihara
|
r34140 | ... except ValueError as inst: print("oops") | ||
Mads Kiilerich
|
r22546 | oops | ||
Yuya Nishihara
|
r34133 | >>> inserthgheader([b'# HG changeset patch'], b'# Date ', b'z') | ||
Mads Kiilerich
|
r22546 | ['# HG changeset patch', '# Date z'] | ||
Yuya Nishihara
|
r34133 | >>> inserthgheader([b'# HG changeset patch', b''], b'# Date ', b'z') | ||
Mads Kiilerich
|
r22546 | ['# HG changeset patch', '# Date z', ''] | ||
Yuya Nishihara
|
r34133 | >>> inserthgheader([b'# HG changeset patch', b'# User y'], b'# Date ', b'z') | ||
Mads Kiilerich
|
r22546 | ['# HG changeset patch', '# User y', '# Date z'] | ||
Yuya Nishihara
|
r34133 | >>> inserthgheader([b'# HG changeset patch', b'# Date x', b'# User y'], | ||
... b'# User ', b'z') | ||||
Mads Kiilerich
|
r23412 | ['# HG changeset patch', '# Date x', '# User z'] | ||
Yuya Nishihara
|
r34133 | >>> inserthgheader([b'# HG changeset patch', b'# Date y'], b'# Date ', b'z') | ||
Mads Kiilerich
|
r22546 | ['# HG changeset patch', '# Date z'] | ||
Yuya Nishihara
|
r34133 | >>> inserthgheader([b'# HG changeset patch', b'', b'# Date y'], | ||
... b'# Date ', b'z') | ||||
Mads Kiilerich
|
r22546 | ['# HG changeset patch', '# Date z', '', '# Date y'] | ||
Yuya Nishihara
|
r34133 | >>> inserthgheader([b'# HG changeset patch', b'# Parent y'], | ||
... b'# Date ', b'z') | ||||
Mads Kiilerich
|
r22546 | ['# HG changeset patch', '# Date z', '# Parent y'] | ||
""" | ||||
start = lines.index('# HG changeset patch') + 1 | ||||
newindex = HGHEADERS.index(header) | ||||
Mads Kiilerich
|
r23412 | bestpos = len(lines) | ||
Mads Kiilerich
|
r22546 | for i in range(start, len(lines)): | ||
line = lines[i] | ||||
Mads Kiilerich
|
r23412 | if not line.startswith('# '): | ||
bestpos = min(bestpos, i) | ||||
break | ||||
Mads Kiilerich
|
r22546 | for lineindex, h in enumerate(HGHEADERS): | ||
if line.startswith(h): | ||||
if lineindex == newindex: | ||||
lines[i] = header + value | ||||
Mads Kiilerich
|
r23412 | return lines | ||
if lineindex > newindex: | ||||
bestpos = min(bestpos, i) | ||||
break # next line | ||||
lines.insert(bestpos, header + value) | ||||
Mads Kiilerich
|
r22546 | return lines | ||
Mads Kiilerich
|
r23345 | def insertplainheader(lines, header, value): | ||
Mads Kiilerich
|
r23442 | """For lines containing a plain patch header, add a header line with value. | ||
Yuya Nishihara
|
r34133 | >>> insertplainheader([], b'Date', b'z') | ||
Mads Kiilerich
|
r23442 | ['Date: z'] | ||
Yuya Nishihara
|
r34133 | >>> insertplainheader([b''], b'Date', b'z') | ||
Mads Kiilerich
|
r23442 | ['Date: z', ''] | ||
Yuya Nishihara
|
r34133 | >>> insertplainheader([b'x'], b'Date', b'z') | ||
Mads Kiilerich
|
r23442 | ['Date: z', '', 'x'] | ||
Yuya Nishihara
|
r34133 | >>> insertplainheader([b'From: y', b'x'], b'Date', b'z') | ||
Mads Kiilerich
|
r23442 | ['From: y', 'Date: z', '', 'x'] | ||
Yuya Nishihara
|
r34133 | >>> insertplainheader([b' date : x', b' from : y', b''], b'From', b'z') | ||
Mads Kiilerich
|
r23442 | [' date : x', 'From: z', ''] | ||
Yuya Nishihara
|
r34133 | >>> insertplainheader([b'', b'Date: y'], b'Date', b'z') | ||
Mads Kiilerich
|
r23442 | ['Date: z', '', 'Date: y'] | ||
Yuya Nishihara
|
r34133 | >>> insertplainheader([b'foo: bar', b'DATE: z', b'x'], b'From', b'y') | ||
Mads Kiilerich
|
r23442 | ['From: y', 'foo: bar', 'DATE: z', '', 'x'] | ||
""" | ||||
newprio = PLAINHEADERS[header.lower()] | ||||
bestpos = len(lines) | ||||
for i, line in enumerate(lines): | ||||
if ':' in line: | ||||
lheader = line.split(':', 1)[0].strip().lower() | ||||
lprio = PLAINHEADERS.get(lheader, newprio + 1) | ||||
if lprio == newprio: | ||||
lines[i] = '%s: %s' % (header, value) | ||||
return lines | ||||
if lprio > newprio and i < bestpos: | ||||
bestpos = i | ||||
else: | ||||
if line: | ||||
lines.insert(i, '') | ||||
if i < bestpos: | ||||
bestpos = i | ||||
break | ||||
lines.insert(bestpos, '%s: %s' % (header, value)) | ||||
Mads Kiilerich
|
r23345 | return lines | ||
Brendan Cully
|
r7399 | class patchheader(object): | ||
Steve Losh
|
r10397 | def __init__(self, pf, plainmode=False): | ||
Cédric Duval
|
r8653 | def eatdiff(lines): | ||
while lines: | ||||
l = lines[-1] | ||||
if (l.startswith("diff -") or | ||||
l.startswith("Index:") or | ||||
l.startswith("===========")): | ||||
del lines[-1] | ||||
else: | ||||
break | ||||
def eatempty(lines): | ||||
while lines: | ||||
Benoit Boissinot
|
r10688 | if not lines[-1].strip(): | ||
Cédric Duval
|
r8653 | del lines[-1] | ||
else: | ||||
break | ||||
message = [] | ||||
comments = [] | ||||
user = None | ||||
date = None | ||||
Steve Losh
|
r10397 | parent = None | ||
Cédric Duval
|
r8653 | format = None | ||
subject = None | ||||
Steve Borho
|
r13229 | branch = None | ||
nodeid = None | ||||
Cédric Duval
|
r8653 | diffstart = 0 | ||
Pulkit Goyal
|
r35936 | for line in open(pf, 'rb'): | ||
Cédric Duval
|
r8653 | line = line.rstrip() | ||
Benoit Boissinot
|
r10730 | if (line.startswith('diff --git') | ||
or (diffstart and line.startswith('+++ '))): | ||||
Cédric Duval
|
r8653 | diffstart = 2 | ||
break | ||||
Benoit Boissinot
|
r10730 | diffstart = 0 # reset | ||
Cédric Duval
|
r8653 | if line.startswith("--- "): | ||
diffstart = 1 | ||||
continue | ||||
elif format == "hgpatch": | ||||
# parse values when importing the result of an hg export | ||||
if line.startswith("# User "): | ||||
user = line[7:] | ||||
elif line.startswith("# Date "): | ||||
date = line[7:] | ||||
Steve Losh
|
r10397 | elif line.startswith("# Parent "): | ||
Mads Kiilerich
|
r22521 | parent = line[9:].lstrip() # handle double trailing space | ||
Steve Borho
|
r13229 | elif line.startswith("# Branch "): | ||
branch = line[9:] | ||||
elif line.startswith("# Node ID "): | ||||
nodeid = line[10:] | ||||
Cédric Duval
|
r8653 | elif not line.startswith("# ") and line: | ||
message.append(line) | ||||
format = None | ||||
elif line == '# HG changeset patch': | ||||
David Soria Parra
|
r9287 | message = [] | ||
Cédric Duval
|
r8653 | format = "hgpatch" | ||
elif (format != "tagdone" and (line.startswith("Subject: ") or | ||||
line.startswith("subject: "))): | ||||
subject = line[9:] | ||||
format = "tag" | ||||
elif (format != "tagdone" and (line.startswith("From: ") or | ||||
line.startswith("from: "))): | ||||
user = line[6:] | ||||
format = "tag" | ||||
Steve Losh
|
r10397 | elif (format != "tagdone" and (line.startswith("Date: ") or | ||
line.startswith("date: "))): | ||||
date = line[6:] | ||||
format = "tag" | ||||
Cédric Duval
|
r8653 | elif format == "tag" and line == "": | ||
# when looking for tags (subject: from: etc) they | ||||
# end once you find a blank line in the source | ||||
format = "tagdone" | ||||
elif message or line: | ||||
message.append(line) | ||||
comments.append(line) | ||||
eatdiff(message) | ||||
eatdiff(comments) | ||||
Steve Borho
|
r13229 | # Remember the exact starting line of the patch diffs before consuming | ||
# empty lines, for external use by TortoiseHg and others | ||||
self.diffstartline = len(comments) | ||||
Cédric Duval
|
r8653 | eatempty(message) | ||
eatempty(comments) | ||||
# make sure message isn't empty | ||||
if format and format.startswith("tag") and subject: | ||||
message.insert(0, subject) | ||||
Brendan Cully
|
r7399 | self.message = message | ||
self.comments = comments | ||||
self.user = user | ||||
self.date = date | ||||
Steve Losh
|
r10397 | self.parent = parent | ||
Steve Borho
|
r13229 | # nodeid and branch are for external use by TortoiseHg and others | ||
self.nodeid = nodeid | ||||
self.branch = branch | ||||
Cédric Duval
|
r8653 | self.haspatch = diffstart > 1 | ||
Mads Kiilerich
|
r22544 | self.plainmode = (plainmode or | ||
'# HG changeset patch' not in self.comments and | ||||
Augie Fackler
|
r25149 | any(c.startswith('Date: ') or | ||
Mads Kiilerich
|
r22544 | c.startswith('From: ') | ||
for c in self.comments)) | ||||
Brendan Cully
|
r7399 | |||
def setuser(self, user): | ||||
Mads Kiilerich
|
r23443 | try: | ||
inserthgheader(self.comments, '# User ', user) | ||||
except ValueError: | ||||
if self.plainmode: | ||||
insertplainheader(self.comments, 'From', user) | ||||
else: | ||||
tmp = ['# HG changeset patch', '# User ' + user] | ||||
self.comments = tmp + self.comments | ||||
Brendan Cully
|
r7399 | self.user = user | ||
def setdate(self, date): | ||||
Mads Kiilerich
|
r23443 | try: | ||
inserthgheader(self.comments, '# Date ', date) | ||||
except ValueError: | ||||
if self.plainmode: | ||||
insertplainheader(self.comments, 'Date', date) | ||||
else: | ||||
tmp = ['# HG changeset patch', '# Date ' + date] | ||||
self.comments = tmp + self.comments | ||||
Yann E. MORIN
|
r9337 | self.date = date | ||
Brendan Cully
|
r7399 | |||
Steve Losh
|
r10397 | def setparent(self, parent): | ||
Mads Kiilerich
|
r23443 | try: | ||
inserthgheader(self.comments, '# Parent ', parent) | ||||
except ValueError: | ||||
if not self.plainmode: | ||||
tmp = ['# HG changeset patch', '# Parent ' + parent] | ||||
self.comments = tmp + self.comments | ||||
Steve Losh
|
r10397 | self.parent = parent | ||
Brendan Cully
|
r7399 | def setmessage(self, message): | ||
if self.comments: | ||||
self._delmsg() | ||||
self.message = [message] | ||||
Mads Kiilerich
|
r23344 | if message: | ||
if self.plainmode and self.comments and self.comments[-1]: | ||||
self.comments.append('') | ||||
self.comments.append(message) | ||||
Brendan Cully
|
r7399 | |||
Pulkit Goyal
|
r35934 | def __bytes__(self): | ||
Mads Kiilerich
|
r22522 | s = '\n'.join(self.comments).rstrip() | ||
if not s: | ||||
Brendan Cully
|
r7399 | return '' | ||
Mads Kiilerich
|
r22522 | return s + '\n\n' | ||
Brendan Cully
|
r7399 | |||
Pulkit Goyal
|
r35934 | __str__ = encoding.strmethod(__bytes__) | ||
Brendan Cully
|
r7399 | def _delmsg(self): | ||
'''Remove existing message, keeping the rest of the comments fields. | ||||
If comments contains 'subject: ', message will prepend | ||||
the field and a blank line.''' | ||||
if self.message: | ||||
subj = 'subject: ' + self.message[0].lower() | ||||
Gregory Szorc
|
r38806 | for i in pycompat.xrange(len(self.comments)): | ||
Brendan Cully
|
r7399 | if subj == self.comments[i].lower(): | ||
del self.comments[i] | ||||
self.message = self.message[2:] | ||||
break | ||||
ci = 0 | ||||
Martin Geisler
|
r8632 | for mi in self.message: | ||
while mi != self.comments[ci]: | ||||
Brendan Cully
|
r7399 | ci += 1 | ||
del self.comments[ci] | ||||
Matt Mackall
|
r16102 | def newcommit(repo, phase, *args, **kwargs): | ||
Pierre-Yves David
|
r16057 | """helper dedicated to ensure a commit respect mq.secret setting | ||
It should be used instead of repo.commit inside the mq source for operation | ||||
creating new changeset. | ||||
Pierre-Yves David
|
r15926 | """ | ||
Pierre-Yves David
|
r18010 | repo = repo.unfiltered() | ||
Patrick Mezard
|
r16100 | if phase is None: | ||
Boris Feld
|
r34185 | if repo.ui.configbool('mq', 'secret'): | ||
Patrick Mezard
|
r16100 | phase = phases.secret | ||
Jun Wu
|
r31460 | overrides = {('ui', 'allowemptycommit'): True} | ||
Patrick Mezard
|
r16100 | if phase is not None: | ||
Jun Wu
|
r31460 | overrides[('phases', 'new-commit')] = phase | ||
with repo.ui.configoverride(overrides, 'mq'): | ||||
Durham Goode
|
r25019 | repo.ui.setconfig('ui', 'allowemptycommit', True) | ||
Pierre-Yves David
|
r15926 | return repo.commit(*args, **kwargs) | ||
Patrick Mezard
|
r16654 | class AbortNoCleanup(error.Abort): | ||
pass | ||||
Benoit Boissinot
|
r8778 | class queue(object): | ||
Simon Heimberg
|
r19064 | def __init__(self, ui, baseui, path, patchdir=None): | ||
mason@suse.com
|
r1808 | self.basepath = path | ||
Henrik Stuart
|
r11229 | try: | ||
Gregory Szorc
|
r36124 | with open(os.path.join(path, 'patches.queue'), r'rb') as fh: | ||
cur = fh.read().rstrip() | ||||
Henrik Stuart
|
r11270 | if not cur: | ||
curpath = os.path.join(path, 'patches') | ||||
else: | ||||
curpath = os.path.join(path, 'patches-' + cur) | ||||
Henrik Stuart
|
r11229 | except IOError: | ||
curpath = os.path.join(path, 'patches') | ||||
self.path = patchdir or curpath | ||||
Pierre-Yves David
|
r31243 | self.opener = vfsmod.vfs(self.path) | ||
mason@suse.com
|
r1808 | self.ui = ui | ||
Simon Heimberg
|
r19064 | self.baseui = baseui | ||
Mads Kiilerich
|
r15879 | self.applieddirty = False | ||
self.seriesdirty = False | ||||
Vishakh H
|
r11462 | self.added = [] | ||
Adrian Buehlmann
|
r14587 | self.seriespath = "series" | ||
Adrian Buehlmann
|
r14588 | self.statuspath = "status" | ||
Adrian Buehlmann
|
r14589 | self.guardspath = "guards" | ||
Adrian Buehlmann
|
r14590 | self.activeguards = None | ||
Adrian Buehlmann
|
r14591 | self.guardsdirty = False | ||
Patrick Mezard
|
r10190 | # Handle mq.git as a bool with extended values | ||
Boris Feld
|
r34182 | gitmode = ui.config('mq', 'git').lower() | ||
Yuya Nishihara
|
r37102 | boolmode = stringutil.parsebool(gitmode) | ||
Boris Feld
|
r34182 | if boolmode is not None: | ||
if boolmode: | ||||
gitmode = 'yes' | ||||
Jordi Gutiérrez Hermoso
|
r24306 | else: | ||
Boris Feld
|
r34182 | gitmode = 'no' | ||
self.gitmode = gitmode | ||||
Matt Mackall
|
r25827 | # deprecated config: mq.plain | ||
Boris Feld
|
r34184 | self.plainmode = ui.configbool('mq', 'plain') | ||
David Soria Parra
|
r19856 | self.checkapplied = True | ||
Thomas Arendsen Hein
|
r1810 | |||
Simon Heimberg
|
r8524 | @util.propertycache | ||
def applied(self): | ||||
Idan Kamara
|
r15258 | def parselines(lines): | ||
for l in lines: | ||||
entry = l.split(':', 1) | ||||
if len(entry) > 1: | ||||
n, name = entry | ||||
yield statusentry(bin(n), name) | ||||
elif l.strip(): | ||||
Pulkit Goyal
|
r38061 | self.ui.warn(_('malformated mq status line: %s\n') % | ||
stringutil.pprint(entry)) | ||||
Idan Kamara
|
r15258 | # else we ignore empty lines | ||
try: | ||||
Adrian Buehlmann
|
r14588 | lines = self.opener.read(self.statuspath).splitlines() | ||
Pierre-Yves David
|
r13507 | return list(parselines(lines)) | ||
Gregory Szorc
|
r25660 | except IOError as e: | ||
Idan Kamara
|
r15258 | if e.errno == errno.ENOENT: | ||
return [] | ||||
raise | ||||
Simon Heimberg
|
r8524 | |||
@util.propertycache | ||||
Adrian Buehlmann
|
r14572 | def fullseries(self): | ||
Idan Kamara
|
r15258 | try: | ||
Mads Kiilerich
|
r15878 | return self.opener.read(self.seriespath).splitlines() | ||
Gregory Szorc
|
r25660 | except IOError as e: | ||
Idan Kamara
|
r15258 | if e.errno == errno.ENOENT: | ||
return [] | ||||
raise | ||||
Simon Heimberg
|
r8524 | |||
@util.propertycache | ||||
def series(self): | ||||
Adrian Buehlmann
|
r14575 | self.parseseries() | ||
Simon Heimberg
|
r8524 | return self.series | ||
@util.propertycache | ||||
Adrian Buehlmann
|
r14573 | def seriesguards(self): | ||
Adrian Buehlmann
|
r14575 | self.parseseries() | ||
Adrian Buehlmann
|
r14573 | return self.seriesguards | ||
mason@suse.com
|
r1808 | |||
Simon Heimberg
|
r8525 | def invalidate(self): | ||
Adrian Buehlmann
|
r14573 | for a in 'applied fullseries series seriesguards'.split(): | ||
Simon Heimberg
|
r8525 | if a in self.__dict__: | ||
delattr(self, a) | ||||
Mads Kiilerich
|
r15879 | self.applieddirty = False | ||
self.seriesdirty = False | ||||
Adrian Buehlmann
|
r14591 | self.guardsdirty = False | ||
Adrian Buehlmann
|
r14590 | self.activeguards = None | ||
Simon Heimberg
|
r8525 | |||
Mads Kiilerich
|
r34092 | def diffopts(self, opts=None, patchfn=None, plain=False): | ||
"""Return diff options tweaked for this mq use, possibly upgrading to | ||||
git format, and possibly plain and without lossy options.""" | ||||
diffopts = patchmod.difffeatureopts(self.ui, opts, | ||||
git=True, whitespace=not plain, formatchanging=not plain) | ||||
Patrick Mezard
|
r10190 | if self.gitmode == 'auto': | ||
diffopts.upgrade = True | ||||
elif self.gitmode == 'keep': | ||||
pass | ||||
elif self.gitmode in ('yes', 'no'): | ||||
diffopts.git = self.gitmode == 'yes' | ||||
else: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('mq.git option can be auto/keep/yes/no' | ||
Patrick Mezard
|
r10190 | ' got %s') % self.gitmode) | ||
Patrick Mezard
|
r10184 | if patchfn: | ||
Patrick Mezard
|
r10185 | diffopts = self.patchopts(diffopts, patchfn) | ||
return diffopts | ||||
Patrick Mezard
|
r10186 | def patchopts(self, diffopts, *patches): | ||
Patrick Mezard
|
r10185 | """Return a copy of input diff options with git set to true if | ||
Patrick Mezard
|
r10190 | referenced patch is a git patch and should be preserved as such. | ||
Patrick Mezard
|
r10185 | """ | ||
diffopts = diffopts.copy() | ||||
Patrick Mezard
|
r10190 | if not diffopts.git and self.gitmode == 'keep': | ||
for patchfn in patches: | ||||
patchf = self.opener(patchfn, 'r') | ||||
# if the patch was a git patch, refresh it as a git patch | ||||
Martin von Zweigbergk
|
r36360 | diffopts.git = any(line.startswith('diff --git') | ||
for line in patchf) | ||||
Patrick Mezard
|
r10190 | patchf.close() | ||
Patrick Mezard
|
r10184 | return diffopts | ||
Vadim Gelfer
|
r2874 | |||
Vadim Gelfer
|
r2819 | def join(self, *p): | ||
return os.path.join(self.path, *p) | ||||
Adrian Buehlmann
|
r14574 | def findseries(self, patch): | ||
Benoit Boissinot
|
r10685 | def matchpatch(l): | ||
l = l.split('#', 1)[0] | ||||
return l.strip() == patch | ||||
Adrian Buehlmann
|
r14572 | for index, l in enumerate(self.fullseries): | ||
Benoit Boissinot
|
r10685 | if matchpatch(l): | ||
return index | ||||
mason@suse.com
|
r1808 | return None | ||
Pulkit Goyal
|
r35145 | guard_re = re.compile(br'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') | ||
Vadim Gelfer
|
r2821 | |||
Adrian Buehlmann
|
r14575 | def parseseries(self): | ||
mason@suse.com
|
r1808 | self.series = [] | ||
Adrian Buehlmann
|
r14573 | self.seriesguards = [] | ||
Adrian Buehlmann
|
r14572 | for l in self.fullseries: | ||
Vadim Gelfer
|
r2821 | h = l.find('#') | ||
if h == -1: | ||||
patch = l | ||||
comment = '' | ||||
elif h == 0: | ||||
continue | ||||
else: | ||||
patch = l[:h] | ||||
comment = l[h:] | ||||
patch = patch.strip() | ||||
if patch: | ||||
Brendan Cully
|
r3184 | if patch in self.series: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('%s appears more than once in %s') % | ||
Adrian Buehlmann
|
r14587 | (patch, self.join(self.seriespath))) | ||
Vadim Gelfer
|
r2821 | self.series.append(patch) | ||
Adrian Buehlmann
|
r14573 | self.seriesguards.append(self.guard_re.findall(comment)) | ||
Vadim Gelfer
|
r2821 | |||
Adrian Buehlmann
|
r14576 | def checkguard(self, guard): | ||
Patrick Mezard
|
r6607 | if not guard: | ||
return _('guard cannot be an empty string') | ||||
Vadim Gelfer
|
r2821 | bad_chars = '# \t\r\n\f' | ||
first = guard[0] | ||||
Simon Heimberg
|
r8288 | if first in '-+': | ||
return (_('guard %r starts with invalid character: %r') % | ||||
(guard, first)) | ||||
Vadim Gelfer
|
r2821 | for c in bad_chars: | ||
if c in guard: | ||||
return _('invalid character in guard %r: %r') % (guard, c) | ||||
Thomas Arendsen Hein
|
r3223 | |||
Adrian Buehlmann
|
r14578 | def setactive(self, guards): | ||
Vadim Gelfer
|
r2821 | for guard in guards: | ||
Adrian Buehlmann
|
r14576 | bad = self.checkguard(guard) | ||
Vadim Gelfer
|
r2821 | if bad: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(bad) | ||
Matt Mackall
|
r8209 | guards = sorted(set(guards)) | ||
Martin Geisler
|
r9467 | self.ui.debug('active guards: %s\n' % ' '.join(guards)) | ||
Adrian Buehlmann
|
r14590 | self.activeguards = guards | ||
Adrian Buehlmann
|
r14591 | self.guardsdirty = True | ||
Vadim Gelfer
|
r2821 | |||
def active(self): | ||||
Adrian Buehlmann
|
r14590 | if self.activeguards is None: | ||
self.activeguards = [] | ||||
Vadim Gelfer
|
r2821 | try: | ||
Adrian Buehlmann
|
r14589 | guards = self.opener.read(self.guardspath).split() | ||
Gregory Szorc
|
r25660 | except IOError as err: | ||
Matt Mackall
|
r10282 | if err.errno != errno.ENOENT: | ||
raise | ||||
Vadim Gelfer
|
r2821 | guards = [] | ||
for i, guard in enumerate(guards): | ||||
Adrian Buehlmann
|
r14576 | bad = self.checkguard(guard) | ||
Vadim Gelfer
|
r2821 | if bad: | ||
self.ui.warn('%s:%d: %s\n' % | ||||
Adrian Buehlmann
|
r14589 | (self.join(self.guardspath), i + 1, bad)) | ||
Vadim Gelfer
|
r2821 | else: | ||
Adrian Buehlmann
|
r14590 | self.activeguards.append(guard) | ||
return self.activeguards | ||||
Vadim Gelfer
|
r2821 | |||
Adrian Buehlmann
|
r14577 | def setguards(self, idx, guards): | ||
Vadim Gelfer
|
r2821 | for g in guards: | ||
if len(g) < 2: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('guard %r too short') % g) | ||
Vadim Gelfer
|
r2821 | if g[0] not in '-+': | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('guard %r starts with invalid char') % g) | ||
Adrian Buehlmann
|
r14576 | bad = self.checkguard(g[1:]) | ||
Vadim Gelfer
|
r2821 | if bad: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(bad) | ||
Adrian Buehlmann
|
r14572 | drop = self.guard_re.sub('', self.fullseries[idx]) | ||
self.fullseries[idx] = drop + ''.join([' #' + g for g in guards]) | ||||
Adrian Buehlmann
|
r14575 | self.parseseries() | ||
Adrian Buehlmann
|
r14593 | self.seriesdirty = True | ||
Thomas Arendsen Hein
|
r3223 | |||
Vadim Gelfer
|
r2821 | def pushable(self, idx): | ||
Gregory Szorc
|
r36123 | if isinstance(idx, bytes): | ||
Vadim Gelfer
|
r2821 | idx = self.series.index(idx) | ||
Adrian Buehlmann
|
r14573 | patchguards = self.seriesguards[idx] | ||
Vadim Gelfer
|
r2821 | if not patchguards: | ||
return True, None | ||||
guards = self.active() | ||||
Pulkit Goyal
|
r37538 | exactneg = [g for g in patchguards | ||
if g.startswith('-') and g[1:] in guards] | ||||
Vadim Gelfer
|
r2821 | if exactneg: | ||
Augie Fackler
|
r39084 | return False, stringutil.pprint(exactneg[0]) | ||
Pulkit Goyal
|
r37538 | pos = [g for g in patchguards if g.startswith('+')] | ||
Vadim Gelfer
|
r2850 | exactpos = [g for g in pos if g[1:] in guards] | ||
Vadim Gelfer
|
r2821 | if pos: | ||
Vadim Gelfer
|
r2850 | if exactpos: | ||
Augie Fackler
|
r39084 | return True, stringutil.pprint(exactpos[0]) | ||
return False, ' '.join([stringutil.pprint(p) for p in pos]) | ||||
Vadim Gelfer
|
r2821 | return True, '' | ||
Adrian Buehlmann
|
r14579 | def explainpushable(self, idx, all_patches=False): | ||
Jordi Gutiérrez Hermoso
|
r24306 | if all_patches: | ||
write = self.ui.write | ||||
else: | ||||
write = self.ui.warn | ||||
Vadim Gelfer
|
r2821 | if all_patches or self.ui.verbose: | ||
Pulkit Goyal
|
r37539 | if isinstance(idx, bytes): | ||
Vadim Gelfer
|
r2821 | idx = self.series.index(idx) | ||
pushable, why = self.pushable(idx) | ||||
if all_patches and pushable: | ||||
if why is None: | ||||
write(_('allowing %s - no guards in effect\n') % | ||||
self.series[idx]) | ||||
else: | ||||
if not why: | ||||
write(_('allowing %s - no matching negative guards\n') % | ||||
self.series[idx]) | ||||
else: | ||||
Martin Geisler
|
r14464 | write(_('allowing %s - guarded by %s\n') % | ||
Vadim Gelfer
|
r2821 | (self.series[idx], why)) | ||
if not pushable: | ||||
Vadim Gelfer
|
r2829 | if why: | ||
Martin Geisler
|
r14464 | write(_('skipping %s - guarded by %s\n') % | ||
Brendan Cully
|
r3870 | (self.series[idx], why)) | ||
Vadim Gelfer
|
r2821 | else: | ||
write(_('skipping %s - no matching guards\n') % | ||||
self.series[idx]) | ||||
Thomas Arendsen Hein
|
r1810 | |||
Adrian Buehlmann
|
r14580 | def savedirty(self): | ||
Adrian Buehlmann
|
r14594 | def writelist(items, path): | ||
Augie Fackler
|
r35861 | fp = self.opener(path, 'wb') | ||
Vadim Gelfer
|
r2772 | for i in items: | ||
Matt Mackall
|
r5878 | fp.write("%s\n" % i) | ||
Vadim Gelfer
|
r2772 | fp.close() | ||
Adrian Buehlmann
|
r14592 | if self.applieddirty: | ||
Augie Fackler
|
r35862 | writelist(map(bytes, self.applied), self.statuspath) | ||
Mads Kiilerich
|
r15883 | self.applieddirty = False | ||
Adrian Buehlmann
|
r14593 | if self.seriesdirty: | ||
Adrian Buehlmann
|
r14594 | writelist(self.fullseries, self.seriespath) | ||
Mads Kiilerich
|
r15883 | self.seriesdirty = False | ||
Adrian Buehlmann
|
r14591 | if self.guardsdirty: | ||
Adrian Buehlmann
|
r14594 | writelist(self.activeguards, self.guardspath) | ||
Mads Kiilerich
|
r15883 | self.guardsdirty = False | ||
Nicolas Dumazet
|
r11546 | if self.added: | ||
qrepo = self.qrepo() | ||||
if qrepo: | ||||
Dan Villiom Podlaski Christiansen
|
r12658 | qrepo[None].add(f for f in self.added if f not in qrepo[None]) | ||
Nicolas Dumazet
|
r11546 | self.added = [] | ||
mason@suse.com
|
r1808 | |||
Brendan Cully
|
r4207 | def removeundo(self, repo): | ||
undo = repo.sjoin('undo') | ||||
if not os.path.exists(undo): | ||||
return | ||||
try: | ||||
os.unlink(undo) | ||||
Gregory Szorc
|
r25660 | except OSError as inst: | ||
Pulkit Goyal
|
r36650 | self.ui.warn(_('error removing undo: %s\n') % | ||
Yuya Nishihara
|
r37102 | stringutil.forcebytestr(inst)) | ||
Brendan Cully
|
r4207 | |||
Patrick Mezard
|
r16634 | def backup(self, repo, files, copy=False): | ||
Patrick Mezard
|
r16633 | # backup local changes in --force case | ||
for f in sorted(files): | ||||
absf = repo.wjoin(f) | ||||
if os.path.lexists(absf): | ||||
Martin von Zweigbergk
|
r41732 | absorig = scmutil.origpath(self.ui, repo, absf) | ||
Patrick Mezard
|
r16633 | self.ui.note(_('saving current version of %s as %s\n') % | ||
Martin von Zweigbergk
|
r41732 | (f, os.path.relpath(absorig))) | ||
Patrick Mezard
|
r16634 | if copy: | ||
Christian Delahousse
|
r26943 | util.copyfile(absf, absorig) | ||
Patrick Mezard
|
r16634 | else: | ||
Christian Delahousse
|
r26943 | util.rename(absf, absorig) | ||
Patrick Mezard
|
r16633 | |||
Patrick Mezard
|
r10184 | def printdiff(self, repo, diffopts, node1, node2=None, files=None, | ||
Gregory Szorc
|
r31394 | fp=None, changes=None, opts=None): | ||
Pierre-Yves David
|
r31432 | if opts is None: | ||
opts = {} | ||||
Brodie Rao
|
r9640 | stat = opts.get('stat') | ||
Matt Mackall
|
r14671 | m = scmutil.match(repo[node1], files, opts) | ||
Yuya Nishihara
|
r35906 | logcmdutil.diffordiffstat(self.ui, repo, diffopts, node1, node2, m, | ||
changes, stat, fp) | ||||
Vadim Gelfer
|
r2874 | |||
Patrick Mezard
|
r10184 | def mergeone(self, repo, mergeq, head, patch, rev, diffopts): | ||
mason@suse.com
|
r1808 | # first try just applying the patch | ||
Matt Mackall
|
r10282 | (err, n) = self.apply(repo, [patch], update_status=False, | ||
Matt Mackall
|
r4917 | strict=True, merge=rev) | ||
mason@suse.com
|
r1808 | |||
if err == 0: | ||||
return (err, n) | ||||
if n is None: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("apply failed for patch %s") % patch) | ||
mason@suse.com
|
r1808 | |||
Martin Geisler
|
r6960 | self.ui.warn(_("patch didn't work out, merging %s\n") % patch) | ||
mason@suse.com
|
r1808 | |||
# apply failed, strip away that rev and merge. | ||||
Matt Mackall
|
r4917 | hg.clean(repo, head) | ||
Jordi Gutiérrez Hermoso
|
r22057 | strip(self.ui, repo, [n], update=False, backup=False) | ||
mason@suse.com
|
r1808 | |||
Matt Mackall
|
r6747 | ctx = repo[rev] | ||
Matt Mackall
|
r4917 | ret = hg.merge(repo, rev) | ||
mason@suse.com
|
r1808 | if ret: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("update returned %d") % ret) | ||
Matt Mackall
|
r16102 | n = newcommit(repo, None, ctx.description(), ctx.user(), force=True) | ||
Martin Geisler
|
r8527 | if n is None: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("repo commit failed")) | ||
mason@suse.com
|
r1808 | try: | ||
Steve Losh
|
r10397 | ph = patchheader(mergeq.join(patch), self.plainmode) | ||
Brodie Rao
|
r16689 | except Exception: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("unable to read %s") % patch) | ||
mason@suse.com
|
r1808 | |||
Patrick Mezard
|
r10185 | diffopts = self.patchopts(diffopts, patch) | ||
Thomas Arendsen Hein
|
r1852 | patchf = self.opener(patch, "w") | ||
Pulkit Goyal
|
r36685 | comments = bytes(ph) | ||
mason@suse.com
|
r1808 | if comments: | ||
patchf.write(comments) | ||||
Patrick Mezard
|
r10184 | self.printdiff(repo, diffopts, head, n, fp=patchf) | ||
mason@suse.com
|
r1808 | patchf.close() | ||
Brendan Cully
|
r4207 | self.removeundo(repo) | ||
mason@suse.com
|
r1808 | return (0, n) | ||
Thomas Arendsen Hein
|
r1810 | |||
mason@suse.com
|
r1808 | def qparents(self, repo, rev=None): | ||
Pierre-Yves David
|
r19816 | """return the mq handled parent or p1 | ||
In some case where mq get himself in being the parent of a merge the | ||||
Mads Kiilerich
|
r19951 | appropriate parent may be p2. | ||
Pierre-Yves David
|
r19816 | (eg: an in progress merge started with mq disabled) | ||
If no parent are managed by mq, p1 is returned. | ||||
""" | ||||
mason@suse.com
|
r1808 | if rev is None: | ||
(p1, p2) = repo.dirstate.parents() | ||||
Matt Mackall
|
r7639 | if p2 == nullid: | ||
mason@suse.com
|
r1808 | return p1 | ||
Benoit Boissinot
|
r10686 | if not self.applied: | ||
mason@suse.com
|
r1808 | return None | ||
Benoit Boissinot
|
r10678 | return self.applied[-1].node | ||
p1, p2 = repo.changelog.parents(rev) | ||||
Benoit Boissinot
|
r10680 | if p2 != nullid and p2 in [x.node for x in self.applied]: | ||
return p2 | ||||
Benoit Boissinot
|
r10678 | return p1 | ||
mason@suse.com
|
r1808 | |||
Patrick Mezard
|
r10184 | def mergepatch(self, repo, mergeq, series, diffopts): | ||
Benoit Boissinot
|
r10686 | if not self.applied: | ||
mason@suse.com
|
r1808 | # each of the patches merged in will have two parents. This | ||
# can confuse the qrefresh, qdiff, and strip code because it | ||||
# needs to know which parent is actually in the patch queue. | ||||
# so, we insert a merge marker with only one parent. This way | ||||
# the first patch in the queue is never a merge patch | ||||
# | ||||
pname = ".hg.patches.merge.marker" | ||||
Matt Mackall
|
r16102 | n = newcommit(repo, None, '[mq]: merge marker', force=True) | ||
Brendan Cully
|
r4207 | self.removeundo(repo) | ||
Benoit Boissinot
|
r10678 | self.applied.append(statusentry(n, pname)) | ||
Mads Kiilerich
|
r15879 | self.applieddirty = True | ||
mason@suse.com
|
r1808 | |||
head = self.qparents(repo) | ||||
for patch in series: | ||||
Chris Mason
|
r2696 | patch = mergeq.lookup(patch, strict=True) | ||
mason@suse.com
|
r1808 | if not patch: | ||
Martin Geisler
|
r6960 | self.ui.warn(_("patch %s does not exist\n") % patch) | ||
mason@suse.com
|
r1808 | return (1, None) | ||
Vadim Gelfer
|
r2821 | pushable, reason = self.pushable(patch) | ||
if not pushable: | ||||
Adrian Buehlmann
|
r14579 | self.explainpushable(patch, all_patches=True) | ||
Vadim Gelfer
|
r2821 | continue | ||
mason@suse.com
|
r1808 | info = mergeq.isapplied(patch) | ||
if not info: | ||||
Martin Geisler
|
r6960 | self.ui.warn(_("patch %s is not applied\n") % patch) | ||
mason@suse.com
|
r1808 | return (1, None) | ||
Benoit Boissinot
|
r10678 | rev = info[1] | ||
Patrick Mezard
|
r10184 | err, head = self.mergeone(repo, mergeq, head, patch, rev, diffopts) | ||
mason@suse.com
|
r1808 | if head: | ||
Benoit Boissinot
|
r10678 | self.applied.append(statusentry(head, patch)) | ||
Mads Kiilerich
|
r15879 | self.applieddirty = True | ||
mason@suse.com
|
r1808 | if err: | ||
return (err, head) | ||||
Adrian Buehlmann
|
r14580 | self.savedirty() | ||
mason@suse.com
|
r1808 | return (0, head) | ||
Brendan Cully
|
r2748 | def patch(self, repo, patchfile): | ||
'''Apply patchfile to the working directory. | ||||
timeless
|
r8761 | patchfile: name of patch file''' | ||
Patrick Mezard
|
r14564 | files = set() | ||
Brendan Cully
|
r2748 | try: | ||
Patrick Mezard
|
r14260 | fuzz = patchmod.patch(self.ui, repo, patchfile, strip=1, | ||
Patrick Mezard
|
r14382 | files=files, eolmode=None) | ||
Patrick Mezard
|
r14260 | return (True, list(files), fuzz) | ||
Gregory Szorc
|
r25660 | except Exception as inst: | ||
Yuya Nishihara
|
r37102 | self.ui.note(stringutil.forcebytestr(inst) + '\n') | ||
Brendan Cully
|
r2919 | if not self.ui.verbose: | ||
Martin Geisler
|
r6960 | self.ui.warn(_("patch failed, unable to continue (try -v)\n")) | ||
Dan Villiom Podlaski Christiansen
|
r15085 | self.ui.traceback() | ||
Patrick Mezard
|
r14260 | return (False, list(files), False) | ||
Benoit Boissinot
|
r2796 | |||
Thomas Arendsen Hein
|
r1810 | def apply(self, repo, series, list=False, update_status=True, | ||
Patrick Mezard
|
r16634 | strict=False, patchdir=None, merge=None, all_files=None, | ||
Patrick Mezard
|
r16733 | tobackup=None, keepchanges=False): | ||
FUJIWARA Katsunori
|
r26578 | wlock = lock = tr = None | ||
Bryan O'Sullivan
|
r4418 | try: | ||
Matt Mackall
|
r4917 | wlock = repo.wlock() | ||
Matt Mackall
|
r4915 | lock = repo.lock() | ||
Steve Borho
|
r10881 | tr = repo.transaction("qpush") | ||
Bryan O'Sullivan
|
r4418 | try: | ||
Matt Mackall
|
r4970 | ret = self._apply(repo, series, list, update_status, | ||
Patrick Mezard
|
r16634 | strict, patchdir, merge, all_files=all_files, | ||
Patrick Mezard
|
r16733 | tobackup=tobackup, keepchanges=keepchanges) | ||
Matt Mackall
|
r4915 | tr.close() | ||
Adrian Buehlmann
|
r14580 | self.savedirty() | ||
Matt Mackall
|
r4915 | return ret | ||
Patrick Mezard
|
r16654 | except AbortNoCleanup: | ||
tr.close() | ||||
self.savedirty() | ||||
Matt Mackall
|
r24826 | raise | ||
Brodie Rao
|
r16705 | except: # re-raises | ||
Matt Mackall
|
r4915 | try: | ||
tr.abort() | ||||
finally: | ||||
Mads Kiilerich
|
r15881 | self.invalidate() | ||
Matt Mackall
|
r4915 | raise | ||
finally: | ||||
FUJIWARA Katsunori
|
r26578 | release(tr, lock, wlock) | ||
Alexis S. L. Carvalho
|
r5527 | self.removeundo(repo) | ||
Bryan O'Sullivan
|
r4418 | |||
Matt Mackall
|
r4970 | def _apply(self, repo, series, list=False, update_status=True, | ||
Patrick Mezard
|
r16634 | strict=False, patchdir=None, merge=None, all_files=None, | ||
Patrick Mezard
|
r16733 | tobackup=None, keepchanges=False): | ||
Patrick Mezard
|
r16634 | """returns (error, hash) | ||
error = 1 for unable to read, 2 for patch failed, 3 for patch | ||||
fuzz. tobackup is None or a set of files to backup before they | ||||
are modified by a patch. | ||||
""" | ||||
mason@suse.com
|
r1808 | # TODO unify with commands.py | ||
if not patchdir: | ||||
patchdir = self.path | ||||
err = 0 | ||||
n = None | ||||
Brendan Cully
|
r2934 | for patchname in series: | ||
pushable, reason = self.pushable(patchname) | ||||
Vadim Gelfer
|
r2821 | if not pushable: | ||
Adrian Buehlmann
|
r14579 | self.explainpushable(patchname, all_patches=True) | ||
Vadim Gelfer
|
r2821 | continue | ||
Martin Geisler
|
r9111 | self.ui.status(_("applying %s\n") % patchname) | ||
Brendan Cully
|
r2934 | pf = os.path.join(patchdir, patchname) | ||
mason@suse.com
|
r1808 | |||
try: | ||||
Steve Losh
|
r10397 | ph = patchheader(self.join(patchname), self.plainmode) | ||
Idan Kamara
|
r14239 | except IOError: | ||
Dirkjan Ochtman
|
r8875 | self.ui.warn(_("unable to read %s\n") % patchname) | ||
mason@suse.com
|
r1808 | err = 1 | ||
break | ||||
Brendan Cully
|
r7399 | message = ph.message | ||
mason@suse.com
|
r1808 | if not message: | ||
Martin Geisler
|
r12849 | # The commit message should not be translated | ||
David Soria Parra
|
r10274 | message = "imported patch %s\n" % patchname | ||
mason@suse.com
|
r1808 | else: | ||
if list: | ||||
Martin Geisler
|
r12849 | # The commit message should not be translated | ||
David Soria Parra
|
r10274 | message.append("\nimported patch %s" % patchname) | ||
mason@suse.com
|
r1808 | message = '\n'.join(message) | ||
Matt Mackall
|
r7782 | if ph.haspatch: | ||
Patrick Mezard
|
r16634 | if tobackup: | ||
touched = patchmod.changedfiles(self.ui, repo, pf) | ||||
touched = set(touched) & tobackup | ||||
Patrick Mezard
|
r16733 | if touched and keepchanges: | ||
Patrick Mezard
|
r16654 | raise AbortNoCleanup( | ||
Matt Mackall
|
r24826 | _("conflicting local changes found"), | ||
hint=_("did you forget to qrefresh?")) | ||||
Patrick Mezard
|
r16634 | self.backup(repo, touched, copy=True) | ||
tobackup = tobackup - touched | ||||
Matt Mackall
|
r7782 | (patcherr, files, fuzz) = self.patch(repo, pf) | ||
Benoit Boissinot
|
r10661 | if all_files is not None: | ||
all_files.update(files) | ||||
Matt Mackall
|
r7782 | patcherr = not patcherr | ||
else: | ||||
self.ui.warn(_("patch %s is empty\n") % patchname) | ||||
patcherr, files, fuzz = 0, [], 0 | ||||
mason@suse.com
|
r1808 | |||
Brendan Cully
|
r2934 | if merge and files: | ||
Alexis S. L. Carvalho
|
r4332 | # Mark as removed/merged and update dirstate parent info | ||
removed = [] | ||||
merged = [] | ||||
for f in files: | ||||
Patrick Mezard
|
r12344 | if os.path.lexists(repo.wjoin(f)): | ||
Alexis S. L. Carvalho
|
r4332 | merged.append(f) | ||
else: | ||||
removed.append(f) | ||||
Augie Fackler
|
r32347 | with repo.dirstate.parentchange(): | ||
for f in removed: | ||||
repo.dirstate.remove(f) | ||||
for f in merged: | ||||
repo.dirstate.merge(f) | ||||
Martin von Zweigbergk
|
r41444 | p1 = repo.dirstate.p1() | ||
Augie Fackler
|
r32347 | repo.setparents(p1, merge) | ||
Matt Mackall
|
r6603 | |||
Angel Ezquerra
|
r19638 | if all_files and '.hgsubstate' in all_files: | ||
Mads Kiilerich
|
r20959 | wctx = repo[None] | ||
pctx = repo['.'] | ||||
Angel Ezquerra
|
r19638 | overwrite = False | ||
Yuya Nishihara
|
r36026 | mergedsubstate = subrepoutil.submerge(repo, pctx, wctx, wctx, | ||
overwrite) | ||||
Angel Ezquerra
|
r19638 | files += mergedsubstate.keys() | ||
Matt Mackall
|
r14322 | match = scmutil.matchfiles(repo, files or []) | ||
Martin von Zweigbergk
|
r39931 | oldtip = repo.changelog.tip() | ||
Matt Mackall
|
r16102 | n = newcommit(repo, None, message, ph.user, ph.date, match=match, | ||
force=True) | ||||
Martin von Zweigbergk
|
r39931 | if repo.changelog.tip() == oldtip: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("qpush exactly duplicates child changeset")) | ||
Martin Geisler
|
r8527 | if n is None: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("repository commit failed")) | ||
mason@suse.com
|
r1808 | |||
if update_status: | ||||
Benoit Boissinot
|
r10678 | self.applied.append(statusentry(n, patchname)) | ||
mason@suse.com
|
r1808 | |||
if patcherr: | ||||
Yuya Nishihara
|
r24365 | self.ui.warn(_("patch failed, rejects left in working " | ||
"directory\n")) | ||||
Dirkjan Ochtman
|
r8875 | err = 2 | ||
mason@suse.com
|
r1808 | break | ||
if fuzz and strict: | ||||
Martin Geisler
|
r6960 | self.ui.warn(_("fuzz found when applying patch, stopping\n")) | ||
Dirkjan Ochtman
|
r8875 | err = 3 | ||
mason@suse.com
|
r1808 | break | ||
return (err, n) | ||||
Dirkjan Ochtman
|
r8833 | def _cleanup(self, patches, numrevs, keep=False): | ||
if not keep: | ||||
r = self.qrepo() | ||||
if r: | ||||
Matt Mackall
|
r14435 | r[None].forget(patches) | ||
for p in patches: | ||||
Mads Kiilerich
|
r18067 | try: | ||
os.unlink(self.join(p)) | ||||
Gregory Szorc
|
r25660 | except OSError as inst: | ||
Mads Kiilerich
|
r18067 | if inst.errno != errno.ENOENT: | ||
raise | ||||
Dirkjan Ochtman
|
r8833 | |||
Pierre-Yves David
|
r15920 | qfinished = [] | ||
Dirkjan Ochtman
|
r8833 | if numrevs: | ||
Pierre-Yves David
|
r14010 | qfinished = self.applied[:numrevs] | ||
Dirkjan Ochtman
|
r8833 | del self.applied[:numrevs] | ||
Mads Kiilerich
|
r15879 | self.applieddirty = True | ||
Dirkjan Ochtman
|
r8833 | |||
Pierre-Yves David
|
r14010 | unknown = [] | ||
Pulkit Goyal
|
r37543 | sortedseries = [] | ||
for p in patches: | ||||
idx = self.findseries(p) | ||||
if idx is None: | ||||
sortedseries.append((-1, p)) | ||||
else: | ||||
sortedseries.append((idx, p)) | ||||
sortedseries.sort(reverse=True) | ||||
for (i, p) in sortedseries: | ||||
if i != -1: | ||||
Adrian Buehlmann
|
r14572 | del self.fullseries[i] | ||
Pierre-Yves David
|
r14010 | else: | ||
unknown.append(p) | ||||
if unknown: | ||||
if numrevs: | ||||
rev = dict((entry.name, entry.node) for entry in qfinished) | ||||
for p in unknown: | ||||
msg = _('revision %s refers to unknown patches: %s\n') | ||||
self.ui.warn(msg % (short(rev[p]), p)) | ||||
else: | ||||
msg = _('unknown patches: %s\n') | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(''.join(msg % p for p in unknown)) | ||
Pierre-Yves David
|
r14010 | |||
Adrian Buehlmann
|
r14575 | self.parseseries() | ||
Mads Kiilerich
|
r15879 | self.seriesdirty = True | ||
Pierre-Yves David
|
r15920 | return [entry.node for entry in qfinished] | ||
Dirkjan Ochtman
|
r6645 | |||
Dirkjan Ochtman
|
r8833 | def _revpatches(self, repo, revs): | ||
Benoit Boissinot
|
r10678 | firstrev = repo[self.applied[0].node].rev() | ||
Dirkjan Ochtman
|
r6645 | patches = [] | ||
Dirkjan Ochtman
|
r8833 | for i, rev in enumerate(revs): | ||
Dirkjan Ochtman
|
r8832 | |||
Dirkjan Ochtman
|
r6645 | if rev < firstrev: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('revision %d is not managed') % rev) | ||
Dirkjan Ochtman
|
r8832 | |||
ctx = repo[rev] | ||||
Benoit Boissinot
|
r10678 | base = self.applied[i].node | ||
Dirkjan Ochtman
|
r8832 | if ctx.node() != base: | ||
msg = _('cannot delete revision %d above applied patches') | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(msg % rev) | ||
Dirkjan Ochtman
|
r8832 | |||
Dirkjan Ochtman
|
r8833 | patch = self.applied[i].name | ||
Dirkjan Ochtman
|
r8832 | for fmt in ('[mq]: %s', 'imported patch %s'): | ||
if ctx.description() == fmt % patch: | ||||
msg = _('patch %s finalized without changeset message\n') | ||||
repo.ui.status(msg % patch) | ||||
break | ||||
Dirkjan Ochtman
|
r8833 | patches.append(patch) | ||
return patches | ||||
Dirkjan Ochtman
|
r6645 | |||
Dirkjan Ochtman
|
r8833 | def finish(self, repo, revs): | ||
Pierre-Yves David
|
r16029 | # Manually trigger phase computation to ensure phasedefaults is | ||
# executed before we remove the patches. | ||||
Patrick Mezard
|
r16657 | repo._phasecache | ||
Dirkjan Ochtman
|
r8833 | patches = self._revpatches(repo, sorted(revs)) | ||
Pierre-Yves David
|
r15920 | qfinished = self._cleanup(patches, len(patches)) | ||
Boris Feld
|
r34185 | if qfinished and repo.ui.configbool('mq', 'secret'): | ||
Pierre-Yves David
|
r16029 | # only use this logic when the secret option is added | ||
Pierre-Yves David
|
r15920 | oldqbase = repo[qfinished[0]] | ||
Boris Feld
|
r34563 | tphase = phases.newcommitphase(repo.ui) | ||
Pierre-Yves David
|
r16290 | if oldqbase.phase() > tphase and oldqbase.p1().phase() <= tphase: | ||
Bryan O'Sullivan
|
r27864 | with repo.transaction('qfinish') as tr: | ||
Pierre-Yves David
|
r22069 | phases.advanceboundary(repo, tr, tphase, qfinished) | ||
Dirkjan Ochtman
|
r6645 | |||
Brendan Cully
|
r3088 | def delete(self, repo, patches, opts): | ||
Brendan Cully
|
r4736 | if not patches and not opts.get('rev'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('qdelete requires at least one revision or ' | ||
Brendan Cully
|
r4737 | 'patch name')) | ||
Brendan Cully
|
r4736 | |||
Greg Ward
|
r11365 | realpatches = [] | ||
Brendan Cully
|
r2905 | for patch in patches: | ||
patch = self.lookup(patch, strict=True) | ||||
info = self.isapplied(patch) | ||||
Brendan Cully
|
r3373 | if info: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("cannot delete applied patch %s") % patch) | ||
Brendan Cully
|
r2905 | if patch not in self.series: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("patch %s not in series file") % patch) | ||
Dan Villiom Podlaski Christiansen
|
r12655 | if patch not in realpatches: | ||
realpatches.append(patch) | ||||
Brendan Cully
|
r3373 | |||
Dirkjan Ochtman
|
r8833 | numrevs = 0 | ||
Brendan Cully
|
r3373 | if opts.get('rev'): | ||
if not self.applied: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no patches applied')) | ||
Matt Mackall
|
r14319 | revs = scmutil.revrange(repo, opts.get('rev')) | ||
Pierre-Yves David
|
r22803 | revs.sort() | ||
Dirkjan Ochtman
|
r8833 | revpatches = self._revpatches(repo, revs) | ||
Greg Ward
|
r11365 | realpatches += revpatches | ||
Dirkjan Ochtman
|
r8833 | numrevs = len(revpatches) | ||
Brendan Cully
|
r2905 | |||
Greg Ward
|
r11365 | self._cleanup(realpatches, numrevs, opts.get('keep')) | ||
Thomas Arendsen Hein
|
r1810 | |||
Adrian Buehlmann
|
r14581 | def checktoppatch(self, repo): | ||
Mads Kiilerich
|
r18343 | '''check that working directory is at qtip''' | ||
Benoit Boissinot
|
r10686 | if self.applied: | ||
Benoit Boissinot
|
r10678 | top = self.applied[-1].node | ||
Patrick Mezard
|
r10191 | patch = self.applied[-1].name | ||
Mads Kiilerich
|
r18343 | if repo.dirstate.p1() != top: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("working directory revision is not qtip")) | ||
Patrick Mezard
|
r10191 | return top, patch | ||
return None, None | ||||
FUJIWARA Katsunori
|
r17152 | def putsubstate2changes(self, substatestate, changes): | ||
for files in changes[:3]: | ||||
if '.hgsubstate' in files: | ||||
return # already listed up | ||||
# not yet listed up | ||||
if substatestate in 'a?': | ||||
changes[1].append('.hgsubstate') | ||||
elif substatestate in 'r': | ||||
changes[2].append('.hgsubstate') | ||||
else: # modified | ||||
changes[0].append('.hgsubstate') | ||||
Pierre-Yves David
|
r19812 | def checklocalchanges(self, repo, force=False, refresh=True): | ||
excsuffix = '' | ||||
Idan Kamara
|
r14256 | if refresh: | ||
timeless@mozdev.org
|
r26780 | excsuffix = ', qrefresh first' | ||
Pierre-Yves David
|
r19812 | # plain versions for i18n tool to detect them | ||
timeless@mozdev.org
|
r26780 | _("local changes found, qrefresh first") | ||
_("local changed subrepos found, qrefresh first") | ||||
Pierre-Yves David
|
r19814 | return checklocalchanges(repo, force, excsuffix) | ||
Brendan Cully
|
r4713 | |||
Idan Kamara
|
r14051 | _reserved = ('series', 'status', 'guards', '.', '..') | ||
Adrian Buehlmann
|
r14584 | def checkreservedname(self, name): | ||
Idan Kamara
|
r14054 | if name in self._reserved: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('"%s" cannot be used as the name of a patch') | ||
Alexis S. L. Carvalho
|
r5981 | % name) | ||
Yuya Nishihara
|
r31556 | if name != name.strip(): | ||
# whitespace is stripped by parseseries() | ||||
raise error.Abort(_('patch name cannot begin or end with ' | ||||
'whitespace')) | ||||
Idan Kamara
|
r14054 | for prefix in ('.hg', '.mq'): | ||
if name.startswith(prefix): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('patch name cannot begin with "%s"') | ||
Idan Kamara
|
r14054 | % prefix) | ||
Augie Fackler
|
r25454 | for c in ('#', ':', '\r', '\n'): | ||
Idan Kamara
|
r14054 | if c in name: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('%r cannot be used in the name of a patch') | ||
Pulkit Goyal
|
r37577 | % pycompat.bytestr(c)) | ||
Idan Kamara
|
r14054 | |||
Idan Kamara
|
r14422 | def checkpatchname(self, name, force=False): | ||
Adrian Buehlmann
|
r14584 | self.checkreservedname(name) | ||
Idan Kamara
|
r14422 | if not force and os.path.exists(self.join(name)): | ||
if os.path.isdir(self.join(name)): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('"%s" already exists as a directory') | ||
Idan Kamara
|
r14422 | % name) | ||
else: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('patch "%s" already exists') % name) | ||
Alexis S. L. Carvalho
|
r5981 | |||
Mads Kiilerich
|
r27918 | def makepatchname(self, title, fallbackname): | ||
"""Return a suitable filename for title, adding a suffix to make | ||||
it unique in the existing list""" | ||||
Gregory Szorc
|
r41673 | namebase = re.sub(br'[\s\W_]+', b'_', title.lower()).strip(b'_') | ||
Pierre-Yves David
|
r28388 | namebase = namebase[:75] # avoid too long name (issue5117) | ||
Mads Kiilerich
|
r27919 | if namebase: | ||
try: | ||||
self.checkreservedname(namebase) | ||||
except error.Abort: | ||||
namebase = fallbackname | ||||
else: | ||||
Mads Kiilerich
|
r27918 | namebase = fallbackname | ||
name = namebase | ||||
i = 0 | ||||
Mads Kiilerich
|
r27919 | while True: | ||
if name not in self.fullseries: | ||||
try: | ||||
self.checkpatchname(name) | ||||
break | ||||
except error.Abort: | ||||
pass | ||||
Mads Kiilerich
|
r27918 | i += 1 | ||
Pulkit Goyal
|
r36049 | name = '%s__%d' % (namebase, i) | ||
Mads Kiilerich
|
r27918 | return name | ||
Patrick Mezard
|
r16733 | def checkkeepchanges(self, keepchanges, force): | ||
if force and keepchanges: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot use both --force and --keep-changes')) | ||
Patrick Mezard
|
r16654 | |||
Brendan Cully
|
r7162 | def new(self, repo, patchfn, *pats, **opts): | ||
Brendan Cully
|
r7157 | """options: | ||
msg: a string or a no-argument function returning a string | ||||
""" | ||||
Pulkit Goyal
|
r36405 | opts = pycompat.byteskwargs(opts) | ||
Brendan Cully
|
r4713 | msg = opts.get('msg') | ||
FUJIWARA Katsunori
|
r21420 | edit = opts.get('edit') | ||
FUJIWARA Katsunori
|
r22003 | editform = opts.get('editform', 'mq.qnew') | ||
peter.arrenbrecht@gmail.com
|
r5673 | user = opts.get('user') | ||
Peter Arrenbrecht
|
r5788 | date = opts.get('date') | ||
Thomas Arendsen Hein
|
r6139 | if date: | ||
Boris Feld
|
r36625 | date = dateutil.parsedate(date) | ||
Mads Kiilerich
|
r34092 | diffopts = self.diffopts({'git': opts.get('git')}, plain=True) | ||
Idan Kamara
|
r14424 | if opts.get('checkname', True): | ||
self.checkpatchname(patchfn) | ||||
Pierre-Yves David
|
r19813 | inclsubs = checksubstate(repo) | ||
Kevin Bullock
|
r13174 | if inclsubs: | ||
FUJIWARA Katsunori
|
r16366 | substatestate = repo.dirstate['.hgsubstate'] | ||
Brendan Cully
|
r4713 | if opts.get('include') or opts.get('exclude') or pats: | ||
Brendan Cully
|
r7161 | # detect missing files in pats | ||
def badfn(f, msg): | ||||
Kevin Bullock
|
r13174 | if f != '.hgsubstate': # .hgsubstate is auto-created | ||
Pierre-Yves David
|
r26587 | raise error.Abort('%s: %s' % (f, msg)) | ||
Matt Harbison
|
r25469 | match = scmutil.match(repo[None], pats, opts, badfn=badfn) | ||
FUJIWARA Katsunori
|
r16366 | changes = repo.status(match=match) | ||
Brendan Cully
|
r4713 | else: | ||
FUJIWARA Katsunori
|
r16366 | changes = self.checklocalchanges(repo, force=True) | ||
FUJIWARA Katsunori
|
r20786 | commitfiles = list(inclsubs) | ||
for files in changes[:3]: | ||||
FUJIWARA Katsunori
|
r20827 | commitfiles.extend(files) | ||
FUJIWARA Katsunori
|
r20786 | match = scmutil.matchfiles(repo, commitfiles) | ||
Augie Fackler
|
r10372 | if len(repo[None].parents()) > 1: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot manage merge changesets')) | ||
Adrian Buehlmann
|
r14581 | self.checktoppatch(repo) | ||
Adrian Buehlmann
|
r14585 | insert = self.fullseriesend() | ||
Bryan O'Sullivan
|
r27827 | with repo.wlock(): | ||
Martin Geisler
|
r12878 | try: | ||
# if patch file write fails, abort early | ||||
p = self.opener(patchfn, "w") | ||||
Gregory Szorc
|
r25660 | except IOError as e: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot write patch "%s": %s') | ||
Augie Fackler
|
r34024 | % (patchfn, encoding.strtolocal(e.strerror))) | ||
Brendan Cully
|
r7162 | try: | ||
FUJIWARA Katsunori
|
r21234 | defaultmsg = "[mq]: %s" % patchfn | ||
FUJIWARA Katsunori
|
r22003 | editor = cmdutil.getcommiteditor(editform=editform) | ||
FUJIWARA Katsunori
|
r21420 | if edit: | ||
FUJIWARA Katsunori
|
r21421 | def finishdesc(desc): | ||
FUJIWARA Katsunori
|
r21234 | if desc.rstrip(): | ||
return desc | ||||
else: | ||||
return defaultmsg | ||||
FUJIWARA Katsunori
|
r21421 | # i18n: this message is shown in editor with "HG: " prefix | ||
extramsg = _('Leave message empty to use default message.') | ||||
editor = cmdutil.getcommiteditor(finishdesc=finishdesc, | ||||
FUJIWARA Katsunori
|
r22003 | extramsg=extramsg, | ||
editform=editform) | ||||
FUJIWARA Katsunori
|
r21234 | commitmsg = msg | ||
else: | ||||
commitmsg = msg or defaultmsg | ||||
Matt Mackall
|
r16102 | n = newcommit(repo, None, commitmsg, user, date, match=match, | ||
FUJIWARA Katsunori
|
r21234 | force=True, editor=editor) | ||
Martin Geisler
|
r8527 | if n is None: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("repo commit failed")) | ||
Brendan Cully
|
r7162 | try: | ||
Adrian Buehlmann
|
r14572 | self.fullseries[insert:insert] = [patchfn] | ||
Benoit Boissinot
|
r10678 | self.applied.append(statusentry(n, patchfn)) | ||
Adrian Buehlmann
|
r14575 | self.parseseries() | ||
Mads Kiilerich
|
r15879 | self.seriesdirty = True | ||
self.applieddirty = True | ||||
FUJIWARA Katsunori
|
r21234 | nctx = repo[n] | ||
Mads Kiilerich
|
r22547 | ph = patchheader(self.join(patchfn), self.plainmode) | ||
if user: | ||||
ph.setuser(user) | ||||
if date: | ||||
Pulkit Goyal
|
r36407 | ph.setdate('%d %d' % date) | ||
Mads Kiilerich
|
r22547 | ph.setparent(hex(nctx.p1().node())) | ||
msg = nctx.description().strip() | ||||
if msg == defaultmsg.strip(): | ||||
msg = '' | ||||
ph.setmessage(msg) | ||||
Pulkit Goyal
|
r35966 | p.write(bytes(ph)) | ||
Brendan Cully
|
r7162 | if commitfiles: | ||
parent = self.qparents(repo, n) | ||||
FUJIWARA Katsunori
|
r16366 | if inclsubs: | ||
FUJIWARA Katsunori
|
r17152 | self.putsubstate2changes(substatestate, changes) | ||
Idan Kamara
|
r14241 | chunks = patchmod.diff(repo, node1=parent, node2=n, | ||
FUJIWARA Katsunori
|
r16366 | changes=changes, opts=diffopts) | ||
Dirkjan Ochtman
|
r7308 | for chunk in chunks: | ||
p.write(chunk) | ||||
Brendan Cully
|
r7162 | p.close() | ||
r = self.qrepo() | ||||
Matt Mackall
|
r10282 | if r: | ||
Dirkjan Ochtman
|
r11303 | r[None].add([patchfn]) | ||
Brodie Rao
|
r16705 | except: # re-raises | ||
Brendan Cully
|
r7162 | repo.rollback() | ||
raise | ||||
Benoit Boissinot
|
r7280 | except Exception: | ||
Brendan Cully
|
r7162 | patchpath = self.join(patchfn) | ||
try: | ||||
os.unlink(patchpath) | ||||
Brodie Rao
|
r16688 | except OSError: | ||
Brendan Cully
|
r7162 | self.ui.warn(_('error unlinking %s\n') % patchpath) | ||
raise | ||||
Matt Mackall
|
r4915 | self.removeundo(repo) | ||
mason@suse.com
|
r1808 | |||
def isapplied(self, patch): | ||||
"""returns (index, rev, patch)""" | ||||
Martin Geisler
|
r8632 | for i, a in enumerate(self.applied): | ||
Brendan Cully
|
r2780 | if a.name == patch: | ||
Benoit Boissinot
|
r10678 | return (i, a.node, a.name) | ||
mason@suse.com
|
r1808 | return None | ||
Thomas Arendsen Hein
|
r3223 | # if the exact patch name does not exist, we try a few | ||
Chris Mason
|
r2696 | # variations. If strict is passed, we try only #1 | ||
# | ||||
Mads Kiilerich
|
r15256 | # 1) a number (as string) to indicate an offset in the series file | ||
Chris Mason
|
r2696 | # 2) a unique substring of the patch name was given | ||
# 3) patchname[-+]num to indicate an offset in the series file | ||||
def lookup(self, patch, strict=False): | ||||
Adrian Buehlmann
|
r14595 | def partialname(s): | ||
Chris Mason
|
r2696 | if s in self.series: | ||
return s | ||||
Vadim Gelfer
|
r2765 | matches = [x for x in self.series if s in x] | ||
if len(matches) > 1: | ||||
self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) | ||||
for m in matches: | ||||
self.ui.warn(' %s\n' % m) | ||||
return None | ||||
if matches: | ||||
return matches[0] | ||||
Benoit Boissinot
|
r10686 | if self.series and self.applied: | ||
Chris Mason
|
r2696 | if s == 'qtip': | ||
Mads Kiilerich
|
r18054 | return self.series[self.seriesend(True) - 1] | ||
Chris Mason
|
r2696 | if s == 'qbase': | ||
return self.series[0] | ||||
return None | ||||
Jason Orendorff
|
r7568 | |||
if patch in self.series: | ||||
return patch | ||||
Chris Mason
|
r2696 | |||
Vadim Gelfer
|
r2819 | if not os.path.isfile(self.join(patch)): | ||
mason@suse.com
|
r1808 | try: | ||
sno = int(patch) | ||||
Matt Mackall
|
r10282 | except (ValueError, OverflowError): | ||
Chris Mason
|
r2696 | pass | ||
else: | ||||
Jason Orendorff
|
r7568 | if -len(self.series) <= sno < len(self.series): | ||
Vadim Gelfer
|
r2821 | return self.series[sno] | ||
Jason Orendorff
|
r7568 | |||
Chris Mason
|
r2696 | if not strict: | ||
Adrian Buehlmann
|
r14595 | res = partialname(patch) | ||
Chris Mason
|
r2696 | if res: | ||
return res | ||||
Thomas Arendsen Hein
|
r3082 | minus = patch.rfind('-') | ||
if minus >= 0: | ||||
Adrian Buehlmann
|
r14595 | res = partialname(patch[:minus]) | ||
Chris Mason
|
r2696 | if res: | ||
i = self.series.index(res) | ||||
try: | ||||
Matt Mackall
|
r10282 | off = int(patch[minus + 1:] or 1) | ||
except (ValueError, OverflowError): | ||||
Chris Mason
|
r2696 | pass | ||
else: | ||||
if i - off >= 0: | ||||
return self.series[i - off] | ||||
Thomas Arendsen Hein
|
r3082 | plus = patch.rfind('+') | ||
if plus >= 0: | ||||
Adrian Buehlmann
|
r14595 | res = partialname(patch[:plus]) | ||
Chris Mason
|
r2696 | if res: | ||
i = self.series.index(res) | ||||
try: | ||||
Matt Mackall
|
r10282 | off = int(patch[plus + 1:] or 1) | ||
except (ValueError, OverflowError): | ||||
Chris Mason
|
r2696 | pass | ||
else: | ||||
if i + off < len(self.series): | ||||
return self.series[i + off] | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("patch %s not in series") % patch) | ||
mason@suse.com
|
r1808 | |||
Patrick Mezard
|
r16654 | def push(self, repo, patch=None, force=False, list=False, mergeq=None, | ||
Patrick Mezard
|
r16733 | all=False, move=False, exact=False, nobackup=False, | ||
keepchanges=False): | ||||
self.checkkeepchanges(keepchanges, force) | ||||
Patrick Mezard
|
r10184 | diffopts = self.diffopts() | ||
Bryan O'Sullivan
|
r27828 | with repo.wlock(): | ||
Kevin Bullock
|
r20119 | heads = [] | ||
for hs in repo.branchmap().itervalues(): | ||||
heads.extend(hs) | ||||
Dirkjan Ochtman
|
r10362 | if not heads: | ||
heads = [nullid] | ||||
Matt Mackall
|
r13878 | if repo.dirstate.p1() not in heads and not exact: | ||
Adrian Buehlmann
|
r8795 | self.ui.status(_("(working directory not at a head)\n")) | ||
Matt Mackall
|
r6340 | |||
Adrian Buehlmann
|
r8795 | if not self.series: | ||
self.ui.warn(_('no patches in series\n')) | ||||
return 0 | ||||
Brendan Cully
|
r7398 | |||
Matt Mackall
|
r4915 | # Suppose our series file is: A B C and the current 'top' | ||
# patch is B. qpush C should be performed (moving forward) | ||||
# qpush B is a NOP (no change) qpush A is an error (can't | ||||
# go backwards with qpush) | ||||
if patch: | ||||
Mads Kiilerich
|
r15257 | patch = self.lookup(patch) | ||
Matt Mackall
|
r4915 | info = self.isapplied(patch) | ||
Afuna
|
r13369 | if info and info[0] >= len(self.applied) - 1: | ||
Brendan Cully
|
r7398 | self.ui.warn( | ||
_('qpush: %s is already at the top\n') % patch) | ||||
Gilles Moris
|
r11439 | return 0 | ||
Afuna
|
r13369 | |||
Brendan Cully
|
r7398 | pushable, reason = self.pushable(patch) | ||
Afuna
|
r13369 | if pushable: | ||
Adrian Buehlmann
|
r14586 | if self.series.index(patch) < self.seriesend(): | ||
Pierre-Yves David
|
r26587 | raise error.Abort( | ||
Afuna
|
r13369 | _("cannot push to a previous patch: %s") % patch) | ||
else: | ||||
Brendan Cully
|
r7398 | if reason: | ||
Martin Geisler
|
r14464 | reason = _('guarded by %s') % reason | ||
Matt Mackall
|
r4915 | else: | ||
Brendan Cully
|
r7398 | reason = _('no matching guards') | ||
self.ui.warn(_("cannot push '%s' - %s\n") % (patch, reason)) | ||||
return 1 | ||||
elif all: | ||||
patch = self.series[-1] | ||||
if self.isapplied(patch): | ||||
self.ui.warn(_('all patches are currently applied\n')) | ||||
return 0 | ||||
Ben Thomas
|
r4100 | |||
Matt Mackall
|
r4915 | # Following the above example, starting at 'top' of B: | ||
# qpush should be performed (pushes C), but a subsequent | ||||
# qpush without an argument is an error (nothing to | ||||
# apply). This allows a loop of "...while hg qpush..." to | ||||
# work as it detects an error when done | ||||
Adrian Buehlmann
|
r14586 | start = self.seriesend() | ||
Brendan Cully
|
r7398 | if start == len(self.series): | ||
Matt Mackall
|
r4915 | self.ui.warn(_('patch series already fully applied\n')) | ||
return 1 | ||||
Patrick Mezard
|
r16733 | if not force and not keepchanges: | ||
Idan Kamara
|
r14732 | self.checklocalchanges(repo, refresh=self.applied) | ||
Thomas Arendsen Hein
|
r1810 | |||
Steve Losh
|
r13033 | if exact: | ||
Patrick Mezard
|
r16733 | if keepchanges: | ||
Pierre-Yves David
|
r26587 | raise error.Abort( | ||
Patrick Mezard
|
r16733 | _("cannot use --exact and --keep-changes together")) | ||
Steve Losh
|
r13033 | if move: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot use --exact and --move ' | ||
Brodie Rao
|
r16683 | 'together')) | ||
Steve Losh
|
r13033 | if self.applied: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot push --exact with applied ' | ||
Brodie Rao
|
r16683 | 'patches')) | ||
Steve Losh
|
r13033 | root = self.series[start] | ||
target = patchheader(self.join(root), self.plainmode).parent | ||||
if not target: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort( | ||
Matt Mackall
|
r16231 | _("%s does not have a parent recorded") % root) | ||
Steve Losh
|
r13033 | if not repo[target] == repo['.']: | ||
hg.update(repo, target) | ||||
Mads Kiilerich
|
r11064 | if move: | ||
Gilles Moris
|
r11715 | if not patch: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("please specify the patch to move")) | ||
Mads Kiilerich
|
r16303 | for fullstart, rpn in enumerate(self.fullseries): | ||
# strip markers for patch guards | ||||
if self.guard_re.split(rpn, 1)[0] == self.series[start]: | ||||
break | ||||
for i, rpn in enumerate(self.fullseries[fullstart:]): | ||||
Gilles Moris
|
r11715 | # strip markers for patch guards | ||
if self.guard_re.split(rpn, 1)[0] == patch: | ||||
break | ||||
Mads Kiilerich
|
r16303 | index = fullstart + i | ||
Adrian Buehlmann
|
r14572 | assert index < len(self.fullseries) | ||
fullpatch = self.fullseries[index] | ||||
del self.fullseries[index] | ||||
Mads Kiilerich
|
r16303 | self.fullseries.insert(fullstart, fullpatch) | ||
Adrian Buehlmann
|
r14575 | self.parseseries() | ||
Mads Kiilerich
|
r15879 | self.seriesdirty = True | ||
self.applieddirty = True | ||||
Matt Mackall
|
r4915 | if start > 0: | ||
Adrian Buehlmann
|
r14581 | self.checktoppatch(repo) | ||
Matt Mackall
|
r4915 | if not patch: | ||
patch = self.series[start] | ||||
end = start + 1 | ||||
Bryan O'Sullivan
|
r4418 | else: | ||
Matt Mackall
|
r4915 | end = self.series.index(patch, start) + 1 | ||
Dirkjan Ochtman
|
r8875 | |||
Patrick Mezard
|
r16634 | tobackup = set() | ||
Patrick Mezard
|
r16733 | if (not nobackup and force) or keepchanges: | ||
Martin von Zweigbergk
|
r22925 | status = self.checklocalchanges(repo, force=True) | ||
Patrick Mezard
|
r16733 | if keepchanges: | ||
Martin von Zweigbergk
|
r22925 | tobackup.update(status.modified + status.added + | ||
status.removed + status.deleted) | ||||
Patrick Mezard
|
r16654 | else: | ||
Martin von Zweigbergk
|
r22925 | tobackup.update(status.modified + status.added) | ||
Patrick Mezard
|
r16634 | |||
Matt Mackall
|
r4915 | s = self.series[start:end] | ||
Benoit Boissinot
|
r10661 | all_files = set() | ||
Matt Mackall
|
r4915 | try: | ||
if mergeq: | ||||
Patrick Mezard
|
r10184 | ret = self.mergepatch(repo, mergeq, s, diffopts) | ||
Matt Mackall
|
r4915 | else: | ||
Patrick Mezard
|
r16634 | ret = self.apply(repo, s, list, all_files=all_files, | ||
Patrick Mezard
|
r16733 | tobackup=tobackup, keepchanges=keepchanges) | ||
Matt Mackall
|
r24826 | except AbortNoCleanup: | ||
raise | ||||
Brodie Rao
|
r16705 | except: # re-raises | ||
Matt Mackall
|
r26654 | self.ui.warn(_('cleaning up working directory...\n')) | ||
cmdutil.revert(self.ui, repo, repo['.'], | ||||
repo.dirstate.parents(), no_backup=True) | ||||
Matt Mackall
|
r4915 | # only remove unknown files that we know we touched or | ||
# created while patching | ||||
Benoit Boissinot
|
r10662 | for f in all_files: | ||
if f not in repo.dirstate: | ||||
Mads Kiilerich
|
r31309 | repo.wvfs.unlinkpath(f, ignoremissing=True) | ||
Matt Mackall
|
r4915 | self.ui.warn(_('done\n')) | ||
raise | ||||
Dirkjan Ochtman
|
r8875 | |||
Benoit Allard
|
r9590 | if not self.applied: | ||
return ret[0] | ||||
Matt Mackall
|
r4915 | top = self.applied[-1].name | ||
Dirkjan Ochtman
|
r8875 | if ret[0] and ret[0] > 1: | ||
timeless@mozdev.org
|
r26780 | msg = _("errors during apply, please fix and qrefresh %s\n") | ||
Dirkjan Ochtman
|
r8875 | self.ui.write(msg % top) | ||
Matt Mackall
|
r4915 | else: | ||
Martin Geisler
|
r7627 | self.ui.write(_("now at: %s\n") % top) | ||
Matt Mackall
|
r4915 | return ret[0] | ||
Dirkjan Ochtman
|
r8875 | |||
Patrick Mezard
|
r16635 | def pop(self, repo, patch=None, force=False, update=True, all=False, | ||
Patrick Mezard
|
r16733 | nobackup=False, keepchanges=False): | ||
self.checkkeepchanges(keepchanges, force) | ||||
Bryan O'Sullivan
|
r27829 | with repo.wlock(): | ||
Matt Mackall
|
r4915 | if patch: | ||
# index, rev, patch | ||||
info = self.isapplied(patch) | ||||
if not info: | ||||
patch = self.lookup(patch) | ||||
info = self.isapplied(patch) | ||||
if not info: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("patch %s is not applied") % patch) | ||
Ben Thomas
|
r4100 | |||
Benoit Boissinot
|
r10686 | if not self.applied: | ||
Matt Mackall
|
r4915 | # Allow qpop -a to work repeatedly, | ||
# but not qpop without an argument | ||||
self.ui.warn(_("no patches applied\n")) | ||||
return not all | ||||
mason@suse.com
|
r1808 | |||
Dirkjan Ochtman
|
r7620 | if all: | ||
start = 0 | ||||
elif patch: | ||||
start = info[0] + 1 | ||||
else: | ||||
start = len(self.applied) - 1 | ||||
if start >= len(self.applied): | ||||
self.ui.warn(_("qpop: %s is already at the top\n") % patch) | ||||
return | ||||
Matt Mackall
|
r4915 | if not update: | ||
parents = repo.dirstate.parents() | ||||
Benoit Boissinot
|
r10678 | rr = [x.node for x in self.applied] | ||
Matt Mackall
|
r4915 | for p in parents: | ||
if p in rr: | ||||
Martin Geisler
|
r6960 | self.ui.warn(_("qpop: forcing dirstate update\n")) | ||
Matt Mackall
|
r4915 | update = True | ||
Dirkjan Ochtman
|
r7621 | else: | ||
Benoit Boissinot
|
r10678 | parents = [p.node() for p in repo[None].parents()] | ||
Martin von Zweigbergk
|
r36361 | update = any(entry.node in parents | ||
for entry in self.applied[start:]) | ||||
mason@suse.com
|
r1808 | |||
Patrick Mezard
|
r16633 | tobackup = set() | ||
if update: | ||||
Martin von Zweigbergk
|
r22925 | s = self.checklocalchanges(repo, force=force or keepchanges) | ||
Patrick Mezard
|
r16653 | if force: | ||
if not nobackup: | ||||
Martin von Zweigbergk
|
r22925 | tobackup.update(s.modified + s.added) | ||
Patrick Mezard
|
r16733 | elif keepchanges: | ||
Martin von Zweigbergk
|
r22925 | tobackup.update(s.modified + s.added + | ||
s.removed + s.deleted) | ||||
Idan Kamara
|
r14732 | |||
Mads Kiilerich
|
r15879 | self.applieddirty = True | ||
Matt Mackall
|
r4915 | end = len(self.applied) | ||
Benoit Boissinot
|
r10678 | rev = self.applied[start].node | ||
Alexis S. L. Carvalho
|
r5980 | |||
Dirkjan Ochtman
|
r7621 | try: | ||
heads = repo.changelog.heads(rev) | ||||
Matt Mackall
|
r7639 | except error.LookupError: | ||
Dirkjan Ochtman
|
r7621 | node = short(rev) | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('trying to pop unknown node %s') % node) | ||
Dirkjan Ochtman
|
r7621 | |||
Benoit Boissinot
|
r10678 | if heads != [self.applied[-1].node]: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("popping would remove a revision not " | ||
Martin Geisler
|
r6960 | "managed by this patch queue")) | ||
Pierre-Yves David
|
r16048 | if not repo[self.applied[-1].node].mutable(): | ||
Pierre-Yves David
|
r26587 | raise error.Abort( | ||
Jordi Gutiérrez Hermoso
|
r25411 | _("popping would remove a public revision"), | ||
timeless
|
r29968 | hint=_("see 'hg help phases' for details")) | ||
Alexis S. L. Carvalho
|
r5980 | |||
Matt Mackall
|
r4915 | # we know there are no local changes, so we can make a simplified | ||
# form of hg.update. | ||||
if update: | ||||
qp = self.qparents(repo, rev) | ||||
Benoit Boissinot
|
r10663 | ctx = repo[qp] | ||
Mads Kiilerich
|
r18342 | m, a, r, d = repo.status(qp, '.')[:4] | ||
Matt Mackall
|
r4915 | if d: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("deletions found between repo revs")) | ||
Patrick Mezard
|
r16633 | |||
Patrick Mezard
|
r16653 | tobackup = set(a + m + r) & tobackup | ||
Patrick Mezard
|
r16733 | if keepchanges and tobackup: | ||
timeless@mozdev.org
|
r26780 | raise error.Abort(_("local changes found, qrefresh first")) | ||
Patrick Mezard
|
r16653 | self.backup(repo, tobackup) | ||
Augie Fackler
|
r32347 | with repo.dirstate.parentchange(): | ||
for f in a: | ||||
repo.wvfs.unlinkpath(f, ignoremissing=True) | ||||
repo.dirstate.drop(f) | ||||
for f in m + r: | ||||
fctx = ctx[f] | ||||
repo.wwrite(f, fctx.data(), fctx.flags()) | ||||
repo.dirstate.normal(f) | ||||
repo.setparents(qp, nullid) | ||||
Mads Kiilerich
|
r9110 | for patch in reversed(self.applied[start:end]): | ||
Martin Geisler
|
r9111 | self.ui.status(_("popping %s\n") % patch.name) | ||
Alexis S. L. Carvalho
|
r5987 | del self.applied[start:end] | ||
Jordi Gutiérrez Hermoso
|
r22057 | strip(self.ui, repo, [rev], update=False, backup=False) | ||
Angel Ezquerra
|
r19638 | for s, state in repo['.'].substate.items(): | ||
repo['.'].sub(s).get(state) | ||||
Benoit Boissinot
|
r10686 | if self.applied: | ||
Martin Geisler
|
r7627 | self.ui.write(_("now at: %s\n") % self.applied[-1].name) | ||
Matt Mackall
|
r4915 | else: | ||
Martin Geisler
|
r7627 | self.ui.write(_("patch queue now empty\n")) | ||
mason@suse.com
|
r1808 | |||
Brendan Cully
|
r2937 | def diff(self, repo, pats, opts): | ||
Adrian Buehlmann
|
r14581 | top, patch = self.checktoppatch(repo) | ||
mason@suse.com
|
r1808 | if not top: | ||
Martin Geisler
|
r7627 | self.ui.write(_("no patches applied\n")) | ||
mason@suse.com
|
r1808 | return | ||
qp = self.qparents(repo, top) | ||||
Martin Geisler
|
r9857 | if opts.get('reverse'): | ||
Yannick Gingras
|
r9725 | node1, node2 = None, qp | ||
else: | ||||
node1, node2 = qp, None | ||||
Patrick Mezard
|
r10191 | diffopts = self.diffopts(opts, patch) | ||
Patrick Mezard
|
r10184 | self.printdiff(repo, diffopts, node1, node2, files=pats, opts=opts) | ||
mason@suse.com
|
r1808 | |||
Brendan Cully
|
r2938 | def refresh(self, repo, pats=None, **opts): | ||
Pulkit Goyal
|
r36405 | opts = pycompat.byteskwargs(opts) | ||
Benoit Boissinot
|
r10686 | if not self.applied: | ||
Martin Geisler
|
r7627 | self.ui.write(_("no patches applied\n")) | ||
Bryan O'Sullivan
|
r3004 | return 1 | ||
Brendan Cully
|
r7399 | msg = opts.get('msg', '').rstrip() | ||
FUJIWARA Katsunori
|
r21422 | edit = opts.get('edit') | ||
FUJIWARA Katsunori
|
r22003 | editform = opts.get('editform', 'mq.qrefresh') | ||
Brendan Cully
|
r7399 | newuser = opts.get('user') | ||
Thomas Arendsen Hein
|
r6139 | newdate = opts.get('date') | ||
if newdate: | ||||
Boris Feld
|
r36625 | newdate = '%d %d' % dateutil.parsedate(newdate) | ||
mason@suse.com
|
r1808 | wlock = repo.wlock() | ||
Dan Villiom Podlaski Christiansen
|
r10366 | |||
Matt Mackall
|
r4915 | try: | ||
Adrian Buehlmann
|
r14581 | self.checktoppatch(repo) | ||
Benoit Boissinot
|
r10678 | (top, patchfn) = (self.applied[-1].node, self.applied[-1].name) | ||
Alexis S. L. Carvalho
|
r5980 | if repo.changelog.heads(top) != [top]: | ||
timeless@mozdev.org
|
r26780 | raise error.Abort(_("cannot qrefresh a revision with children")) | ||
Pierre-Yves David
|
r16048 | if not repo[top].mutable(): | ||
timeless@mozdev.org
|
r26780 | raise error.Abort(_("cannot qrefresh public revision"), | ||
timeless
|
r29968 | hint=_("see 'hg help phases' for details")) | ||
Dan Villiom Podlaski Christiansen
|
r10366 | |||
FUJIWARA Katsunori
|
r17153 | cparents = repo.changelog.parents(top) | ||
patchparent = self.qparents(repo, top) | ||||
Martin von Zweigbergk
|
r37399 | inclsubs = checksubstate(repo, patchparent) | ||
FUJIWARA Katsunori
|
r17152 | if inclsubs: | ||
substatestate = repo.dirstate['.hgsubstate'] | ||||
Kevin Bullock
|
r13174 | |||
Steve Losh
|
r10397 | ph = patchheader(self.join(patchfn), self.plainmode) | ||
Mads Kiilerich
|
r34092 | diffopts = self.diffopts({'git': opts.get('git')}, patchfn, | ||
plain=True) | ||||
peter.arrenbrecht@gmail.com
|
r5673 | if newuser: | ||
Brendan Cully
|
r7399 | ph.setuser(newuser) | ||
Peter Arrenbrecht
|
r5788 | if newdate: | ||
Brendan Cully
|
r7399 | ph.setdate(newdate) | ||
Steve Losh
|
r10397 | ph.setparent(hex(patchparent)) | ||
Brendan Cully
|
r5180 | |||
Brendan Cully
|
r7400 | # only commit new patch when write is complete | ||
patchf = self.opener(patchfn, 'w', atomictemp=True) | ||||
Dan Villiom Podlaski Christiansen
|
r10366 | # update the dirstate in place, strip off the qtip commit | ||
# and then commit. | ||||
# | ||||
# this should really read: | ||||
Martin Geisler
|
r13005 | # mm, dd, aa = repo.status(top, patchparent)[:3] | ||
Mads Kiilerich
|
r17425 | # but we do it backwards to take advantage of manifest/changelog | ||
Dan Villiom Podlaski Christiansen
|
r10366 | # caching against the next repo.status call | ||
Kevin Bullock
|
r13004 | mm, aa, dd = repo.status(patchparent, top)[:3] | ||
Dan Villiom Podlaski Christiansen
|
r10366 | changes = repo.changelog.read(top) | ||
Durham Goode
|
r30369 | man = repo.manifestlog[changes[0]].read() | ||
Dan Villiom Podlaski Christiansen
|
r10366 | aaa = aa[:] | ||
Martin von Zweigbergk
|
r34085 | match1 = scmutil.match(repo[None], pats, opts) | ||
Dan Villiom Podlaski Christiansen
|
r10366 | # in short mode, we only diff the files included in the | ||
# patch already plus specified files | ||||
if opts.get('short'): | ||||
# if amending a patch, we start with existing | ||||
# files plus specified files - unfiltered | ||||
Martin von Zweigbergk
|
r34085 | match = scmutil.matchfiles(repo, mm + aa + dd + match1.files()) | ||
Mads Kiilerich
|
r17424 | # filter with include/exclude options | ||
Martin von Zweigbergk
|
r34085 | match1 = scmutil.match(repo[None], opts=opts) | ||
Dan Villiom Podlaski Christiansen
|
r10366 | else: | ||
Matt Mackall
|
r14322 | match = scmutil.matchall(repo) | ||
Dan Villiom Podlaski Christiansen
|
r10366 | m, a, r, d = repo.status(match=match)[:4] | ||
Nicolas Dumazet
|
r12948 | mm = set(mm) | ||
aa = set(aa) | ||||
dd = set(dd) | ||||
mason@suse.com
|
r1808 | |||
Dan Villiom Podlaski Christiansen
|
r10366 | # we might end up with files that were added between | ||
# qtip and the dirstate parent, but then changed in the | ||||
# local dirstate. in this case, we want them to only | ||||
# show up in the added section | ||||
for x in m: | ||||
if x not in aa: | ||||
Nicolas Dumazet
|
r12948 | mm.add(x) | ||
Dan Villiom Podlaski Christiansen
|
r10366 | # we might end up with files added by the local dirstate that | ||
# were deleted by the patch. In this case, they should only | ||||
# show up in the changed section. | ||||
for x in a: | ||||
if x in dd: | ||||
Nicolas Dumazet
|
r12948 | dd.remove(x) | ||
mm.add(x) | ||||
Dan Villiom Podlaski Christiansen
|
r10366 | else: | ||
Nicolas Dumazet
|
r12948 | aa.add(x) | ||
Dan Villiom Podlaski Christiansen
|
r10366 | # make sure any files deleted in the local dirstate | ||
# are not in the add or change column of the patch | ||||
forget = [] | ||||
for x in d + r: | ||||
if x in aa: | ||||
Nicolas Dumazet
|
r12948 | aa.remove(x) | ||
Dan Villiom Podlaski Christiansen
|
r10366 | forget.append(x) | ||
continue | ||||
Nicolas Dumazet
|
r12948 | else: | ||
mm.discard(x) | ||||
dd.add(x) | ||||
m = list(mm) | ||||
r = list(dd) | ||||
a = list(aa) | ||||
Durham Goode
|
r17888 | |||
Mads Kiilerich
|
r18644 | # create 'match' that includes the files to be recommitted. | ||
Martin von Zweigbergk
|
r34085 | # apply match1 via repo.status to ensure correct case handling. | ||
cm, ca, cr, cd = repo.status(patchparent, match=match1)[:4] | ||||
Durham Goode
|
r17888 | allmatches = set(cm + ca + cr + cd) | ||
refreshchanges = [x.intersection(allmatches) for x in (mm, aa, dd)] | ||||
files = set(inclsubs) | ||||
for x in refreshchanges: | ||||
FUJIWARA Katsunori
|
r20827 | files.update(x) | ||
Durham Goode
|
r17888 | match = scmutil.matchfiles(repo, files) | ||
David Soria Parra
|
r17730 | bmlist = repo[top].bookmarks() | ||
mason@suse.com
|
r1808 | |||
FUJIWARA Katsunori
|
r24997 | dsguard = None | ||
Dan Villiom Podlaski Christiansen
|
r10366 | try: | ||
Augie Fackler
|
r30489 | dsguard = dirstateguard.dirstateguard(repo, 'mq.refresh') | ||
Patrick Mezard
|
r10368 | if diffopts.git or diffopts.upgrade: | ||
Dan Villiom Podlaski Christiansen
|
r10366 | copies = {} | ||
for dst in a: | ||||
src = repo.dirstate.copied(dst) | ||||
# during qfold, the source file for copies may | ||||
# be removed. Treat this as a simple add. | ||||
if src is not None and src in repo.dirstate: | ||||
copies.setdefault(src, []).append(dst) | ||||
repo.dirstate.add(dst) | ||||
# remember the copies between patchparent and qtip | ||||
for dst in aaa: | ||||
f = repo.file(dst) | ||||
src = f.renamed(man[dst]) | ||||
if src: | ||||
Patrick Mezard
|
r10368 | copies.setdefault(src[0], []).extend( | ||
copies.get(dst, [])) | ||||
Dan Villiom Podlaski Christiansen
|
r10366 | if dst in a: | ||
copies[src[0]].append(dst) | ||||
# we can't copy a file created by the patch itself | ||||
if dst in copies: | ||||
del copies[dst] | ||||
for src, dsts in copies.iteritems(): | ||||
for dst in dsts: | ||||
repo.dirstate.copy(src, dst) | ||||
else: | ||||
for dst in a: | ||||
repo.dirstate.add(dst) | ||||
# Drop useless copy information | ||||
for f in list(repo.dirstate.copies()): | ||||
repo.dirstate.copy(None, f) | ||||
for f in r: | ||||
repo.dirstate.remove(f) | ||||
# if the patch excludes a modified file, mark that | ||||
# file with mtime=0 so status can see it. | ||||
mm = [] | ||||
Gregory Szorc
|
r38806 | for i in pycompat.xrange(len(m) - 1, -1, -1): | ||
Martin von Zweigbergk
|
r34085 | if not match1(m[i]): | ||
Dan Villiom Podlaski Christiansen
|
r10366 | mm.append(m[i]) | ||
del m[i] | ||||
for f in m: | ||||
repo.dirstate.normal(f) | ||||
for f in mm: | ||||
repo.dirstate.normallookup(f) | ||||
for f in forget: | ||||
Matt Mackall
|
r14434 | repo.dirstate.drop(f) | ||
mason@suse.com
|
r1808 | |||
Dan Villiom Podlaski Christiansen
|
r10366 | user = ph.user or changes[1] | ||
peter.arrenbrecht@gmail.com
|
r5673 | |||
Pierre-Yves David
|
r16026 | oldphase = repo[top].phase() | ||
Dan Villiom Podlaski Christiansen
|
r10366 | # assumes strip can roll itself back if interrupted | ||
Patrick Mezard
|
r16551 | repo.setparents(*cparents) | ||
Dan Villiom Podlaski Christiansen
|
r10366 | self.applied.pop() | ||
Mads Kiilerich
|
r15879 | self.applieddirty = True | ||
Jordi Gutiérrez Hermoso
|
r22057 | strip(self.ui, repo, [top], update=False, backup=False) | ||
FUJIWARA Katsunori
|
r24997 | dsguard.close() | ||
finally: | ||||
release(dsguard) | ||||
Dan Villiom Podlaski Christiansen
|
r10366 | |||
try: | ||||
# might be nice to attempt to roll back strip after this | ||||
Patrick Mezard
|
r16100 | |||
FUJIWARA Katsunori
|
r21236 | defaultmsg = "[mq]: %s" % patchfn | ||
FUJIWARA Katsunori
|
r22003 | editor = cmdutil.getcommiteditor(editform=editform) | ||
FUJIWARA Katsunori
|
r21422 | if edit: | ||
FUJIWARA Katsunori
|
r21423 | def finishdesc(desc): | ||
FUJIWARA Katsunori
|
r21236 | if desc.rstrip(): | ||
ph.setmessage(desc) | ||||
return desc | ||||
return defaultmsg | ||||
FUJIWARA Katsunori
|
r21423 | # i18n: this message is shown in editor with "HG: " prefix | ||
extramsg = _('Leave message empty to use default message.') | ||||
editor = cmdutil.getcommiteditor(finishdesc=finishdesc, | ||||
FUJIWARA Katsunori
|
r22003 | extramsg=extramsg, | ||
editform=editform) | ||||
FUJIWARA Katsunori
|
r21236 | message = msg or "\n".join(ph.message) | ||
elif not msg: | ||||
FUJIWARA Katsunori
|
r21235 | if not ph.message: | ||
FUJIWARA Katsunori
|
r21236 | message = defaultmsg | ||
FUJIWARA Katsunori
|
r21235 | else: | ||
message = "\n".join(ph.message) | ||||
else: | ||||
message = msg | ||||
ph.setmessage(msg) | ||||
Patrick Mezard
|
r16100 | # Ensure we create a new changeset in the same phase than | ||
# the old one. | ||||
Laurent Charignon
|
r27001 | lock = tr = None | ||
try: | ||||
lock = repo.lock() | ||||
tr = repo.transaction('mq') | ||||
Laurent Charignon
|
r27000 | n = newcommit(repo, oldphase, message, user, ph.date, | ||
FUJIWARA Katsunori
|
r21236 | match=match, force=True, editor=editor) | ||
Laurent Charignon
|
r27000 | # only write patch after a successful commit | ||
c = [list(x) for x in refreshchanges] | ||||
if inclsubs: | ||||
self.putsubstate2changes(substatestate, c) | ||||
chunks = patchmod.diff(repo, patchparent, | ||||
changes=c, opts=diffopts) | ||||
Pulkit Goyal
|
r35966 | comments = bytes(ph) | ||
Laurent Charignon
|
r27000 | if comments: | ||
patchf.write(comments) | ||||
for chunk in chunks: | ||||
patchf.write(chunk) | ||||
patchf.close() | ||||
marks = repo._bookmarks | ||||
Boris Feld
|
r33489 | marks.applychanges(repo, tr, [(bm, n) for bm in bmlist]) | ||
Laurent Charignon
|
r27001 | tr.close() | ||
Laurent Charignon
|
r27000 | |||
self.applied.append(statusentry(n, patchfn)) | ||||
Laurent Charignon
|
r27001 | finally: | ||
Pierre-Yves David
|
r30070 | lockmod.release(tr, lock) | ||
Brodie Rao
|
r16705 | except: # re-raises | ||
Dan Villiom Podlaski Christiansen
|
r10366 | ctx = repo[cparents[0]] | ||
repo.dirstate.rebuild(ctx.node(), ctx.manifest()) | ||||
Adrian Buehlmann
|
r14580 | self.savedirty() | ||
timeless@mozdev.org
|
r26780 | self.ui.warn(_('qrefresh interrupted while patch was popped! ' | ||
Dan Villiom Podlaski Christiansen
|
r10366 | '(revert --all, qpush to recover)\n')) | ||
raise | ||||
Matt Mackall
|
r4915 | finally: | ||
Ronny Pfannschmidt
|
r8112 | wlock.release() | ||
Brendan Cully
|
r7401 | self.removeundo(repo) | ||
mason@suse.com
|
r1808 | |||
def init(self, repo, create=False): | ||||
Alexis S. L. Carvalho
|
r4071 | if not create and os.path.isdir(self.path): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("patch queue directory already exists")) | ||
Alexis S. L. Carvalho
|
r4071 | try: | ||
os.mkdir(self.path) | ||||
Gregory Szorc
|
r25660 | except OSError as inst: | ||
Alexis S. L. Carvalho
|
r4071 | if inst.errno != errno.EEXIST or not create: | ||
raise | ||||
mason@suse.com
|
r1808 | if create: | ||
return self.qrepo(create=True) | ||||
def unapplied(self, repo, patch=None): | ||||
if patch and patch not in self.series: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("patch %s is not in series file") % patch) | ||
mason@suse.com
|
r1808 | if not patch: | ||
Adrian Buehlmann
|
r14586 | start = self.seriesend() | ||
mason@suse.com
|
r1808 | else: | ||
start = self.series.index(patch) + 1 | ||||
Vadim Gelfer
|
r2821 | unapplied = [] | ||
Gregory Szorc
|
r38806 | for i in pycompat.xrange(start, len(self.series)): | ||
Vadim Gelfer
|
r2821 | pushable, reason = self.pushable(i) | ||
if pushable: | ||||
unapplied.append((i, self.series[i])) | ||||
Adrian Buehlmann
|
r14579 | self.explainpushable(i) | ||
Vadim Gelfer
|
r2821 | return unapplied | ||
Thomas Arendsen Hein
|
r1810 | |||
Thomas Arendsen Hein
|
r4239 | def qseries(self, repo, missing=None, start=0, length=None, status=None, | ||
Brendan Cully
|
r3183 | summary=False): | ||
Brodie Rao
|
r10824 | def displayname(pfx, patchname, state): | ||
Dan Villiom Podlaski Christiansen
|
r10932 | if pfx: | ||
self.ui.write(pfx) | ||||
Brendan Cully
|
r3183 | if summary: | ||
Steve Losh
|
r10397 | ph = patchheader(self.join(patchname), self.plainmode) | ||
Jordi Gutiérrez Hermoso
|
r24306 | if ph.message: | ||
msg = ph.message[0] | ||||
else: | ||||
msg = '' | ||||
Dan Villiom Podlaski Christiansen
|
r11327 | if self.ui.formatted(): | ||
Augie Fackler
|
r12689 | width = self.ui.termwidth() - len(pfx) - len(patchname) - 2 | ||
Dan Villiom Podlaski Christiansen
|
r9874 | if width > 0: | ||
Yuya Nishihara
|
r37102 | msg = stringutil.ellipsis(msg, width) | ||
Dan Villiom Podlaski Christiansen
|
r9874 | else: | ||
msg = '' | ||||
Dan Villiom Podlaski Christiansen
|
r10932 | self.ui.write(patchname, label='qseries.' + state) | ||
self.ui.write(': ') | ||||
self.ui.write(msg, label='qseries.message.' + state) | ||||
Brendan Cully
|
r3183 | else: | ||
Dan Villiom Podlaski Christiansen
|
r10932 | self.ui.write(patchname, label='qseries.' + state) | ||
self.ui.write('\n') | ||||
Brendan Cully
|
r3183 | |||
Martin Geisler
|
r8152 | applied = set([p.name for p in self.applied]) | ||
Thomas Arendsen Hein
|
r4239 | if length is None: | ||
Brendan Cully
|
r3183 | length = len(self.series) - start | ||
mason@suse.com
|
r1808 | if not missing: | ||
Dan Villiom Podlaski Christiansen
|
r9016 | if self.ui.verbose: | ||
Pulkit Goyal
|
r36686 | idxwidth = len("%d" % (start + length - 1)) | ||
Gregory Szorc
|
r38806 | for i in pycompat.xrange(start, start + length): | ||
Thomas Arendsen Hein
|
r4239 | patch = self.series[i] | ||
if patch in applied: | ||||
Brodie Rao
|
r10824 | char, state = 'A', 'applied' | ||
Thomas Arendsen Hein
|
r4239 | elif self.pushable(i)[0]: | ||
Brodie Rao
|
r10824 | char, state = 'U', 'unapplied' | ||
Thomas Arendsen Hein
|
r4239 | else: | ||
Brodie Rao
|
r10824 | char, state = 'G', 'guarded' | ||
Brendan Cully
|
r3183 | pfx = '' | ||
mason@suse.com
|
r1808 | if self.ui.verbose: | ||
Brodie Rao
|
r10824 | pfx = '%*d %s ' % (idxwidth, i, char) | ||
elif status and status != char: | ||||
Thomas Arendsen Hein
|
r4238 | continue | ||
Brodie Rao
|
r10824 | displayname(pfx, patch, state) | ||
mason@suse.com
|
r1808 | else: | ||
Benoit Boissinot
|
r2794 | msng_list = [] | ||
mason@suse.com
|
r1808 | for root, dirs, files in os.walk(self.path): | ||
d = root[len(self.path) + 1:] | ||||
for f in files: | ||||
fl = os.path.join(d, f) | ||||
Thomas Arendsen Hein
|
r1852 | if (fl not in self.series and | ||
Adrian Buehlmann
|
r14588 | fl not in (self.statuspath, self.seriespath, | ||
Adrian Buehlmann
|
r14589 | self.guardspath) | ||
Thomas Arendsen Hein
|
r1852 | and not fl.startswith('.')): | ||
Benoit Boissinot
|
r2794 | msng_list.append(fl) | ||
Matt Mackall
|
r8209 | for x in sorted(msng_list): | ||
Brendan Cully
|
r3183 | pfx = self.ui.verbose and ('D ') or '' | ||
Brodie Rao
|
r10824 | displayname(pfx, x, 'missing') | ||
mason@suse.com
|
r1808 | |||
def issaveline(self, l): | ||||
Brendan Cully
|
r2816 | if l.name == '.hg.patches.save.line': | ||
mason@suse.com
|
r1808 | return True | ||
def qrepo(self, create=False): | ||||
Simon Heimberg
|
r19064 | ui = self.baseui.copy() | ||
Yuya Nishihara
|
r34919 | # copy back attributes set by ui.pager() | ||
if self.ui.pageractive and not ui.pageractive: | ||||
ui.pageractive = self.ui.pageractive | ||||
# internal config: ui.formatted | ||||
ui.setconfig('ui', 'formatted', | ||||
self.ui.config('ui', 'formatted'), 'mqpager') | ||||
ui.setconfig('ui', 'interactive', | ||||
self.ui.config('ui', 'interactive'), 'mqpager') | ||||
Vadim Gelfer
|
r2819 | if create or os.path.isdir(self.join(".hg")): | ||
Mads Kiilerich
|
r11965 | return hg.repository(ui, path=self.path, create=create) | ||
mason@suse.com
|
r1808 | |||
def restore(self, repo, rev, delete=None, qupdate=None): | ||||
Benoit Boissinot
|
r10681 | desc = repo[rev].description().strip() | ||
mason@suse.com
|
r1808 | lines = desc.splitlines() | ||
i = 0 | ||||
datastart = None | ||||
series = [] | ||||
applied = [] | ||||
qpp = None | ||||
Martin Geisler
|
r8632 | for i, line in enumerate(lines): | ||
if line == 'Patch Data:': | ||||
mason@suse.com
|
r1808 | datastart = i + 1 | ||
Martin Geisler
|
r8632 | elif line.startswith('Dirstate:'): | ||
l = line.rstrip() | ||||
mason@suse.com
|
r1808 | l = l[10:].split(' ') | ||
Matt Mackall
|
r10282 | qpp = [bin(x) for x in l] | ||
Martin Geisler
|
r13031 | elif datastart is not None: | ||
Martin Geisler
|
r8632 | l = line.rstrip() | ||
Benoit Boissinot
|
r10683 | n, name = l.split(':', 1) | ||
if n: | ||||
applied.append(statusentry(bin(n), name)) | ||||
Brendan Cully
|
r3185 | else: | ||
Benoit Boissinot
|
r10682 | series.append(l) | ||
Martin Geisler
|
r8527 | if datastart is None: | ||
Martin Geisler
|
r16929 | self.ui.warn(_("no saved patch data found\n")) | ||
mason@suse.com
|
r1808 | return 1 | ||
Martin Geisler
|
r6960 | self.ui.warn(_("restoring status: %s\n") % lines[0]) | ||
Adrian Buehlmann
|
r14572 | self.fullseries = series | ||
mason@suse.com
|
r1808 | self.applied = applied | ||
Adrian Buehlmann
|
r14575 | self.parseseries() | ||
Mads Kiilerich
|
r15879 | self.seriesdirty = True | ||
self.applieddirty = True | ||||
mason@suse.com
|
r1808 | heads = repo.changelog.heads() | ||
if delete: | ||||
if rev not in heads: | ||||
Martin Geisler
|
r6960 | self.ui.warn(_("save entry has children, leaving it alone\n")) | ||
mason@suse.com
|
r1808 | else: | ||
Martin Geisler
|
r6960 | self.ui.warn(_("removing save entry %s\n") % short(rev)) | ||
mason@suse.com
|
r1808 | pp = repo.dirstate.parents() | ||
if rev in pp: | ||||
update = True | ||||
else: | ||||
update = False | ||||
Jordi Gutiérrez Hermoso
|
r22057 | strip(self.ui, repo, [rev], update=update, backup=False) | ||
mason@suse.com
|
r1808 | if qpp: | ||
Martin Geisler
|
r6960 | self.ui.warn(_("saved queue repository parents: %s %s\n") % | ||
Joel Rosdahl
|
r6217 | (short(qpp[0]), short(qpp[1]))) | ||
mason@suse.com
|
r1808 | if qupdate: | ||
timeless
|
r12848 | self.ui.status(_("updating queue directory\n")) | ||
mason@suse.com
|
r1808 | r = self.qrepo() | ||
if not r: | ||||
Martin Geisler
|
r16929 | self.ui.warn(_("unable to load queue repository\n")) | ||
mason@suse.com
|
r1808 | return 1 | ||
Matt Mackall
|
r2808 | hg.clean(r, qpp[0]) | ||
mason@suse.com
|
r1808 | |||
def save(self, repo, msg=None): | ||||
Benoit Boissinot
|
r10686 | if not self.applied: | ||
Martin Geisler
|
r6960 | self.ui.warn(_("save: no patches applied, exiting\n")) | ||
mason@suse.com
|
r1808 | return 1 | ||
if self.issaveline(self.applied[-1]): | ||||
Martin Geisler
|
r6960 | self.ui.warn(_("status is already saved\n")) | ||
mason@suse.com
|
r1808 | return 1 | ||
Thomas Arendsen Hein
|
r1810 | |||
mason@suse.com
|
r1808 | if not msg: | ||
Martin Geisler
|
r6960 | msg = _("hg patches saved state") | ||
mason@suse.com
|
r1808 | else: | ||
msg = "hg patches: " + msg.rstrip('\r\n') | ||||
r = self.qrepo() | ||||
if r: | ||||
pp = r.dirstate.parents() | ||||
Joel Rosdahl
|
r6217 | msg += "\nDirstate: %s %s" % (hex(pp[0]), hex(pp[1])) | ||
mason@suse.com
|
r1808 | msg += "\n\nPatch Data:\n" | ||
Benoit Boissinot
|
r10679 | msg += ''.join('%s\n' % x for x in self.applied) | ||
Adrian Buehlmann
|
r14572 | msg += ''.join(':%s\n' % x for x in self.fullseries) | ||
Benoit Boissinot
|
r10679 | n = repo.commit(msg, force=True) | ||
mason@suse.com
|
r1808 | if not n: | ||
Martin Geisler
|
r6960 | self.ui.warn(_("repo commit failed\n")) | ||
mason@suse.com
|
r1808 | return 1 | ||
Benoit Boissinot
|
r10684 | self.applied.append(statusentry(n, '.hg.patches.save.line')) | ||
Mads Kiilerich
|
r15879 | self.applieddirty = True | ||
Matt Mackall
|
r4209 | self.removeundo(repo) | ||
mason@suse.com
|
r1808 | |||
Adrian Buehlmann
|
r14585 | def fullseriesend(self): | ||
Benoit Boissinot
|
r10686 | if self.applied: | ||
Brendan Cully
|
r2780 | p = self.applied[-1].name | ||
Adrian Buehlmann
|
r14574 | end = self.findseries(p) | ||
Martin Geisler
|
r8527 | if end is None: | ||
Adrian Buehlmann
|
r14572 | return len(self.fullseries) | ||
Chris Mason
|
r2698 | return end + 1 | ||
return 0 | ||||
Adrian Buehlmann
|
r14586 | def seriesend(self, all_patches=False): | ||
Patrick Mezard
|
r4406 | """If all_patches is False, return the index of the next pushable patch | ||
in the series, or the series length. If all_patches is True, return the | ||||
index of the first patch past the last applied one. | ||||
""" | ||||
mason@suse.com
|
r1808 | end = 0 | ||
Augie Fackler
|
r19500 | def nextpatch(start): | ||
Benoit Boissinot
|
r10687 | if all_patches or start >= len(self.series): | ||
Vadim Gelfer
|
r2821 | return start | ||
Gregory Szorc
|
r38806 | for i in pycompat.xrange(start, len(self.series)): | ||
Vadim Gelfer
|
r2821 | p, reason = self.pushable(i) | ||
if p: | ||||
Patrick Mezard
|
r16063 | return i | ||
Adrian Buehlmann
|
r14579 | self.explainpushable(i) | ||
Patrick Mezard
|
r16063 | return len(self.series) | ||
Benoit Boissinot
|
r10686 | if self.applied: | ||
Brendan Cully
|
r2780 | p = self.applied[-1].name | ||
mason@suse.com
|
r1808 | try: | ||
end = self.series.index(p) | ||||
except ValueError: | ||||
return 0 | ||||
Augie Fackler
|
r19500 | return nextpatch(end + 1) | ||
return nextpatch(end) | ||||
mason@suse.com
|
r1808 | |||
def appliedname(self, index): | ||||
Brendan Cully
|
r2780 | pname = self.applied[index].name | ||
mason@suse.com
|
r1808 | if not self.ui.verbose: | ||
"Mathieu Clabaut "
|
r2677 | p = pname | ||
else: | ||||
Pulkit Goyal
|
r36686 | p = ("%d" % self.series.index(pname)) + " " + pname | ||
mason@suse.com
|
r1808 | return p | ||
Thomas Arendsen Hein
|
r1810 | |||
Brendan Cully
|
r3141 | def qimport(self, repo, files, patchname=None, rev=None, existing=None, | ||
Brendan Cully
|
r3691 | force=None, git=False): | ||
Brendan Cully
|
r3141 | def checkseries(patchname): | ||
if patchname in self.series: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('patch %s is already in the series file') | ||
Brendan Cully
|
r3141 | % patchname) | ||
if rev: | ||||
if files: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('option "-r" not valid when importing ' | ||
Brendan Cully
|
r3141 | 'files')) | ||
Matt Mackall
|
r14319 | rev = scmutil.revrange(repo, rev) | ||
Alejandro Santos
|
r9032 | rev.sort(reverse=True) | ||
Thomas Arendsen Hein
|
r16987 | elif not files: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no files or revisions specified')) | ||
Brendan Cully
|
r3141 | if (len(files) > 1 or len(rev) > 1) and patchname: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('option "-n" not valid when importing multiple ' | ||
Brendan Cully
|
r3141 | 'patches')) | ||
Patrick Mezard
|
r16119 | imported = [] | ||
Brendan Cully
|
r3141 | if rev: | ||
# If mq patches are applied, we can only import revisions | ||||
# that form a linear path to qbase. | ||||
# Otherwise, they should form a linear path to a head. | ||||
Pierre-Yves David
|
r22821 | heads = repo.changelog.heads(repo.changelog.node(rev.first())) | ||
Brendan Cully
|
r3141 | if len(heads) > 1: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('revision %d is the root of more than one ' | ||
Pierre-Yves David
|
r22819 | 'branch') % rev.last()) | ||
Brendan Cully
|
r3141 | if self.applied: | ||
Pierre-Yves David
|
r22821 | base = repo.changelog.node(rev.first()) | ||
Benoit Boissinot
|
r10678 | if base in [n.node for n in self.applied]: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('revision %d is already managed') | ||
Pierre-Yves David
|
r23128 | % rev.first()) | ||
Benoit Boissinot
|
r10678 | if heads != [self.applied[-1].node]: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('revision %d is not the parent of ' | ||
Pierre-Yves David
|
r22821 | 'the queue') % rev.first()) | ||
Benoit Boissinot
|
r10678 | base = repo.changelog.rev(self.applied[0].node) | ||
Brendan Cully
|
r3141 | lastparent = repo.changelog.parentrevs(base)[0] | ||
else: | ||||
Pierre-Yves David
|
r22821 | if heads != [repo.changelog.node(rev.first())]: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('revision %d has unmanaged children') | ||
Pierre-Yves David
|
r22821 | % rev.first()) | ||
Brendan Cully
|
r3141 | lastparent = None | ||
Patrick Mezard
|
r10184 | diffopts = self.diffopts({'git': git}) | ||
Bryan O'Sullivan
|
r27865 | with repo.transaction('qimport') as tr: | ||
Pierre-Yves David
|
r22049 | for r in rev: | ||
if not repo[r].mutable(): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('revision %d is not mutable') % r, | ||
timeless
|
r29968 | hint=_("see 'hg help phases' " | ||
Pierre-Yves David
|
r22049 | 'for details')) | ||
p1, p2 = repo.changelog.parentrevs(r) | ||||
n = repo.changelog.node(r) | ||||
if p2 != nullrev: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot import merge revision %d') | ||
Pierre-Yves David
|
r22049 | % r) | ||
if lastparent and lastparent != r: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('revision %d is not the parent of ' | ||
Pierre-Yves David
|
r22049 | '%d') | ||
% (r, lastparent)) | ||||
lastparent = p1 | ||||
if not patchname: | ||||
Mads Kiilerich
|
r27918 | patchname = self.makepatchname( | ||
FUJIWARA Katsunori
|
r27513 | repo[r].description().split('\n', 1)[0], | ||
'%d.diff' % r) | ||||
Pierre-Yves David
|
r22049 | checkseries(patchname) | ||
self.checkpatchname(patchname, force) | ||||
self.fullseries.insert(0, patchname) | ||||
Yuya Nishihara
|
r37621 | with self.opener(patchname, "w") as fp: | ||
cmdutil.exportfile(repo, [n], fp, opts=diffopts) | ||||
Pierre-Yves David
|
r22049 | |||
se = statusentry(n, patchname) | ||||
self.applied.insert(0, se) | ||||
self.added.append(patchname) | ||||
imported.append(patchname) | ||||
patchname = None | ||||
Boris Feld
|
r34185 | if rev and repo.ui.configbool('mq', 'secret'): | ||
Pierre-Yves David
|
r22049 | # if we added anything with --rev, move the secret root | ||
Pierre-Yves David
|
r22070 | phases.retractboundary(repo, tr, phases.secret, [n]) | ||
Pierre-Yves David
|
r22049 | self.parseseries() | ||
self.applieddirty = True | ||||
self.seriesdirty = True | ||||
Brendan Cully
|
r3141 | |||
Benoit Boissinot
|
r10687 | for i, filename in enumerate(files): | ||
mason@suse.com
|
r1808 | if existing: | ||
Brendan Cully
|
r3547 | if filename == '-': | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('-e is incompatible with import from -') | ||
) | ||||
Nicolas Dumazet
|
r11699 | filename = normname(filename) | ||
Adrian Buehlmann
|
r14584 | self.checkreservedname(filename) | ||
Matt Mackall
|
r20402 | if util.url(filename).islocal(): | ||
Matt Mackall
|
r20394 | originpath = self.join(filename) | ||
if not os.path.isfile(originpath): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort( | ||
Matt Mackall
|
r20402 | _("patch %s does not exist") % filename) | ||
Nicolas Dumazet
|
r11699 | |||
if patchname: | ||||
Idan Kamara
|
r14423 | self.checkpatchname(patchname, force) | ||
Nicolas Dumazet
|
r11699 | |||
self.ui.write(_('renaming %s to %s\n') | ||||
% (filename, patchname)) | ||||
Patrick Mezard
|
r11701 | util.rename(originpath, self.join(patchname)) | ||
Nicolas Dumazet
|
r11699 | else: | ||
patchname = filename | ||||
mason@suse.com
|
r1808 | else: | ||
Idan Kamara
|
r14395 | if filename == '-' and not patchname: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('need --name to import a patch from -')) | ||
Idan Kamara
|
r14395 | elif not patchname: | ||
Idan Kamara
|
r14396 | patchname = normname(os.path.basename(filename.rstrip('/'))) | ||
Idan Kamara
|
r14423 | self.checkpatchname(patchname, force) | ||
mason@suse.com
|
r1808 | try: | ||
Brendan Cully
|
r3547 | if filename == '-': | ||
Idan Kamara
|
r14636 | text = self.ui.fin.read() | ||
Brendan Cully
|
r3547 | else: | ||
Siddharth Agarwal
|
r17887 | fp = hg.openpath(self.ui, filename) | ||
Dan Villiom Podlaski Christiansen
|
r13400 | text = fp.read() | ||
fp.close() | ||||
Benoit Boissinot
|
r7421 | except (OSError, IOError): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("unable to read file %s") % filename) | ||
Brendan Cully
|
r3133 | patchf = self.opener(patchname, "w") | ||
mason@suse.com
|
r1808 | patchf.write(text) | ||
Dan Villiom Podlaski Christiansen
|
r13400 | patchf.close() | ||
Brendan Cully
|
r7160 | if not force: | ||
checkseries(patchname) | ||||
if patchname not in self.series: | ||||
Adrian Buehlmann
|
r14585 | index = self.fullseriesend() + i | ||
Adrian Buehlmann
|
r14572 | self.fullseries[index:index] = [patchname] | ||
Adrian Buehlmann
|
r14575 | self.parseseries() | ||
Adrian Buehlmann
|
r14593 | self.seriesdirty = True | ||
Martin Geisler
|
r7597 | self.ui.warn(_("adding %s to series file\n") % patchname) | ||
Vishakh H
|
r11462 | self.added.append(patchname) | ||
Patrick Mezard
|
r16119 | imported.append(patchname) | ||
Brendan Cully
|
r3133 | patchname = None | ||
mason@suse.com
|
r1808 | |||
André Sintzoff
|
r13409 | self.removeundo(repo) | ||
Patrick Mezard
|
r16119 | return imported | ||
André Sintzoff
|
r13409 | |||
Patrick Mezard
|
r16733 | def fixkeepchangesopts(ui, opts): | ||
if (not ui.configbool('mq', 'keepchanges') or opts.get('force') | ||||
Patrick Mezard
|
r16656 | or opts.get('exact')): | ||
return opts | ||||
opts = dict(opts) | ||||
Patrick Mezard
|
r16733 | opts['keep_changes'] = True | ||
Patrick Mezard
|
r16656 | return opts | ||
Martin Geisler
|
r14298 | @command("qdelete|qremove|qrm", | ||
[('k', 'keep', None, _('keep patch file')), | ||||
('r', 'rev', [], | ||||
_('stop managing a revision (DEPRECATED)'), _('REV'))], | ||||
rdamazio@google.com
|
r40329 | _('hg qdelete [-k] [PATCH]...'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
Brendan Cully
|
r3373 | def delete(ui, repo, *patches, **opts): | ||
Brendan Cully
|
r2905 | """remove patches from queue | ||
Brendan Cully
|
r2752 | |||
Olav Reinert
|
r15798 | The patches must not be applied, and at least one patch is required. Exact | ||
patch identifiers must be given. With -k/--keep, the patch files are | ||||
preserved in the patch directory. | ||||
Cédric Duval
|
r8904 | |||
To stop managing a patch and move it into permanent history, | ||||
Martin Geisler
|
r11307 | use the :hg:`qfinish` command.""" | ||
Brendan Cully
|
r2724 | q = repo.mq | ||
Pulkit Goyal
|
r36295 | q.delete(repo, patches, pycompat.byteskwargs(opts)) | ||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
mason@suse.com
|
r1808 | return 0 | ||
Martin Geisler
|
r14298 | @command("qapplied", | ||
Patrick Mezard
|
r16188 | [('1', 'last', None, _('show only the preceding applied patch')) | ||
Martin Geisler
|
r14298 | ] + seriesopts, | ||
rdamazio@google.com
|
r40329 | _('hg qapplied [-1] [-s] [PATCH]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
mason@suse.com
|
r1808 | def applied(ui, repo, patch=None, **opts): | ||
Erik Zielke
|
r12538 | """print the patches already applied | ||
Returns 0 on success.""" | ||||
Dirkjan Ochtman
|
r9364 | |||
Brendan Cully
|
r3183 | q = repo.mq | ||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Dirkjan Ochtman
|
r9364 | |||
Brendan Cully
|
r3183 | if patch: | ||
if patch not in q.series: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("patch %s is not in series file") % patch) | ||
Brendan Cully
|
r3183 | end = q.series.index(patch) + 1 | ||
else: | ||||
Adrian Buehlmann
|
r14586 | end = q.seriesend(True) | ||
Dirkjan Ochtman
|
r9364 | |||
if opts.get('last') and not end: | ||||
ui.write(_("no patches applied\n")) | ||||
return 1 | ||||
elif opts.get('last') and end == 1: | ||||
ui.write(_("only one patch applied\n")) | ||||
return 1 | ||||
elif opts.get('last'): | ||||
start = end - 2 | ||||
end = 1 | ||||
else: | ||||
start = 0 | ||||
Erik Zielke
|
r12539 | q.qseries(repo, length=end, start=start, status='A', | ||
summary=opts.get('summary')) | ||||
mason@suse.com
|
r1808 | |||
Martin Geisler
|
r14298 | @command("qunapplied", | ||
[('1', 'first', None, _('show only the first patch'))] + seriesopts, | ||||
rdamazio@google.com
|
r40329 | _('hg qunapplied [-1] [-s] [PATCH]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
mason@suse.com
|
r1808 | def unapplied(ui, repo, patch=None, **opts): | ||
Erik Zielke
|
r12538 | """print the patches not yet applied | ||
Returns 0 on success.""" | ||||
Dirkjan Ochtman
|
r9364 | |||
Brendan Cully
|
r3183 | q = repo.mq | ||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Brendan Cully
|
r3183 | if patch: | ||
if patch not in q.series: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("patch %s is not in series file") % patch) | ||
Brendan Cully
|
r3183 | start = q.series.index(patch) + 1 | ||
else: | ||||
Adrian Buehlmann
|
r14586 | start = q.seriesend(True) | ||
Dirkjan Ochtman
|
r9364 | |||
if start == len(q.series) and opts.get('first'): | ||||
ui.write(_("all patches applied\n")) | ||||
return 1 | ||||
Jordi Gutiérrez Hermoso
|
r24306 | if opts.get('first'): | ||
length = 1 | ||||
else: | ||||
length = None | ||||
Erik Zielke
|
r12539 | q.qseries(repo, start=start, length=length, status='U', | ||
summary=opts.get('summary')) | ||||
mason@suse.com
|
r1808 | |||
Martin Geisler
|
r14298 | @command("qimport", | ||
[('e', 'existing', None, _('import file in patch directory')), | ||||
('n', 'name', '', | ||||
_('name of patch file'), _('NAME')), | ||||
('f', 'force', None, _('overwrite existing files')), | ||||
('r', 'rev', [], | ||||
_('place existing revisions under mq control'), _('REV')), | ||||
('g', 'git', None, _('use git extended diff format')), | ||||
('P', 'push', None, _('qpush after importing'))], | ||||
rdamazio@google.com
|
r40329 | _('hg qimport [-e] [-n NAME] [-f] [-g] [-P] [-r REV]... [FILE]...'), | ||
helpcategory=command.CATEGORY_IMPORT_EXPORT) | ||||
mason@suse.com
|
r1808 | def qimport(ui, repo, *filename, **opts): | ||
Matt Mackall
|
r16152 | """import a patch or existing changeset | ||
Brendan Cully
|
r3141 | |||
Martin Geisler
|
r7994 | The patch is inserted into the series after the last applied | ||
patch. If no patches have been applied, qimport prepends the patch | ||||
Adrian Buehlmann
|
r6634 | to the series. | ||
Brendan Cully
|
r3141 | The patch will have the same name as its source file unless you | ||
Martin Geisler
|
r8076 | give it a new one with -n/--name. | ||
Brendan Cully
|
r3141 | |||
Martin Geisler
|
r7994 | You can register an existing patch inside the patch directory with | ||
Martin Geisler
|
r8076 | the -e/--existing flag. | ||
Brendan Cully
|
r3141 | |||
Martin Geisler
|
r8076 | With -f/--force, an existing patch of the same name will be | ||
Martin Geisler
|
r7994 | overwritten. | ||
Brendan Cully
|
r3141 | |||
Martin Geisler
|
r8076 | An existing changeset may be placed under mq control with -r/--rev | ||
Matt Mackall
|
r19397 | (e.g. qimport --rev . -n patch will place the current revision | ||
under mq control). With -g/--git, patches imported with --rev will | ||||
use the git diff format. See the diffs help topic for information | ||||
on why this is important for preserving rename/copy information | ||||
and permission changes. Use :hg:`qfinish` to remove changesets | ||||
from mq control. | ||||
David Frey
|
r8075 | |||
To import a patch from standard input, pass - as the patch file. | ||||
When importing from standard input, a patch name must be specified | ||||
using the --name flag. | ||||
Nicolas Dumazet
|
r11700 | |||
Nicolas Dumazet
|
r11706 | To import an existing patch while renaming it:: | ||
Nicolas Dumazet
|
r11700 | |||
hg qimport -e existing-patch -n new-name | ||||
Erik Zielke
|
r12538 | |||
Returns 0 if import succeeded. | ||||
Brendan Cully
|
r3141 | """ | ||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Bryan O'Sullivan
|
r27832 | with repo.lock(): # cause this may move phase | ||
Pierre-Yves David
|
r16027 | q = repo.mq | ||
try: | ||||
Patrick Mezard
|
r16119 | imported = q.qimport( | ||
repo, filename, patchname=opts.get('name'), | ||||
existing=opts.get('existing'), force=opts.get('force'), | ||||
rev=opts.get('rev'), git=opts.get('git')) | ||||
Pierre-Yves David
|
r16027 | finally: | ||
q.savedirty() | ||||
Pierre-Yves David
|
r16681 | |||
if imported and opts.get('push') and not opts.get('rev'): | ||||
return q.push(repo, imported[-1]) | ||||
mason@suse.com
|
r1808 | return 0 | ||
Brendan Cully
|
r10480 | def qinit(ui, repo, create): | ||
"""initialize a new queue repository | ||||
Brendan Cully
|
r2754 | |||
Brendan Cully
|
r10480 | This command also creates a series file for ordering patches, and | ||
an mq-specific .hgignore file in the queue repository, to exclude | ||||
Erik Zielke
|
r12538 | the status and guards files (these contain mostly transient state). | ||
Returns 0 if initialization succeeded.""" | ||||
Brendan Cully
|
r2724 | q = repo.mq | ||
Brendan Cully
|
r10480 | r = q.init(repo, create) | ||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
mason@suse.com
|
r1808 | if r: | ||
Alexis S. L. Carvalho
|
r4071 | if not os.path.exists(r.wjoin('.hgignore')): | ||
Angel Ezquerra
|
r23879 | fp = r.wvfs('.hgignore', 'w') | ||
Alexis S. L. Carvalho
|
r6034 | fp.write('^\\.hg\n') | ||
fp.write('^\\.mq\n') | ||||
Alexis S. L. Carvalho
|
r4071 | fp.write('syntax: glob\n') | ||
fp.write('status\n') | ||||
fp.write('guards\n') | ||||
fp.close() | ||||
if not os.path.exists(r.wjoin('series')): | ||||
Angel Ezquerra
|
r23879 | r.wvfs('series', 'w').close() | ||
Dirkjan Ochtman
|
r11303 | r[None].add(['.hgignore', 'series']) | ||
Alexis S. L. Carvalho
|
r4071 | commands.add(ui, r) | ||
mason@suse.com
|
r1808 | return 0 | ||
Rodrigo Damazio
|
r40331 | @command("qinit", | ||
Martin Geisler
|
r14298 | [('c', 'create-repo', None, _('create queue repository'))], | ||
rdamazio@google.com
|
r40329 | _('hg qinit [-c]'), | ||
Rodrigo Damazio
|
r40331 | helpcategory=command.CATEGORY_REPO_CREATION, | ||
helpbasic=True) | ||||
Brendan Cully
|
r10480 | def init(ui, repo, **opts): | ||
"""init a new queue repository (DEPRECATED) | ||||
The queue repository is unversioned by default. If | ||||
-c/--create-repo is specified, qinit will create a separate nested | ||||
repository for patches (qinit -c may also be run later to convert | ||||
an unversioned patch repository into a versioned one). You can use | ||||
qcommit to commit changes to this queue repository. | ||||
This command is deprecated. Without -c, it's implied by other relevant | ||||
Martin Geisler
|
r11193 | commands. With -c, use :hg:`init --mq` instead.""" | ||
Pulkit Goyal
|
r34506 | return qinit(ui, repo, create=opts.get(r'create_repo')) | ||
Brendan Cully
|
r10480 | |||
Martin Geisler
|
r14298 | @command("qclone", | ||
[('', 'pull', None, _('use pull protocol to copy metadata')), | ||||
Brodie Rao
|
r16683 | ('U', 'noupdate', None, | ||
_('do not update the new working directories')), | ||||
Martin Geisler
|
r14298 | ('', 'uncompressed', None, | ||
_('use uncompressed transfer (fast over LAN)')), | ||||
('p', 'patches', '', | ||||
_('location of source patch repository'), _('REPO')), | ||||
Yuya Nishihara
|
r32375 | ] + cmdutil.remoteopts, | ||
Gregory Szorc
|
r21771 | _('hg qclone [OPTION]... SOURCE [DEST]'), | ||
rdamazio@google.com
|
r40329 | helpcategory=command.CATEGORY_REPO_CREATION, | ||
Gregory Szorc
|
r21771 | norepo=True) | ||
Vadim Gelfer
|
r2720 | def clone(ui, source, dest=None, **opts): | ||
'''clone main and patch repository at same time | ||||
Martin Geisler
|
r7983 | If source is local, destination will have no patches applied. If | ||
Vadim Gelfer
|
r2720 | source is remote, this command can not check if patches are | ||
applied in source, so cannot guarantee that patches are not | ||||
Martin Geisler
|
r7983 | applied in destination. If you clone remote repository, be sure | ||
Vadim Gelfer
|
r2720 | before that it has no patches applied. | ||
Source patch repository is looked for in <src>/.hg/patches by | ||||
Martin Geisler
|
r7983 | default. Use -p <url> to change. | ||
Brendan Cully
|
r4862 | |||
timeless
|
r8760 | The patch directory must be a nested Mercurial repository, as | ||
Martin Geisler
|
r11193 | would be created by :hg:`init --mq`. | ||
Erik Zielke
|
r12538 | |||
Return 0 on success. | ||||
Vadim Gelfer
|
r2720 | ''' | ||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Alexis S. L. Carvalho
|
r5226 | def patchdir(repo): | ||
Pierre-Yves David
|
r15921 | """compute a patch repo url from a repo object""" | ||
Alexis S. L. Carvalho
|
r5226 | url = repo.url() | ||
if url.endswith('/'): | ||||
url = url[:-1] | ||||
return url + '/.hg/patches' | ||||
Pierre-Yves David
|
r15921 | |||
# main repo (destination and sources) | ||||
Vadim Gelfer
|
r2720 | if dest is None: | ||
dest = hg.defaultdest(source) | ||||
Sune Foldager
|
r17191 | sr = hg.peer(ui, opts, ui.expandpath(source)) | ||
Pierre-Yves David
|
r15921 | |||
# patches repo (source only) | ||||
Christian Ebert
|
r12281 | if opts.get('patches'): | ||
patchespath = ui.expandpath(opts.get('patches')) | ||||
John Mulligan
|
r7729 | else: | ||
patchespath = patchdir(sr) | ||||
Brendan Cully
|
r4862 | try: | ||
Sune Foldager
|
r17191 | hg.peer(ui, opts, patchespath) | ||
Matt Mackall
|
r7637 | except error.RepoError: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('versioned patch repository not found' | ||
Cédric Duval
|
r10690 | ' (see init --mq)')) | ||
Vadim Gelfer
|
r2720 | qbase, destrev = None, None | ||
if sr.local(): | ||||
Sune Foldager
|
r17191 | repo = sr.local() | ||
if repo.mq.applied and repo[qbase].phase() != phases.secret: | ||||
qbase = repo.mq.applied[0].node | ||||
Vadim Gelfer
|
r2720 | if not hg.islocal(dest): | ||
Sune Foldager
|
r17191 | heads = set(repo.heads()) | ||
destrev = list(heads.difference(repo.heads(qbase))) | ||||
destrev.append(repo.changelog.parents(qbase)[0]) | ||||
Peter Arrenbrecht
|
r6164 | elif sr.capable('lookup'): | ||
Alexis S. L. Carvalho
|
r6380 | try: | ||
qbase = sr.lookup('qbase') | ||||
Matt Mackall
|
r7637 | except error.RepoError: | ||
Alexis S. L. Carvalho
|
r6380 | pass | ||
Pierre-Yves David
|
r15921 | |||
Martin Geisler
|
r8027 | ui.note(_('cloning main repository\n')) | ||
Peter Arrenbrecht
|
r14553 | sr, dr = hg.clone(ui, opts, sr.url(), dest, | ||
Christian Ebert
|
r12281 | pull=opts.get('pull'), | ||
Martin von Zweigbergk
|
r37279 | revs=destrev, | ||
Vadim Gelfer
|
r2720 | update=False, | ||
Christian Ebert
|
r12281 | stream=opts.get('uncompressed')) | ||
Pierre-Yves David
|
r15921 | |||
Martin Geisler
|
r8027 | ui.note(_('cloning patch repository\n')) | ||
Peter Arrenbrecht
|
r14553 | hg.clone(ui, opts, opts.get('patches') or patchdir(sr), patchdir(dr), | ||
Christian Ebert
|
r12281 | pull=opts.get('pull'), update=not opts.get('noupdate'), | ||
stream=opts.get('uncompressed')) | ||||
Pierre-Yves David
|
r15921 | |||
Vadim Gelfer
|
r2720 | if dr.local(): | ||
Sune Foldager
|
r17191 | repo = dr.local() | ||
Vadim Gelfer
|
r2720 | if qbase: | ||
Martin Geisler
|
r8027 | ui.note(_('stripping applied patches from destination ' | ||
'repository\n')) | ||||
Pierre-Yves David
|
r19819 | strip(ui, repo, [qbase], update=False, backup=None) | ||
Christian Ebert
|
r12281 | if not opts.get('noupdate'): | ||
Martin Geisler
|
r8027 | ui.note(_('updating destination repository\n')) | ||
Sune Foldager
|
r17191 | hg.update(repo, repo.changelog.tip()) | ||
Vadim Gelfer
|
r2720 | |||
Martin Geisler
|
r14298 | @command("qcommit|qci", | ||
Rodrigo Damazio
|
r40331 | commands.table["commit|ci"][1], | ||
Gregory Szorc
|
r21786 | _('hg qcommit [OPTION]... [FILE]...'), | ||
rdamazio@google.com
|
r40329 | helpcategory=command.CATEGORY_COMMITTING, | ||
Gregory Szorc
|
r21786 | inferrepo=True) | ||
mason@suse.com
|
r1808 | def commit(ui, repo, *pats, **opts): | ||
Dirkjan Ochtman
|
r10361 | """commit changes in the queue repository (DEPRECATED) | ||
Martin Geisler
|
r11193 | This command is deprecated; use :hg:`commit --mq` instead.""" | ||
Brendan Cully
|
r2724 | q = repo.mq | ||
mason@suse.com
|
r1808 | r = q.qrepo() | ||
Matt Mackall
|
r10282 | if not r: | ||
Pierre-Yves David
|
r26587 | raise error.Abort('no queue repository') | ||
mason@suse.com
|
r1808 | commands.commit(r.ui, r, *pats, **opts) | ||
Martin Geisler
|
r14298 | @command("qseries", | ||
[('m', 'missing', None, _('print patches not in series')), | ||||
] + seriesopts, | ||||
rdamazio@google.com
|
r40329 | _('hg qseries [-ms]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
mason@suse.com
|
r1808 | def series(ui, repo, **opts): | ||
Erik Zielke
|
r12538 | """print the entire series file | ||
Returns 0 on success.""" | ||||
Pulkit Goyal
|
r34506 | repo.mq.qseries(repo, missing=opts.get(r'missing'), | ||
summary=opts.get(r'summary')) | ||||
mason@suse.com
|
r1808 | return 0 | ||
rdamazio@google.com
|
r40329 | @command("qtop", seriesopts, _('hg qtop [-s]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
mason@suse.com
|
r1808 | def top(ui, repo, **opts): | ||
Erik Zielke
|
r12538 | """print the name of the current patch | ||
Returns 0 on success.""" | ||||
Brendan Cully
|
r3183 | q = repo.mq | ||
Jordi Gutiérrez Hermoso
|
r24306 | if q.applied: | ||
t = q.seriesend(True) | ||||
else: | ||||
t = 0 | ||||
Brendan Cully
|
r3183 | if t: | ||
Erik Zielke
|
r12539 | q.qseries(repo, start=t - 1, length=1, status='A', | ||
Pulkit Goyal
|
r34506 | summary=opts.get(r'summary')) | ||
Brendan Cully
|
r3183 | else: | ||
Martin Geisler
|
r7627 | ui.write(_("no patches applied\n")) | ||
Brendan Cully
|
r3183 | return 1 | ||
mason@suse.com
|
r1808 | |||
rdamazio@google.com
|
r40329 | @command("qnext", seriesopts, _('hg qnext [-s]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
mason@suse.com
|
r1808 | def next(ui, repo, **opts): | ||
Patrick Mezard
|
r16063 | """print the name of the next pushable patch | ||
Erik Zielke
|
r12538 | |||
Returns 0 on success.""" | ||||
Brendan Cully
|
r3183 | q = repo.mq | ||
Adrian Buehlmann
|
r14586 | end = q.seriesend() | ||
Brendan Cully
|
r3183 | if end == len(q.series): | ||
Martin Geisler
|
r7627 | ui.write(_("all patches applied\n")) | ||
Brendan Cully
|
r3183 | return 1 | ||
Pulkit Goyal
|
r34506 | q.qseries(repo, start=end, length=1, summary=opts.get(r'summary')) | ||
mason@suse.com
|
r1808 | |||
rdamazio@google.com
|
r40329 | @command("qprev", seriesopts, _('hg qprev [-s]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
mason@suse.com
|
r1808 | def prev(ui, repo, **opts): | ||
Patrick Mezard
|
r16188 | """print the name of the preceding applied patch | ||
Erik Zielke
|
r12538 | |||
Returns 0 on success.""" | ||||
Brendan Cully
|
r3183 | q = repo.mq | ||
l = len(q.applied) | ||||
if l == 1: | ||||
Martin Geisler
|
r7627 | ui.write(_("only one patch applied\n")) | ||
Brendan Cully
|
r3183 | return 1 | ||
if not l: | ||||
Martin Geisler
|
r7627 | ui.write(_("no patches applied\n")) | ||
Brendan Cully
|
r3183 | return 1 | ||
Patrick Mezard
|
r16064 | idx = q.series.index(q.applied[-2].name) | ||
q.qseries(repo, start=idx, length=1, status='A', | ||||
Pulkit Goyal
|
r34506 | summary=opts.get(r'summary')) | ||
mason@suse.com
|
r1808 | |||
peter.arrenbrecht@gmail.com
|
r5673 | def setupheaderopts(ui, opts): | ||
Martin Geisler
|
r9733 | if not opts.get('user') and opts.get('currentuser'): | ||
opts['user'] = ui.username() | ||||
if not opts.get('date') and opts.get('currentdate'): | ||||
Boris Feld
|
r36625 | opts['date'] = "%d %d" % dateutil.makedate() | ||
peter.arrenbrecht@gmail.com
|
r5673 | |||
Rodrigo Damazio
|
r40331 | @command("qnew", | ||
FUJIWARA Katsunori
|
r21952 | [('e', 'edit', None, _('invoke editor on commit messages')), | ||
Martin Geisler
|
r14298 | ('f', 'force', None, _('import uncommitted changes (DEPRECATED)')), | ||
('g', 'git', None, _('use git extended diff format')), | ||||
('U', 'currentuser', None, _('add "From: <current user>" to patch')), | ||||
('u', 'user', '', | ||||
_('add "From: <USER>" to patch'), _('USER')), | ||||
('D', 'currentdate', None, _('add "Date: <current date>" to patch')), | ||||
('d', 'date', '', | ||||
_('add "Date: <DATE>" to patch'), _('DATE')) | ||||
Yuya Nishihara
|
r32375 | ] + cmdutil.walkopts + cmdutil.commitopts, | ||
Gregory Szorc
|
r21786 | _('hg qnew [-e] [-m TEXT] [-l FILE] PATCH [FILE]...'), | ||
Rodrigo Damazio
|
r40331 | helpcategory=command.CATEGORY_COMMITTING, helpbasic=True, | ||
Gregory Szorc
|
r21786 | inferrepo=True) | ||
Brendan Cully
|
r4713 | def new(ui, repo, patch, *args, **opts): | ||
Brendan Cully
|
r2754 | """create a new patch | ||
Martin Geisler
|
r7994 | qnew creates a new patch on top of the currently-applied patch (if | ||
Wagner Bruna
|
r10808 | any). The patch will be initialized with any outstanding changes | ||
in the working directory. You may also use -I/--include, | ||||
Martin Geisler
|
r8076 | -X/--exclude, and/or a list of files after the patch name to add | ||
only changes to matching files to the new patch, leaving the rest | ||||
as uncommitted modifications. | ||||
Brendan Cully
|
r2754 | |||
Martin Geisler
|
r8076 | -u/--user and -d/--date can be used to set the (given) user and | ||
date, respectively. -U/--currentuser and -D/--currentdate set user | ||||
to current user and date to current date. | ||||
Dirkjan Ochtman
|
r7306 | |||
Martin Geisler
|
r8076 | -e/--edit, -m/--message or -l/--logfile set the patch header as | ||
well as the commit message. If none is specified, the header is | ||||
empty and the commit message is '[mq]: PATCH'. | ||||
Dirkjan Ochtman
|
r7307 | |||
Martin Geisler
|
r8076 | Use the -g/--git option to keep the patch in the git extended diff | ||
Matt Mackall
|
r7387 | format. Read the diffs help topic for more information on why this | ||
is important for preserving permission changes and copy/rename | ||||
information. | ||||
Erik Zielke
|
r12538 | |||
Returns 0 on successful creation of a new patch. | ||||
Dirkjan Ochtman
|
r7306 | """ | ||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Idan Kamara
|
r14635 | msg = cmdutil.logmessage(ui, opts) | ||
Brendan Cully
|
r2724 | q = repo.mq | ||
Brendan Cully
|
r7157 | opts['msg'] = msg | ||
peter.arrenbrecht@gmail.com
|
r5673 | setupheaderopts(ui, opts) | ||
Pulkit Goyal
|
r34506 | q.new(repo, patch, *args, **pycompat.strkwargs(opts)) | ||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
mason@suse.com
|
r1808 | return 0 | ||
Rodrigo Damazio
|
r40331 | @command("qrefresh", | ||
FUJIWARA Katsunori
|
r21952 | [('e', 'edit', None, _('invoke editor on commit messages')), | ||
Martin Geisler
|
r14298 | ('g', 'git', None, _('use git extended diff format')), | ||
('s', 'short', None, | ||||
_('refresh only files already in the patch and specified files')), | ||||
('U', 'currentuser', None, | ||||
_('add/update author field in patch with current user')), | ||||
('u', 'user', '', | ||||
_('add/update author field in patch with given user'), _('USER')), | ||||
('D', 'currentdate', None, | ||||
_('add/update date field in patch with current date')), | ||||
('d', 'date', '', | ||||
_('add/update date field in patch with given date'), _('DATE')) | ||||
Yuya Nishihara
|
r32375 | ] + cmdutil.walkopts + cmdutil.commitopts, | ||
Gregory Szorc
|
r21786 | _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...'), | ||
Rodrigo Damazio
|
r40331 | helpcategory=command.CATEGORY_COMMITTING, helpbasic=True, | ||
Gregory Szorc
|
r21786 | inferrepo=True) | ||
Brendan Cully
|
r2938 | def refresh(ui, repo, *pats, **opts): | ||
Brendan Cully
|
r2940 | """update the current patch | ||
Martin Geisler
|
r7994 | If any file patterns are provided, the refreshed patch will | ||
contain only the modifications that match those patterns; the | ||||
remaining modifications will remain in the working directory. | ||||
Thomas Arendsen Hein
|
r4048 | |||
Martin Geisler
|
r8076 | If -s/--short is specified, files currently included in the patch | ||
Martin Geisler
|
r7994 | will be refreshed just like matched files and remain in the patch. | ||
Mads Kiilerich
|
r7113 | |||
Renato Cunha
|
r11947 | If -e/--edit is specified, Mercurial will start your configured editor for | ||
you to enter a message. In case qrefresh fails, you will find a backup of | ||||
your message in ``.hg/last-message.txt``. | ||||
Martin Geisler
|
r7994 | hg add/remove/copy/rename work as usual, though you might want to | ||
Martin Geisler
|
r8076 | use git-style patches (-g/--git or [diff] git=1) to track copies | ||
and renames. See the diffs help topic for more information on the | ||||
git diff format. | ||||
Erik Zielke
|
r12538 | |||
Returns 0 on success. | ||||
Brendan Cully
|
r2940 | """ | ||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Brendan Cully
|
r2724 | q = repo.mq | ||
Idan Kamara
|
r14635 | message = cmdutil.logmessage(ui, opts) | ||
peter.arrenbrecht@gmail.com
|
r5673 | setupheaderopts(ui, opts) | ||
Bryan O'Sullivan
|
r27830 | with repo.wlock(): | ||
Pulkit Goyal
|
r34506 | ret = q.refresh(repo, pats, msg=message, **pycompat.strkwargs(opts)) | ||
Yuya Nishihara
|
r14620 | q.savedirty() | ||
return ret | ||||
mason@suse.com
|
r1808 | |||
Rodrigo Damazio
|
r40331 | @command("qdiff", | ||
Yuya Nishihara
|
r32375 | cmdutil.diffopts + cmdutil.diffopts2 + cmdutil.walkopts, | ||
Gregory Szorc
|
r21786 | _('hg qdiff [OPTION]... [FILE]...'), | ||
Rodrigo Damazio
|
r40331 | helpcategory=command.CATEGORY_FILE_CONTENTS, helpbasic=True, | ||
Gregory Szorc
|
r21786 | inferrepo=True) | ||
Brendan Cully
|
r2937 | def diff(ui, repo, *pats, **opts): | ||
Dirkjan Ochtman
|
r6606 | """diff of the current patch and subsequent modifications | ||
Dirkjan Ochtman
|
r6621 | |||
Martin Geisler
|
r7994 | Shows a diff which includes the current patch as well as any | ||
changes which have been made in the working directory since the | ||||
last refresh (thus showing what the current patch would become | ||||
after a qrefresh). | ||||
Dirkjan Ochtman
|
r6621 | |||
Martin Geisler
|
r10973 | Use :hg:`diff` if you only want to see the changes made since the | ||
last qrefresh, or :hg:`export qtip` if you want to see changes | ||||
made by the current patch without including changes made since the | ||||
Martin Geisler
|
r7994 | qrefresh. | ||
Erik Zielke
|
r12538 | |||
Returns 0 on success. | ||||
Dirkjan Ochtman
|
r6606 | """ | ||
Augie Fackler
|
r31033 | ui.pager('qdiff') | ||
Pulkit Goyal
|
r34506 | repo.mq.diff(repo, pats, pycompat.byteskwargs(opts)) | ||
mason@suse.com
|
r1808 | return 0 | ||
Martin Geisler
|
r14298 | @command('qfold', | ||
FUJIWARA Katsunori
|
r21952 | [('e', 'edit', None, _('invoke editor on commit messages')), | ||
Martin Geisler
|
r14298 | ('k', 'keep', None, _('keep folded patch files')), | ||
Yuya Nishihara
|
r32375 | ] + cmdutil.commitopts, | ||
rdamazio@google.com
|
r40329 | _('hg qfold [-e] [-k] [-m TEXT] [-l FILE] PATCH...'), | ||
helpcategory=command.CATEGORY_CHANGE_MANAGEMENT) | ||||
Brendan Cully
|
r2753 | def fold(ui, repo, *files, **opts): | ||
Brendan Cully
|
r2748 | """fold the named patches into the current patch | ||
Brendan Cully
|
r2753 | |||
Brendan Cully
|
r2771 | Patches must not yet be applied. Each patch will be successively | ||
applied to the current patch in the order given. If all the | ||||
patches apply successfully, the current patch will be refreshed | ||||
Martin Geisler
|
r7994 | with the new cumulative patch, and the folded patches will be | ||
deleted. With -k/--keep, the folded patch files will not be | ||||
removed afterwards. | ||||
Brendan Cully
|
r2771 | |||
Martin Geisler
|
r7994 | The header for each folded patch will be concatenated with the | ||
Erik Zielke
|
r12755 | current patch header, separated by a line of ``* * *``. | ||
Erik Zielke
|
r12538 | |||
Returns 0 on success.""" | ||||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Brendan Cully
|
r2748 | q = repo.mq | ||
if not files: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('qfold requires at least one patch name')) | ||
Adrian Buehlmann
|
r14581 | if not q.checktoppatch(repo)[0]: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no patches applied')) | ||
Adrian Buehlmann
|
r14583 | q.checklocalchanges(repo) | ||
Brendan Cully
|
r2748 | |||
Idan Kamara
|
r14635 | message = cmdutil.logmessage(ui, opts) | ||
Brendan Cully
|
r2753 | |||
Brendan Cully
|
r2748 | parent = q.lookup('qtip') | ||
patches = [] | ||||
messages = [] | ||||
for f in files: | ||||
Brendan Cully
|
r2936 | p = q.lookup(f) | ||
if p in patches or p == parent: | ||||
Martin Geisler
|
r16929 | ui.warn(_('skipping already folded patch %s\n') % p) | ||
Brendan Cully
|
r2936 | if q.isapplied(p): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('qfold cannot fold already applied patch %s') | ||
Brodie Rao
|
r16683 | % p) | ||
Brendan Cully
|
r2936 | patches.append(p) | ||
Brendan Cully
|
r2748 | |||
Brendan Cully
|
r2936 | for p in patches: | ||
Brendan Cully
|
r2753 | if not message: | ||
Steve Losh
|
r10397 | ph = patchheader(q.join(p), q.plainmode) | ||
Brendan Cully
|
r7454 | if ph.message: | ||
messages.append(ph.message) | ||||
Brendan Cully
|
r2936 | pf = q.join(p) | ||
Brendan Cully
|
r2748 | (patchsuccess, files, fuzz) = q.patch(repo, pf) | ||
if not patchsuccess: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('error folding patch %s') % p) | ||
Brendan Cully
|
r2748 | |||
Brendan Cully
|
r2753 | if not message: | ||
Steve Losh
|
r10397 | ph = patchheader(q.join(parent), q.plainmode) | ||
FUJIWARA Katsunori
|
r21270 | message = ph.message | ||
Brendan Cully
|
r2753 | for msg in messages: | ||
Mads Kiilerich
|
r20053 | if msg: | ||
if message: | ||||
message.append('* * *') | ||||
message.extend(msg) | ||||
Brendan Cully
|
r2753 | message = '\n'.join(message) | ||
Patrick Mezard
|
r10186 | diffopts = q.patchopts(q.diffopts(), *patches) | ||
Bryan O'Sullivan
|
r27831 | with repo.wlock(): | ||
FUJIWARA Katsunori
|
r22003 | q.refresh(repo, msg=message, git=diffopts.git, edit=opts.get('edit'), | ||
editform='mq.qfold') | ||||
Yuya Nishihara
|
r14620 | q.delete(repo, patches, opts) | ||
q.savedirty() | ||||
Brendan Cully
|
r2748 | |||
Martin Geisler
|
r14298 | @command("qgoto", | ||
Patrick Mezard
|
r16733 | [('', 'keep-changes', None, | ||
_('tolerate non-conflicting local changes')), | ||||
Patrick Mezard
|
r16655 | ('f', 'force', None, _('overwrite any local changes')), | ||
Patrick Mezard
|
r16635 | ('', 'no-backup', None, _('do not save backup copies of files'))], | ||
rdamazio@google.com
|
r40329 | _('hg qgoto [OPTION]... PATCH'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
Bryan O'Sullivan
|
r4432 | def goto(ui, repo, patch, **opts): | ||
Erik Zielke
|
r12538 | '''push or pop patches until named patch is at top of stack | ||
Returns 0 on success.''' | ||||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Patrick Mezard
|
r16733 | opts = fixkeepchangesopts(ui, opts) | ||
Bryan O'Sullivan
|
r4432 | q = repo.mq | ||
patch = q.lookup(patch) | ||||
Patrick Mezard
|
r16635 | nobackup = opts.get('no_backup') | ||
Patrick Mezard
|
r16733 | keepchanges = opts.get('keep_changes') | ||
Bryan O'Sullivan
|
r4432 | if q.isapplied(patch): | ||
Patrick Mezard
|
r16655 | ret = q.pop(repo, patch, force=opts.get('force'), nobackup=nobackup, | ||
Patrick Mezard
|
r16733 | keepchanges=keepchanges) | ||
Bryan O'Sullivan
|
r4432 | else: | ||
Patrick Mezard
|
r16655 | ret = q.push(repo, patch, force=opts.get('force'), nobackup=nobackup, | ||
Patrick Mezard
|
r16733 | keepchanges=keepchanges) | ||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
Bryan O'Sullivan
|
r4432 | return ret | ||
Martin Geisler
|
r14298 | @command("qguard", | ||
[('l', 'list', None, _('list all patches and guards')), | ||||
('n', 'none', None, _('drop all guards'))], | ||||
rdamazio@google.com
|
r40329 | _('hg qguard [-l] [-n] [PATCH] [-- [+GUARD]... [-GUARD]...]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
Vadim Gelfer
|
r2821 | def guard(ui, repo, *args, **opts): | ||
'''set or print guards for a patch | ||||
Brendan Cully
|
r2940 | Guards control whether a patch can be pushed. A patch with no | ||
guards is always pushed. A patch with a positive guard ("+foo") is | ||||
Martin Geisler
|
r11307 | pushed only if the :hg:`qselect` command has activated it. A patch with | ||
a negative guard ("-foo") is never pushed if the :hg:`qselect` command | ||||
Brendan Cully
|
r2940 | has activated it. | ||
Vadim Gelfer
|
r2821 | |||
Brendan Cully
|
r2940 | With no arguments, print the currently active guards. | ||
With arguments, set guards for the named patch. | ||||
Erik Zielke
|
r12389 | |||
.. note:: | ||||
Simon Heimberg
|
r19997 | |||
Erik Zielke
|
r12389 | Specifying negative guards now requires '--'. | ||
Vadim Gelfer
|
r2821 | |||
Martin Geisler
|
r9824 | To set guards on another patch:: | ||
Martin Geisler
|
r10476 | hg qguard other.patch -- +2.6.17 -stable | ||
Erik Zielke
|
r12538 | |||
Returns 0 on success. | ||||
Vadim Gelfer
|
r2821 | ''' | ||
def status(idx): | ||||
Adrian Buehlmann
|
r14573 | guards = q.seriesguards[idx] or ['unguarded'] | ||
Dan Villiom Podlaski Christiansen
|
r11819 | if q.series[idx] in applied: | ||
state = 'applied' | ||||
elif q.pushable(idx)[0]: | ||||
state = 'unapplied' | ||||
else: | ||||
state = 'guarded' | ||||
label = 'qguard.patch qguard.%s qseries.%s' % (state, state) | ||||
ui.write('%s: ' % ui.label(q.series[idx], label)) | ||||
Brodie Rao
|
r10822 | for i, guard in enumerate(guards): | ||
if guard.startswith('+'): | ||||
Steve Borho
|
r11310 | ui.write(guard, label='qguard.positive') | ||
Brodie Rao
|
r10822 | elif guard.startswith('-'): | ||
Steve Borho
|
r11310 | ui.write(guard, label='qguard.negative') | ||
Brodie Rao
|
r10822 | else: | ||
Steve Borho
|
r11310 | ui.write(guard, label='qguard.unguarded') | ||
Brodie Rao
|
r10822 | if i != len(guards) - 1: | ||
Steve Borho
|
r11310 | ui.write(' ') | ||
ui.write('\n') | ||||
Vadim Gelfer
|
r2821 | q = repo.mq | ||
Dan Villiom Podlaski Christiansen
|
r11819 | applied = set(p.name for p in q.applied) | ||
Vadim Gelfer
|
r2821 | patch = None | ||
args = list(args) | ||||
Pulkit Goyal
|
r34506 | if opts.get(r'list'): | ||
Pulkit Goyal
|
r38060 | if args or opts.get(r'none'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot mix -l/--list with options or ' | ||
Brodie Rao
|
r16683 | 'arguments')) | ||
Gregory Szorc
|
r38806 | for i in pycompat.xrange(len(q.series)): | ||
Vadim Gelfer
|
r2821 | status(i) | ||
return | ||||
if not args or args[0][0:1] in '-+': | ||||
if not q.applied: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no patches applied')) | ||
Vadim Gelfer
|
r2821 | patch = q.applied[-1].name | ||
if patch is None and args[0][0:1] not in '-+': | ||||
patch = args.pop(0) | ||||
if patch is None: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no patch to work with')) | ||
Pulkit Goyal
|
r38060 | if args or opts.get(r'none'): | ||
Adrian Buehlmann
|
r14574 | idx = q.findseries(patch) | ||
Christian Ebert
|
r4133 | if idx is None: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no patch named %s') % patch) | ||
Adrian Buehlmann
|
r14577 | q.setguards(idx, args) | ||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
Vadim Gelfer
|
r2821 | else: | ||
status(q.series.index(q.lookup(patch))) | ||||
rdamazio@google.com
|
r40329 | @command("qheader", [], _('hg qheader [PATCH]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
Brendan Cully
|
r2747 | def header(ui, repo, patch=None): | ||
Erik Zielke
|
r12538 | """print the header of the topmost or specified patch | ||
Returns 0 on success.""" | ||||
Brendan Cully
|
r2747 | q = repo.mq | ||
if patch: | ||||
patch = q.lookup(patch) | ||||
else: | ||||
if not q.applied: | ||||
Benoit Boissinot
|
r10510 | ui.write(_('no patches applied\n')) | ||
Bryan O'Sullivan
|
r3008 | return 1 | ||
Brendan Cully
|
r2747 | patch = q.lookup('qtip') | ||
Steve Losh
|
r10397 | ph = patchheader(q.join(patch), q.plainmode) | ||
Brendan Cully
|
r2747 | |||
Brendan Cully
|
r7399 | ui.write('\n'.join(ph.message) + '\n') | ||
Brendan Cully
|
r2747 | |||
mason@suse.com
|
r1808 | def lastsavename(path): | ||
Benoit Boissinot
|
r2794 | (directory, base) = os.path.split(path) | ||
names = os.listdir(directory) | ||||
mason@suse.com
|
r1808 | namere = re.compile("%s.([0-9]+)" % base) | ||
Benoit Boissinot
|
r2794 | maxindex = None | ||
mason@suse.com
|
r1808 | maxname = None | ||
for f in names: | ||||
m = namere.match(f) | ||||
if m: | ||||
index = int(m.group(1)) | ||||
Martin Geisler
|
r8527 | if maxindex is None or index > maxindex: | ||
Benoit Boissinot
|
r2794 | maxindex = index | ||
mason@suse.com
|
r1808 | maxname = f | ||
if maxname: | ||||
Benoit Boissinot
|
r2794 | return (os.path.join(directory, maxname), maxindex) | ||
mason@suse.com
|
r1808 | return (None, None) | ||
Thomas Arendsen Hein
|
r1810 | |||
mason@suse.com
|
r1808 | def savename(path): | ||
(last, index) = lastsavename(path) | ||||
if last is None: | ||||
index = 0 | ||||
newpath = path + ".%d" % (index + 1) | ||||
return newpath | ||||
Rodrigo Damazio
|
r40331 | @command("qpush", | ||
Patrick Mezard
|
r16733 | [('', 'keep-changes', None, | ||
_('tolerate non-conflicting local changes')), | ||||
Patrick Mezard
|
r16654 | ('f', 'force', None, _('apply on top of local changes')), | ||
Brodie Rao
|
r16683 | ('e', 'exact', None, | ||
_('apply the target patch to its recorded parent')), | ||||
Martin Geisler
|
r14298 | ('l', 'list', None, _('list patch name in commit text')), | ||
('a', 'all', None, _('apply all patches')), | ||||
('m', 'merge', None, _('merge from another queue (DEPRECATED)')), | ||||
('n', 'name', '', | ||||
_('merge queue name (DEPRECATED)'), _('NAME')), | ||||
Patrick Mezard
|
r16635 | ('', 'move', None, | ||
_('reorder patch series and apply only the patch')), | ||||
('', 'no-backup', None, _('do not save backup copies of files'))], | ||||
rdamazio@google.com
|
r40329 | _('hg qpush [-f] [-l] [-a] [--move] [PATCH | INDEX]'), | ||
Rodrigo Damazio
|
r40331 | helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, | ||
helpbasic=True) | ||||
mason@suse.com
|
r1808 | def push(ui, repo, patch=None, **opts): | ||
Dirkjan Ochtman
|
r6552 | """push the next patch onto the stack | ||
Dirkjan Ochtman
|
r6553 | |||
Patrick Mezard
|
r16654 | By default, abort if the working directory contains uncommitted | ||
Patrick Mezard
|
r16733 | changes. With --keep-changes, abort only if the uncommitted files | ||
Patrick Mezard
|
r16654 | overlap with patched files. With -f/--force, backup and patch over | ||
uncommitted changes. | ||||
Erik Zielke
|
r12538 | |||
Stefano Tortarolo
|
r13725 | Return 0 on success. | ||
Dirkjan Ochtman
|
r6552 | """ | ||
Brendan Cully
|
r2724 | q = repo.mq | ||
mason@suse.com
|
r1808 | mergeq = None | ||
Thomas Arendsen Hein
|
r1810 | |||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Patrick Mezard
|
r16733 | opts = fixkeepchangesopts(ui, opts) | ||
Christian Ebert
|
r12281 | if opts.get('merge'): | ||
if opts.get('name'): | ||||
Pierre-Yves David
|
r31333 | newpath = repo.vfs.join(opts.get('name')) | ||
mason@suse.com
|
r1808 | else: | ||
Thomas Arendsen Hein
|
r1810 | newpath, i = lastsavename(q.path) | ||
mason@suse.com
|
r1808 | if not newpath: | ||
Martin Geisler
|
r6960 | ui.warn(_("no saved queues found, please use -n\n")) | ||
mason@suse.com
|
r1808 | return 1 | ||
Simon Heimberg
|
r19064 | mergeq = queue(ui, repo.baseui, repo.path, newpath) | ||
Martin Geisler
|
r6960 | ui.warn(_("merging with queue at: %s\n") % mergeq.path) | ||
Christian Ebert
|
r12281 | ret = q.push(repo, patch, force=opts.get('force'), list=opts.get('list'), | ||
Steve Losh
|
r13033 | mergeq=mergeq, all=opts.get('all'), move=opts.get('move'), | ||
Patrick Mezard
|
r16654 | exact=opts.get('exact'), nobackup=opts.get('no_backup'), | ||
Patrick Mezard
|
r16733 | keepchanges=opts.get('keep_changes')) | ||
mason@suse.com
|
r1808 | return ret | ||
Rodrigo Damazio
|
r40331 | @command("qpop", | ||
Martin Geisler
|
r14298 | [('a', 'all', None, _('pop all patches')), | ||
('n', 'name', '', | ||||
_('queue name to pop (DEPRECATED)'), _('NAME')), | ||||
Patrick Mezard
|
r16733 | ('', 'keep-changes', None, | ||
_('tolerate non-conflicting local changes')), | ||||
Patrick Mezard
|
r16635 | ('f', 'force', None, _('forget any local changes to patched files')), | ||
('', 'no-backup', None, _('do not save backup copies of files'))], | ||||
rdamazio@google.com
|
r40329 | _('hg qpop [-a] [-f] [PATCH | INDEX]'), | ||
Rodrigo Damazio
|
r40331 | helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, | ||
helpbasic=True) | ||||
mason@suse.com
|
r1808 | def pop(ui, repo, patch=None, **opts): | ||
Dirkjan Ochtman
|
r6611 | """pop the current patch off the stack | ||
Dirkjan Ochtman
|
r6621 | |||
Patrick Mezard
|
r16653 | Without argument, pops off the top of the patch stack. If given a | ||
patch name, keeps popping off patches until the named patch is at | ||||
the top of the stack. | ||||
By default, abort if the working directory contains uncommitted | ||||
Patrick Mezard
|
r16733 | changes. With --keep-changes, abort only if the uncommitted files | ||
Patrick Mezard
|
r16653 | overlap with patched files. With -f/--force, backup and discard | ||
changes made to such files. | ||||
Erik Zielke
|
r12538 | |||
Return 0 on success. | ||||
Dirkjan Ochtman
|
r6611 | """ | ||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Patrick Mezard
|
r16733 | opts = fixkeepchangesopts(ui, opts) | ||
mason@suse.com
|
r1808 | localupdate = True | ||
Christian Ebert
|
r12281 | if opts.get('name'): | ||
Pierre-Yves David
|
r31333 | q = queue(ui, repo.baseui, repo.path, repo.vfs.join(opts.get('name'))) | ||
Martin Geisler
|
r6960 | ui.warn(_('using patch queue: %s\n') % q.path) | ||
mason@suse.com
|
r1808 | localupdate = False | ||
else: | ||||
Brendan Cully
|
r2724 | q = repo.mq | ||
Christian Ebert
|
r12281 | ret = q.pop(repo, patch, force=opts.get('force'), update=localupdate, | ||
Patrick Mezard
|
r16653 | all=opts.get('all'), nobackup=opts.get('no_backup'), | ||
Patrick Mezard
|
r16733 | keepchanges=opts.get('keep_changes')) | ||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
Alexis S. L. Carvalho
|
r4099 | return ret | ||
mason@suse.com
|
r1808 | |||
rdamazio@google.com
|
r40329 | @command("qrename|qmv", [], _('hg qrename PATCH1 [PATCH2]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
Brendan Cully
|
r2750 | def rename(ui, repo, patch, name=None, **opts): | ||
"""rename a patch | ||||
With one argument, renames the current patch to PATCH1. | ||||
Erik Zielke
|
r12538 | With two arguments, renames PATCH1 to PATCH2. | ||
Returns 0 on success.""" | ||||
Brendan Cully
|
r2750 | q = repo.mq | ||
if not name: | ||||
name = patch | ||||
patch = None | ||||
if patch: | ||||
patch = q.lookup(patch) | ||||
else: | ||||
if not q.applied: | ||||
Martin Geisler
|
r7627 | ui.write(_('no patches applied\n')) | ||
Brendan Cully
|
r2750 | return | ||
patch = q.lookup('qtip') | ||||
Brendan Cully
|
r3083 | absdest = q.join(name) | ||
if os.path.isdir(absdest): | ||||
Patrick Mezard
|
r4037 | name = normname(os.path.join(name, os.path.basename(patch))) | ||
Brendan Cully
|
r3083 | absdest = q.join(name) | ||
Idan Kamara
|
r14423 | q.checkpatchname(name) | ||
Brendan Cully
|
r2750 | |||
Benoit Boissinot
|
r10510 | ui.note(_('renaming %s to %s\n') % (patch, name)) | ||
Adrian Buehlmann
|
r14574 | i = q.findseries(patch) | ||
Adrian Buehlmann
|
r14572 | guards = q.guard_re.findall(q.fullseries[i]) | ||
q.fullseries[i] = name + ''.join([' #' + g for g in guards]) | ||||
Adrian Buehlmann
|
r14575 | q.parseseries() | ||
Mads Kiilerich
|
r15879 | q.seriesdirty = True | ||
Brendan Cully
|
r2750 | |||
info = q.isapplied(patch) | ||||
if info: | ||||
Brendan Cully
|
r2818 | q.applied[info[0]] = statusentry(info[1], name) | ||
Mads Kiilerich
|
r15879 | q.applieddirty = True | ||
Brendan Cully
|
r2750 | |||
Yuya Nishihara
|
r11513 | destdir = os.path.dirname(absdest) | ||
if not os.path.isdir(destdir): | ||||
os.makedirs(destdir) | ||||
Vadim Gelfer
|
r2819 | util.rename(q.join(patch), absdest) | ||
Brendan Cully
|
r2750 | r = q.qrepo() | ||
Patrick Mezard
|
r12875 | if r and patch in r.dirstate: | ||
Dirkjan Ochtman
|
r11303 | wctx = r[None] | ||
Bryan O'Sullivan
|
r27848 | with r.wlock(): | ||
Weijun Wang
|
r6648 | if r.dirstate[patch] == 'a': | ||
Matt Mackall
|
r14434 | r.dirstate.drop(patch) | ||
Weijun Wang
|
r6648 | r.dirstate.add(name) | ||
else: | ||||
Dirkjan Ochtman
|
r11303 | wctx.copy(patch, name) | ||
Matt Mackall
|
r14435 | wctx.forget([patch]) | ||
Brendan Cully
|
r2750 | |||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
Brendan Cully
|
r2750 | |||
Martin Geisler
|
r14298 | @command("qrestore", | ||
[('d', 'delete', None, _('delete save entry')), | ||||
('u', 'update', None, _('update queue working directory'))], | ||||
rdamazio@google.com
|
r40329 | _('hg qrestore [-d] [-u] REV'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
mason@suse.com
|
r1808 | def restore(ui, repo, rev, **opts): | ||
Dirkjan Ochtman
|
r10360 | """restore the queue state saved by a revision (DEPRECATED) | ||
Dan Villiom Podlaski Christiansen
|
r12352 | This command is deprecated, use :hg:`rebase` instead.""" | ||
mason@suse.com
|
r1808 | rev = repo.lookup(rev) | ||
Brendan Cully
|
r2724 | q = repo.mq | ||
Pulkit Goyal
|
r34506 | q.restore(repo, rev, delete=opts.get(r'delete'), | ||
qupdate=opts.get(r'update')) | ||||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
mason@suse.com
|
r1808 | return 0 | ||
Martin Geisler
|
r14298 | @command("qsave", | ||
[('c', 'copy', None, _('copy patch directory')), | ||||
('n', 'name', '', | ||||
_('copy directory name'), _('NAME')), | ||||
('e', 'empty', None, _('clear queue status file')), | ||||
Yuya Nishihara
|
r32375 | ('f', 'force', None, _('force copy'))] + cmdutil.commitopts, | ||
rdamazio@google.com
|
r40329 | _('hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
mason@suse.com
|
r1808 | def save(ui, repo, **opts): | ||
Dirkjan Ochtman
|
r10360 | """save current queue state (DEPRECATED) | ||
Dan Villiom Podlaski Christiansen
|
r12352 | This command is deprecated, use :hg:`rebase` instead.""" | ||
Brendan Cully
|
r2724 | q = repo.mq | ||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Idan Kamara
|
r14635 | message = cmdutil.logmessage(ui, opts) | ||
"Mathieu Clabaut "
|
r2694 | ret = q.save(repo, msg=message) | ||
mason@suse.com
|
r1808 | if ret: | ||
return ret | ||||
Mads Kiilerich
|
r15880 | q.savedirty() # save to .hg/patches before copying | ||
Christian Ebert
|
r12281 | if opts.get('copy'): | ||
mason@suse.com
|
r1808 | path = q.path | ||
Christian Ebert
|
r12281 | if opts.get('name'): | ||
newpath = os.path.join(q.basepath, opts.get('name')) | ||||
mason@suse.com
|
r1808 | if os.path.exists(newpath): | ||
if not os.path.isdir(newpath): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('destination %s exists and is not ' | ||
Vadim Gelfer
|
r2712 | 'a directory') % newpath) | ||
Christian Ebert
|
r12281 | if not opts.get('force'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('destination %s exists, ' | ||
Vadim Gelfer
|
r2712 | 'use -f to force') % newpath) | ||
mason@suse.com
|
r1808 | else: | ||
newpath = savename(path) | ||||
Martin Geisler
|
r6960 | ui.warn(_("copy %s to %s\n") % (path, newpath)) | ||
mason@suse.com
|
r1808 | util.copyfiles(path, newpath) | ||
Christian Ebert
|
r12281 | if opts.get('empty'): | ||
Mads Kiilerich
|
r15880 | del q.applied[:] | ||
q.applieddirty = True | ||||
q.savedirty() | ||||
mason@suse.com
|
r1808 | return 0 | ||
Thomas Arendsen Hein
|
r1810 | |||
mason@suse.com
|
r1808 | |||
Martin Geisler
|
r14298 | @command("qselect", | ||
[('n', 'none', None, _('disable all guards')), | ||||
('s', 'series', None, _('list all guards in series file')), | ||||
('', 'pop', None, _('pop to before first guarded applied patch')), | ||||
('', 'reapply', None, _('pop, then reapply patches'))], | ||||
rdamazio@google.com
|
r40329 | _('hg qselect [OPTION]... [GUARD]...'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
Vadim Gelfer
|
r2821 | def select(ui, repo, *args, **opts): | ||
'''set or print guarded patches to push | ||||
Martin Geisler
|
r11307 | Use the :hg:`qguard` command to set or print guards on patch, then use | ||
Martin Geisler
|
r7994 | qselect to tell mq which guards to use. A patch will be pushed if | ||
it has no guards or any positive guards match the currently | ||||
selected guard, but will not be pushed if any negative guards | ||||
Martin Geisler
|
r9824 | match the current guard. For example:: | ||
Vadim Gelfer
|
r2821 | |||
timeless@gmail.com
|
r13791 | qguard foo.patch -- -stable (negative guard) | ||
qguard bar.patch +stable (positive guard) | ||||
Vadim Gelfer
|
r2821 | qselect stable | ||
Brendan Cully
|
r2940 | This activates the "stable" guard. mq will skip foo.patch (because | ||
Martin Geisler
|
r7994 | it has a negative match) but push bar.patch (because it has a | ||
positive match). | ||||
Vadim Gelfer
|
r2821 | |||
Brendan Cully
|
r2940 | With no arguments, prints the currently active guards. | ||
With one argument, sets the active guard. | ||||
Thomas Arendsen Hein
|
r3223 | |||
Brendan Cully
|
r2940 | Use -n/--none to deactivate guards (no other arguments needed). | ||
Martin Geisler
|
r7994 | When no guards are active, patches with positive guards are | ||
skipped and patches with negative guards are pushed. | ||||
Vadim Gelfer
|
r2821 | |||
Brendan Cully
|
r2940 | qselect can change the guards on applied patches. It does not pop | ||
Martin Geisler
|
r7994 | guarded patches by default. Use --pop to pop back to the last | ||
applied patch that is not guarded. Use --reapply (which implies | ||||
--pop) to push back to the current patch afterwards, but skip | ||||
guarded patches. | ||||
Vadim Gelfer
|
r2844 | |||
Martin Geisler
|
r7994 | Use -s/--series to print a list of all guards in the series file | ||
Erik Zielke
|
r12538 | (no other arguments needed). Use -v for more information. | ||
Returns 0 on success.''' | ||||
Vadim Gelfer
|
r2821 | |||
q = repo.mq | ||||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
Vadim Gelfer
|
r2821 | guards = q.active() | ||
FUJIWARA Katsunori
|
r22453 | pushable = lambda i: q.pushable(q.applied[i].name)[0] | ||
Christian Ebert
|
r12281 | if args or opts.get('none'): | ||
Vadim Gelfer
|
r2844 | old_unapplied = q.unapplied(repo) | ||
Gregory Szorc
|
r38806 | old_guarded = [i for i in pycompat.xrange(len(q.applied)) | ||
if not pushable(i)] | ||||
Adrian Buehlmann
|
r14578 | q.setactive(args) | ||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
Vadim Gelfer
|
r2821 | if not args: | ||
ui.status(_('guards deactivated\n')) | ||||
Christian Ebert
|
r12281 | if not opts.get('pop') and not opts.get('reapply'): | ||
Vadim Gelfer
|
r2844 | unapplied = q.unapplied(repo) | ||
Gregory Szorc
|
r38806 | guarded = [i for i in pycompat.xrange(len(q.applied)) | ||
if not pushable(i)] | ||||
Vadim Gelfer
|
r2844 | if len(unapplied) != len(old_unapplied): | ||
ui.status(_('number of unguarded, unapplied patches has ' | ||||
'changed from %d to %d\n') % | ||||
(len(old_unapplied), len(unapplied))) | ||||
if len(guarded) != len(old_guarded): | ||||
ui.status(_('number of guarded, applied patches has changed ' | ||||
'from %d to %d\n') % | ||||
(len(old_guarded), len(guarded))) | ||||
Christian Ebert
|
r12281 | elif opts.get('series'): | ||
Vadim Gelfer
|
r2821 | guards = {} | ||
noguards = 0 | ||||
Adrian Buehlmann
|
r14573 | for gs in q.seriesguards: | ||
Vadim Gelfer
|
r2821 | if not gs: | ||
noguards += 1 | ||||
for g in gs: | ||||
guards.setdefault(g, 0) | ||||
guards[g] += 1 | ||||
if ui.verbose: | ||||
guards['NONE'] = noguards | ||||
Pulkit Goyal
|
r36296 | guards = list(guards.items()) | ||
Alejandro Santos
|
r9032 | guards.sort(key=lambda x: x[0][1:]) | ||
Vadim Gelfer
|
r2821 | if guards: | ||
ui.note(_('guards in series file:\n')) | ||||
for guard, count in guards: | ||||
ui.note('%2d ' % count) | ||||
ui.write(guard, '\n') | ||||
else: | ||||
ui.note(_('no guards in series file\n')) | ||||
else: | ||||
if guards: | ||||
ui.note(_('active guards:\n')) | ||||
for g in guards: | ||||
ui.write(g, '\n') | ||||
else: | ||||
ui.write(_('no active guards\n')) | ||||
FUJIWARA Katsunori
|
r22454 | reapply = opts.get('reapply') and q.applied and q.applied[-1].name | ||
Vadim Gelfer
|
r2844 | popped = False | ||
Christian Ebert
|
r12281 | if opts.get('pop') or opts.get('reapply'): | ||
Gregory Szorc
|
r38806 | for i in pycompat.xrange(len(q.applied)): | ||
FUJIWARA Katsunori
|
r22456 | if not pushable(i): | ||
Vadim Gelfer
|
r2844 | ui.status(_('popping guarded patches\n')) | ||
popped = True | ||||
if i == 0: | ||||
q.pop(repo, all=True) | ||||
else: | ||||
FUJIWARA Katsunori
|
r22455 | q.pop(repo, q.applied[i - 1].name) | ||
Vadim Gelfer
|
r2844 | break | ||
if popped: | ||||
try: | ||||
if reapply: | ||||
ui.status(_('reapplying unguarded patches\n')) | ||||
q.push(repo, reapply) | ||||
finally: | ||||
Adrian Buehlmann
|
r14580 | q.savedirty() | ||
Vadim Gelfer
|
r2821 | |||
Martin Geisler
|
r14298 | @command("qfinish", | ||
[('a', 'applied', None, _('finish all applied changesets'))], | ||||
rdamazio@google.com
|
r40329 | _('hg qfinish [-a] [REV]...'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
Dirkjan Ochtman
|
r6645 | def finish(ui, repo, *revrange, **opts): | ||
"""move applied patches into repository history | ||||
Martin Geisler
|
r7994 | Finishes the specified revisions (corresponding to applied | ||
patches) by moving them out of mq control into regular repository | ||||
history. | ||||
Dirkjan Ochtman
|
r6645 | |||
Martin Geisler
|
r8076 | Accepts a revision range or the -a/--applied option. If --applied | ||
is specified, all applied mq revisions are removed from mq | ||||
control. Otherwise, the given revisions must be at the base of the | ||||
stack of applied patches. | ||||
Dirkjan Ochtman
|
r6645 | |||
Martin Geisler
|
r7994 | This can be especially useful if your changes have been applied to | ||
an upstream repository, or if you are about to push your changes | ||||
to upstream. | ||||
Erik Zielke
|
r12538 | |||
Returns 0 on success. | ||||
Dirkjan Ochtman
|
r6645 | """ | ||
Pulkit Goyal
|
r34506 | if not opts.get(r'applied') and not revrange: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no revisions specified')) | ||
Pulkit Goyal
|
r34506 | elif opts.get(r'applied'): | ||
Matt Mackall
|
r11730 | revrange = ('qbase::qtip',) + revrange | ||
Dirkjan Ochtman
|
r6645 | |||
q = repo.mq | ||||
if not q.applied: | ||||
ui.status(_('no patches applied\n')) | ||||
return 0 | ||||
Matt Mackall
|
r14319 | revs = scmutil.revrange(repo, revrange) | ||
Matt Mackall
|
r15476 | if repo['.'].rev() in revs and repo[None].files(): | ||
ui.warn(_('warning: uncommitted changes in the working directory\n')) | ||||
timeless@mozdev.org
|
r17512 | # queue.finish may changes phases but leave the responsibility to lock the | ||
Pierre-Yves David
|
r15920 | # repo to the caller to avoid deadlock with wlock. This command code is | ||
Mads Kiilerich
|
r17424 | # responsibility for this locking. | ||
Bryan O'Sullivan
|
r27847 | with repo.lock(): | ||
Pierre-Yves David
|
r15920 | q.finish(repo, revs) | ||
q.savedirty() | ||||
Dirkjan Ochtman
|
r6645 | return 0 | ||
Martin Geisler
|
r14298 | @command("qqueue", | ||
[('l', 'list', False, _('list all available queues')), | ||||
"Yann E. MORIN"
|
r14987 | ('', 'active', False, _('print name of active queue')), | ||
Martin Geisler
|
r14298 | ('c', 'create', False, _('create new queue')), | ||
('', 'rename', False, _('rename active queue')), | ||||
('', 'delete', False, _('delete reference to queue')), | ||||
('', 'purge', False, _('delete queue, and remove patch dir')), | ||||
], | ||||
rdamazio@google.com
|
r40329 | _('[OPTION] [QUEUE]'), | ||
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION) | ||||
Henrik Stuart
|
r11229 | def qqueue(ui, repo, name=None, **opts): | ||
'''manage multiple patch queues | ||||
Supports switching between different patch queues, as well as creating | ||||
new patch queues and deleting existing ones. | ||||
Omitting a queue name or specifying -l/--list will show you the registered | ||||
queues - by default the "normal" patches queue is registered. The currently | ||||
"Yann E. MORIN"
|
r14987 | active queue will be marked with "(active)". Specifying --active will print | ||
only the name of the active queue. | ||||
Henrik Stuart
|
r11229 | |||
To create a new queue, use -c/--create. The queue is automatically made | ||||
active, except in the case where there are applied patches from the | ||||
currently active queue in the repository. Then the queue will only be | ||||
created and switching will fail. | ||||
To delete an existing queue, use --delete. You cannot delete the currently | ||||
active queue. | ||||
Erik Zielke
|
r12538 | |||
Returns 0 on success. | ||||
Henrik Stuart
|
r11229 | ''' | ||
q = repo.mq | ||||
_defaultqueue = 'patches' | ||||
Henrik Stuart
|
r11270 | _allqueues = 'patches.queues' | ||
_activequeue = 'patches.queue' | ||||
Henrik Stuart
|
r11229 | |||
def _getcurrent(): | ||||
Henrik Stuart
|
r11270 | cur = os.path.basename(q.path) | ||
if cur.startswith('patches-'): | ||||
cur = cur[8:] | ||||
return cur | ||||
Henrik Stuart
|
r11229 | |||
def _noqueues(): | ||||
try: | ||||
Angel Ezquerra
|
r23877 | fh = repo.vfs(_allqueues, 'r') | ||
Henrik Stuart
|
r11229 | fh.close() | ||
except IOError: | ||||
return True | ||||
return False | ||||
def _getqueues(): | ||||
current = _getcurrent() | ||||
try: | ||||
Angel Ezquerra
|
r23877 | fh = repo.vfs(_allqueues, 'r') | ||
Henrik Stuart
|
r11229 | queues = [queue.strip() for queue in fh if queue.strip()] | ||
Dan Villiom Podlaski Christiansen
|
r13400 | fh.close() | ||
Henrik Stuart
|
r11229 | if current not in queues: | ||
queues.append(current) | ||||
except IOError: | ||||
queues = [_defaultqueue] | ||||
return sorted(queues) | ||||
def _setactive(name): | ||||
if q.applied: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('new queue created, but cannot make active ' | ||
Bryan O'Sullivan
|
r17708 | 'as patches are applied')) | ||
"Yann E. MORIN"
|
r11938 | _setactivenocheck(name) | ||
def _setactivenocheck(name): | ||||
Angel Ezquerra
|
r23877 | fh = repo.vfs(_activequeue, 'w') | ||
Henrik Stuart
|
r11270 | if name != 'patches': | ||
fh.write(name) | ||||
Henrik Stuart
|
r11229 | fh.close() | ||
def _addqueue(name): | ||||
Angel Ezquerra
|
r23877 | fh = repo.vfs(_allqueues, 'a') | ||
Henrik Stuart
|
r11229 | fh.write('%s\n' % (name,)) | ||
fh.close() | ||||
"Yann E. MORIN"
|
r11939 | def _queuedir(name): | ||
if name == 'patches': | ||||
Pierre-Yves David
|
r31333 | return repo.vfs.join('patches') | ||
"Yann E. MORIN"
|
r11939 | else: | ||
Pierre-Yves David
|
r31333 | return repo.vfs.join('patches-' + name) | ||
"Yann E. MORIN"
|
r11939 | |||
Henrik Stuart
|
r11270 | def _validname(name): | ||
for n in name: | ||||
if n in ':\\/.': | ||||
return False | ||||
return True | ||||
"Yann E. MORIN"
|
r11966 | def _delete(name): | ||
if name not in existing: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot delete queue that does not exist')) | ||
"Yann E. MORIN"
|
r11966 | |||
current = _getcurrent() | ||||
if name == current: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot delete currently active queue')) | ||
"Yann E. MORIN"
|
r11966 | |||
Angel Ezquerra
|
r23877 | fh = repo.vfs('patches.queues.new', 'w') | ||
"Yann E. MORIN"
|
r11966 | for queue in existing: | ||
if queue == name: | ||||
continue | ||||
fh.write('%s\n' % (queue,)) | ||||
fh.close() | ||||
Mads Kiilerich
|
r31312 | repo.vfs.rename('patches.queues.new', _allqueues) | ||
"Yann E. MORIN"
|
r11966 | |||
Pulkit Goyal
|
r34506 | opts = pycompat.byteskwargs(opts) | ||
"Yann E. MORIN"
|
r14987 | if not name or opts.get('list') or opts.get('active'): | ||
Henrik Stuart
|
r11229 | current = _getcurrent() | ||
"Yann E. MORIN"
|
r14987 | if opts.get('active'): | ||
ui.write('%s\n' % (current,)) | ||||
return | ||||
Henrik Stuart
|
r11229 | for queue in _getqueues(): | ||
ui.write('%s' % (queue,)) | ||||
"Yann E. MORIN"
|
r11767 | if queue == current and not ui.quiet: | ||
Henrik Stuart
|
r11229 | ui.write(_(' (active)\n')) | ||
else: | ||||
ui.write('\n') | ||||
return | ||||
Henrik Stuart
|
r11270 | if not _validname(name): | ||
Pierre-Yves David
|
r26587 | raise error.Abort( | ||
Henrik Stuart
|
r11270 | _('invalid queue name, may not contain the characters ":\\/."')) | ||
Pierre-Yves David
|
r29752 | with repo.wlock(): | ||
existing = _getqueues() | ||||
if opts.get('create'): | ||||
if name in existing: | ||||
raise error.Abort(_('queue "%s" already exists') % name) | ||||
if _noqueues(): | ||||
_addqueue(_defaultqueue) | ||||
_addqueue(name) | ||||
_setactive(name) | ||||
elif opts.get('rename'): | ||||
current = _getcurrent() | ||||
if name == current: | ||||
raise error.Abort(_('can\'t rename "%s" to its current name') | ||||
% name) | ||||
if name in existing: | ||||
raise error.Abort(_('queue "%s" already exists') % name) | ||||
olddir = _queuedir(current) | ||||
newdir = _queuedir(name) | ||||
if os.path.exists(newdir): | ||||
raise error.Abort(_('non-queue directory "%s" already exists') % | ||||
newdir) | ||||
fh = repo.vfs('patches.queues.new', 'w') | ||||
for queue in existing: | ||||
if queue == current: | ||||
fh.write('%s\n' % (name,)) | ||||
if os.path.exists(olddir): | ||||
util.rename(olddir, newdir) | ||||
else: | ||||
fh.write('%s\n' % (queue,)) | ||||
fh.close() | ||||
Mads Kiilerich
|
r31312 | repo.vfs.rename('patches.queues.new', _allqueues) | ||
Pierre-Yves David
|
r29752 | _setactivenocheck(name) | ||
elif opts.get('delete'): | ||||
"Yann E. MORIN"
|
r11967 | _delete(name) | ||
Pierre-Yves David
|
r29752 | elif opts.get('purge'): | ||
if name in existing: | ||||
_delete(name) | ||||
qdir = _queuedir(name) | ||||
if os.path.exists(qdir): | ||||
shutil.rmtree(qdir) | ||||
else: | ||||
if name not in existing: | ||||
raise error.Abort(_('use --create to create a new queue')) | ||||
_setactive(name) | ||||
Henrik Stuart
|
r11229 | |||
Pierre-Yves David
|
r15928 | def mqphasedefaults(repo, roots): | ||
"""callback used to set mq changeset as secret when no phase data exists""" | ||||
if repo.mq.applied: | ||||
Boris Feld
|
r34185 | if repo.ui.configbool('mq', 'secret'): | ||
Pierre-Yves David
|
r16028 | mqphase = phases.secret | ||
else: | ||||
mqphase = phases.draft | ||||
Augie Fackler
|
r15972 | qbase = repo[repo.mq.applied[0].node] | ||
Pierre-Yves David
|
r16028 | roots[mqphase].add(qbase.node()) | ||
Pierre-Yves David
|
r15928 | return roots | ||
mason@suse.com
|
r1808 | def reposetup(ui, repo): | ||
Brendan Cully
|
r2818 | class mqrepo(repo.__class__): | ||
Pierre-Yves David
|
r19395 | @localrepo.unfilteredpropertycache | ||
Simon Heimberg
|
r8524 | def mq(self): | ||
Simon Heimberg
|
r19064 | return queue(self.ui, self.baseui, self.path) | ||
Simon Heimberg
|
r8524 | |||
Yuya Nishihara
|
r20628 | def invalidateall(self): | ||
super(mqrepo, self).invalidateall() | ||||
Yuya Nishihara
|
r40396 | if localrepo.hasunfilteredcache(self, r'mq'): | ||
Yuya Nishihara
|
r20629 | # recreate mq in case queue path was changed | ||
Yuya Nishihara
|
r40396 | delattr(self.unfiltered(), r'mq') | ||
Yuya Nishihara
|
r20628 | |||
Adrian Buehlmann
|
r14596 | def abortifwdirpatched(self, errmsg, force=False): | ||
David Soria Parra
|
r19856 | if self.mq.applied and self.mq.checkapplied and not force: | ||
Martin Geisler
|
r13520 | parents = self.dirstate.parents() | ||
patches = [s.node for s in self.mq.applied] | ||||
Martin von Zweigbergk
|
r41418 | if any(p in patches for p in parents): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(errmsg) | ||
Thomas Arendsen Hein
|
r3223 | |||
Matt Mackall
|
r8711 | def commit(self, text="", user=None, date=None, match=None, | ||
Pierre-Yves David
|
r31407 | force=False, editor=False, extra=None): | ||
if extra is None: | ||||
extra = {} | ||||
Adrian Buehlmann
|
r14596 | self.abortifwdirpatched( | ||
Vadim Gelfer
|
r2848 | _('cannot commit over an applied mq patch'), | ||
force) | ||||
Brendan Cully
|
r2845 | |||
Matt Mackall
|
r8711 | return super(mqrepo, self).commit(text, user, date, match, force, | ||
editor, extra) | ||||
Brendan Cully
|
r2845 | |||
Pierre-Yves David
|
r20924 | def checkpush(self, pushop): | ||
if self.mq.applied and self.mq.checkapplied and not pushop.force: | ||||
Pierre-Yves David
|
r15952 | outapplied = [e.node for e in self.mq.applied] | ||
Pierre-Yves David
|
r20924 | if pushop.revs: | ||
Pierre-Yves David
|
r15952 | # Assume applied patches have no non-patch descendants and | ||
# are not on remote already. Filtering any changeset not | ||||
# pushed. | ||||
Pierre-Yves David
|
r20924 | heads = set(pushop.revs) | ||
Pierre-Yves David
|
r15952 | for node in reversed(outapplied): | ||
if node in heads: | ||||
break | ||||
else: | ||||
outapplied.pop() | ||||
# looking for pushed and shared changeset | ||||
for node in outapplied: | ||||
Bryan O'Sullivan
|
r17954 | if self[node].phase() < phases.secret: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('source has mq patches applied')) | ||
Pierre-Yves David
|
r15952 | # no non-secret patches pushed | ||
Pierre-Yves David
|
r20924 | super(mqrepo, self).checkpush(pushop) | ||
Thomas Arendsen Hein
|
r3223 | |||
Greg Ward
|
r9145 | def _findtags(self): | ||
'''augment tags from base class with patch tags''' | ||||
result = super(mqrepo, self)._findtags() | ||||
Brendan Cully
|
r2682 | |||
Brendan Cully
|
r2724 | q = self.mq | ||
Brendan Cully
|
r2723 | if not q.applied: | ||
Greg Ward
|
r9145 | return result | ||
Brendan Cully
|
r2663 | |||
Benoit Boissinot
|
r10678 | mqtags = [(patch.node, patch.name) for patch in q.applied] | ||
Alexis S. L. Carvalho
|
r5979 | |||
Matt Mackall
|
r13508 | try: | ||
Pierre-Yves David
|
r18011 | # for now ignore filtering business | ||
self.unfiltered().changelog.rev(mqtags[-1][0]) | ||||
Idan Kamara
|
r14600 | except error.LookupError: | ||
Martin Geisler
|
r6960 | self.ui.warn(_('mq status file refers to unknown node %s\n') | ||
Matt Mackall
|
r7639 | % short(mqtags[-1][0])) | ||
Greg Ward
|
r9145 | return result | ||
Alexis S. L. Carvalho
|
r5979 | |||
Pierre-Yves David
|
r18662 | # do not add fake tags for filtered revisions | ||
included = self.changelog.hasnode | ||||
mqtags = [mqt for mqt in mqtags if included(mqt[0])] | ||||
if not mqtags: | ||||
return result | ||||
Brendan Cully
|
r2723 | mqtags.append((mqtags[-1][0], 'qtip')) | ||
mqtags.append((mqtags[0][0], 'qbase')) | ||||
Brendan Cully
|
r4219 | mqtags.append((self.changelog.parents(mqtags[0][0])[0], 'qparent')) | ||
Greg Ward
|
r9145 | tags = result[0] | ||
Brendan Cully
|
r2723 | for patch in mqtags: | ||
Greg Ward
|
r9145 | if patch[1] in tags: | ||
Martin Geisler
|
r16929 | self.ui.warn(_('tag %s overrides mq patch of the same ' | ||
Brodie Rao
|
r16683 | 'name\n') % patch[1]) | ||
Brendan Cully
|
r2723 | else: | ||
Greg Ward
|
r9145 | tags[patch[1]] = patch[0] | ||
Brendan Cully
|
r2682 | |||
Greg Ward
|
r9145 | return result | ||
Brendan Cully
|
r2664 | |||
Vadim Gelfer
|
r2851 | if repo.local(): | ||
repo.__class__ = mqrepo | ||||
mason@suse.com
|
r1808 | |||
Pierre-Yves David
|
r15928 | repo._phasedefaults.append(mqphasedefaults) | ||
Matt Mackall
|
r7216 | def mqimport(orig, ui, repo, *args, **kwargs): | ||
Patrick Mezard
|
r16416 | if (util.safehasattr(repo, 'abortifwdirpatched') | ||
Pulkit Goyal
|
r34506 | and not kwargs.get(r'no_commit', False)): | ||
Adrian Buehlmann
|
r14596 | repo.abortifwdirpatched(_('cannot import over an applied patch'), | ||
Pulkit Goyal
|
r34506 | kwargs.get(r'force')) | ||
Matt Mackall
|
r7216 | return orig(ui, repo, *args, **kwargs) | ||
Brendan Cully
|
r10402 | def mqinit(orig, ui, *args, **kwargs): | ||
Pulkit Goyal
|
r34506 | mq = kwargs.pop(r'mq', None) | ||
Brendan Cully
|
r10402 | |||
if not mq: | ||||
return orig(ui, *args, **kwargs) | ||||
Cédric Duval
|
r10691 | if args: | ||
repopath = args[0] | ||||
if not hg.islocal(repopath): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('only a local queue repository ' | ||
Cédric Duval
|
r10691 | 'may be initialized')) | ||
else: | ||||
Matt Harbison
|
r39843 | repopath = cmdutil.findrepo(encoding.getcwd()) | ||
Cédric Duval
|
r10691 | if not repopath: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('there is no Mercurial repository here ' | ||
Cédric Duval
|
r10691 | '(.hg not found)')) | ||
Brendan Cully
|
r10402 | repo = hg.repository(ui, repopath) | ||
Brendan Cully
|
r10480 | return qinit(ui, repo, True) | ||
Brendan Cully
|
r10402 | |||
Brendan Cully
|
r10359 | def mqcommand(orig, ui, repo, *args, **kwargs): | ||
"""Add --mq option to operate on patch repository instead of main""" | ||||
# some commands do not like getting unknown options | ||||
Pulkit Goyal
|
r32193 | mq = kwargs.pop(r'mq', None) | ||
Brendan Cully
|
r10359 | |||
if not mq: | ||||
return orig(ui, repo, *args, **kwargs) | ||||
q = repo.mq | ||||
r = q.qrepo() | ||||
if not r: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no queue repository')) | ||
Brendan Cully
|
r10407 | return orig(r.ui, r, *args, **kwargs) | ||
Brendan Cully
|
r10359 | |||
Bryan O'Sullivan
|
r19212 | def summaryhook(ui, repo): | ||
Matt Mackall
|
r11107 | q = repo.mq | ||
m = [] | ||||
a, u = len(q.applied), len(q.unapplied(repo)) | ||||
if a: | ||||
Eric Eisner
|
r11121 | m.append(ui.label(_("%d applied"), 'qseries.applied') % a) | ||
Matt Mackall
|
r11107 | if u: | ||
Eric Eisner
|
r11121 | m.append(ui.label(_("%d unapplied"), 'qseries.unapplied') % u) | ||
Matt Mackall
|
r11107 | if m: | ||
FUJIWARA Katsunori
|
r17893 | # i18n: column positioning for "hg summary" | ||
ui.write(_("mq: %s\n") % ', '.join(m)) | ||||
Matt Mackall
|
r11107 | else: | ||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Martin Geisler
|
r11119 | ui.note(_("mq: (empty queue)\n")) | ||
Matt Mackall
|
r11107 | |||
FUJIWARA Katsunori
|
r28394 | revsetpredicate = registrar.revsetpredicate() | ||
FUJIWARA Katsunori
|
r27586 | |||
@revsetpredicate('mq()') | ||||
Idan Kamara
|
r14210 | def revsetmq(repo, subset, x): | ||
FUJIWARA Katsunori
|
r27586 | """Changesets managed by MQ. | ||
Idan Kamara
|
r14210 | """ | ||
Yuya Nishihara
|
r31024 | revsetlang.getargs(x, 0, 0, _("mq takes no arguments")) | ||
Idan Kamara
|
r14210 | applied = set([repo[r.node].rev() for r in repo.mq.applied]) | ||
Yuya Nishihara
|
r31023 | return smartset.baseset([r for r in subset if r in applied]) | ||
Idan Kamara
|
r14210 | |||
# tell hggettext to extract docstrings from these functions: | ||||
i18nfunctions = [revsetmq] | ||||
Matt Harbison
|
r17101 | def extsetup(ui): | ||
# Ensure mq wrappers are called first, regardless of extension load order by | ||||
# NOT wrapping in uisetup() and instead deferring to init stage two here. | ||||
Matt Mackall
|
r10591 | mqopt = [('', 'mq', None, _("operate on patch repository"))] | ||
Brendan Cully
|
r10402 | |||
Matt Mackall
|
r7216 | extensions.wrapcommand(commands.table, 'import', mqimport) | ||
Bryan O'Sullivan
|
r19212 | cmdutil.summaryhooks.add('mq', summaryhook) | ||
Brendan Cully
|
r10402 | |||
entry = extensions.wrapcommand(commands.table, 'init', mqinit) | ||||
entry[1].extend(mqopt) | ||||
Dan Villiom Podlaski Christiansen
|
r12036 | def dotable(cmdtable): | ||
Yuya Nishihara
|
r28313 | for cmd, entry in cmdtable.iteritems(): | ||
Dan Villiom Podlaski Christiansen
|
r12036 | cmd = cmdutil.parsealiases(cmd)[0] | ||
Yuya Nishihara
|
r28313 | func = entry[0] | ||
Augie Fackler
|
r30485 | if func.norepo: | ||
Dan Villiom Podlaski Christiansen
|
r12036 | continue | ||
entry = extensions.wrapcommand(cmdtable, cmd, mqcommand) | ||||
entry[1].extend(mqopt) | ||||
dotable(commands.table) | ||||
for extname, extmodule in extensions.extensions(): | ||||
if extmodule.__file__ != __file__: | ||||
dotable(getattr(extmodule, 'cmdtable', {})) | ||||
Brendan Cully
|
r7142 | |||
Brodie Rao
|
r10826 | colortable = {'qguard.negative': 'red', | ||
'qguard.positive': 'yellow', | ||||
'qguard.unguarded': 'green', | ||||
'qseries.applied': 'blue bold underline', | ||||
'qseries.guarded': 'black bold', | ||||
'qseries.missing': 'red bold', | ||||
'qseries.unapplied': 'black bold'} | ||||