From patchwork Sun Apr 21 08:11:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910459 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 E2BAE1515 for ; Sun, 21 Apr 2019 08:11:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB9B3288AD for ; Sun, 21 Apr 2019 08:11:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE32128901; Sun, 21 Apr 2019 08:11:30 +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 4805B288AD for ; Sun, 21 Apr 2019 08:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726328AbfDUILW (ORCPT ); Sun, 21 Apr 2019 04:11:22 -0400 Received: from mail-pf1-f170.google.com ([209.85.210.170]:33796 "EHLO mail-pf1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbfDUILW (ORCPT ); Sun, 21 Apr 2019 04:11:22 -0400 Received: by mail-pf1-f170.google.com with SMTP id b3so4348108pfd.1 for ; Sun, 21 Apr 2019 01:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YIpNgmtjm/IKU2D7Re+t7rQlv8nv59iT7Vl5eG5Yb0Y=; b=hVhSHkXzMuGJadlIJPt2tqGP3KcmCY4y7PTE+HchSjv4iM8ImeXVEyhrd5e/fmgPLl YIu/eO/wF0vA5kfIgbxdtHIImbIbIFtrj8FREKERl3mVi5EVKL0oO28BEdfcg/3T9CxV LYFLcMSxmQH5w1epjBM6VzrVmlLxrxVmNHWw3uhC8TmZP2ZdGxDgfHySSHyn7VaU7O4F 0mJThl7x4Xk7iOLsKrlcD4SiuDDAWDsalE0WnChS2n6tPUih2y9u6mkxAeLndeFfFhzR eS1EWkepJutgSHSI08x+s/yIwP3eysxqNtUUxxqAvOX6IaDInSXKyoeY892EWa8qcY9O 3zFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YIpNgmtjm/IKU2D7Re+t7rQlv8nv59iT7Vl5eG5Yb0Y=; b=IlLqdQ1AaQhn7nsMgNbGXbThvjj6mS1NW5sXZl/UtaIhwUWpSc+Zpkhgn2MfKxBrp1 QrI25YHOV4PzFmUL3r4m4rCLss58y5h9Z4FjZ5hCIr9gQhYKnakVopHCkATaYWfHXBNQ cjTSevK/BU5rP5RePx/4lhl7bVA4O401nFzEhfTFaVmjg7sOZPlDA/xQG7qZlsAKRyNt zzp6a95zi5xpCo5zje7sOrjncf6aE3y543Opr0L1KAswd6dM6NyliZ8os5bjJEqn9+CO 86OcCVjEhkhnITH/qa/x2zrNsyNvaFERiGqn2bRtJ5Ro2p3tqRyjFLzXmn/BXAnhx1Bj v2kw== X-Gm-Message-State: APjAAAXD60yd/fc5ELVh2MYosqXt52qB7QuReHsdTl3DJ25+IC6L1MOX 8me0b8A8hj8zdKbKog6OzVV+WzLl X-Google-Smtp-Source: APXvYqyvIEDITJkLdkti3qVXMNTwzXXfybLR6N3O2b9/E0jvlRVZNL/1DW7YBgLqI06LK/OBh54LpQ== X-Received: by 2002:a63:c61:: with SMTP id 33mr13246497pgm.293.1555834280974; Sun, 21 Apr 2019 01:11:20 -0700 (PDT) Received: from archbookpro.localdomain ([2601:647:4b00:5d::661d]) by smtp.gmail.com with ESMTPSA id m131sm20793967pga.3.2019.04.21.01.11.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 01:11:20 -0700 (PDT) Date: Sun, 21 Apr 2019 01:11:18 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Johannes Schindelin , Johannes Sixt , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v7 1/6] t3431: add rebase --fork-point tests Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Denton Liu --- t/t3431-rebase-fork-point.sh | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 t/t3431-rebase-fork-point.sh diff --git a/t/t3431-rebase-fork-point.sh b/t/t3431-rebase-fork-point.sh new file mode 100755 index 0000000000..9b517d87a3 --- /dev/null +++ b/t/t3431-rebase-fork-point.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# +# Copyright (c) 2019 Denton Liu +# + +test_description='git rebase --fork-point test' + +. ./test-lib.sh + +# A---B---D---E (master) +# \ +# C*---F---G (side) +# +# C was formerly part of master but master was rewound to remove C +# +test_expect_success setup ' + test_commit A && + test_commit B && + test_commit C && + git branch -t side && + git reset --hard HEAD^ && + test_commit D && + test_commit E && + git checkout side && + test_commit F && + test_commit G +' + +test_rebase() { + expected="$1" && + shift && + test_expect_success "git rebase $*" " + git checkout master && + git reset --hard E && + git checkout side && + git reset --hard G && + git rebase $* && + test_write_lines $expected >expect && + git log --pretty=%s >actual && + test_cmp expect actual + " +} + +test_rebase 'G F E D B A' +test_rebase 'G F D B A' --onto D +test_rebase 'G F C E D B A' --no-fork-point +test_rebase 'G F C D B A' --no-fork-point --onto D +test_rebase 'G F E D B A' --fork-point refs/heads/master +test_rebase 'G F D B A' --fork-point --onto D refs/heads/master +test_rebase 'G F C E D B A' refs/heads/master +test_rebase 'G F C D B A' --onto D refs/heads/master + +test_done From patchwork Sun Apr 21 08:11:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910463 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 4963F161F for ; Sun, 21 Apr 2019 08:11:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37F10288AD for ; Sun, 21 Apr 2019 08:11:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2922A288BD; Sun, 21 Apr 2019 08:11:32 +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 68A39288B2 for ; Sun, 21 Apr 2019 08:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727175AbfDUILZ (ORCPT ); Sun, 21 Apr 2019 04:11:25 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45241 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbfDUILY (ORCPT ); Sun, 21 Apr 2019 04:11:24 -0400 Received: by mail-pg1-f193.google.com with SMTP id y3so4471639pgk.12 for ; Sun, 21 Apr 2019 01:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1W03mRQJZnatbdyKXVZnSz5/NReI+zKNW2yofV3vAII=; b=ACT8XyARbi1cF9GWYidAIysnNI0oF/EQ3BucOiZbKtnFLaPgw+IjkuJlMAqx2YuHxY cb1uHAObCwi7MYUM4olFK2clhH7MeaInt+0dA1swJrykdyfw689ESBa7KkY8fLgNZzOn 8rW7vwPLwo/lueB6rJnzBiT6w5PK48qL2hV1qms3CGebCCP+b4XtcA8X8rXliA8+Eza9 RQo2/gtVQxfQDc5vFFwFYzAOm+NsDybmz4vYpPPR0CauVGZOfwuQuwiwBE3pJBdrwSr7 xLryFL005WABjWxpdZk58eF8cNJOELyTjoULzcgIS/dYIgYVZPf8azwNc7kOhI0ji77F gwfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1W03mRQJZnatbdyKXVZnSz5/NReI+zKNW2yofV3vAII=; b=GO1rikEVCyRydUyrJUdffQxIc5pC4JXjj7J4g/VTV3ssva3fnvA29CTwmo9BAvvb0Y rldWMQrIsSP7jOQMR9MKqNWABk9hzrghem44E4imLtEYpXoSMmu6zn6pE3AKxeFbMx37 VXVf1QJnDToN8yJV3hZzzSHLICBe+iyNd/mEKoJnEZ8Bhe8R3eoV3sV5xJ00PdZwazcI uXLxTw3lKnUD0S3A8P9jN62flC8oYOOlbJFujdAwnVQDTjJtReJyjGp5Ah40kwKNrUOG hNK6oESYtyS4IBu2ufdw0mOJiGX+jSE5eB4CBGZYvgJwUrMrQ4uFpdFGtswQPIjnU2OO dWxA== X-Gm-Message-State: APjAAAV+tjk1kInFxsKIxxSnuQ1R51e85U1FQNsrwyE1X7qtHg1nfzQ/ KqSSA1tSj8ASw54qhIfA/5knnutC X-Google-Smtp-Source: APXvYqxlkg4dgcpvexEO3gG30ltiHxGZDpI7CUYzGZZ6m8bFKZ/j9QLToEF2mx2K2We1ksoZYeL1IQ== X-Received: by 2002:a63:5149:: with SMTP id r9mr12970111pgl.177.1555834283835; Sun, 21 Apr 2019 01:11:23 -0700 (PDT) Received: from archbookpro.localdomain ([2601:647:4b00:5d::661d]) by smtp.gmail.com with ESMTPSA id b7sm16769125pfj.67.2019.04.21.01.11.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 01:11:23 -0700 (PDT) Date: Sun, 21 Apr 2019 01:11:21 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Johannes Schindelin , Johannes Sixt , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v7 2/6] t3432: test rebase fast-forward behavior Message-ID: <4c087ec0413880e1d3e6cbba95ff62224a4d95e6.1555832783.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When rebase is run on a branch that can be fast-forwarded, this should automatically be done. Create test to ensure this behavior happens. There are some cases that currently don't pass. The first case is where a feature and master have diverged, running "git rebase master... master" causes a full rebase to happen even though a fast-forward should happen. The second case is when we are doing "git rebase --fork-point" and a fork-point commit is found. Once again, a full rebase happens even though a fast-forward should happen. Mark these cases as failure so we can fix it later. Signed-off-by: Denton Liu --- t/t3432-rebase-fast-forward.sh | 72 ++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 t/t3432-rebase-fast-forward.sh diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh new file mode 100755 index 0000000000..4f04d67fd7 --- /dev/null +++ b/t/t3432-rebase-fast-forward.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# +# Copyright (c) 2019 Denton Liu +# + +test_description='ensure rebase fast-forwards commits when possible' + +. ./test-lib.sh + +test_expect_success setup ' + test_commit A && + test_commit B && + test_commit C && + test_commit D && + git checkout -t -b side +' + +test_rebase_same_head() { + status="$1" && + shift && + test_expect_$status "git rebase $* with $changes is no-op" " + oldhead=\$(git rev-parse HEAD) && + test_when_finished 'git reset --hard \$oldhead' && + git rebase $* && + newhead=\$(git rev-parse HEAD) && + test_cmp_rev \$oldhead \$newhead + " +} + +changes='no changes' +test_rebase_same_head success +test_rebase_same_head success master +test_rebase_same_head success --onto B B +test_rebase_same_head success --onto B... B +test_rebase_same_head success --onto master... master +test_rebase_same_head success --no-fork-point +test_rebase_same_head success --fork-point master +test_rebase_same_head failure --fork-point --onto B B +test_rebase_same_head failure --fork-point --onto B... B +test_rebase_same_head success --fork-point --onto master... master + +test_expect_success 'add work to side' ' + test_commit E +' + +changes='our changes' +test_rebase_same_head success +test_rebase_same_head success master +test_rebase_same_head success --onto B B +test_rebase_same_head success --onto B... B +test_rebase_same_head success --onto master... master +test_rebase_same_head success --no-fork-point +test_rebase_same_head success --fork-point master +test_rebase_same_head failure --fork-point --onto B B +test_rebase_same_head failure --fork-point --onto B... B +test_rebase_same_head success --fork-point --onto master... master + +test_expect_success 'add work to upstream' ' + git checkout master && + test_commit F && + git checkout side +' + +changes='our and their changes' +test_rebase_same_head success --onto B B +test_rebase_same_head success --onto B... B +test_rebase_same_head failure --onto master... master +test_rebase_same_head failure --fork-point --onto B B +test_rebase_same_head failure --fork-point --onto B... B +test_rebase_same_head failure --fork-point --onto master... master + +test_done From patchwork Sun Apr 21 08:11:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910461 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 3707B161F for ; Sun, 21 Apr 2019 08:11:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28CB1288AD for ; Sun, 21 Apr 2019 08:11:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A45E28901; Sun, 21 Apr 2019 08:11:31 +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 89CB6288BD for ; Sun, 21 Apr 2019 08:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727235AbfDUIL2 (ORCPT ); Sun, 21 Apr 2019 04:11:28 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41389 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbfDUIL1 (ORCPT ); Sun, 21 Apr 2019 04:11:27 -0400 Received: by mail-pf1-f193.google.com with SMTP id 188so4326325pfd.8 for ; Sun, 21 Apr 2019 01:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wrqY35OffwIk/CRgdxskcpAs6xPOXUlgAECFzIg2odY=; b=nkBdxU60+pkZUOO92gmOOpdK7IuEVmAAmpBvu6cBGpWpZoYRIN6odLbsHppJzYXNki aS0gTgYnS7BCZXCuzQS4T6nzHEMr7f+1ugLwxRtrNSHjxyldUguAbVVroyS/FiCRvEQu TfHgCs/Q4SobgLiEpYpuZqOMf/1BBw0UePfBmNgLZO9Ll0MS9ep3IPtjWC887ywL5d6k YGg0y5G2NUvO6TIFE22d8R91Ryh4A508AcAYlXzTxz6e0+VRmrhauYPmJChpdg8/fD7U k/QoR5RlI5CtJXqnefBLcFXw/x8SYyGLUxio1s1+nDA/gp3ZQeWwCupH8puyXobUyAok oXUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wrqY35OffwIk/CRgdxskcpAs6xPOXUlgAECFzIg2odY=; b=XADbP7qtJ50RrIbmuJmIxQOf5Dyr1UOiTPJRHdn1u4G+I1sWyebH/6DWcxyBz+iBNy 25FZ0QVySpQULn2AZWYomkcNBZU5VKgiV3qCkCC83+MgbWNqN1iD2TptBwNJREg97D27 4FXOMIJ3o0e8mOGlNZIvCo/V0GsF55WnbciEC9Xxn/xptIXTsChcxWs4S41XEEEu3/z4 ddVkzRO5zy2S47aLlFI0AHzdFscEURf7wT55Eggot/9NzokDVHyBW68bqJGGY4yI7HMi fviWsp8NVRiHrayVTyI9tzw1yEBG9AkkzLLwYRmGC0YwBSANdX2mzrrWraf1x7ySpXHg YNqA== X-Gm-Message-State: APjAAAXKSKem6XPZjWyoLpVq4aEo3rmcJatmqYai3Ogvo5tUYqQeBbxR etdu5eWAk6IAZFgjaI4WgbU6t+uS X-Google-Smtp-Source: APXvYqxGjgkcvi+qP0wPVtZSf3Tm/xxpjvTxZ8uQRedTbmP2VzZ6MRB2+zuwNH2OhHdeXnY15jZ9WQ== X-Received: by 2002:a65:41ca:: with SMTP id b10mr13243179pgq.256.1555834286483; Sun, 21 Apr 2019 01:11:26 -0700 (PDT) Received: from archbookpro.localdomain ([2601:647:4b00:5d::661d]) by smtp.gmail.com with ESMTPSA id b63sm26974020pfj.54.2019.04.21.01.11.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 01:11:25 -0700 (PDT) Date: Sun, 21 Apr 2019 01:11:24 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Johannes Schindelin , Johannes Sixt , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v7 3/6] rebase: refactor can_fast_forward into goto tower Message-ID: <3d348d2c37751b8ecbbd244e03bd9fdd860290e2.1555832783.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before, can_fast_forward was written with an if-else statement. However, in the future, we may be adding more termination cases which would lead to deeply nested if statements. Refactor to use a goto tower so that future cases can be easily inserted. Signed-off-by: Denton Liu --- builtin/rebase.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 77deebc65c..de10b6f5ad 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -899,21 +899,27 @@ static int can_fast_forward(struct commit *onto, struct object_id *head_oid, struct object_id *merge_base) { struct commit *head = lookup_commit(the_repository, head_oid); - struct commit_list *merge_bases; - int res; + struct commit_list *merge_bases = NULL; + int res = 0; if (!head) - return 0; + goto done; merge_bases = get_merge_bases(onto, head); - if (merge_bases && !merge_bases->next) { - oidcpy(merge_base, &merge_bases->item->object.oid); - res = oideq(merge_base, &onto->object.oid); - } else { + if (!merge_bases || merge_bases->next) { oidcpy(merge_base, &null_oid); - res = 0; + goto done; } - free_commit_list(merge_bases); + + oidcpy(merge_base, &merge_bases->item->object.oid); + if (!oideq(merge_base, &onto->object.oid)) + goto done; + + res = 1; + +done: + if (merge_bases) + free_commit_list(merge_bases); return res && is_linear_history(onto, head); } From patchwork Sun Apr 21 08:11:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910465 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 ACC6B1515 for ; Sun, 21 Apr 2019 08:11:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DB06288AD for ; Sun, 21 Apr 2019 08:11:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91AFA288BD; Sun, 21 Apr 2019 08:11:33 +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 DB495288AD for ; Sun, 21 Apr 2019 08:11:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727244AbfDUILb (ORCPT ); Sun, 21 Apr 2019 04:11:31 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42184 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbfDUILa (ORCPT ); Sun, 21 Apr 2019 04:11:30 -0400 Received: by mail-pf1-f193.google.com with SMTP id w25so4329714pfi.9 for ; Sun, 21 Apr 2019 01:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=w/JpLdHjhw5Ion9B01LEHJOAGwOhB0QrGVWJolHkpps=; b=pcspQtZNxdjNUYlwCXqMjzQIYHSlDM+vgw0v7VZ2P3LIO1O7UNcCViHBwBYe7LyW8Y kHveygyS87/2Tpw3Vm32+vlQYA2RbgoW4ObCOTy6qRJuZrOUZ0wP+dha3l+FMcswOfUu pqYNvsosv8Q8tVInyquhdb9MPjKvVjG7zd4lSf+tEwdxr1oQbgXqYLsB4A+DB7yv8XXY XQ2/gbBhCjngXEhaI797GHrFGGzq9x9AdCP8url1X3UlcoWYoD22V5vNH7Mw0xUw7/kA /vbYniPObB2mjw2xXW5lk4sMxCvubyopJohTSWhNFZGIbaibfPgI6Wuv5RePfOP4etL7 v2Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=w/JpLdHjhw5Ion9B01LEHJOAGwOhB0QrGVWJolHkpps=; b=K3Xf+vVmwzC+DoUhBIrYaevKovZ06RLQXEld8ALgqLNTdKv3/Y2htPOJraMMA8DG+Z D1+I8/AiL5cocx4ePGJos3o4hWU7QlNGn2HSo6oaFs0iVKkcmJqnTNJpWKvi+3d9NUA/ F9BaIHWgX7lMyyKjrtqkPi1LFz5+4fb0txOEQG2UHGPfLMI6kl0mjMyqa/uBGRdA/iR/ A+s0hEOaQOqTQ17lysKwaBiD7nFlzOK0qGC6w6tUxnmBfVTllq2ePAq9Rxzgl6CbZ3f0 Mmji5FDc5MbBQcsZT/+eo6wAj6GOLmHk0vKxcZSxUVYK3tsDFHrsGWUtvi4C+J0di8xY bA2A== X-Gm-Message-State: APjAAAXBHrIXM3LAJ2+lyw1ZHfm7W+ZvVG7Ef2qvlEz4NtwMDMp/dAqp WonF03VPqhfGMTI8v3OO241rylmn X-Google-Smtp-Source: APXvYqzgZRpEdeqORaaLxwSwo/20scffXcXHBzhp1UNAjo1qLr8no30qkSRhB3KrKzSgLTzhLlb8hQ== X-Received: by 2002:a63:5a4b:: with SMTP id k11mr12858972pgm.119.1555834289275; Sun, 21 Apr 2019 01:11:29 -0700 (PDT) Received: from archbookpro.localdomain ([2601:647:4b00:5d::661d]) by smtp.gmail.com with ESMTPSA id e8sm14839462pfc.47.2019.04.21.01.11.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 01:11:28 -0700 (PDT) Date: Sun, 21 Apr 2019 01:11:26 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Johannes Schindelin , Johannes Sixt , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v7 4/6] rebase: fast-forward --onto in more cases Message-ID: <27cbcfaeae91b9abe2726995b5f26d23892cb7ec.1555832783.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before, when we had the following graph, A---B---C (master) \ D (side) running 'git rebase --onto master... master side' would result in D being always rebased, no matter what. However, the desired behavior is that rebase should notice that this is fast-forwardable and do that instead. Add detection to `can_fast_forward` so that this case can be detected and a fast-forward will be performed. First of all, rewrite the function to use gotos which simplifies the logic. Next, since the options.upstream && !oidcmp(&options.upstream->object.oid, &options.onto->object.oid) conditions were removed in `cmd_rebase`, we reintroduce a substitute in `can_fast_forward`. In particular, checking the merge bases of `upstream` and `head` fixes a failing case in t3416. The abbreviated graph for t3416 is as follows: F---G topic / A---B---C---D---E master and the failing command was git rebase --onto master...topic F topic Before, Git would see that there was one merge base (C), and the merge and onto were the same so it would incorrectly return 1, indicating that we could fast-forward. This would cause the rebased graph to be 'ABCFG' when we were expecting 'ABCG'. With the additional logic, we detect that upstream and head's merge base is F. Since onto isn't F, it means we're not rebasing the full set of commits from master..topic. Since we're excluding some commits, a fast-forward cannot be performed and so we correctly return 0. Add '-f' to test cases that failed as a result of this change because they were not expecting a fast-forward so that a rebase is forced. While we're at it, remove a trailing whitespace from rebase.c. Helped-by: Phillip Wood Signed-off-by: Denton Liu --- builtin/rebase.c | 29 ++++++++++++++++++++--------- t/t3400-rebase.sh | 2 +- t/t3404-rebase-interactive.sh | 2 +- t/t3432-rebase-fast-forward.sh | 4 ++-- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index de10b6f5ad..fdb42eb09f 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -895,8 +895,8 @@ static int is_linear_history(struct commit *from, struct commit *to) return 1; } -static int can_fast_forward(struct commit *onto, struct object_id *head_oid, - struct object_id *merge_base) +static int can_fast_forward(struct commit *onto, struct commit *upstream, + struct object_id *head_oid, struct object_id *merge_base) { struct commit *head = lookup_commit(the_repository, head_oid); struct commit_list *merge_bases = NULL; @@ -915,6 +915,17 @@ static int can_fast_forward(struct commit *onto, struct object_id *head_oid, if (!oideq(merge_base, &onto->object.oid)) goto done; + if (!upstream) + goto done; + + free_commit_list(merge_bases); + merge_bases = get_merge_bases(upstream, head); + if (!merge_bases || merge_bases->next) + goto done; + + if (!oideq(&onto->object.oid, &merge_bases->item->object.oid)) + goto done; + res = 1; done: @@ -1688,13 +1699,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) /* * Check if we are already based on onto with linear history, - * but this should be done only when upstream and onto are the same - * and if this is not an interactive rebase. + * in which case we could fast-forward without replacing the commits + * 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.orig_head, &merge_base) && - !is_interactive(&options) && !options.restrict_revision && - options.upstream && - !oidcmp(&options.upstream->object.oid, &options.onto->object.oid)) { + if (can_fast_forward(options.onto, options.upstream, &options.orig_head, + &merge_base) && + !is_interactive(&options) && !options.restrict_revision) { int flag; if (!(options.flags & REBASE_FORCE)) { @@ -1788,7 +1799,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); if (reset_head(&options.onto->object.oid, "checkout", NULL, - RESET_HEAD_DETACH | RESET_ORIG_HEAD | + RESET_HEAD_DETACH | RESET_ORIG_HEAD | RESET_HEAD_RUN_POST_CHECKOUT_HOOK, NULL, msg.buf)) die(_("Could not detach HEAD")); diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 460d0523be..604d624ff8 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -295,7 +295,7 @@ test_expect_success 'rebase--am.sh and --show-current-patch' ' echo two >>init.t && git commit -a -m two && git tag two && - test_must_fail git rebase --onto init HEAD^ && + test_must_fail git rebase -f --onto init HEAD^ && GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr && grep "show.*$(git rev-parse two)" stderr ) diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index b60b11f9f2..f054186cc7 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1066,7 +1066,7 @@ test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-int git reset --hard && git checkout conflict-branch && set_fake_editor && - test_must_fail git rebase --onto HEAD~2 HEAD~ && + test_must_fail git rebase -f --onto HEAD~2 HEAD~ && test_must_fail git rebase --edit-todo && git rebase --abort ' diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh index 4f04d67fd7..d0e5b1f3e6 100755 --- a/t/t3432-rebase-fast-forward.sh +++ b/t/t3432-rebase-fast-forward.sh @@ -64,9 +64,9 @@ test_expect_success 'add work to upstream' ' changes='our and their changes' test_rebase_same_head success --onto B B test_rebase_same_head success --onto B... B -test_rebase_same_head failure --onto master... master +test_rebase_same_head success --onto master... master test_rebase_same_head failure --fork-point --onto B B test_rebase_same_head failure --fork-point --onto B... B -test_rebase_same_head failure --fork-point --onto master... master +test_rebase_same_head success --fork-point --onto master... master test_done From patchwork Sun Apr 21 08:11:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910469 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 834BF1515 for ; Sun, 21 Apr 2019 08:11:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74717288A9 for ; Sun, 21 Apr 2019 08:11:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67D75288B2; Sun, 21 Apr 2019 08:11:36 +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 EFBA6288A9 for ; Sun, 21 Apr 2019 08:11:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727250AbfDUILe (ORCPT ); Sun, 21 Apr 2019 04:11:34 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:38434 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbfDUILd (ORCPT ); Sun, 21 Apr 2019 04:11:33 -0400 Received: by mail-pl1-f194.google.com with SMTP id f36so4430661plb.5 for ; Sun, 21 Apr 2019 01:11:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=FaK3V2X0tbv/BZURnkk1VChlpGtK4yvs41+AmQmQKb0=; b=f05LbXm5UPMl6pNTIoh4cfhP7U/7w1PwFCF+0gDIisK1HvTlT6fyjc+I5foCO8cjdz xrhFIb3lExdNC5sdKj/Plfy3skO8tU/8eoOKiftSmsQ+l5vOwAY797qv9sKjeNC/S7js J4s8QzN/8iuQXCA40VGdwSX/z9LDffe70iU69AKMr2JNMiHpdqCzRcHzgEmPpZVy3thx 4hEZHfBxY2vIo5iy/IKk596CaojM+PJgMD2uRJifW96pl7wE/n76K3Ln/YKSWuuxJeVP cT79dPO/sVaFEvzDnPZqTSY/3uFKIg4LBKivrclKMBlhlwuRZOfP3fjJYvi6ZaUAMx2F BkXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=FaK3V2X0tbv/BZURnkk1VChlpGtK4yvs41+AmQmQKb0=; b=CYOqnfMPlOL+8mdaFb3wx9BR7ZwRKc0E3JEywGxAT3R4SP58zUEEQNg+JXCB7ehPJL 0FzWfUe85Iady/AfL4T4LXysW1bbOv/wP3UgWJPCQ2oHil45+LPfuZB6CHA1G/Zehm4l WyAPds/LNO2jWfEgRAIKKqZEN4KXVNCQ6iornPty0nXXg8DY++15OS9LAxGMD4sRqYW2 iXbdJbA4aoeBVWuVOzGWyX0hn9g1+OdCVdS1hN8bbg0swCtJU9UZPdZp9oGl/w80zMVD mhBJPXj6g4G+8gq2bfTuN9l79B+VasZ+56Dvx20PddEkKtWW+hP0g6rCzhGh+cV8pDg9 Z3mQ== X-Gm-Message-State: APjAAAUX+JbCtGyEgfgeQPBTUNa1oP50uWpigBcLz7zIsEXX9s1zDeaf kW6O6YV5KrDZDE5HY3ozjZYYY8At X-Google-Smtp-Source: APXvYqzqLX9M0ZooVMgzpAG/lux205Bf8Abv8SAFlS2vPQOS1+3AeY3XvBl0fcc/CFLr8M2E2vl6fA== X-Received: by 2002:a17:902:6bc8:: with SMTP id m8mr4582616plt.21.1555834292307; Sun, 21 Apr 2019 01:11:32 -0700 (PDT) Received: from archbookpro.localdomain ([2601:647:4b00:5d::661d]) by smtp.gmail.com with ESMTPSA id z14sm13222144pfn.161.2019.04.21.01.11.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 01:11:31 -0700 (PDT) Date: Sun, 21 Apr 2019 01:11:29 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Johannes Schindelin , Johannes Sixt , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v7 5/6] rebase: fast-forward --fork-point in more cases Message-ID: <8254730810eed7b413baebe918efb43e26e04af8.1555832783.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- builtin/rebase.c | 10 +++++++--- t/t3432-rebase-fast-forward.sh | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index fdb42eb09f..66c59ebe22 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -896,6 +896,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); @@ -915,6 +916,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; @@ -1703,9 +1707,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 d0e5b1f3e6..1cb2896fb4 100755 --- a/t/t3432-rebase-fast-forward.sh +++ b/t/t3432-rebase-fast-forward.sh @@ -35,8 +35,8 @@ test_rebase_same_head success --onto B... B test_rebase_same_head success --onto master... master test_rebase_same_head success --no-fork-point test_rebase_same_head success --fork-point master -test_rebase_same_head failure --fork-point --onto B B -test_rebase_same_head failure --fork-point --onto B... B +test_rebase_same_head success --fork-point --onto B B +test_rebase_same_head success --fork-point --onto B... B test_rebase_same_head success --fork-point --onto master... master test_expect_success 'add work to side' ' @@ -51,8 +51,8 @@ test_rebase_same_head success --onto B... B test_rebase_same_head success --onto master... master test_rebase_same_head success --no-fork-point test_rebase_same_head success --fork-point master -test_rebase_same_head failure --fork-point --onto B B -test_rebase_same_head failure --fork-point --onto B... B +test_rebase_same_head success --fork-point --onto B B +test_rebase_same_head success --fork-point --onto B... B test_rebase_same_head success --fork-point --onto master... master test_expect_success 'add work to upstream' ' @@ -65,8 +65,8 @@ changes='our and their changes' test_rebase_same_head success --onto B B test_rebase_same_head success --onto B... B test_rebase_same_head success --onto master... master -test_rebase_same_head failure --fork-point --onto B B -test_rebase_same_head failure --fork-point --onto B... B +test_rebase_same_head success --fork-point --onto B B +test_rebase_same_head success --fork-point --onto B... B test_rebase_same_head success --fork-point --onto master... master test_done From patchwork Sun Apr 21 08:11:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10910471 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 DFF8A161F for ; Sun, 21 Apr 2019 08:11:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCD14288A9 for ; Sun, 21 Apr 2019 08:11:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0BE6288B2; Sun, 21 Apr 2019 08:11:38 +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 8945A288A9 for ; Sun, 21 Apr 2019 08:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727274AbfDUILg (ORCPT ); Sun, 21 Apr 2019 04:11:36 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33159 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbfDUILg (ORCPT ); Sun, 21 Apr 2019 04:11:36 -0400 Received: by mail-pl1-f194.google.com with SMTP id t16so4446111plo.0 for ; Sun, 21 Apr 2019 01:11:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=FIJjFbAc1ED2nZnVPfSrkqJpuWl3onwZowjl4zcLUyg=; b=tKheTzab7xNOS2KLU5m2r9vYKtefXOQlw5AuWftnnZN5giIs/ULyaNpLuCtFxgLJB+ pUxH01XLwS4UFoURrDVpDrYTCqEsKyGwrDCfvrsA7kxd60JL1NBO1Pnq3uWUosYS2Mlh HoKA9evOivPjsTP1qCso//k2kMDYtVCL0ozwEcQNw78m/EZE9bEsc+uWeAKigAQ1Cah4 JdPt00kVfEmYSf1bO0lW+lIQBruwk4FjKibu0TLEbP+BNJfsEEh6994fRnjjjY35n07C zZE9wph5zfepRwW1nsRsBLKLTSR41uoZdQ9DhifjblE6eYZTBjx2oZvtyg315K0QFwpv mwsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=FIJjFbAc1ED2nZnVPfSrkqJpuWl3onwZowjl4zcLUyg=; b=c2hCAQSW95xc8sdrfBpU2PFEr2/bFp7+bpk8BSfVurn05uuz1TvN4Op9ZA8WlozBLk 4jufKJReSD/phEtmNv4voqaVfPxq6nNR4H31PeOc3p5HS/q7y2J9g4cIy58BFi3Z0Qv8 UsSoFsv6RVbmyZByYtznBoUa63B8nApuqOPXdKYKec4/hE89CCDuAltMdeE0kH/k1TWB Pmf40NtDR5M325VgALrtHytDKCD/hpQHPuzyJUDI1lPWwZiFvbd1v4XVDolTXD3ZkB1p COVTO+/7iRglAVbVCX/Dz4MOn5wc7kZVQW1f9Rr2Namrgs40fGKbWGEtY2kw1vodtHci 4Elw== X-Gm-Message-State: APjAAAUQol2Gf9L2BbFxbW15dHTO6eDw+8BBu7cU50J2y/AooSpCgnDo w2GjOcGuyAjT0jxL9EOu2WDE+v0H X-Google-Smtp-Source: APXvYqyrsHU7F21XxIquflzCOr4lkXK7+DzfAXGvugHWNaqLkTTIISACXPtHTO01lf4BH3Uxc9LDrw== X-Received: by 2002:a17:902:e684:: with SMTP id cn4mr13506090plb.71.1555834295029; Sun, 21 Apr 2019 01:11:35 -0700 (PDT) Received: from archbookpro.localdomain ([2601:647:4b00:5d::661d]) by smtp.gmail.com with ESMTPSA id p7sm14622953pfp.70.2019.04.21.01.11.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 01:11:34 -0700 (PDT) Date: Sun, 21 Apr 2019 01:11:32 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Johannes Schindelin , Johannes Sixt , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v7 6/6] rebase: teach rebase --keep-base Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A common scenario is if a user is working on a topic branch and they wish to make some changes to intermediate commits or autosquash, they would run something such as git rebase -i --onto master... master in order to preserve the merge base. This is useful when contributing a patch series to the Git mailing list, one often starts on top of the current 'master'. However, while developing the patches, 'master' is also developed further and it is sometimes not the bst idea to keep rebasing on top of 'master', but to keep the base commit as-is. Alternatively, a user wishing to test individual commits in a topic branch without changing anything may run git rebase -x ./test.sh master... master Since rebasing onto the merge base of the branch and the upstream is such a common case, introduce the --keep-base option as a shortcut. This allows us to rewrite the above as git rebase -i --keep-base master and git rebase -x ./test.sh --keep-base master respectively. Add tests to ensure --keep-base works correctly in the normal case and fails when there are multiple merge bases, both in regular and interactive mode. Also, test to make sure conflicting options cause rebase to fail. While we're adding test cases, add a missing set_fake_editor call to 'rebase -i --onto master...side'. While we're documenting the --keep-base option, change an instance of "merge-base" to "merge base", which is the consistent spelling. Helped-by: Eric Sunshine Helped-by: Junio C Hamano Helped-by: Ævar Arnfjörð Bjarmason Helped-by: Johannes Schindelin Signed-off-by: Denton Liu --- Documentation/git-rebase.txt | 30 ++++++++++++-- builtin/rebase.c | 32 ++++++++++++--- contrib/completion/git-completion.bash | 2 +- t/t3416-rebase-onto-threedots.sh | 57 ++++++++++++++++++++++++++ t/t3431-rebase-fork-point.sh | 4 ++ t/t3432-rebase-fast-forward.sh | 11 +++++ 6 files changed, 126 insertions(+), 10 deletions(-) diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 6363d674b7..569ab708d4 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -8,8 +8,8 @@ git-rebase - Reapply commits on top of another base tip SYNOPSIS -------- [verse] -'git rebase' [-i | --interactive] [] [--exec ] [--onto ] - [ []] +'git rebase' [-i | --interactive] [] [--exec ] + [--onto | --keep-base] [ []] 'git rebase' [-i | --interactive] [] [--exec ] [--onto ] --root [] 'git rebase' --continue | --skip | --abort | --quit | --edit-todo | --show-current-patch @@ -217,6 +217,24 @@ As a special case, you may use "A\...B" as a shortcut for the merge base of A and B if there is exactly one merge base. You can leave out at most one of A and B, in which case it defaults to HEAD. +--keep-base:: + Set the starting point at which to create the new commits to the + merge base of . Running + 'git rebase --keep-base ' is equivalent to + running 'git rebase --onto ... '. ++ +This option is useful in the case where one is developing a feature on +top of an upstream branch. While the feature is being worked on, the +upstream branch may advance and it may not be the best idea to keep +rebasing on top of the upstream but to keep the base commit as-is. ++ +Although both this option and --fork-point find the merge base between + and , this option uses the merge base as the _starting +point_ on which new commits will be created, whereas --fork-point uses +the merge base to determine the _set of commits_ which will be rebased. ++ +See also INCOMPATIBLE OPTIONS below. + :: Upstream branch to compare against. May be any valid commit, not just an existing branch name. Defaults to the configured @@ -364,6 +382,10 @@ ends up being empty, the will be used as a fallback. + If either or --root is given on the command line, then the default is `--no-fork-point`, otherwise the default is `--fork-point`. ++ +If your branch was based on but was rewound and +your branch contains commits which were dropped, this option can be used +with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: --whitespace=