Extension to reorder mq patches
Andrei Vermel
avermel at mail.ru
Thu Feb 21 06:03:17 CST 2008
Below is an extension to avoid using an editor for MQ patch reordering in
.hg/patches/series. It moves specified patches to the top of patch queue.
It's trivial but handy.
Usage:
X:\>hg qseries
1.diff
2.diff
3.diff
4.diff
5.diff
X:\>hg qup 2.diff 4.diff
X:\>hg qseries
2.diff
4.diff
1.diff
3.diff
5.diff
# qup.py - pull and merge remote changes
#
# Copyright 2008 Andrei Vermel <andrei.vermel at gmail.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
from mercurial.i18n import _
from mercurial.node import *
from mercurial import commands, cmdutil, hg, node, util
import os
def qup(ui, repo, *patches, **opts):
'''Move MW patches to top'''
try:
series = file(repo.path+'/patches/series', 'r+')
except:
raise util.Abort(_('patch queue not found'))
q = repo.mq
if not patches:
raise util.Abort(_('qup requires at least one patch name'))
if q.check_toppatch(repo):
raise util.Abort(_('can\'t modify series when patches applied'))
tofront={}
toback=[]
for line in series:
if line.strip().startswith('#'):
toback.append(line)
else:
spl = line.split('#')
firstword=''
if spl:
firstword = spl[0].strip()
if firstword in patches:
tofront[firstword]=line
else:
toback.append(line)
if not tofront:
raise util.Abort(_('none of specified patches found in the series'))
series.seek(0)
series.truncate()
for patch in patches:
try:
series.write(tofront[patch].rstrip('\n')+'\n')
except:
print ('patch %s not in the series' % patch)
series.writelines(toback)
cmdtable = {
'qup':
(qup, [],
_('hg qup PATCH...')),
}
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: qup.py
Url: http://selenic.com/pipermail/mercurial/attachments/20080221/7fa6e080/attachment.txt
More information about the Mercurial
mailing list