From patchwork Fri Jan 18 15:09:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10770617 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 F0E98186E for ; Fri, 18 Jan 2019 15:09:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE61A2E0B0 for ; Fri, 18 Jan 2019 15:09:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2DE82E0FE; Fri, 18 Jan 2019 15:09: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 1F24D2DFDD for ; Fri, 18 Jan 2019 15:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727755AbfARPJ2 (ORCPT ); Fri, 18 Jan 2019 10:09:28 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:43868 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727448AbfARPJ1 (ORCPT ); Fri, 18 Jan 2019 10:09:27 -0500 Received: by mail-ed1-f68.google.com with SMTP id f9so11346179eds.10 for ; Fri, 18 Jan 2019 07:09:26 -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=yrJPdEdi6W38ctW75TQeUk4t5HU9FnnOCPf3eM5gtgI=; b=FYdLvofNJrtn/E15jSmsb5qbaMYzizplzhIde3EKF+lORK0NxfkYyizixderG2dg9w 6l9j+gT2cbk6rF5iYtVGMUXzXKilv8bNF6LoHHnWsy8sToW7LnuIUg8TuVAIezsaNjHl UkXsWBzZlzKE9wL8K0X/pu3SzHknILpajDsgjmL9UMBG7PFNSwkt+jysNr+/Xo5CivW0 +DgQLDF0DA7jyFakZhn1zyRh76iRBbDB2kN54p+FMo4VyjN650tqKjCBOcaMaELBm69b 1QG5IK2/kTwpWAdm9jgQtxasBI0Q1yJiXlrzcSxqBihOwfPK+MEIRegbnUKORCU/ULNy hBBA== 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=yrJPdEdi6W38ctW75TQeUk4t5HU9FnnOCPf3eM5gtgI=; b=O39OulthhDNUkkq3em1fVnIZJF1Z35iw8gNDCZaGdWYgFOqNyWcc92wrBqS/blG97Y 2vmSIeZJyOk2+CX3EAzx45RBdc9f4w5fGZ1Zcp0dJw+RRVbjeAciZC6jHt+d5RQotDSy Gs0lynWnnhY/0egSZz3+Ltnp72BkLmFO0RaMBw7EMSUFlw4I/7bvZVsHAGRiIFfMI3IZ jyoX/Pd6/Sc2QoKroo3+SnG56Qi2wv1v5nJnyQIXrlpHsg+iauWO3imOu+4jWziWEVA8 W8ysiaF0c+1CgcJBNnDnBeTgx8yAe703YF8IaK7QZWlX54bkEZDZAtQnJNbb0coBzyQ6 GOvw== X-Gm-Message-State: AJcUukcoNo8qaj9Btu5TXkhGxR1Tgx7MP35QNH+CRqhdMJxuJemPrWjf UwC9OAM7yLCrKx4OIpFhTnBUsbr2 X-Google-Smtp-Source: ALg8bN6TBJpy/Y78mg6Z6kIC4f5Mlg9eDgGTxD8hZG4axMNbmbi7Y5QfSFbWzYGY/LxdMN33wUo3Nw== X-Received: by 2002:aa7:db0e:: with SMTP id t14mr16309690eds.292.1547824165471; Fri, 18 Jan 2019 07:09:25 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q16sm6794828eds.60.2019.01.18.07.09.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 07:09:24 -0800 (PST) Date: Fri, 18 Jan 2019 07:09:24 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 15:09:19 GMT Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH v2 1/4] rebase: move `reset_head()` into a better spot Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 Over the next commits, we want to make use of it in `run_am()` (i.e. running the `--am` backend directly, without detouring to Unix shell script code) which in turn will be called from `run_specific_rebase()`. So let's move it before that latter function. This commit is best viewed using --color-moved. Signed-off-by: Johannes Schindelin --- builtin/rebase.c | 238 +++++++++++++++++++++++------------------------ 1 file changed, 119 insertions(+), 119 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 00de70365e..efa90ca894 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -333,6 +333,125 @@ static void add_var(struct strbuf *buf, const char *name, const char *value) } } +#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" + +#define RESET_HEAD_DETACH (1<<0) +#define RESET_HEAD_HARD (1<<1) + +static int reset_head(struct object_id *oid, const char *action, + const char *switch_to_branch, unsigned flags, + const char *reflog_orig_head, const char *reflog_head) +{ + unsigned detach_head = flags & RESET_HEAD_DETACH; + unsigned reset_hard = flags & RESET_HEAD_HARD; + struct object_id head_oid; + struct tree_desc desc[2] = { { NULL }, { NULL } }; + struct lock_file lock = LOCK_INIT; + struct unpack_trees_options unpack_tree_opts; + struct tree *tree; + const char *reflog_action; + struct strbuf msg = STRBUF_INIT; + size_t prefix_len; + struct object_id *orig = NULL, oid_orig, + *old_orig = NULL, oid_old_orig; + int ret = 0, nr = 0; + + if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) + BUG("Not a fully qualified branch: '%s'", switch_to_branch); + + if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) { + ret = -1; + goto leave_reset_head; + } + + if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) { + ret = error(_("could not determine HEAD revision")); + goto leave_reset_head; + } + + if (!oid) + oid = &head_oid; + + memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); + setup_unpack_trees_porcelain(&unpack_tree_opts, action); + unpack_tree_opts.head_idx = 1; + unpack_tree_opts.src_index = the_repository->index; + unpack_tree_opts.dst_index = the_repository->index; + unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; + unpack_tree_opts.update = 1; + unpack_tree_opts.merge = 1; + if (!detach_head) + unpack_tree_opts.reset = 1; + + if (read_index_unmerged(the_repository->index) < 0) { + ret = error(_("could not read index")); + goto leave_reset_head; + } + + if (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) { + ret = error(_("failed to find tree of %s"), + oid_to_hex(&head_oid)); + goto leave_reset_head; + } + + if (!fill_tree_descriptor(&desc[nr++], oid)) { + ret = error(_("failed to find tree of %s"), oid_to_hex(oid)); + goto leave_reset_head; + } + + if (unpack_trees(nr, desc, &unpack_tree_opts)) { + ret = -1; + goto leave_reset_head; + } + + tree = parse_tree_indirect(oid); + prime_cache_tree(the_repository, the_repository->index, tree); + + if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) { + ret = error(_("could not write index")); + goto leave_reset_head; + } + + reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); + 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 (!reflog_head) { + strbuf_setlen(&msg, prefix_len); + strbuf_addstr(&msg, "updating HEAD"); + reflog_head = msg.buf; + } + if (!switch_to_branch) + ret = update_ref(reflog_head, "HEAD", oid, orig, + detach_head ? REF_NO_DEREF : 0, + UPDATE_REFS_MSG_ON_ERR); + else { + ret = create_symref("HEAD", switch_to_branch, msg.buf); + if (!ret) + ret = update_ref(reflog_head, "HEAD", oid, NULL, 0, + UPDATE_REFS_MSG_ON_ERR); + } + +leave_reset_head: + strbuf_release(&msg); + rollback_lock_file(&lock); + while (nr) + free((void *)desc[--nr].buffer); + return ret; +} + static const char *resolvemsg = N_("Resolve all conflicts manually, mark them as resolved with\n" "\"git add/rm \", then run \"git rebase --continue\".\n" @@ -526,125 +645,6 @@ static int run_specific_rebase(struct rebase_options *opts) return status ? -1 : 0; } -#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" - -#define RESET_HEAD_DETACH (1<<0) -#define RESET_HEAD_HARD (1<<1) - -static int reset_head(struct object_id *oid, const char *action, - const char *switch_to_branch, unsigned flags, - const char *reflog_orig_head, const char *reflog_head) -{ - unsigned detach_head = flags & RESET_HEAD_DETACH; - unsigned reset_hard = flags & RESET_HEAD_HARD; - struct object_id head_oid; - struct tree_desc desc[2] = { { NULL }, { NULL } }; - struct lock_file lock = LOCK_INIT; - struct unpack_trees_options unpack_tree_opts; - struct tree *tree; - const char *reflog_action; - struct strbuf msg = STRBUF_INIT; - size_t prefix_len; - struct object_id *orig = NULL, oid_orig, - *old_orig = NULL, oid_old_orig; - int ret = 0, nr = 0; - - if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) - BUG("Not a fully qualified branch: '%s'", switch_to_branch); - - if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) { - ret = -1; - goto leave_reset_head; - } - - if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) { - ret = error(_("could not determine HEAD revision")); - goto leave_reset_head; - } - - if (!oid) - oid = &head_oid; - - memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); - setup_unpack_trees_porcelain(&unpack_tree_opts, action); - unpack_tree_opts.head_idx = 1; - unpack_tree_opts.src_index = the_repository->index; - unpack_tree_opts.dst_index = the_repository->index; - unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; - unpack_tree_opts.update = 1; - unpack_tree_opts.merge = 1; - if (!detach_head) - unpack_tree_opts.reset = 1; - - if (read_index_unmerged(the_repository->index) < 0) { - ret = error(_("could not read index")); - goto leave_reset_head; - } - - if (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) { - ret = error(_("failed to find tree of %s"), - oid_to_hex(&head_oid)); - goto leave_reset_head; - } - - if (!fill_tree_descriptor(&desc[nr++], oid)) { - ret = error(_("failed to find tree of %s"), oid_to_hex(oid)); - goto leave_reset_head; - } - - if (unpack_trees(nr, desc, &unpack_tree_opts)) { - ret = -1; - goto leave_reset_head; - } - - tree = parse_tree_indirect(oid); - prime_cache_tree(the_repository, the_repository->index, tree); - - if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) { - ret = error(_("could not write index")); - goto leave_reset_head; - } - - reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); - 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 (!reflog_head) { - strbuf_setlen(&msg, prefix_len); - strbuf_addstr(&msg, "updating HEAD"); - reflog_head = msg.buf; - } - if (!switch_to_branch) - ret = update_ref(reflog_head, "HEAD", oid, orig, - detach_head ? REF_NO_DEREF : 0, - UPDATE_REFS_MSG_ON_ERR); - else { - ret = create_symref("HEAD", switch_to_branch, msg.buf); - if (!ret) - ret = update_ref(reflog_head, "HEAD", oid, NULL, 0, - UPDATE_REFS_MSG_ON_ERR); - } - -leave_reset_head: - strbuf_release(&msg); - rollback_lock_file(&lock); - while (nr) - free((void *)desc[--nr].buffer); - return ret; -} - static int rebase_config(const char *var, const char *value, void *data) { struct rebase_options *opts = data; From patchwork Fri Jan 18 15:09:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10770621 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 CC5E2186E for ; Fri, 18 Jan 2019 15:09:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8A2E2DFDD for ; Fri, 18 Jan 2019 15:09:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC7832E361; Fri, 18 Jan 2019 15:09: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 5C2FB2DFDD for ; Fri, 18 Jan 2019 15:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbfARPJa (ORCPT ); Fri, 18 Jan 2019 10:09:30 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:38144 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727406AbfARPJ2 (ORCPT ); Fri, 18 Jan 2019 10:09:28 -0500 Received: by mail-ed1-f68.google.com with SMTP id h50so11374257ede.5 for ; Fri, 18 Jan 2019 07:09:27 -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=FIyLCbey3PbXvVqkh1z5koLrEsdzO2fqsBTPCaHKMFk=; b=msXSrC5i0uCODRx4UkoS9NHIMO1z8srmShbqhP7SGQ/z3YY0PfIfRK04LGEe/D/RYV cQwm/urxQxCp2A8ZvRZHD/Mzw8ecNJ3tnHqAknw8D3JVIfUw03k51VcsBLmcpBaXBTve YQNdn6uDzgWF0liiPltgkn61qRF6PcMGQsmS9U2RX+8UL+ntis1QpakYymLOZA0nVNoM kfoYbZC0BL2UukvQCWPcGOyxVEJ61jxf+OWqS98pDVup1cuLbdZ807pxFUqry5/bZeMz rFkdB+zHvmuQBt1DnHw+htirgjnKkJp7Q+LLe1y3diZkdGVJwSgx4PiTNjhMpRflAcfO UnbA== 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=FIyLCbey3PbXvVqkh1z5koLrEsdzO2fqsBTPCaHKMFk=; b=gZzOTylRx7LaBRrYNPIRCpY25ybPtbgAwTt3tXwIqeyIsaozDyhtrvTPj6XZBLskmu tgSDwxVZ6u8yGrY/cqcVFcbbSHyoK2/EPAg54Z4beITAOUVkmOv4p8a8peyVoVb2Akbs xgkEJWBNPvx9kljIUz77XvaO0jRS9pggcqe2FCjiZu367Jw5JZMXzyY2zyXRnImjShYa 4Me7cMoavHBb/3Ec3X7Ig9ALS2KWtLpfmLSKKTK/kRpWAO30Me7CVqkJKKhA+KctcUWu rXy+CeBBFU+Vak+CizUPasM4/VvRyCvkaaMpt4wf1UY146UG0CD0NWn3Zzvb+iMlmmSh Uelw== X-Gm-Message-State: AJcUukehayL6LEHEetmh3o5jqt6Mpvbi7uglcuo9c2U/n2xhSvqF5U38 gItvHyfsHrtbckTPq8mhyqwfp660 X-Google-Smtp-Source: ALg8bN7ryLajKN6FWu8fpTV1TUC+Bqw8Avn8DuINrI2H7QcWcmdcbjuDiecv+7buXHwbhM4qlNY7vQ== X-Received: by 2002:a50:cc04:: with SMTP id m4mr16534862edi.171.1547824166670; Fri, 18 Jan 2019 07:09:26 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p36sm7280927edc.78.2019.01.18.07.09.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 07:09:25 -0800 (PST) Date: Fri, 18 Jan 2019 07:09:25 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 15:09:20 GMT Message-Id: <3a68f1c509a357447bddf8bae6f1685b47673f89.1547824162.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH v2 2/4] rebase: avoid double reflog entry when switching branches Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 When switching a branch *and* updating said branch to a different revision, let's avoid a double entry in HEAD's reflog by first updating the branch and then adjusting the symbolic ref HEAD. Signed-off-by: Johannes Schindelin --- builtin/rebase.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index efa90ca894..5c827b2f03 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -438,10 +438,11 @@ static int reset_head(struct object_id *oid, const char *action, detach_head ? REF_NO_DEREF : 0, UPDATE_REFS_MSG_ON_ERR); else { - ret = create_symref("HEAD", switch_to_branch, msg.buf); + ret = update_ref(reflog_orig_head, switch_to_branch, oid, + NULL, 0, UPDATE_REFS_MSG_ON_ERR); if (!ret) - ret = update_ref(reflog_head, "HEAD", oid, NULL, 0, - UPDATE_REFS_MSG_ON_ERR); + ret = create_symref("HEAD", switch_to_branch, + reflog_head); } leave_reset_head: From patchwork Fri Jan 18 15:09:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10770625 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 98063139A for ; Fri, 18 Jan 2019 15:09:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8611B2DFDD for ; Fri, 18 Jan 2019 15:09:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A80D2E0B0; Fri, 18 Jan 2019 15:09: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 224582DFDD for ; Fri, 18 Jan 2019 15:09:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727777AbfARPJb (ORCPT ); Fri, 18 Jan 2019 10:09:31 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:36336 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727448AbfARPJ3 (ORCPT ); Fri, 18 Jan 2019 10:09:29 -0500 Received: by mail-ed1-f66.google.com with SMTP id f23so11394189edb.3 for ; Fri, 18 Jan 2019 07:09:28 -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=EguGS/Ij6ZWIXe+6jbCGARauW7KnnwKr0BDH5wbiM3A=; b=Ureo0Gc7Vo9o9peMkn04hzseLDaZT1NvJSfNjfluXGyyFZ+f84xPKVB+I1MGpKTAcT H/jIzh71mDqKusvE2gkCgIA6uF4A+6syAwNHPewDkMFe/dQ3jGVZFZLO+WyVycyc1FoA vmHj6AGEZksRvqAKWI1X8/KGs/1D1PRltTjKuhkLZC16AdzfhElhkoA2aqBK2KcWPVRU kmSah6SAeRbONa9n1t+8BEZp7uLsMxnXwkj7jZkgpqndQDX+mqgqFpZe79qYseRYpzsG nEpEYPyHHHQxDjiNJqRWPZ/8byVbuF29oWT/bn1M4vTmtVzEovzaaVvjWeYf4ImcjRsa bEQw== 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=EguGS/Ij6ZWIXe+6jbCGARauW7KnnwKr0BDH5wbiM3A=; b=JbqDz3N7OVuHbiVurw1AbSL787KLOZ3/Pk9MSlt1LWKzIhmcFSgXz0AblFl4Dwx3vB j5Q2Uwm6G1NI9ZFgyJuteyjXyiG03OsHK+Fv5FlsDEaz4vrC4VRlbw3G7/Ia79HWasUd gkb9GA7o8ThxHBx5XyvlTByumjXV5GNdDUfFcpmbe401nWSzY9LjSGuyBywWQ+Ix8Lc+ qV+lxzo4CpuWAyjntTmQVXMOsn1yc3tGM80CX9g7u6kR2d7HDYnIFZfdY45eaeAplHDp nGsr+/+NfajOe69NdIVHnY5OVhe+l506FtAQvn727Yt7OVAR5hOfGduytbiGNRY43zpi wshw== X-Gm-Message-State: AJcUukdsL+gDZwd0td2hSJrINXGKoTe90ABmQfVMHWOy0XrW/YonnBwO 4IVYU3OWsJfbBiaBblZO1FMIwr6+ X-Google-Smtp-Source: ALg8bN679SBXpgq9D5UVFMg60ZNLyhF2j2AOsqnJse0cO/4vJygiuq+UH/EDLaSFHo+ngUrfbyL8Zw== X-Received: by 2002:a17:906:6085:: with SMTP id t5-v6mr15067630ejj.47.1547824167559; Fri, 18 Jan 2019 07:09:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b49sm7377261edb.73.2019.01.18.07.09.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 07:09:26 -0800 (PST) Date: Fri, 18 Jan 2019 07:09:26 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 15:09:21 GMT Message-Id: <387071dcd77fde6ceef1daea623b4ae2e0e08166.1547824162.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH v2 3/4] rebase: teach `reset_head()` to optionally skip the worktree Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 This is what the legacy (scripted) rebase does in `move_to_original_branch`, and we will need this functionality in the next commit. Signed-off-by: Johannes Schindelin --- builtin/rebase.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 5c827b2f03..c65493a484 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -337,6 +337,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) static int reset_head(struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -344,6 +345,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; struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; @@ -359,7 +361,7 @@ static int reset_head(struct object_id *oid, const char *action, if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) BUG("Not a fully qualified branch: '%s'", switch_to_branch); - if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) { + if (!refs_only && hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) { ret = -1; goto leave_reset_head; } @@ -372,6 +374,9 @@ static int reset_head(struct object_id *oid, const char *action, if (!oid) oid = &head_oid; + if (refs_only) + goto reset_head_refs; + memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); setup_unpack_trees_porcelain(&unpack_tree_opts, action); unpack_tree_opts.head_idx = 1; @@ -412,6 +417,7 @@ static int reset_head(struct object_id *oid, const char *action, goto leave_reset_head; } +reset_head_refs: reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase"); prefix_len = msg.len; From patchwork Fri Jan 18 15:09:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10770627 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 53B16139A for ; Fri, 18 Jan 2019 15:09:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 403372D4AF for ; Fri, 18 Jan 2019 15:09:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 348C92E0FE; Fri, 18 Jan 2019 15:09: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 70A002D4AF for ; Fri, 18 Jan 2019 15:09:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727784AbfARPJc (ORCPT ); Fri, 18 Jan 2019 10:09:32 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:38144 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727764AbfARPJb (ORCPT ); Fri, 18 Jan 2019 10:09:31 -0500 Received: by mail-ed1-f65.google.com with SMTP id h50so11374349ede.5 for ; Fri, 18 Jan 2019 07:09:29 -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=sBiosw+sgbq1pY5ahxumEp2L3R+AfaZgNynGeKv9lUk=; b=mpi3LUEozCkUxc1MzvP566jo/LSEh/T9XHAnc9rrlQyzBin5BQ7VrGZieFptjXmL9T +8D9yGw5xGhYVJhFJzXBLVQWKV3WhxhrlO0c2Skj/96dH7PfEirVJExDKkFT8U+QGm93 xFwSAnAOZ1VXoR1Og6zgjEIuK0PuI5St5VSnSQflldR7QcDSUD2B2UcXrsPsp/wk7F4k Wta1xFcupUSkmILXhBFJuBzHK0y6ilkbkuDvZEn+izJevlq/eS4gxiHKNZVDUfzZ3Bwg zC9opokzKYHCSGJUgx9uTEIeE6H6tZVoxkjt0iKa+mb6PJDjQbKKswZ9W8maQ1ys9Uac KUqg== 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=sBiosw+sgbq1pY5ahxumEp2L3R+AfaZgNynGeKv9lUk=; b=NvpHPwPjA2ocpB7Z4c1WCjxVA3GAiREw7JKlBUBPX3JBr+wQaUfXDmJoZYJJLNfpVf rpQSpx+J/pNfMB6sWJsKgraiEFpjj7Z+IVsquVQWK2A8lkREpxLqxcsj22lNmfpzZaKm EUui/f3bcevs5e75m11jQ9We/VuI552REguPhn3jNRimRitkE8fuEHxNG3s5CuErNRqB df0fOa9hkyIZuI12bN+nGVPKe2jsCPhHi1WB5Gj8lsLfhcAS3oPsT/eEq9HbMV7/JSwu p0bNilg2TnJdIntoib3hi91AFjogg+yVPokwqcu65Oeyi+Z5TluukQHNzMa+a9OyRGRD OCzg== X-Gm-Message-State: AJcUukfPFxqE5rIhPgTCntrzwhlMBzlgcO7QZJlTsNf5NFkMQgzS4D3T xFBsdTbsK7c9KUHsKnizHD3ytFB1 X-Google-Smtp-Source: ALg8bN6uwK8d82VbvhcfxxT+QvaefNXyUHw+WGafPLq5jJAcPQ5n79RSk8iquBWe5IjK3feMJnXMHQ== X-Received: by 2002:a50:ef18:: with SMTP id m24mr16062634eds.136.1547824168513; Fri, 18 Jan 2019 07:09:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i46sm7088989eda.37.2019.01.18.07.09.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 07:09:27 -0800 (PST) Date: Fri, 18 Jan 2019 07:09:27 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 15:09:22 GMT Message-Id: <3c4031868204862ea4e2a53a03cd8d7ec066a891.1547824162.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH v2 4/4] built-in rebase: call `git am` directly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 While the scripted `git rebase` still has to rely on the `git-rebase--am.sh` script to implement the glue between the `rebase` and the `am` commands, we can go a more direct route in the built-in rebase and avoid using a shell script altogether. This patch represents a straight-forward port of `git-rebase--am.sh` to C, along with the glue code to call it directly from within `builtin/rebase.c`. This reduces the chances of Git for Windows running into trouble due to problems with the POSIX emulation layer (known as "MSYS2 runtime", itself a derivative of the Cygwin runtime): when no shell script is called, the POSIX emulation layer is avoided altogether. Note: we pass an empty action to `reset_head()` here when moving back to the original branch, as no other action is applicable, really. This parameter is used to initialize `unpack_trees()`' messages. Signed-off-by: Johannes Schindelin --- builtin/rebase.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/builtin/rebase.c b/builtin/rebase.c index c65493a484..0727ddaf00 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -246,6 +246,37 @@ static int read_basic_state(struct rebase_options *opts) return 0; } +static int write_basic_state(struct rebase_options *opts) +{ + write_file(state_dir_path("head-name", opts), "%s", + opts->head_name ? opts->head_name : "detached HEAD"); + write_file(state_dir_path("onto", opts), "%s", + opts->onto ? oid_to_hex(&opts->onto->object.oid) : ""); + write_file(state_dir_path("orig-head", opts), "%s", + oid_to_hex(&opts->orig_head)); + write_file(state_dir_path("quiet", opts), "%s", + opts->flags & REBASE_NO_QUIET ? "" : "t"); + if (opts->flags & REBASE_VERBOSE) + write_file(state_dir_path("verbose", opts), "%s", ""); + if (opts->strategy) + write_file(state_dir_path("strategy", opts), "%s", + opts->strategy); + if (opts->strategy_opts) + write_file(state_dir_path("strategy_opts", opts), "%s", + opts->strategy_opts); + if (opts->allow_rerere_autoupdate >= 0) + write_file(state_dir_path("allow_rerere_autoupdate", opts), + "-%s-rerere-autoupdate", + opts->allow_rerere_autoupdate ? "" : "-no"); + if (opts->gpg_sign_opt) + write_file(state_dir_path("gpg_sign_opt", opts), "%s", + opts->gpg_sign_opt); + if (opts->signoff) + write_file(state_dir_path("strategy", opts), "--signoff"); + + return 0; +} + static int apply_autostash(struct rebase_options *opts) { const char *path = state_dir_path("autostash", opts); @@ -459,6 +490,29 @@ static int reset_head(struct object_id *oid, const char *action, return ret; } +static int move_to_original_branch(struct rebase_options *opts) +{ + struct strbuf orig_head_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT; + int ret; + + if (!opts->head_name) + return 0; /* nothing to move back to */ + + if (!opts->onto) + BUG("move_to_original_branch without onto"); + + strbuf_addf(&orig_head_reflog, "rebase finished: %s onto %s", + opts->head_name, oid_to_hex(&opts->onto->object.oid)); + strbuf_addf(&head_reflog, "rebase finished: returning to %s", + opts->head_name); + ret = reset_head(NULL, "", opts->head_name, RESET_HEAD_REFS_ONLY, + orig_head_reflog.buf, head_reflog.buf); + + strbuf_release(&orig_head_reflog); + strbuf_release(&head_reflog); + return ret; +} + static const char *resolvemsg = N_("Resolve all conflicts manually, mark them as resolved with\n" "\"git add/rm \", then run \"git rebase --continue\".\n" @@ -466,6 +520,126 @@ N_("Resolve all conflicts manually, mark them as resolved with\n" "To abort and get back to the state before \"git rebase\", run " "\"git rebase --abort\"."); +static int run_am(struct rebase_options *opts) +{ + struct child_process am = CHILD_PROCESS_INIT; + struct child_process format_patch = CHILD_PROCESS_INIT; + struct strbuf revisions = STRBUF_INIT; + int status; + char *rebased_patches; + + am.git_cmd = 1; + argv_array_push(&am.args, "am"); + + if (opts->action && !strcmp("continue", opts->action)) { + argv_array_push(&am.args, "--resolved"); + argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); + if (opts->gpg_sign_opt) + argv_array_push(&am.args, opts->gpg_sign_opt); + status = run_command(&am); + if (status) + return status; + + return move_to_original_branch(opts); + } + if (opts->action && !strcmp("skip", opts->action)) { + argv_array_push(&am.args, "--skip"); + argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); + status = run_command(&am); + if (status) + return status; + + return move_to_original_branch(opts); + } + if (opts->action && !strcmp("show-current-patch", opts->action)) { + argv_array_push(&am.args, "--show-current-patch"); + return run_command(&am); + } + + strbuf_addf(&revisions, "%s...%s", + oid_to_hex(opts->root ? + /* this is now equivalent to !opts->upstream */ + &opts->onto->object.oid : + &opts->upstream->object.oid), + oid_to_hex(&opts->orig_head)); + + rebased_patches = xstrdup(git_path("rebased-patches")); + format_patch.out = open(rebased_patches, + O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (format_patch.out < 0) { + status = error_errno(_("could not open '%s' for writing"), + rebased_patches); + free(rebased_patches); + argv_array_clear(&am.args); + return status; + } + + format_patch.git_cmd = 1; + argv_array_pushl(&format_patch.args, "format-patch", "-k", "--stdout", + "--full-index", "--cherry-pick", "--right-only", + "--src-prefix=a/", "--dst-prefix=b/", "--no-renames", + "--no-cover-letter", "--pretty=mboxrd", NULL); + if (opts->git_format_patch_opt.len) + argv_array_split(&format_patch.args, + opts->git_format_patch_opt.buf); + argv_array_push(&format_patch.args, revisions.buf); + if (opts->restrict_revision) + argv_array_pushf(&format_patch.args, "^%s", + oid_to_hex(&opts->restrict_revision->object.oid)); + + status = run_command(&format_patch); + if (status) { + unlink(rebased_patches); + free(rebased_patches); + argv_array_clear(&am.args); + + reset_head(&opts->orig_head, "checkout", opts->head_name, 0, + "HEAD", NULL); + error(_("\ngit encountered an error while preparing the " + "patches to replay\n" + "these revisions:\n" + "\n %s\n\n" + "As a result, git cannot rebase them."), + opts->revisions); + + strbuf_release(&revisions); + return status; + } + strbuf_release(&revisions); + + am.in = open(rebased_patches, O_RDONLY); + if (am.in < 0) { + status = error_errno(_("could not open '%s' for reading"), + rebased_patches); + free(rebased_patches); + argv_array_clear(&am.args); + return status; + } + + argv_array_pushv(&am.args, opts->git_am_opts.argv); + argv_array_push(&am.args, "--rebasing"); + argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); + argv_array_push(&am.args, "--patch-format=mboxrd"); + if (opts->allow_rerere_autoupdate > 0) + argv_array_push(&am.args, "--rerere-autoupdate"); + else if (opts->allow_rerere_autoupdate == 0) + argv_array_push(&am.args, "--no-rerere-autoupdate"); + if (opts->gpg_sign_opt) + argv_array_push(&am.args, opts->gpg_sign_opt); + status = run_command(&am); + unlink(rebased_patches); + free(rebased_patches); + + if (!status) { + return move_to_original_branch(opts); + } + + if (is_directory(opts->state_dir)) + write_basic_state(opts); + + return status; +} + static int run_specific_rebase(struct rebase_options *opts) { const char *argv[] = { NULL, NULL }; @@ -546,6 +720,11 @@ static int run_specific_rebase(struct rebase_options *opts) goto finished_rebase; } + if (opts->type == REBASE_AM) { + status = run_am(opts); + goto finished_rebase; + } + add_var(&script_snippet, "GIT_DIR", absolute_path(get_git_dir())); add_var(&script_snippet, "state_dir", opts->state_dir);