[Google SOC] Rebase command

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Wed Mar 26 06:48:54 CDT 2008


On Wed, Mar 26, 2008 at 12:31 PM, Stefano <stefano at inventati.org> wrote:
> Peter Arrenbrecht wrote:
>  > Basically yes, but:
>  >
>  > 1. It gets more interesting if both A and B work on the same file (a
>  > suitable line distance apart) so three-way-merge will be needed.
>  >
>  > 2. The "transplant" case is more interesting, too, where A wants to
>  > cherry-pick change Y from B's repo where B has new unpushed changes X,
>  > Y, Z.
>  >
>  Would you mind checking if I've understood the problems?
>  case 1 => test_rebase_2
>  case 2 => test_rebase_transplant
>
>  Thank you
>  Stefano
>
> #!/bin/sh
>  BASEDIR=`pwd`
>
>  echo "-- Initializing Master repository"
>  hg init Master
>
>  echo -e "\n-- User a clones, adds a file and pushes"
>  hg clone Master user_a && cd user_a
>  echo "testa1" > a_1; hg add a_1; hg commit -m "added file a_1" ; hg push
>
>  echo -e "\n-- User b clones, modifies the same file without pushing"
>  cd $BASEDIR
>  hg clone Master user_b && cd user_b
>  echo "testb1" >> a_1; hg commit -m "(b) modified a_1"
>
>  echo -e "\n-- User a modifies the same file and pushes"
>  cd $BASEDIR/user_a
>  echo "testa2" >> a_1; hg commit -m "(a) modified a_1" ; hg push
>
>  echo -e "\n-- Now user b pulls from Master"
>  cd $BASEDIR/user_b
>  hg pull ; hg heads
>
>  # In this use case there's a conflict
>  hg merge
>  cd $BASEDIR && rm -rf Master user_a user_b a_1 a_2 b_1
>
> #!/bin/sh
>  BASEDIR=`pwd`
>
>  echo "-- Initializing Master repository"
>  hg init Master
>
>  echo -e "\n-- User a clones, adds a file and pushes"
>  hg clone Master user_a && cd user_a
>  echo "testa1" > a_1; hg add a_1; hg commit -m "added file a_1" ; hg push
>
>  # In the meanwhile a codes other stuffs...
>
>  echo -e "\n-- User b clones, modifies the same file without pushing"
>  cd $BASEDIR
>  hg clone Master user_b && cd user_b
>  echo "testbX" >> a_1; hg commit -m "(b) modified a_1 X-feature"
>
>  echo -e "\n-- User b modifies the same file without pushing"
>  echo "testbY" >> a_1; hg commit -m "(b) modified a_1 Y-feature"
>
>  echo -e "\n-- User b modifies the same file without pushing"
>  echo "testbZ" >> a_1; hg commit -m "(b) modified a_1 Z-feature"
>
>  echo -e "\n-- User a wants to cherry-pick just the Y-feature"
>  # Something like:
>  # cd $BASEDIR/user_a
>  # hg rebase user_b -r 2

This would probably be "hg transplant" rather than rebase, but with
transplant augmented to do proper three-way merge. This is part of
what your work would encompass.

>  cd $BASEDIR && rm -rf Master user_a user_b a_1

In both cases, don't just append. Use a base file with a number of
predefined lines, then make the changes modify lines that are a few
lines apart. Otherwise three-way merge will give you conflicts. But I
think the most interesting case is where it does not.
-peo


More information about the Mercurial-devel mailing list