Skip to content

Commit 4469851

Browse files
Denton-Lgitster
authored andcommitted
rebase: fast-forward --fork-point in more cases
Before, when we rebased with a --fork-point invocation where the fork-point wasn't empty, we would be setting options.restrict_revision. The fast-forward logic would automatically declare that the rebase was not fast-forwardable if it was set. However, this was painting with a very broad brush. Refine the logic so that we can fast-forward in the case where the restricted revision is equal to the merge base, since we stop rebasing at the merge base anyway. Helped-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 10572de commit 4469851

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

builtin/rebase.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ static int is_linear_history(struct commit *from, struct commit *to)
896896
}
897897

898898
static int can_fast_forward(struct commit *onto, struct commit *upstream,
899+
struct commit *restrict_revision,
899900
struct object_id *head_oid, struct object_id *merge_base)
900901
{
901902
struct commit *head = lookup_commit(the_repository, head_oid);
@@ -915,6 +916,9 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream,
915916
if (!oideq(merge_base, &onto->object.oid))
916917
goto done;
917918

919+
if (restrict_revision && !oideq(&restrict_revision->object.oid, merge_base))
920+
goto done;
921+
918922
if (!upstream)
919923
goto done;
920924

@@ -1703,9 +1707,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17031707
* with new commits recreated by replaying their changes. This
17041708
* optimization must not be done if this is an interactive rebase.
17051709
*/
1706-
if (can_fast_forward(options.onto, options.upstream, &options.orig_head,
1707-
&merge_base) &&
1708-
!is_interactive(&options) && !options.restrict_revision) {
1710+
if (can_fast_forward(options.onto, options.upstream, options.restrict_revision,
1711+
&options.orig_head, &merge_base) &&
1712+
!is_interactive(&options)) {
17091713
int flag;
17101714

17111715
if (!(options.flags & REBASE_FORCE)) {

t/t3432-rebase-fast-forward.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ test_rebase_same_head success --onto B... B
3535
test_rebase_same_head success --onto master... master
3636
test_rebase_same_head success --no-fork-point
3737
test_rebase_same_head success --fork-point master
38-
test_rebase_same_head failure --fork-point --onto B B
39-
test_rebase_same_head failure --fork-point --onto B... B
38+
test_rebase_same_head success --fork-point --onto B B
39+
test_rebase_same_head success --fork-point --onto B... B
4040
test_rebase_same_head success --fork-point --onto master... master
4141

4242
test_expect_success 'add work to side' '
@@ -51,8 +51,8 @@ test_rebase_same_head success --onto B... B
5151
test_rebase_same_head success --onto master... master
5252
test_rebase_same_head success --no-fork-point
5353
test_rebase_same_head success --fork-point master
54-
test_rebase_same_head failure --fork-point --onto B B
55-
test_rebase_same_head failure --fork-point --onto B... B
54+
test_rebase_same_head success --fork-point --onto B B
55+
test_rebase_same_head success --fork-point --onto B... B
5656
test_rebase_same_head success --fork-point --onto master... master
5757

5858
test_expect_success 'add work to upstream' '
@@ -65,8 +65,8 @@ changes='our and their changes'
6565
test_rebase_same_head success --onto B B
6666
test_rebase_same_head success --onto B... B
6767
test_rebase_same_head success --onto master... master
68-
test_rebase_same_head failure --fork-point --onto B B
69-
test_rebase_same_head failure --fork-point --onto B... B
68+
test_rebase_same_head success --fork-point --onto B B
69+
test_rebase_same_head success --fork-point --onto B... B
7070
test_rebase_same_head success --fork-point --onto master... master
7171

7272
test_done

0 commit comments

Comments
 (0)