From patchwork Wed May 8 00:12:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10933937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1CF101575 for ; Wed, 8 May 2019 00:13:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CF0A28485 for ; Wed, 8 May 2019 00:13:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01187286A7; Wed, 8 May 2019 00:13:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73BFE28485 for ; Wed, 8 May 2019 00:13:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726597AbfEHANT (ORCPT ); Tue, 7 May 2019 20:13:19 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38400 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbfEHANT (ORCPT ); Tue, 7 May 2019 20:13:19 -0400 Received: by mail-wr1-f66.google.com with SMTP id v11so4530228wru.5 for ; Tue, 07 May 2019 17:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ECiS3gbMx4ytWbpfFMx49BViOX/CnCW4n6byFv6bCCs=; b=UVGBDWJcAFrg9h80tD6fW00+rclaGGJ+99rdaCYRO+DBfYNr4yznKQWAyZKG6W9x4W +4ndNbHJ2N6gKyCQuvW8hLaeB+xCVQQ5oIaHvqmXU+LdskwhF+CKkq5azCfa8qm0XI5E 3Xm99cG6VPycdjePHwgvVR3D0VOg/wIAxTAPw1JvcTILYItvBk4Kkmcclxsw/wDU/8fR zhf+nzOEKzoklwnel7WZHuY7ZB0cYOjdzWNPFDFTcNZETrDNz47zOTZY1iG2VV/1O++y kfmlkjFKaBKF88OZrTLpFbuteTrVwLOMy/p/9Sry/9twzJQkD2A7DtG+dvOvR2RgGXbg 7Lww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ECiS3gbMx4ytWbpfFMx49BViOX/CnCW4n6byFv6bCCs=; b=P6jE818vEmFUcOteppYYxQB1CB5+/OMP5VH9ttJr8CRvHAv1VYwBVZbBvvsMMymCPP rpKMEgatuse6/E9yyNaQ90nPxhnG1Q37E3TUA0/Dk2cYhCQ7krKRldyt00Rn73itoLs5 g9DRwjdoiJPTs91DXhOCqjxoZqVF/XRsmQfgIdSzgt4THBBNbG8+E7ka47U+3I6l+O7g zustZM5qBzP8yDHiYbIwdgMoqjUMELo6/A0tilZ9mx8u+VHWGpLmX1ZHYQsZ3cPXxp20 sZSI+hWG3RyWHKMutl2eVt7mlSD/XpmZzlZ+hy8jXgevh8e7ngbSvG6Zk322DQOgf3RS qLAA== X-Gm-Message-State: APjAAAU41A65sMy3ITO92KIOnsKul1bh3RajaBP3gLOfgO1F1+rJwyN7 KUnhP82t5LAYrMYSC0amlc79pV2wXV0= X-Google-Smtp-Source: APXvYqwecF0LQabaSuYHoA5CFNgIeNqchroahAU8z9/u0g4s8hTia1zWTN4kNUhUDFeDmH8YcDVwMA== X-Received: by 2002:a5d:6b10:: with SMTP id v16mr1735997wrw.294.1557274396548; Tue, 07 May 2019 17:13:16 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n15sm5167825wrp.58.2019.05.07.17.13.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 07 May 2019 17:13:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Denton Liu , Eric Sunshine , Johannes Schindelin , Johannes Sixt , =?utf-8?q?SZEDER_G=C3=A1bor?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC WIP PATCH v8 07/13] rebase: fast-forward --fork-point in more cases Date: Wed, 8 May 2019 02:12:46 +0200 Message-Id: <20190508001252.15752-8-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Denton Liu 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 Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- builtin/rebase.c | 10 +++++++--- t/t3432-rebase-fast-forward.sh | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index c1000c159d..5f9beda46b 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -879,6 +879,7 @@ static int is_linear_history(struct commit *from, struct commit *to) } static int can_fast_forward(struct commit *onto, struct commit *upstream, + struct commit *restrict_revision, struct object_id *head_oid, struct object_id *merge_base) { struct commit *head = lookup_commit(the_repository, head_oid); @@ -898,6 +899,9 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream, if (!oideq(merge_base, &onto->object.oid)) goto done; + if (restrict_revision && !oideq(&restrict_revision->object.oid, merge_base)) + goto done; + if (!upstream) goto done; @@ -1679,9 +1683,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) * with new commits recreated by replaying their changes. This * optimization must not be done if this is an interactive rebase. */ - if (can_fast_forward(options.onto, options.upstream, &options.orig_head, - &merge_base) && - !is_interactive(&options) && !options.restrict_revision) { + if (can_fast_forward(options.onto, options.upstream, options.restrict_revision, + &options.orig_head, &merge_base) && + !is_interactive(&options)) { int flag; if (!(options.flags & REBASE_FORCE)) { diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh index 59cd437301..8f4996e476 100755 --- a/t/t3432-rebase-fast-forward.sh +++ b/t/t3432-rebase-fast-forward.sh @@ -70,32 +70,32 @@ test_rebase_same_head_ () { } changes='no changes' -test_rebase_same_head success work same success work same +test_rebase_same_head success noop same success work same test_rebase_same_head success noop same success noop-force same master test_rebase_same_head success noop same success noop-force diff --onto B B test_rebase_same_head success noop same success noop-force diff --onto B... B test_rebase_same_head success noop same success noop-force same --onto master... master test_rebase_same_head success noop same success noop-force same --no-fork-point -test_rebase_same_head success work same success work same --fork-point master -test_rebase_same_head failure noop same success work diff --fork-point --onto B B -test_rebase_same_head failure work same success work diff --fork-point --onto B... B -test_rebase_same_head success work same success work same --fork-point --onto master... master +test_rebase_same_head success noop same success work same --fork-point master +test_rebase_same_head success noop same success work diff --fork-point --onto B B +test_rebase_same_head success noop same success work diff --fork-point --onto B... B +test_rebase_same_head success noop same success work same --fork-point --onto master... master test_expect_success 'add work same to side' ' test_commit E ' changes='our changes' -test_rebase_same_head success work same success work same +test_rebase_same_head success noop same success work same test_rebase_same_head success noop same success noop-force same master test_rebase_same_head success noop same success noop-force diff --onto B B test_rebase_same_head success noop same success noop-force diff --onto B... B test_rebase_same_head success noop same success noop-force same --onto master... master test_rebase_same_head success noop same success noop-force same --no-fork-point -test_rebase_same_head success work same success work same --fork-point master -test_rebase_same_head failure work same success work diff --fork-point --onto B B -test_rebase_same_head failure work same success work diff --fork-point --onto B... B -test_rebase_same_head success work same success work same --fork-point --onto master... master +test_rebase_same_head success noop same success work same --fork-point master +test_rebase_same_head success noop same success work diff --fork-point --onto B B +test_rebase_same_head success noop same success work diff --fork-point --onto B... B +test_rebase_same_head success noop same success work same --fork-point --onto master... master test_expect_success 'add work same to upstream' ' git checkout master &&