From patchwork Thu Feb 28 15:27:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 10833351 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 30EDF17E9 for ; Thu, 28 Feb 2019 15:28:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20FC12E4B7 for ; Thu, 28 Feb 2019 15:28:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1500F2EF84; Thu, 28 Feb 2019 15:28:00 +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 A2E4C2E4B7 for ; Thu, 28 Feb 2019 15:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387846AbfB1P16 (ORCPT ); Thu, 28 Feb 2019 10:27:58 -0500 Received: from mail-ed1-f51.google.com ([209.85.208.51]:41229 "EHLO mail-ed1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387458AbfB1P1s (ORCPT ); Thu, 28 Feb 2019 10:27:48 -0500 Received: by mail-ed1-f51.google.com with SMTP id x7so17286714eds.8 for ; Thu, 28 Feb 2019 07:27:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=8LfcSrLOEv9iR3BQW0qnYzjf0jxEkvjaoepxZHwCoxE=; b=lNw28W0BaKKjGExkF5O3n0f+SlJWXM7PS5c7nTfCHwC1zb1qeF74WLFKN7Hvgn/vFz YT01XA1Q49259N0AsS5CvMdS5gn3DyjJiBNlu0Sn7VIg6vszVQ+GGbwLUyMoreEqKi8o HG/S7j0XteYi5+Yc4DhjpwwPFH+V2toXZHAL1uSN5Y9uCBgMG/eGy/QTVLD9OcnW3CW5 Hi0JNdj9TDip+l1m5DbybHGAvTeebubDpmq/BLnQ6VHuUfs6Z6RAmdimTeIH8TFRHln9 0SWAmbA8dlxEK8TsR2pna0CsrWMayKfkg15GwLTeNLb3SfVM13zqLb2YBvWT9bWDOO85 qoLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=8LfcSrLOEv9iR3BQW0qnYzjf0jxEkvjaoepxZHwCoxE=; b=GJfm025DTfiVGzOFC1mcpkIXUAHwdhOuQkaQqsgjoGIUiqz+INQ7p6/FYr+RGKdIZh yBMsOnqoGCvkMDCAe4ZF2viRYUC+tMMQf7x3Lb1zNR2rq8fUeCPkkgJ12vTKEYTHJ1sl zvfbliLMtMeaozFsSqr1ku7DpqF+y6pmZWh/pIhZPd4mgFq94aojA5LFZGdAQ3uDbEQ3 hfVhjh9B/DnbK3emaKSURQZp24Rqry8CXPWKz9vvKhOUPUF/KZXjT/cJHC3cOfvwyrod 6dhil4jJwVi7R3aPUOGL+eV5IdlGARi1Ci5j54qS/K1a1DTGcfT4UAuhR3w2RbgPqORz +XLw== X-Gm-Message-State: AHQUAuYXG54srwwjhlLl7RG9Bl/e1xSe3p1cFj2xhtf1e3wjALMlKr3M GW4sss0+8rmNyQCCIzzb2n44EPjG X-Google-Smtp-Source: AHgI3IZ5icmmuZtFs9GXIaF6Tl6CceavNeOx/LuPtYRixd13poi/Ma4uJL/OfvsJH0U9QGHpMxCfmQ== X-Received: by 2002:a17:906:3b8e:: with SMTP id u14mr5849224ejf.130.1551367666071; Thu, 28 Feb 2019 07:27:46 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t25sm1527257eda.69.2019.02.28.07.27.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 07:27:45 -0800 (PST) Date: Thu, 28 Feb 2019 07:27:45 -0800 (PST) X-Google-Original-Date: Thu, 28 Feb 2019 15:27:41 GMT Message-Id: <2d99429387ba63526efe233bbefe851c5d556fdc.1551367664.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 1/4] built-in rebase: no need to check out `onto` twice Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Nazri Ramliy , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin In the case that the rebase boils down to a fast-forward, the built-in rebase reset the working tree twice: once to start the rebase at `onto`, then realizing that the original HEAD was an ancestor, `reset_head()` was called to update the original ref and to point HEAD back to it. That second `reset_head()` call does not need to touch the working tree, though, as it does not change the actual tip commit. So let's avoid that unnecessary work. Signed-off-by: Johannes Schindelin --- builtin/rebase.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 08ec4d52c7..813ec284ca 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1740,8 +1740,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "rebase finished: %s onto %s", options.head_name ? options.head_name : "detached HEAD", oid_to_hex(&options.onto->object.oid)); - reset_head(NULL, "Fast-forwarded", options.head_name, 0, - "HEAD", msg.buf); + reset_head(NULL, "Fast-forwarded", options.head_name, + RESET_HEAD_REFS_ONLY, "HEAD", msg.buf); strbuf_release(&msg); ret = !!finish_rebase(&options); goto cleanup; From patchwork Thu Feb 28 15:27:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 10833347 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 079A61399 for ; Thu, 28 Feb 2019 15:27:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC2232E4B7 for ; Thu, 28 Feb 2019 15:27:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDA372EF84; Thu, 28 Feb 2019 15:27:55 +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 88D072E4B7 for ; Thu, 28 Feb 2019 15:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389100AbfB1P1t (ORCPT ); Thu, 28 Feb 2019 10:27:49 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:40377 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388109AbfB1P1s (ORCPT ); Thu, 28 Feb 2019 10:27:48 -0500 Received: by mail-ed1-f65.google.com with SMTP id 10so17308110eds.7 for ; Thu, 28 Feb 2019 07:27:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qeKfQwcLlkFWz4gPjlZ2UmNVoHDBzu39T3HJbs1zShg=; b=mnP5ZO9uOGJUdt//pAs/Hh6mzjo49y2h5idaPmQVIA6/j8NcU3GCIS/RTQx/Q4sne3 E/V3p8R3jGnu6z7zM4yy8FVvFAdLtOzyth6Un1DJnw+x+DciQ5qzTnYBtUGcCiGezihW NB4anAOcWzkRjBSGC9NudIICeLGGM+31/5dVs1n/zMgsB9jJLvwwSYHPkjx4RU9fAMUg +4Zas+T0MYFfVFQq7JZF4sYXvB1N1IvB+x95RopGe2n1nTb9NoBmCxi9L/Vxqxbi6eQL jpBr0kZ0aCiJWBAtgJ9khEOpcDbMYrdH49DzpAF5DiSIc3os0L/9VSlhViDIoDrE6QbC QMVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qeKfQwcLlkFWz4gPjlZ2UmNVoHDBzu39T3HJbs1zShg=; b=K8BQqHeUpAOWNhgeXnV0ArEal6KO+4VEd8rUfQyK+QD2IcTdbXJSuGrzSOBaqog57l VVMbi57BoEC5EGLgCA39kV6hRBcfe4wRxnrBDBQBaLQ8ZR6tfZLBhGeUK95+Gh+zTwKu +t4dF0JHrUR9JpLzEKnHdrQGK7tOJDvhfBu9NvrpbOJG9EX2X5Qiv4MYOXUJa5DqoWYQ YAgNwqqA0e1FVaQ16AsfmLmnlZaSFBmQx/fNwIwpGkHpA3fNOKgOFZF8gqbtEPTp1CCA 3QoOToLhbKLA+UBoqYL4aVyDQKElwzhg0PtrpjeyQXS1petv/eQTJfr2lyg6+jP8pEua swbQ== X-Gm-Message-State: APjAAAVjDtffZ6CYX0ZOW3rHH59HpBvgP1OowWD6HT0MLPku+x/HmtDK s0AdmtCd3iXkfRPTapspEDcluMMj X-Google-Smtp-Source: APXvYqzK0VDIfYGX/fBwH02bwotpw93leW7c86g6fMfPVnOPK6AnfCekTZXdDS+vrO8XfV8XxWxxWw== X-Received: by 2002:a50:b1cd:: with SMTP id n13mr137674edd.224.1551367666905; Thu, 28 Feb 2019 07:27:46 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h27sm3205289eja.73.2019.02.28.07.27.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 07:27:46 -0800 (PST) Date: Thu, 28 Feb 2019 07:27:46 -0800 (PST) X-Google-Original-Date: Thu, 28 Feb 2019 15:27:42 GMT Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 2/4] built-in rebase: use the correct reflog when switching branches Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Nazri Ramliy , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin By mistake, we used the reflog intended for ORIG_HEAD. Signed-off-by: Johannes Schindelin --- builtin/rebase.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 813ec284ca..aa469ec964 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -475,7 +475,7 @@ static int reset_head(struct object_id *oid, const char *action, detach_head ? REF_NO_DEREF : 0, UPDATE_REFS_MSG_ON_ERR); else { - ret = update_ref(reflog_orig_head, switch_to_branch, oid, + ret = update_ref(reflog_head, switch_to_branch, oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); if (!ret) ret = create_symref("HEAD", switch_to_branch, From patchwork Thu Feb 28 15:27:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 10833343 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 CD8CA17E9 for ; Thu, 28 Feb 2019 15:27:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB0F12E4B7 for ; Thu, 28 Feb 2019 15:27:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF5662F20C; Thu, 28 Feb 2019 15:27:52 +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 593302E4B7 for ; Thu, 28 Feb 2019 15:27:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389115AbfB1P1u (ORCPT ); Thu, 28 Feb 2019 10:27:50 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:45823 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730287AbfB1P1t (ORCPT ); Thu, 28 Feb 2019 10:27:49 -0500 Received: by mail-ed1-f66.google.com with SMTP id f19so7930645eds.12 for ; Thu, 28 Feb 2019 07:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=w9D51nzePpOyGIwULQ/4KBCN7t8Dy6bXd4Z3X/qKuvQ=; b=O2zFk3pswYnXlS9IjhTIowQVn22uwW/FFz2xHUubD6AnffjDXeUxEn3awcIYTTEXa0 rZBt2D+vXF0QhQFbwelKP8S8GPE3UVnaKsIa2u8gj9QmcNzIewAn7m9brudE5D4ywcik S5uaix+owMqNzk1nq1TVs7pTJsUrOXCFtD7VBitWmsrf2cXBBXSfCkrLxofLy3rjJ6CO /ZYIE48yAmfxvyDumuS11rpY2LN9OuRAuIRKrizN+7fApESAxpGY3vL6rsZZUdR2XS2x BUHkypddlP3PrY1mR/wvU6u5HHYsdoy3+saZ1V5lu6G6PwRwEt9OyW7qdIQHwwkkK7as 5fcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=w9D51nzePpOyGIwULQ/4KBCN7t8Dy6bXd4Z3X/qKuvQ=; b=ka6G3iwFMvYlr72U0ooJJOP16hU55Q2zS8LikcIhENlfX59ayCniA4IHCTOrmC5MM3 QVJ0au1jZy+AovBXwS6KpWwfZ9VOstwVjPSt+ibXuxChrFdKIcPAc5Fw4ForuMzYyy7J bfytmxyUtHZmikB2FTlQG48esyXCyjhH2YHL19B0lvH0RM3OcLp3HCUlhJCRkNOuLUgo 2QR5ebooVjm1Nu1dqUcX9rVc5JuMK4L2bZWXdmy+p/8n9PI4KKC1wvv1OH7fsz5tatDH oOlmxSL7G3qHQtJtMWPeu3Zui/j0eFsFxdIDDs8GSh4vZ6idLJn54cV0yjPWl/j8GOcY +XnA== X-Gm-Message-State: APjAAAWjZHzxHlO0NvAihpA1oxhWSWkZXXmIyMCVfkp3GRO0qQNgGsLd TqI2F8DHpZxJS1iTTK4e8tpxt1B+ X-Google-Smtp-Source: APXvYqxCVEiAV1Wk7Vp08G0r/1bt0f4tydzP97ufd4RJJ25FYcD0sJLh4fZZpAE8XoUe2pbbCRgJ5Q== X-Received: by 2002:a50:9012:: with SMTP id b18mr166567eda.30.1551367667503; Thu, 28 Feb 2019 07:27:47 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g20sm3279735ejk.72.2019.02.28.07.27.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 07:27:47 -0800 (PST) Date: Thu, 28 Feb 2019 07:27:47 -0800 (PST) X-Google-Original-Date: Thu, 28 Feb 2019 15:27:43 GMT Message-Id: <1bc3cbad265926d963655a0112db74e2c655adb4.1551367664.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 3/4] built-in rebase: demonstrate that ORIG_HEAD is not set correctly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Nazri Ramliy , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin The ORIG_HEAD pseudo ref is supposed to refer to the original, pre-rebase state after a successful rebase. Let's add a regression test to prove that this regressed: With GIT_TEST_REBASE_USE_BUILTIN=false, this test case passes, with GIT_TEST_REBASE_USE_BUILTIN=true (or unset), it fails. Reported by Nazri Ramliy. Signed-off-by: Johannes Schindelin --- t/t3400-rebase.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 3e73f7584c..7e8d5bb200 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -59,6 +59,14 @@ test_expect_success 'rebase against master' ' git rebase master ' +test_expect_failure 'rebase sets ORIG_HEAD to pre-rebase state' ' + git checkout -b orig-head topic && + pre="$(git rev-parse --verify HEAD)" && + git rebase master && + test_cmp_rev "$pre" ORIG_HEAD && + ! test_cmp_rev "$pre" HEAD +' + test_expect_success 'rebase, with and specified as :/quuxery' ' test_when_finished "git branch -D torebase" && git checkout -b torebase my-topic-branch^ && From patchwork Thu Feb 28 15:27:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 10833345 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 D8D7617E9 for ; Thu, 28 Feb 2019 15:27:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C44E22E4B7 for ; Thu, 28 Feb 2019 15:27:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B89542F1D5; Thu, 28 Feb 2019 15:27:53 +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 4DB632E4B7 for ; Thu, 28 Feb 2019 15:27:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388623AbfB1P1u (ORCPT ); Thu, 28 Feb 2019 10:27:50 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:32895 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388345AbfB1P1u (ORCPT ); Thu, 28 Feb 2019 10:27:50 -0500 Received: by mail-ed1-f68.google.com with SMTP id c55so17347417edb.0 for ; Thu, 28 Feb 2019 07:27:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=g+pGs+pPQS4yupX4F+r6Rl4wu7svmR1go94XtrRFlIY=; b=vVtemPVYE9nOT+i1sR+CLA9S8dt6P5DJP7zPhNMnzjbyCwgWWL9zmI0ABjcZMhDr4j JxwOTz31f66ZNG7bM9AtWv++hSe2UYiT+K8ELB5d//nIIEjknQ9bA3fgdb6S5rnrgH21 qTGruDcz4EM/I9MA/yx6cJUz/Ko9l04UH10Lk8hHipbq7wMknzdRTzSfjY8/lMhyITGl KVCRP3weUQJmNsxBGD+CkokLhHfMT0J0OuQixK8DaWpF3R7YooFY0c9FRghauP7qfQwX yK4tXtiiAvJlwjo72qAlfHhkVBfFVF26bPswnBykgq1aNjOfXuiybI6LKT0kR2+MSSaE WSMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=g+pGs+pPQS4yupX4F+r6Rl4wu7svmR1go94XtrRFlIY=; b=kXXoVxbOKFUeyj2rdwjPtoKYsVfp0t/nMgO0OQRf6DFisg/4mEgSkeeznOAiX/8sbk 8+6ggs0ngPLNyc3XBKjd9VDeYfbZ5W33t+MprHixz2+QACRle1zZJsnOdNLh4Z8p1S9s 4fTJ8sAK4lpfmPgYaac/gR6W11ziwbh1uQfIk52G75oLgMYcfliTHGjI840b5LWFidUH EZawdYkc3xLj2dJMLWp6M4/vWYqCMo5x+P2ByM75+FsfCFtyg/PyMbz/DUTerXXLg8e6 d6Xjoo0xQNeHpBp8QO8qZu7/EaMC93xSOvX8ZZbvXYTn6cYRBS7vDV9fNHWJ3bYC01mr tr2w== X-Gm-Message-State: APjAAAV/1q0ifX0UD9ot+ZgH4eu79jcfeAdKLPUCbx1LbaMLFtUlXGfQ kEKWziyw7zEtZg/6e+7AW3aGFqBQ X-Google-Smtp-Source: AHgI3IYrGU+4u0p/968QU/wBKTbPwQHuImJT6BA8RHpdSK0LxXPvxoVXD+agdx2cc/KUQ+17xosOjQ== X-Received: by 2002:a50:ac09:: with SMTP id v9mr124664edc.3.1551367668338; Thu, 28 Feb 2019 07:27:48 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b29sm5184258eda.48.2019.02.28.07.27.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 07:27:47 -0800 (PST) Date: Thu, 28 Feb 2019 07:27:47 -0800 (PST) X-Google-Original-Date: Thu, 28 Feb 2019 15:27:44 GMT Message-Id: <1786c172effb38fa44cea0c1d98de604602a5634.1551367664.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 4/4] built-in rebase: set ORIG_HEAD just once, before the rebase Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Nazri Ramliy , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin Technically, the scripted version set ORIG_HEAD only in two spots (which really could have been one, because it called `git checkout $onto^0` to start the rebase and also if it could take a shortcut, and in both cases it called `git update-ref $orig_head`). Practically, it *implicitly* reset ORIG_HEAD whenever `git reset --hard` was called. However, what we really want is that it is set exactly once, at the beginning of the rebase. So let's do that. Signed-off-by: Johannes Schindelin --- builtin/rebase.c | 31 ++++++++++++++++++------------- t/t3400-rebase.sh | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index aa469ec964..0f4e1ead49 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -369,6 +369,7 @@ static void add_var(struct strbuf *buf, const char *name, const char *value) #define RESET_HEAD_DETACH (1<<0) #define RESET_HEAD_HARD (1<<1) #define RESET_HEAD_REFS_ONLY (1<<2) +#define RESET_ORIG_HEAD (1<<3) static int reset_head(struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -377,6 +378,7 @@ static int reset_head(struct object_id *oid, const char *action, unsigned detach_head = flags & RESET_HEAD_DETACH; unsigned reset_hard = flags & RESET_HEAD_HARD; unsigned refs_only = flags & RESET_HEAD_REFS_ONLY; + unsigned update_orig_head = flags & RESET_ORIG_HEAD; struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; @@ -453,18 +455,21 @@ static int reset_head(struct object_id *oid, const char *action, strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase"); prefix_len = msg.len; - if (!get_oid("ORIG_HEAD", &oid_old_orig)) - old_orig = &oid_old_orig; - if (!get_oid("HEAD", &oid_orig)) { - orig = &oid_orig; - if (!reflog_orig_head) { - strbuf_addstr(&msg, "updating ORIG_HEAD"); - reflog_orig_head = msg.buf; - } - update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0, - UPDATE_REFS_MSG_ON_ERR); - } else if (old_orig) - delete_ref(NULL, "ORIG_HEAD", old_orig, 0); + if (update_orig_head) { + if (!get_oid("ORIG_HEAD", &oid_old_orig)) + old_orig = &oid_old_orig; + if (!get_oid("HEAD", &oid_orig)) { + orig = &oid_orig; + if (!reflog_orig_head) { + strbuf_addstr(&msg, "updating ORIG_HEAD"); + reflog_orig_head = msg.buf; + } + update_ref(reflog_orig_head, "ORIG_HEAD", orig, + old_orig, 0, UPDATE_REFS_MSG_ON_ERR); + } else if (old_orig) + delete_ref(NULL, "ORIG_HEAD", old_orig, 0); + } + if (!reflog_head) { strbuf_setlen(&msg, prefix_len); strbuf_addstr(&msg, "updating HEAD"); @@ -1725,7 +1730,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, NULL, msg.buf)) + RESET_HEAD_DETACH | RESET_ORIG_HEAD, NULL, msg.buf)) die(_("Could not detach HEAD")); strbuf_release(&msg); diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 7e8d5bb200..460d0523be 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -59,7 +59,7 @@ test_expect_success 'rebase against master' ' git rebase master ' -test_expect_failure 'rebase sets ORIG_HEAD to pre-rebase state' ' +test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' ' git checkout -b orig-head topic && pre="$(git rev-parse --verify HEAD)" && git rebase master &&