[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
1-2-3-5-6
| \4
7
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>
./mqmerge
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 --------------
#!/bin/bash
# List hg branch history
# by <xiaofeng.ling at intel.com>
get_changeset()
{
cat |head -n1|awk -F : '{print $3}'|tr -d " "
}
get_changesetnum()
{
hg log -r $1|head -n1|awk -F : '{print $2}'|tr -d " "
}
get_parents()
{
rev=$1
parents=`hg log -r $rev|grep "parent:"|wc -l`
if [ $parents -eq 0 ];then
rev=`get_changesetnum $rev`
rev=`expr $rev - 1`
else
rev=`hg log -r $rev|grep "parent:"|awk -F: 'NR==1 {print $2}'|tr -d " "`
rev=`get_changesetnum $rev`
fi
echo $rev
}
revs=`cat .hg/patches/status|awk -F : '{print $1}'`
trev=`hg parents|get_changeset`
newrev=$trev
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
fi
oldrev=`get_parents $firstrev`
echo "rebase from $oldrev to `get_changesetnum $newrev`"
first=1
for rev in $revs;
do
hg co -m $rev
ret=$?
if [ $ret -ne 0 ];then
break
fi
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`
first=0
fi
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`
lastpatch=$patch
done
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