[PATCH]mq:a patch stores

Xiaofeng Ling xiaofeng.ling at intel.com
Thu Sep 15 01:23:28 CDT 2005

Chris Mason wrote:
> Thanks.  BTW, fl.startswith('.') will do the same as your re match, but
> will be faster.
ok. thanks

>>What do you think about it?
> I was thinking of something similar, but we should be able to use two
> heads to solve this.  Assuming you've got a queue of patches on rev A,
> and want to update them to rev B:
> 1) hg checkout -C A
> 2) hg qpush -a
> 3) hg checkout -C B
> 4) mkdir .hg/tmppatches
> 5) for each revision from hg qapplied -v
>        hg update -m revision
>        hg commit -m 'merge with revision:patchname'
>        diff from tip to parent in B head
>        Create patch in .hg/tmppatches (preserving comments)
> Once all revisions are merged, strip away all the new revisions from
> heads A and B, and copy patches from .hg/tmppatches into .hg/patches.
> While merging each patch, there might be patches that already exist in
> some form in rev B, so there needs to be a prompt about keeping a given
> revision once the merge is done.
As I'm not familiar  with python, I wrote a shell script to do as your 
description at first, it works for me now.
But I notice by your way, there is two limitations
1. we can not get correct result if the first ancestor of patch series
is not the ancestor of new base revision
   |  \4
5,6 is our mq managed patches, if we want to rebase 5,6 to 7
by this way, 3 will also be merged to 8, not only 5.

2. we can not rebase the patches to old revision.

Attach is my script.
hg co -C <dest revison>

old patches will be moved to .hg/patches/<baserev>
if not all the paches is applied at first, only merge applied patches.
comments are lost currently.

-------------- next part --------------
#      List hg branch history
#      by <xiaofeng.ling at intel.com>

    cat |head -n1|awk -F : '{print $3}'|tr -d " "

    hg log -r $1|head -n1|awk -F : '{print $2}'|tr -d " "

    parents=`hg log -r $rev|grep "parent:"|wc -l`
    if [ $parents -eq 0 ];then
        rev=`get_changesetnum $rev`
        rev=`expr $rev - 1`
        rev=`hg log -r $rev|grep "parent:"|awk -F: 'NR==1 {print $2}'|tr -d " "`
        rev=`get_changesetnum $rev`
    echo $rev

revs=`cat .hg/patches/status|awk -F : '{print $1}'`
trev=`hg parents|get_changeset`
firstrev=`cat .hg/patches/status|head -n 1|awk -F : '{print $1}'`
if [ -z $firstrev ];then
    echo "at least one patch shall be pushed"
    exit -1
oldrev=`get_parents $firstrev`
echo "rebase from $oldrev to `get_changesetnum $newrev`"
for rev in $revs;
    hg co -m $rev
    if [ $ret -ne 0 ];then
    patch=`cat .hg/patches/status|grep $rev|awk -F : '{print $2}'`
    hg commit -m "merged:$patch"
    if [ $first -eq 1 ];then
        newfirstrev=`hg parents|get_changeset`
    hg diff -r $trev > .hg/patches/$patch.$newrev
    mkdir -p .hg/patches/$oldrev
    mv -f .hg/patches/$patch .hg/patches/$oldrev
    mv .hg/patches/$patch.$newrev .hg/patches/$patch
    trev=`hg parents|get_changeset`
hg strip $newfirstrev
hg strip $firstrev
rm -f .hg/patches/status
hg co -C $newrev
hg qpush -av $lastpatch

More information about the Mercurial mailing list