Differences between revisions 6 and 7
Revision 6 as of 2009-07-21 08:51:59
Size: 9477
Comment: Put notes from RebaseProject inline, with minor updates.
Revision 7 as of 2009-08-05 08:28:52
Size: 2441
Editor: Max Hofer
Comment: Removed redundant (broken) information located in rebase project, linked rebase extension to rebase project and fixed broken link to SoC 2008
Deletions are marked like this. Additions are marked like this.
Line 25: Line 25:
This feature was implemented as part of the SummerOfCode in 2008. This feature was implemented as part of the [[SummerOfCode/2008]] RebaseProject.

{{{#!wiki tip
'''Tip'''

Please refer to the RebaseProject for common use cases and detailed information how to use rebase.
}}}
Line 72: Line 78:
== A common case ==
It's important to notice that this extension can be invoked with no arguments.

Semantically, invoking plain rebase can be intended as ''take the branch I'm working on and make it current'', in other words this means moving the local changes onto the most recent head of the checked out named branch.

Let's imagine this situation:

{{{#!dot
digraph {
  rankdir=LR
  node [shape=box]
  C1 -> C2 -> L1 -> L2
}
}}}

L* represent our local changes after our last pull.

{{{
   hg pull
}}}

pulls from mainstream two new revisions:

{{{#!dot
digraph {
  rankdir=LR
  node [shape=box]
  C1 -> C2 -> L1 -> L2
  node [color=green];
  C2 -> R1 -> R2
}
}}}

Usually what we would like to do is move L* onto R2 and this can be easily achieved with:

{{{
   hg rebase
}}}

Result:

{{{#!dot
digraph {
    rankdir=LR;
    node [shape=box];

    C1 -> C2 -> R1 -> R2;
    node [color=red];
    R2 -> L1 -> L2;
    L1 [label="L1''"];
    L2 [label="L2''"];
}
}}}

== Dealing with conflicting merges ==
Sometimes could happen that some changes in L* conflicts with some changes in R*.
In these cases the extension will stop, store the current status and let user the ability to solve
the conflict on his own.

In event of interruption users have two choices:
 * abort
 * continue

=== Abort ===
An interrupted process can be aborted, thus restoring the repository to its original state, with:

{{{
   $ hg rebase --abort
}}}

=== Continue ===
The most common situation, however, is resuming an interrupted process and this can be done with:

{{{
   $ hg rebase --continue
}}}

== When rebase is not allowed ==
There are situations in which a rebasing process is not allowed:
 * the rebasing point (source) is an ancestor of target
 * the rebasing point (source) is a descendant of target
 * the rebasing point (source) is a merge revision and both of its parents are external

== Notes about MQ Patches ==
In the current implementation MQ patches are qfinished and qimported after being rebased, this adds an export-like header to each rebased patch.
e.g.,
 * Original Patch
   {{{
   Description P0

   diff --git a/f b/f
   etc...
   }}}

 * Rebased Patch
   {{{
   # HG changeset patch
   # User Stefano Tortarolo <stefano.tortarolo@gmail.com>
   # Date 1217929313 -7200
   # Node ID 92bd85e9196feac01fdf2eb2ce7275e9a575a730
   # Parent 6e55161e68b2062d629c05b89b0ea3424eec9a2f
   Description P0
   
   diff --git a/f b/f
   etc...
   }}}



== Scenarios ==
Now will be analyzed the most interesting scenarios.

=== Scenario A ===
The first one is the simplest one, a simple branch.

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];

    A -> D -> E;
    A -> B -> C;
}
}}}

In this scenario there are two interesting interactions:

 * rebase on top

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];

    A -> D -> E;
    node [color=red];
    E -> B -> C;
    B [label="B''"];
    C [label="C''"];
}
}}}

 * rebase on an intermediate revision

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];

    A -> D -> E;
    node [color=red];
    D -> B -> C;
    B [label="B''"];
    C [label="C''"];
}
}}}

=== Scenario B ===
The second scenario involves something more complicated.
In this scenario the user cloned from upstream, then merged several times.

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];

    A -> C -> E -> F -> I;
    A -> B -> D -> G -> H;
    C -> D;
    F -> H;
}
}}}

 * rebase D on I

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];

    A -> C -> E -> F -> I;
    A -> B;
    node [color=red];
    I -> D -> G;
    B -> D;
    D [label="D''"];
    G [label="G''"];
}
}}}
 Despite being a merge revision D hasn't been '''skipped''' in this case, as opposite to H.

 * rebase B on I

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];

    A -> C -> E -> F -> I;
    node [color=red];
    I -> B -> G;
    B [label="B''"];
    G [label="G''"];
}
}}}
 In this case two revisions (D and H) have been skipped.

 * rebase C on B

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];

    A -> B;
    node [color=red];
    B -> C -> E -> F -> I;
    C -> G -> H;
    F -> H;

    C [label="C''"];
    E [label="E''"];
    F [label="F''"];
    I [label="I''"];
    G [label="G''"];
    H [label="H''"];
}
}}}

 * rebase G onto I

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];

    A -> C -> E -> F -> I;
    A -> B -> D;
    C -> D;
    node [color=red];
    D -> G;
    I -> G;
    G [label="G''"];
}
}}}

'''Note:''' Rebase drops a parent relationship '''only''' if the parent is an ancestor of target.

=== Scenario C ===
This case represents a quite common situation, a repository with just one (merge) head.

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];
    A -> B -> C;
    A -> D -> E;
    C -> F;
    E -> F;
}
}}}

 * D onto C

{{{#!dot
digraph {
    node [shape=box];
    graph [rankdir=LR];
    A -> B -> C;
    node [color=red];
    C -> D -> E;
    D [label="D''"];
    E [label="E''"];
}
}}}
 Obviously the revision F has been skipped.

== Details ==
=== Parent relationships ===
When rebasing a given node ('''N''') different situations may happen, depending on the status of its parent(s).

From now on P1,,N,, is used to refer to the first parent of '''N''', P2,,N,, to the second one.

e.g., P1',,N,, identifies the rebased first parent of '''N'''

These situations are summed up in the following table:

|| |||| '''P2,,N,, = A''' |||| '''P2,,N,, = S''' |||| '''P2,,N,, = E''' |||| '''P2,,N,, = N''' ||
|| '''P1,,N,, = A''' |||| |||| p1 = P2',,N,, |||| p1 = target, p2 = P2,,N,, |||| p1 = target ||
|| '''P1,,N,, = S''' |||| p1 = P1',,N,, |||| p1 = P1',,N,,, p2 = P2',,N,, |||| p1 = P1',,N,,, p2 = P2,,N,, |||| p1 = P1',,N,, ||
|| '''P1,,N,, = E''' |||| p1 = target, p2 = P1,,N,, |||| p1 = P2',,N,,, p2 = P1,,N,, |||| |||| p1 = target, p2 = P1,,N,, ||

A: In ancestors(target)
S: In the rebasing series
E: External
N: None

The empty cells cover the cases in which:
 * P1,,N,, = P2,,N,, = A
 
 that means that also '''N''' is in ancestors(target) and this scenario is disallowed
 
 * P1,,N,, = P2,,N,, = E
 
 that means that '''N''' is a merged revision and none of its parents is ancestor of target.
 This scenario is disallowed (Idea: Can we make assumptions about a better revision point?)
 Note that this case can happen only if '''N''' is the rebasing point.

Also note that:
 * P1,,N,, = None entails that P2,,N,, = None
 * P1,,N,, = P2,,N,, = None is true only if '''N''' is root (this scenario is disallowed by the rule that a node can't be rebased onto a descendant)
Line 385: Line 79:
 * RebaseProject

Rebase Extension

This extension is distributed along with Mercurial releases (starting with 1.1)

Author: Stefano Tortarolo

1. Configuration

Enable the extension in the configuration file (.hgrc):

[extensions]
rebase = 

Introduction

When contributing to a project, sometimes there is the need to keep some patches private, while keeping the whole repository up-to-date.

In those cases it can be useful to "detach" the local changes, synchronize the repository with the mainstream and then append the private changes on top of the new remote changes. This operation is called rebase.

In general, this extension allows to move revisions from a point to another, some common scenarios are shown in the section "Scenarios".

This feature was implemented as part of the SummerOfCode/2008 RebaseProject.

Tip

Please refer to the RebaseProject for common use cases and detailed information how to use rebase.

1. Features

  • rebase both simple and complex cases
  • abort of an interrupted rebasing
  • resume of an interrupted rebasing
  • mq patches handling
  • detect changes during interruptions

Usage

1. Synopsis

   hg rebase [--source rev | --base rev] [--dest rev] | [--collapse] | [--continue] | [--abort] | [--keep]

2. Description

  • --source rev

    • allows to specify a revision that will be rebased onto dest with all its descendants
  • --base rev

    • the revision specified will be rebased along with its descendants and its ancestors up to the common point (excluded) between rev and dest's ancestors

      Note that this option conflicts with --source

  • --dest rev

    • the destination onto which the required revisions will be rebased
  • --continue

    • resume an interrupted rebase
  • --abort

    • abort an interrupted rebase
  • --collapse

    • collapse the rebased revisions
  • --keep

    • keep original revisions

3. Integration with pull

Rebase provides an extra option for pull.

   hg pull --rebase

that pulls and rebases the local revisions if there's something to rebase. Otherwise it behaves like hg pull --update.


CategoryExtension

RebaseExtension (last edited 2017-03-28 19:44:56 by SietseBrouwer)