Extension to reorder mq patches

Mark Williamson mark.williamson at cl.cam.ac.uk
Thu Feb 21 08:32:59 CST 2008


Hi!

This sounds really quite useful; I do occasionally need to reorder patches, 
due to getting mixed up and creating them at logically the wrong position in 
the stack!  Using an editor isn't that much of a hardship but it is a bit 
annoying, so it would be nice to have a simpler way to do this.

> def qup(ui, repo, *patches, **opts):
>     '''Move MW patches to top'''

MW?  Another typo, sorry ;-)  Not really important though!

>     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'))

I was thinking it might be nice to be able to modify the patch queue whilst 
patches are applied as long as it doesn't affect the order of currently 
applied patches?  e.g.

hg qseries
1
2
3
4

hg qtop
1

hg qup 4

hg qseries
1
4
2
3

This makes it easier to perform arbitrary reorderings since instead of having 
to qpop -a, followed by qup-ing the entire sequence of patches up till the 
one I have to move, I could just qpop to the right location in the stack and 
then qup the patch in question.

What do you think of this idea?

>
>     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)

If somebody had a really big patch queue then this might take a while, 
especially if they're working over a network filesystem.  That's not a 
problem as far as I'm concerned but what if you hit Ctrl-C for some reason 
during this process?  As far as I can see they could end up with a truncated 
series file, which wouldn't be good.

Not entirely sure what would be the hg way of going about this but maybe you 
could write a new series file and then move it in place?

Cool idea though.  I wonder if it could be implemented directly in mq.py?  
It's definitely something I'd want to use.

Cheers,
Mark

-- 
Push Me Pull You - Distributed SCM tool (http://www.cl.cam.ac.uk/~maw48/pmpu/)


More information about the Mercurial mailing list