From patchwork Wed Apr 17 18:01: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: 10905743 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 1D24417E6 for ; Wed, 17 Apr 2019 18:01:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 085EF28706 for ; Wed, 17 Apr 2019 18:01:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F054A28B26; Wed, 17 Apr 2019 18:01:29 +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 9E01428706 for ; Wed, 17 Apr 2019 18:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730682AbfDQSB2 (ORCPT ); Wed, 17 Apr 2019 14:01:28 -0400 Received: from mail-pl1-f180.google.com ([209.85.214.180]:46755 "EHLO mail-pl1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbfDQSB1 (ORCPT ); Wed, 17 Apr 2019 14:01:27 -0400 Received: by mail-pl1-f180.google.com with SMTP id y6so12366695pll.13 for ; Wed, 17 Apr 2019 11:01: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=bbooXkmfFrU3lzEiQrq3qhvTIrSt4itjBeJHI2ai+q0=; b=Sjc5Frjoe09SrQimI6GyCRcP8RRkRNy/bTKpSD0n4creklu1SY+GMfsR9gLO8lg86t KDdsx0mZLBoiBBGVbcKQfQ3wkE93ik+d3EoSxDaw6Jo0pe6q28Bjl5Ay0rsfTLMsJVF9 /mo8SwResZDteOFwKN0gK3p2qImApWqZw0Le2Xsq7yOIIve/kHjEYieQrvGKy0cA8LOV gss4rNU0GJN6Yqc/rTm7FOZUl5bRQSGunfj4h7OXCguRDaPnCft0K+NtcJcalJ/CyP1a GgaJqvK58K+iN0UroSy/Su1mDWWQe4zoF7a3TdwTqPS0DphlquDMKs9NzHJnPFrzlDu+ H7ng== 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=bbooXkmfFrU3lzEiQrq3qhvTIrSt4itjBeJHI2ai+q0=; b=iwUxv9tSyygrPRmHv1wA0X8V2GnmoNuIe7ETuops5pjCefPPWLTFkg29LOfcPKmYpj J7c93AW2ndLrrltNBJ4wdsO+yx0zGmFj6hnwHa5IPNABDTxYB3Evuw5x+6QfLPL9Ph6H 2dFi4mGGVjE36JzvAZq7g3UoNFh0tRzdNVN3VzCo+RHqGFdzTDMR8BOH6jgHu8NyzQD7 JeK78SPVwmboLT4sTMvDj1cvXYwuPUs4lyLvYIJcBaUagjQqx/d2JL/bfVWEHFnvxk5A x02MqUDiLkdR/MnHSmPqlhTNymgymw3+sKTk0K06byOwfJ/0dgYA6CJh2roS11T69Zst sa9w== X-Gm-Message-State: APjAAAUGt2R5GVqe1AB/pwU04Zb6GRqB/7IoEAzRUVP2IbBvHobXHU4A b5UljNfUV8cYXH/VFEjZ1HqCMwn/tMI= X-Google-Smtp-Source: APXvYqyKMeBoor0e6qFtp8lBeSCzxyxahy3ADmNBrfHszhmn/SKwahAfd1phgxHwlVF/vwT2d7wrGg== X-Received: by 2002:a17:902:9b83:: with SMTP id y3mr87707338plp.165.1555524086598; Wed, 17 Apr 2019 11:01:26 -0700 (PDT) Received: from dev-l ([149.28.200.39]) by smtp.gmail.com with ESMTPSA id i15sm79012768pfd.162.2019.04.17.11.01.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 11:01:25 -0700 (PDT) Date: Wed, 17 Apr 2019 11:01: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 v6 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.5.24 (2015-08-30) 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 Wed Apr 17 18:01: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: 10905747 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 23882922 for ; Wed, 17 Apr 2019 18:01:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D2F028706 for ; Wed, 17 Apr 2019 18:01:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 014A228B26; Wed, 17 Apr 2019 18:01: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 8F6D828706 for ; Wed, 17 Apr 2019 18:01:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731696AbfDQSB3 (ORCPT ); Wed, 17 Apr 2019 14:01:29 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37341 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731116AbfDQSB3 (ORCPT ); Wed, 17 Apr 2019 14:01:29 -0400 Received: by mail-pl1-f194.google.com with SMTP id w23so12390674ply.4 for ; Wed, 17 Apr 2019 11:01:28 -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=s6mCxr6PGltFjwNoWk/s4dm40wr6oDRyNZVJ+5whTFA=; b=PFJXUFpDARiDaUa7/hdAKpPtqJVCWdtm/Oc9CqCvLWRYDbe6eLmBpt8iK3GP36xKh4 HfrafnhwkXwVt5+tmWKxkhKkH29vnZmHMko3BGXhwP/neOgKyBEHFlakfogbS2J7YQzv wBLGv5BnsLneiQaJ81t7s5pDtqawEh+if50RnaaOuBJypbRYVqtThEegW1qOO67SIG6r lgktoD0vwSFjxZl8wfjvqmr3xdscY8LJJZRSHITo3BhZqVHRt0xOXvrjTY4tN9SjehMn GHI6ai0TlXAza0DUaxWsqGLyjrwudtrtev02kD/IJQ/nl2jQh3nckz3yPIUE6aoUCIHL 5raw== 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=s6mCxr6PGltFjwNoWk/s4dm40wr6oDRyNZVJ+5whTFA=; b=rbyfUXQ1tefm2CgfbR8NChabr0uX/9s7/5+xWfH+ewvmE8rR+c1AsTEno1oMz1N5po AAgACMpbOoeYmOuloW3LT4JSn+uxzsSnEJ2NucJY0EzUhkOg3f7jH88WwNLgduONBDt2 QYXVjz0hmg4GAiv5Zzjczx4IJhBlpR66Fz403l9Oiy6cCgZHJG+gIVZB70BkerrdxjKo tbqcyyi6OBlsRyqu+sLt9NKzBOHSZf0ROAnmWqMs9V8tyVlxmd0g12dVn6phwgI6O0t3 AT2utfBuFExVtGotIsII77w5D6FQL3bZlwYYI3wk1o3MRr4tlmLMNEkMkLtYsqS0+yVs 58mg== X-Gm-Message-State: APjAAAUo+S3o+TmoxWQpTalaZz3Hk/rTzZxpPVYLwcsX9AK7MmEyJuEb WapQMaSdcrp1b2x6Ym1BoTl2SlQqNsE= X-Google-Smtp-Source: APXvYqyuFKhdeG73V/tZKEXgIipNhhzV41LQHc+rTyHClOSpQjwMDpqJznhqE0Q6iilFuN24W477nw== X-Received: by 2002:a17:902:2862:: with SMTP id e89mr71705682plb.203.1555524088077; Wed, 17 Apr 2019 11:01:28 -0700 (PDT) Received: from dev-l ([149.28.200.39]) by smtp.gmail.com with ESMTPSA id b15sm76834377pgg.90.2019.04.17.11.01.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 11:01:27 -0700 (PDT) Date: Wed, 17 Apr 2019 11:01: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 v6 2/6] t3432: test rebase fast-forward behavior Message-ID: <4c087ec0413880e1d3e6cbba95ff62224a4d95e6.1555523176.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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 Wed Apr 17 18:01:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10905749 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 A9AB51515 for ; Wed, 17 Apr 2019 18:01:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90AFA28706 for ; Wed, 17 Apr 2019 18:01:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EBF728B26; Wed, 17 Apr 2019 18:01: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 700A728706 for ; Wed, 17 Apr 2019 18:01:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731844AbfDQSBb (ORCPT ); Wed, 17 Apr 2019 14:01:31 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:35842 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731116AbfDQSBa (ORCPT ); Wed, 17 Apr 2019 14:01:30 -0400 Received: by mail-pg1-f196.google.com with SMTP id 85so12362748pgc.3 for ; Wed, 17 Apr 2019 11:01: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=c8lWj/k6hpVKUyKqXhPc38soSAt9paNJntaTWM/Fp4k=; b=lEtv7QV6rhrWFkEOUr6+a3RhO1Jdlw3ewBX2/qJBRbAKWsET5uZjEIGAfQx91wFVLy 1g9CmJBZbPf8loTYUJToppQx5Duk9FVq7bVrm4WZxOmfesZRWqJxNCi02YYTWi1NqgiW 9iHRpefHUZMkH3tGvKxeI5ntrCE3yZvRMf34IdtQ1KxI5Aus8zt/fxRPaE4TI5uRL/Ju xvquE4/B1AM89NnHVnqs2xLgYbXl+kzQBXVmKKFntGJf0bC75neDBurFkOu1VDIJIqFP 8POzqvkdgSr5zrb5NEegZGlg+LBKHTbLjOZ1oNSCrgVPyzkrRLt8EUQKo2ll3S+Hd1Yk 2Ypg== 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=c8lWj/k6hpVKUyKqXhPc38soSAt9paNJntaTWM/Fp4k=; b=Hp6/eRkgSzJBhPJl3pOLj5x7ML/MLDugJtEVIDLjdKors8KTui2zrR3OUKKAlFlKES oGMfd83uwV/qVdjl4GhAgo/dS+pY/oKGGVP4ax7GWdT7jJyqAhIsfQZzY3SXPQSSljgL dTJPdT0itqIsNH98YQirh5DLND1+Mi2eli+4KmXzE1/bjCf31P90D9SxIToGubZ1Bknh wuJorE03Uc7G7sgE2x/BNsPaWWB6kurBMARKOFMVPkD//gV9xnZ4lUUEpAA23ga+xfnM TQLA12ZEf2m+oVR3B2nxbtDbB1cnauh7ElnzErhudLINUeg6oWatlLrxGO+oA4nYFu+w wgNg== X-Gm-Message-State: APjAAAX1CpKMoSeHo4tL5Dugyyhr0JrouWlPwDkpbAUOaSaiH6vFORuO sp6giNoTPADTmRwBqTKdA10DT/NXjNU= X-Google-Smtp-Source: APXvYqwyAKmhpcYc2fYjb3DwRwb67dGt4CCUWYPnLC9h5UxJkOwYreDRHj50jPuYfFPb6BZRwnri3Q== X-Received: by 2002:a63:6849:: with SMTP id d70mr83618246pgc.21.1555524089431; Wed, 17 Apr 2019 11:01:29 -0700 (PDT) Received: from dev-l ([149.28.200.39]) by smtp.gmail.com with ESMTPSA id k1sm79946757pfc.83.2019.04.17.11.01.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 11:01:28 -0700 (PDT) Date: Wed, 17 Apr 2019 11:01:28 -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 v6 3/6] rebase: refactor can_fast_forward into goto tower Message-ID: <3d348d2c37751b8ecbbd244e03bd9fdd860290e2.1555523176.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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 Wed Apr 17 18:01:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10905751 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 0C14A1515 for ; Wed, 17 Apr 2019 18:01:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAE2A28706 for ; Wed, 17 Apr 2019 18:01:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEADF28B26; Wed, 17 Apr 2019 18:01:35 +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 468CB28706 for ; Wed, 17 Apr 2019 18:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732450AbfDQSBe (ORCPT ); Wed, 17 Apr 2019 14:01:34 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45713 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731116AbfDQSBc (ORCPT ); Wed, 17 Apr 2019 14:01:32 -0400 Received: by mail-pl1-f195.google.com with SMTP id bf11so12371991plb.12 for ; Wed, 17 Apr 2019 11:01:31 -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=QnvcPpABEYJPvPenuDZVn36suLvAo9oTH2nTnpnPGzA=; b=mbytz7JOtAkgHww+o6odya1YwdJ/wZo0g4D1C+viqVZSr3SiIrIphOq3VjjkEg64cl OAjbec/rO3IdDtbHH8YWb3l486zF+GFx1u+Xx73Qza4AWzyqZsFpvUCLhjs1PMHKVgjy x9biUZD534Wg1UZez1BM9qoVn/4vi2VjODwEh514Bsm17koFIJX9Zxip1VcNpaAarE4l lc3NN6LT8ULMBg2X744CQX7FRtp7v6Nz/dkTuJ6WWpTKBjS1JpCEzF/G46KDANZfUlCG /Etpr2IMIIwmVQs8uHUWz74jMWsnEvE9sXk3i7g6JxyeAetGUk99Ac13j2ftrMSrHW1h 75NQ== 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=QnvcPpABEYJPvPenuDZVn36suLvAo9oTH2nTnpnPGzA=; b=g7IYhqJ5mdvFyR7DrYEi4Wmg1GldwXI2LomOVgKVuXbX3r2Ncq99FTDXgDYp0X9crv xu+kJ478vCnUGpum9kuObYzByozBMyXEeQM6q9ocLFo87b3B5bjapOeFYKz0KwTtokDs TVXOiI2FYQ5gI7h6/NL/eSpP4rHLkKlvMV84xQj8hZF7HggSJYCYdlpoUys4Px1AUAnH kjsvahUe35w3svHYMobNpr72Riee6YPkdYsbSVhrq2V3g30S0Zl6QHvE+q/Dw0wpBt+r kitB0zCNleJuhbYFmkpj74LBtqxzIwXoG4tME9cUpb6Y6EcjYxc087WmRVQ5eXMEyUN4 vcGA== X-Gm-Message-State: APjAAAVFVeh2i72c1fntiMBC3PIeKaxiTgfLabMK7aSJrwM42OXNXaNB wWljP0l8WldS6oNtXy/V8N5yBDCmqUs= X-Google-Smtp-Source: APXvYqwxmOWvS6pQJrOaDyswEH4tD7wGPsumzfptuLgKrhtPNeatq4dTH38HCfO0nNlFe60D6n17OA== X-Received: by 2002:a17:902:121:: with SMTP id 30mr55882556plb.174.1555524091153; Wed, 17 Apr 2019 11:01:31 -0700 (PDT) Received: from dev-l ([149.28.200.39]) by smtp.gmail.com with ESMTPSA id j19sm69072191pfh.41.2019.04.17.11.01.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 11:01:30 -0700 (PDT) Date: Wed, 17 Apr 2019 11:01: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 v6 4/6] rebase: fast-forward --onto in more cases Message-ID: <2559ab54a2c6e5544595e0d66a431e249bf73ca8.1555523176.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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 | 28 +++++++++++++++++++--------- t/t3400-rebase.sh | 2 +- t/t3404-rebase-interactive.sh | 2 +- t/t3432-rebase-fast-forward.sh | 4 ++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index de10b6f5ad..f5aca1eee0 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,18 @@ 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 +1700,11 @@ 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. + * but this should be done if this is not 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 +1798,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 Wed Apr 17 18:01:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10905753 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 CF4FC922 for ; Wed, 17 Apr 2019 18:01:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B918328706 for ; Wed, 17 Apr 2019 18:01:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD9EC28B26; Wed, 17 Apr 2019 18:01: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 3F76F28706 for ; Wed, 17 Apr 2019 18:01:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732244AbfDQSBe (ORCPT ); Wed, 17 Apr 2019 14:01:34 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39859 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731968AbfDQSBd (ORCPT ); Wed, 17 Apr 2019 14:01:33 -0400 Received: by mail-pg1-f194.google.com with SMTP id k3so12356237pga.6 for ; Wed, 17 Apr 2019 11:01:33 -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=25BB9G9B49LVIFNoKqRFbyVLgzCBukpzISPRjgi3sOk=; b=qo57R9PBz0TmLB85IV4xkSAn47yOn8FJzM2Z/1YCT1OT8fzB/jiVsyMcWv4T4fcDmo OGwGCJRM5+kde+AS1pQA+chPPxONrhmZGLzrPTwqfxvmizDb9MpRl2hqPFyYOVDU8muw 0K3ZPRq54QD4r5fI0NTCflN/+8oiTFjQ7ezjg5GPwDM2pXjHczrNACf8za7YDHcDKj1t MPxsAeqHRLdJkVgvMIcqfQGtzsdEXV+GPAVnbV6nF6YivKR+tal5f9xzgvFr8tLzED9R W43LqyqbPfGvdtOKg8M0BgZwxZhOoZ4/tPVDVIojcUUepRG0+S8AWSyyLNd89FtHhrZP Y1gA== 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=25BB9G9B49LVIFNoKqRFbyVLgzCBukpzISPRjgi3sOk=; b=AhaDZrUxnPrwSA9EdxigNJaJWoah50mo2p5Ve+lOCWSyvzmCKtr0ihlSeDfqIanR5Y PjFwNZnyzO8cRLQzWVCMlm3/jN2T/qIkedeO8ELTdXEL8E3Lb0HIN+wS/n+89H9RxKOR yTj9P7lUCczLzB3P9ukhT2qV4GFjzfQ2OT4kM18MgLtKcYSBINwoiOFLTjMQNxr9OI6Z SF/1/4glSD2V6FrUd4ICzwejC3jrqHGxKZy5Dz4opDOye0/HBbAdhe/wbAeG47XN8xY+ /HrTZaNTfuHOvlcsaJd8ysFjSINKkxjZQZ48HUrVCxtBbvbt/laK6SjOsp+b2tf+IXB/ T5Ow== X-Gm-Message-State: APjAAAVFTy+e8s2GjP/djzhxiY1czalGC87BJtcChO9EyGwfDCNwG8MG SBnEmdj1ibPKs5sFW0GOD+6MSKFvek0= X-Google-Smtp-Source: APXvYqxvzUGOT1IIHiihRWohUMKG4O5X0U2/XfBFKxTuQB2Hj2I5PmwlfXlEbfe08Jpr0Z8ihsU5rQ== X-Received: by 2002:aa7:9888:: with SMTP id r8mr37072918pfl.116.1555524092514; Wed, 17 Apr 2019 11:01:32 -0700 (PDT) Received: from dev-l ([149.28.200.39]) by smtp.gmail.com with ESMTPSA id n26sm162551438pfi.165.2019.04.17.11.01.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 11:01:31 -0700 (PDT) Date: Wed, 17 Apr 2019 11:01:31 -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 v6 5/6] rebase: fast-forward --fork-point in more cases Message-ID: <0a466e830f7704f3ae75691db535946a3d57ddc9.1555523176.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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 f5aca1eee0..2e29ea652f 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; @@ -1702,9 +1706,9 @@ 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 if this is not 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 Wed Apr 17 18:01: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: 10905755 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 B98F0922 for ; Wed, 17 Apr 2019 18:01:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A06D328706 for ; Wed, 17 Apr 2019 18:01:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9479528B26; Wed, 17 Apr 2019 18:01:39 +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 7F1EF28706 for ; Wed, 17 Apr 2019 18:01:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732507AbfDQSBh (ORCPT ); Wed, 17 Apr 2019 14:01:37 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:34544 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731116AbfDQSBf (ORCPT ); Wed, 17 Apr 2019 14:01:35 -0400 Received: by mail-pg1-f193.google.com with SMTP id v12so12372618pgq.1 for ; Wed, 17 Apr 2019 11:01:34 -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=VgHeVfZ4JXet4urFM85LcKHE9ODyyaHX+LEXJBAiSGo=; b=MSgAn89UPNjcxpGsy/Jyq+Uwl+av1TYjljQ5jQx0ATK065Rj1S4+q77KlqY/WBSAXm 7tDxRtEFHL65DPFRIdMdBXTEWDHb9FCE1T2GNXpz9liImlu8qItxAxa6I6/3b7iZRl94 VL+du5YPMcslpRPlQNTHQqGB4o7GjZqqehP/GrYdvA3A8VONEWJlZ7wQ8hVND3f+TKNo COouM7P/KSyXGN/JYogv10dFL4DAiCgSgUmySaokq2zxzuJ3HUgBv1H6VirYtFl5I9R9 Yd9OEvrjdqcbJzF/RhWbwz/mvmMQTd9Vy7pmWX9j8nzH6qg7RQsEX3QUhNc7INh+wTa6 33PA== 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=VgHeVfZ4JXet4urFM85LcKHE9ODyyaHX+LEXJBAiSGo=; b=R1QtYOr0Ik1Bj5YQ+Z+wPl1VhxbcGnx2Ti49O+VF1MYGZi9eBzL2ae5PAxlblWb09W f20zl0v8Pz6p69cZ77qldsCu4YqUQq3pujWx94csEUdVoSvX+rFq+lLBITZ9GnStJyRD AUH8HPRh1VNn39UU3ttIWer6Sbsg13TFDp3dEpwNSrBx+DMLe5uFPwXz87/vTHYUlr5n K6Ugyxg6XD8r7Kz+ni7by+esvnPNb1ZKubXVfpnMZSW7G3H9pmNaXmmCyIF5nFOsKI0B tiTQVmypZc8UZcTpKDB6FY3H6gDTIDlE6WWgfZIL2VgHic6ZPxFy0woCGF2mZLgfUMM0 RO7Q== X-Gm-Message-State: APjAAAVWnHhW7knxYGNWq56B5UtN0p78ieLO9XpSrtHZJ0gKmBrL7oqd wn0dBFFtY46mLeKeyAWfwdtu6mtnDBQ= X-Google-Smtp-Source: APXvYqynnP5YfU2HP/+I9TXR6h6i2o7agkjJCOEpZev9ljlRe7+R6nEZXKPwA9/sDUOeEcnhunlIFw== X-Received: by 2002:a63:5d44:: with SMTP id o4mr3504029pgm.15.1555524093856; Wed, 17 Apr 2019 11:01:33 -0700 (PDT) Received: from dev-l ([149.28.200.39]) by smtp.gmail.com with ESMTPSA id y1sm105045392pgc.29.2019.04.17.11.01.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 11:01:33 -0700 (PDT) Date: Wed, 17 Apr 2019 11:01: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 v6 6/6] rebase: teach rebase --keep-base Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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 ++++++++++++++---- t/t3416-rebase-onto-threedots.sh | 57 ++++++++++++++++++++++++++++++++ t/t3431-rebase-fork-point.sh | 4 +++ t/t3432-rebase-fast-forward.sh | 11 ++++++ 5 files changed, 125 insertions(+), 9 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=