[PATCH 0 of 2] Cherry picking with rebase

Tomasz Barszczak mercurial at barszczak.com
Tue Mar 31 01:29:48 CDT 2009


Thanks for doing this.
Here is one improvement.
The following script (based on test-rebase-cherrypicking):


#!/bin/sh

echo "[extensions]" >> $HGRCPATH
echo "graphlog=" >> $HGRCPATH
echo "rebase=" >> $HGRCPATH

BASE=`pwd`

addcommit () {
    echo $1 > $1
    hg add $1
    hg commit -d "${2} 0" -u test -m $1
}

commit () {
    hg commit -d "${2} 0" -u test -m $1
}

createrepo () {
    cd $BASE
    rm -rf a
    hg init a
    cd a
    addcommit "A" 0
    addcommit "B" 1
    addcommit "C" 2

    hg update -C 0
    addcommit "D" 3
    addcommit "E" 4

    hg update -C 3
    addcommit "F" 5
    addcommit "G" 6
}

echo '% Cherry picking D, F onto C'
createrepo > /dev/null 2>&1
hg glog  --template '{rev}: {desc}\n'
hg rebase --upto 5 -b 3 -d 2 2>&1 | sed 's/\(saving bundle to \).*/\1/'
hg glog  --template '{rev}: {desc}\n'
echo "Expected A, B, C, D, F"
hg manifest


Produces an unexpected output:


% Cherry picking D, F onto C
@  6: G
|
o  5: F
|
| o  4: E
|/
o  3: D
|
| o  2: C
| |
| o  1: B
|/
o  0: A

rebase completed
@  9: F
|
| o  8: E
|/
o  7: D
|
| o  6: G
| |
| o  5: F
| |
| | o  4: E
| |/
| o  3: D
| |
o |  2: C
| |
o |  1: B
|/
o  0: A

Expected A, B, C, D, F
A
B
C
D
F


The following patch can fix this (it may not be the most efficient way 
to fix this):


diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -416,6 +416,8 @@
         if upto != source and upto not in descendants:
             raise util.Abort(_('upto revision is not a descendant of 
source '
                                                     'revision'))
+        uptoancestors = repo.changelog.ancestors(upto)
+        descendants = filter(lambda x: x == upto or x in uptoancestors, 
descendants)
     state = dict.fromkeys(descendants, nullrev)
     external = nullrev
     if collapse:


Now, the output is:


% Cherry picking D, F onto C
@  6: G
|
o  5: F
|
| o  4: E
|/
o  3: D
|
| o  2: C
| |
| o  1: B
|/
o  0: A

rebase completed
@  8: F
|
o  7: D
|
| o  6: G
| |
| o  5: F
| |
| | o  4: E
| |/
| o  3: D
| |
o |  2: C
| |
o |  1: B
|/
o  0: A

Expected A, B, C, D, F
A
B
C
D
F


Stefano Tortarolo wrote:
> These patches allows to rebase just some revisions of a branch.
> e.g. rebase -s x --upto x+3 -d y
>
> It's important to notice that rebasing an intermediate
> revision implies rebasing also their parents up to its base.
>
> With the first patch a "cherry picking" starting from an
> intermediate revision is like the same operation starting
> from its base (--base).
> The latter instead treats the same request as follows:
> rebase and collapse upto x and then rebase from x to x+3
> The only difference in regard to --collapse is that the commit
> messages are not collapsed.
>
> There are tests attached to both test and explain the feature.
> Comments are very welcomed.
>
> Note: These patches have been developed on top of the other two I've
> just sent, so they don't apply cleanly on crew tip.
> Obviously I'll modify them if the first ones will be rejected
> and these accepted.
>
> => This feature has been inspired by Tomasz Barszczak, he is/was also
> working on this feature on his own. <=
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>   



More information about the Mercurial-devel mailing list