From patchwork Wed Sep 8 13:41:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12481189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D00FFC433FE for ; Wed, 8 Sep 2021 13:41:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B84AD60E77 for ; Wed, 8 Sep 2021 13:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237856AbhIHNmY (ORCPT ); Wed, 8 Sep 2021 09:42:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232509AbhIHNmX (ORCPT ); Wed, 8 Sep 2021 09:42:23 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5059C061575 for ; Wed, 8 Sep 2021 06:41:15 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v10so3393078wrd.4 for ; Wed, 08 Sep 2021 06:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2iPLUGTOJY4odLXStPmKukFtdEo+mKLcOyoakKL0eR8=; b=CGLRhSps+bcKdEzMO96hfwChOvoag7BuH6a55mz0NoeWvaz9dW6DFj0r6s68sGzMYW eJzpXSnZLUTIgrRP9vtej+WctGoRlUFI8I6ITiOnmipNluFQo3mcKJYobiKEvbzxySz4 QMczjTRVMwNq4GDLSPIPVfTsu/j91vjKjjdnAa8ap3c/7Q1DjSc1Rq/WwJHB/qNcuf9B bCfOYUE5b/0+UfRldSXMNw7tcqJu50Dh0MxJIWEzS57/j69nsdbqr4NDS8eMyGbnSNIa xox3WqSPjC+1nzkbaZmkdW1f/C8YjBnlJIlFuiYn6ArfdF3vTJ1oQWH5BspIoS2Klt1C gFOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2iPLUGTOJY4odLXStPmKukFtdEo+mKLcOyoakKL0eR8=; b=1J17La1R9wKQnkyMJrhXzoUZRFeFo03ewhG5SNwptYAVLtxqM4hgSwQQRSW0ADzGqD YTjNQVcI2DRXxdTZhrIsajl/zsQUk4gvTZc0f5xGij6PX1Rlw3vQpXxzMbtdOH+Y/X8t wV5DB0h6R2AVOUWGb8GdmwLXYqBa4J0BFm1jxozocM0Z9dpJj9V/n/g2yA093OPltjQU 5R75r9PIs0GInJuvmC9JzJViraPG2Nv3Fj6oQKdXvxGbUxl6LkW6DoxoPEJITvQsfCu/ TCXak/R1MelDmiBvBKzDcCGbVs3m3teYDsSa6Poq0R47exzDnvGqdt9vu5UYJvqM6Md8 UJHA== X-Gm-Message-State: AOAM532KGXMNfVQRDbIGWSJYCr2b0FoPKCyDBKWyBrTpmRCnmNOEolTd VzpqNJzzoHQS3bKPPXG/vsLkOZZEfU4= X-Google-Smtp-Source: ABdhPJxhdJ898tNjPAso72mkxfeBWhgBRiMBeY6vYY0oy4rqHAQQI9Ee4SFpq7HjMxeN3POQ+st+ZQ== X-Received: by 2002:a5d:58ef:: with SMTP id f15mr4310257wrd.160.1631108474423; Wed, 08 Sep 2021 06:41:14 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d7sm2207954wrf.3.2021.09.08.06.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 06:41:14 -0700 (PDT) Message-Id: <53cde4825b408e5fb893bbd9a222e7387d69a408.1631108472.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 13:41:08 +0000 Subject: [PATCH 1/5] sequencer.c: factor out a function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood This code is heavily indented and obscures the high level logic within the loop. Lets move it to its own function before modifying it in the next commit. Signed-off-by: Phillip Wood --- sequencer.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/sequencer.c b/sequencer.c index 7f07cd00f3f..a248c886c27 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4254,6 +4254,27 @@ static int stopped_at_head(struct repository *r) } +static int reread_todo_if_changed(struct repository *r, + struct todo_list *todo_list, + struct replay_opts *opts) +{ + struct stat st; + + if (stat(get_todo_path(opts), &st)) { + return error_errno(_("could not stat '%s'"), + get_todo_path(opts)); + } else if (match_stat_data(&todo_list->stat, &st)) { + /* Reread the todo file if it has changed. */ + todo_list_release(todo_list); + if (read_populate_todo(r, todo_list, opts)) + return -1; /* message was printed */ + /* `current` will be incremented on return */ + todo_list->current = -1; + } + + return 0; +} + static const char rescheduled_advice[] = N_("Could not execute the todo command\n" "\n" @@ -4433,20 +4454,9 @@ static int pick_commits(struct repository *r, item->commit, arg, item->arg_len, opts, res, 0); - } else if (is_rebase_i(opts) && check_todo && !res) { - struct stat st; - - if (stat(get_todo_path(opts), &st)) { - res = error_errno(_("could not stat '%s'"), - get_todo_path(opts)); - } else if (match_stat_data(&todo_list->stat, &st)) { - /* Reread the todo file if it has changed. */ - todo_list_release(todo_list); - if (read_populate_todo(r, todo_list, opts)) - res = -1; /* message was printed */ - /* `current` will be incremented below */ - todo_list->current = -1; - } + } else if (is_rebase_i(opts) && check_todo && !res && + reread_todo_if_changed(r, todo_list, opts)) { + return -1; } todo_list->current++; From patchwork Wed Sep 8 13:41:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12481193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B65D6C433F5 for ; Wed, 8 Sep 2021 13:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A20136109F for ; Wed, 8 Sep 2021 13:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344264AbhIHNmZ (ORCPT ); Wed, 8 Sep 2021 09:42:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbhIHNmY (ORCPT ); Wed, 8 Sep 2021 09:42:24 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E3C2C061757 for ; Wed, 8 Sep 2021 06:41:16 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso1665722wmb.2 for ; Wed, 08 Sep 2021 06:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=ibBQ+7uaw6ueHo7XYx4nlC0yYyK8Q0lpvoaB4wSy1eI=; b=NxqrTWr+xepyGAXp+y//wA39T57491/FG0bCPUndFk/eTavVxv7luF0VKRlzx5Cr3j fCNdbhxFOySRtqnHIMVDSnMY+Fowo9TfWzFQ+zLdVf2WvXpZQ3EvC4Nnxp/dErKxIr7D T3NXwOoX1xNei7RHKpWbnCXKJ99IUEB9TwtIooGRrES78Mv5sd5MYYzji/pmYUp4+vu8 sAJJzCVnOQi4PlEurr8sGlueo8nKW6kceTvauFWFe94eysr+sZSXDc/emSkA3pfaN/sP c/++gPlY+31p9L/x9G9hR+wSmlMSHz3aLx+tYqdXGaLyiYEr/FvINQs+1NqZIsuOnrUj 0JcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=ibBQ+7uaw6ueHo7XYx4nlC0yYyK8Q0lpvoaB4wSy1eI=; b=Be/LpyLL8+OU/JwhAzM5oG7dJLl38FBBIxwtqTns/itctiMIgNv0QqFdL21h9rDRRo PXOIYP0qTGOp6Ruau0lQbdvEi1ERUbXyV9VggLQyPapeOKVuq20G9vrjU5l92sF+E0A0 /IpftjQH5s07/SZeA1yn4FLpD116lMgfeXLSnCQutlS2XoFR6SM9Soi1uGCS97erTGPG tB69c9XdJh9KCbdL9wTM0ZluUN7wtuC/IWebU+hMPwcEky++C9s22xsWNk3AifVf+5pV SGj9S0BfNDrPrtofkEYYn84+N3gQsSaUB1ZCKLyAZVTEzBX0oY25er3V2haLzoKAoV6H w+bQ== X-Gm-Message-State: AOAM533ZkQDm3LtuX+uLXXxgUjhKsOCQurcGtpGPVf707WSPFROCkS0I YfYaj6yPtZh6b4Vdy4TVrbyEvll/xnA= X-Google-Smtp-Source: ABdhPJyabq6h1xtuEJOoR3WU3amjIk1HkHCAHaGYWw3FVP1CQ2rhPW5EBsUc9r5LkapbxIWCBLd3+g== X-Received: by 2002:a1c:a78a:: with SMTP id q132mr3742118wme.91.1631108475021; Wed, 08 Sep 2021 06:41:15 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l13sm2228150wrb.11.2021.09.08.06.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 06:41:14 -0700 (PDT) Message-Id: <3b17a4e3d3fa620638299294a56adb9237fd5c56.1631108472.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 13:41:09 +0000 Subject: [PATCH 2/5] rebase: fix todo-list rereading MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood 54fd3243da ("rebase -i: reread the todo list if `exec` touched it", 2017-04-26) sought to reread the todo list after running an exec command only if it had been changed. To accomplish this it checks the stat data of the todo list after running an exec command to see if it has changed. Unfortunately there are two problems, firstly the implementation is buggy we actually reread the list after each exec which is quadratic in the number of commit lookups and secondly the design is predicated on using nanosecond time stamps which are not the default. The implementation bug stems from the fact that we write a new todo list to disk before running each command but do not update the stat data to reflect this[1]. The design problem is that it is possible for the user to edit the todo list without changing its size or inode which means we have to rely on the mtime to tell us if it has changed. Unfortunately unless git is built with USE_NSEC it is possible for the original and edited list to share the same mtime. Ideally "git rebase --edit-todo" would set a flag that we would then check in sequencer.c. Unfortunately this is approach will not work as there are scripts in the wild that write to the todo list directly without running "git rebase --edit-todo". Instead of relying on stat data this patch simply reads the possibly edited todo list and compares it to the original with memcmp(). This is much faster than reparsing the todo list each time. This patch reduces the time to run git rebase -r -xtrue v2.32.0~100 v2.32.0 which runs 419 exec commands by 6.6%. For comparison fixing the implementation bug in stat based approach reduces the time by a further 1.4% and is indistinguishable from never rereading the todo list. [1] https://lore.kernel.org/git/20191125131833.GD23183@szeder.dev/ Reported-by: SZEDER Gábor Signed-off-by: Phillip Wood --- sequencer.c | 19 ++++++++----------- sequencer.h | 1 - 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/sequencer.c b/sequencer.c index a248c886c27..d51440ddcd9 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2671,7 +2671,6 @@ static int read_populate_todo(struct repository *r, struct todo_list *todo_list, struct replay_opts *opts) { - struct stat st; const char *todo_file = get_todo_path(opts); int res; @@ -2679,11 +2678,6 @@ static int read_populate_todo(struct repository *r, if (strbuf_read_file_or_whine(&todo_list->buf, todo_file) < 0) return -1; - res = stat(todo_file, &st); - if (res) - return error(_("could not stat '%s'"), todo_file); - fill_stat_data(&todo_list->stat, &st); - res = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list); if (res) { if (is_rebase_i(opts)) @@ -4258,12 +4252,14 @@ static int reread_todo_if_changed(struct repository *r, struct todo_list *todo_list, struct replay_opts *opts) { - struct stat st; + int offset; + struct strbuf buf = STRBUF_INIT; - if (stat(get_todo_path(opts), &st)) { - return error_errno(_("could not stat '%s'"), - get_todo_path(opts)); - } else if (match_stat_data(&todo_list->stat, &st)) { + if (strbuf_read_file_or_whine(&buf, get_todo_path(opts)) < 0) + return -1; + offset = get_item_line_offset(todo_list, todo_list->current + 1); + if (buf.len != todo_list->buf.len - offset || + memcmp(buf.buf, todo_list->buf.buf + offset, buf.len)) { /* Reread the todo file if it has changed. */ todo_list_release(todo_list); if (read_populate_todo(r, todo_list, opts)) @@ -4271,6 +4267,7 @@ static int reread_todo_if_changed(struct repository *r, /* `current` will be incremented on return */ todo_list->current = -1; } + strbuf_release(&buf); return 0; } diff --git a/sequencer.h b/sequencer.h index d57d8ea23d7..cdeb0c6be47 100644 --- a/sequencer.h +++ b/sequencer.h @@ -116,7 +116,6 @@ struct todo_list { struct todo_item *items; int nr, alloc, current; int done_nr, total_nr; - struct stat_data stat; }; #define TODO_LIST_INIT { STRBUF_INIT } From patchwork Wed Sep 8 13:41:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12481191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9E1BC433EF for ; Wed, 8 Sep 2021 13:41:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A797E6109F for ; Wed, 8 Sep 2021 13:41:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344667AbhIHNm0 (ORCPT ); Wed, 8 Sep 2021 09:42:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237967AbhIHNmY (ORCPT ); Wed, 8 Sep 2021 09:42:24 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E30BBC061575 for ; Wed, 8 Sep 2021 06:41:16 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 196-20020a1c04cd000000b002fa489ffe1fso1208073wme.4 for ; Wed, 08 Sep 2021 06:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=82mj4O3sQeL4xRrDph3+NBTpjhpDJqHGG56do4lmAug=; b=AVca6gXrdSzsVc0AvgiBZjOOJDbJb/yiYpnqbl60jYL9Oju8DcV3qHuqqUKmmQ37aR 9eyWQy6DxiQ+yZE2h2CFBwZsA3tvNlihvP9jlkzv03H+49/cS6m1nR7USFKvoj0Wh13R t3wYH4O4rs0nzhAuAGvueiVinscMjKvO5NjI3uFHCUk3C480G0JTAFgRe51nUjtSZTr0 c9FYgRNn1qLxOZzmtPOYtQbPLzXCNOX3QfClXy1+n4fCUh/S876EGcdMhvVkrJWXJgqY 5wnaZ02aHX3Q7l64rIUGYzsrR3mjjI35C3PQquil5cwVWppVtCeq02KH7be2X5/dMixq u3JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=82mj4O3sQeL4xRrDph3+NBTpjhpDJqHGG56do4lmAug=; b=0hsA36wo0HtIkAt8N2ZD4n+/41lhCQTDvpKS7ZkDkWKDKDLEPLPKSoHHHTd2zLtx7R qkVzx5leacuDPkSy/6tUB/vPecjQQgpjdYJcd085f4JTDaXKqSYwWG6o+kdGjSPmEFJH xS09EpiRSs7szbUulz/suGInKDPzFmGb3xMpfggH/siRaQZ+DLxvl/BcZjMT7q2SwxKs tfn9YWj2q0hF8b+ZNYVEABEonq8Q2GqhsiKLDGADN+hp2VSKf/G1iQFU3hy6QXTDz08Y wugCHLqw6mTIR3vC7RzrepE4h4wqkxUFl6Njp3V2QI9k2ePlvVf0p8UF7BGrfVEyVOaN F55A== X-Gm-Message-State: AOAM530lMcQ+o9fepFhmxV5Ppx2E27UsaqcpdM7+xLanT5o13Fnax9E3 xVeC821pfb4QguWLmRrG+nxGNNybBZE= X-Google-Smtp-Source: ABdhPJxx70Bh+Sj0Nucb0NsvsdQtdVW+inSABp5NKkCne5mMLoLO0xRCL/dAIJe78EDpiOal/qpsgw== X-Received: by 2002:a7b:c405:: with SMTP id k5mr3615683wmi.87.1631108475590; Wed, 08 Sep 2021 06:41:15 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v21sm2335559wra.92.2021.09.08.06.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 06:41:15 -0700 (PDT) Message-Id: <614555fc10f336cc6f7681501247209aac879269.1631108472.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 13:41:10 +0000 Subject: [PATCH 3/5] reset_head(): mark oid parameter as const Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood We do not write to oid so mark it as const in preparation for the next commit. Signed-off-by: Phillip Wood --- reset.c | 4 ++-- reset.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/reset.c b/reset.c index 4bea758053b..5b578d6bb68 100644 --- a/reset.c +++ b/reset.c @@ -8,8 +8,8 @@ #include "tree.h" #include "unpack-trees.h" -int reset_head(struct repository *r, struct object_id *oid, const char *action, - const char *switch_to_branch, unsigned flags, +int reset_head(struct repository *r, const struct object_id *oid, + const char *action, const char *switch_to_branch, unsigned flags, const char *reflog_orig_head, const char *reflog_head, const char *default_reflog_action) { diff --git a/reset.h b/reset.h index 12f83c78e28..6d2be511b8c 100644 --- a/reset.h +++ b/reset.h @@ -12,8 +12,8 @@ #define RESET_HEAD_REFS_ONLY (1<<3) #define RESET_ORIG_HEAD (1<<4) -int reset_head(struct repository *r, struct object_id *oid, const char *action, - const char *switch_to_branch, unsigned flags, +int reset_head(struct repository *r, const struct object_id *oid, + const char *action, const char *switch_to_branch, unsigned flags, const char *reflog_orig_head, const char *reflog_head, const char *default_reflog_action); From patchwork Wed Sep 8 13:41:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12481195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1EFDC433F5 for ; Wed, 8 Sep 2021 13:41:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAC6E60E97 for ; Wed, 8 Sep 2021 13:41:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348801AbhIHNm2 (ORCPT ); Wed, 8 Sep 2021 09:42:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243881AbhIHNmZ (ORCPT ); Wed, 8 Sep 2021 09:42:25 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74F20C061757 for ; Wed, 8 Sep 2021 06:41:17 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id i3so1765223wmq.3 for ; Wed, 08 Sep 2021 06:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=oFa9M4k19kNRart/HjXJxyS+9vVejrqwfcHUQrTobqk=; b=YahGNggaNXzTnXB99KiaWBc8UReQXDn6TPpP6sfRulg0hNPTLgRxqjbdfzIW7+4Sri md6D0Sahv2VhdrlhjV2jlGduPTt2OGBfHgk3ERfgBFo5W4d9ymdsXQrDnm3h7yme64u1 WA/2XJmcEPCZsjT+lPOz/Uv21uVHVrFeOeWH97uRrcas1HbWLWkybga2U5Q7Ff84259D FQxIwCfwjtsHFtIzyvVibcf8Llj/vv8IInvEV5D3jsTI1A/dGaM8doyEZqTpDKGJffzj dknSMF+LEPdjq7tQA3Xm1Ia5BuCBv4kMZgR80J9fmu/ioLaqayCf9pNoFaWeDK4qHQ5T +HRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=oFa9M4k19kNRart/HjXJxyS+9vVejrqwfcHUQrTobqk=; b=sr7xMIfAiml5hKItTGtIMzqXajLHgjFKXYhxTvu1gtxy5Zz2YiQddFEzCFKlacGJKg t0mJnxo1svaWYHktA8Z2ZZt+DDoW8Y1rTgR4EqFsvyf7WvOuG49bf2tfKVdvG3hwzcxI KkY57DhO2L/+46+OWDLvHPqnTCgn5Rwer+Er4UCWvmBtP9+403DppPoKEGbOG8G6H4Ph nEvulIrV+l2/Rr7blvYd/BqyuBQeNQxtSrySy7oBoTwl1Mndue4T0tJHUiPWRewY9CvF mutAKiOPHKXTGpw0G9PtpqwsrhdeOXZ06qfE+J4R+XDUO99eeBk6BFgkDTwl3zTzUWKf Quqg== X-Gm-Message-State: AOAM5335euMH1cj3a7FBuS31os5evnNBqLapqe5JY+JuF3PgHf3Qh2ls J9inwU0KebVLuSm0S3Vbi1qNk6FlQ6E= X-Google-Smtp-Source: ABdhPJzISZyUdtClaqJfO79lAjfsx3HuMhu9WBulgJs3ozrE0QwzElUlOVHS/omnLDZiNlKDaFw84Q== X-Received: by 2002:a7b:c192:: with SMTP id y18mr3685200wmi.163.1631108476131; Wed, 08 Sep 2021 06:41:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 19sm2140325wmo.39.2021.09.08.06.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 06:41:15 -0700 (PDT) Message-Id: <39ad40c9297531a2d42b7263a1d41b1ecbc23c0a.1631108472.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 13:41:11 +0000 Subject: [PATCH 4/5] rebase -i: don't fork git checkout Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood The "apply" based rebase has avoided forking git checkout since ac7f467fef ("builtin/rebase: support running "git rebase "", 2018-08-07). The code that handles the checkout was moved into libgit by b309a97108 ("reset: extract reset_head() from rebase", 2020-04-07) so lets start using it for the "merge" based rebase as well. This opens the way for us to stop calling the post-checkout hook in the future. Signed-off-by: Phillip Wood --- sequencer.c | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/sequencer.c b/sequencer.c index d51440ddcd9..1a9dbc70d3c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4192,42 +4192,21 @@ int apply_autostash_oid(const char *stash_oid) return apply_save_autostash_oid(stash_oid, 1); } -static int run_git_checkout(struct repository *r, struct replay_opts *opts, - const char *commit, const char *action) -{ - struct child_process cmd = CHILD_PROCESS_INIT; - int ret; - - cmd.git_cmd = 1; - - strvec_push(&cmd.args, "checkout"); - strvec_push(&cmd.args, commit); - strvec_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action); - - if (opts->verbose) - ret = run_command(&cmd); - else - ret = run_command_silent_on_success(&cmd); - - if (!ret) - discard_index(r->index); - - return ret; -} - static int checkout_onto(struct repository *r, struct replay_opts *opts, const char *onto_name, const struct object_id *onto, const struct object_id *orig_head) { const char *action = reflog_message(opts, "start", "checkout %s", onto_name); - if (run_git_checkout(r, opts, oid_to_hex(onto), action)) { + if (reset_head(r, onto, "checkout", NULL, RESET_HEAD_DETACH | + RESET_ORIG_HEAD | RESET_HEAD_RUN_POST_CHECKOUT_HOOK, + NULL, action, "rebase")) { apply_autostash(rebase_path_autostash()); sequencer_remove_state(opts); return error(_("could not detach HEAD")); } - return update_ref(NULL, "ORIG_HEAD", orig_head, NULL, 0, UPDATE_REFS_MSG_ON_ERR); + return 0; } static int stopped_at_head(struct repository *r) From patchwork Wed Sep 8 13:41:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12481197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB3E8C433FE for ; Wed, 8 Sep 2021 13:41:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D69AC60E97 for ; Wed, 8 Sep 2021 13:41:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344707AbhIHNm3 (ORCPT ); Wed, 8 Sep 2021 09:42:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344532AbhIHNm0 (ORCPT ); Wed, 8 Sep 2021 09:42:26 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10663C061575 for ; Wed, 8 Sep 2021 06:41:18 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id d6so3338381wrc.11 for ; Wed, 08 Sep 2021 06:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=rmRBP5gqh6McvajV8o0dq4SeUyNVcIizrxGNl0q3wLA=; b=Hib0Vetz4dGa4chjUXHhyZR/z8k4kxOaQ4zQEUcUQFexFNn3It2ZjHxDb+3ZqqdTor q+h+osgczpWOhg3J+7sQdZ74BIK92mmBxG3xyfk36GspZ8B+VA7117cRaFW/Im+y+hQQ t/lb4F7LXojBEPR5/bKheofOWo8SuHSfgGJoo0tzVjtA/2u6FTQiXwCbuMeCwyLaDlA8 nZbqKVD4GvoSgCV/vsULFBFGzvqN+lseWUgj66WHFbFqQVAN+XXagDNB1NSlsjeKuAj2 2fnR4nofNZdDeMuN3uxwqKCaPNyVklGCNDgPzVyK3mvbjq8VVHwpy4sMK9tAJkSJAEy1 vL1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=rmRBP5gqh6McvajV8o0dq4SeUyNVcIizrxGNl0q3wLA=; b=r3KJTNwHt61P9Gdvqbupwz2fuI8HKez6tHVqPbqh5cVOd98641V7DTSA13anrdnXlw XKSveObDP7MGys8HkehIvcCe0WYEKggYoNdaIDr/ZB3GuLcC/neg1XjEWgQiZuWb85MQ sBH3N41HtSPFQ+z64oNitHZaVniUVF+ptc/+Vmg6Kq8OaWwA0lwBabqb7cwMEv+SkCMS Bc5aPMDUpSU2N2fxCzMNtqOvVXkQXrLUIoG+2F21jS0adt/B+LCwkvdiQ3AQe5/u76dp C8xwxNvdjeGxni57vTiNisRO5rS3ZBXOwcuyfP6XrVd/4rG4JMZtBLwgRwnn6oWrEc3q 1KIw== X-Gm-Message-State: AOAM530i7w+3VBRxtOmAFmKuxFXRNJpLXrl7EKtagfJNDH5u8d7XwUHk fmDSDKtCbLXJSMoxQqkJy5COGRk6KZM= X-Google-Smtp-Source: ABdhPJxljw0oWw3yP7QGKCNiC3ZhydjitD0BYSzvV/vf7LLIwh8ZSHndxnxOqdlZekZgPpwzgf8ylQ== X-Received: by 2002:a5d:5042:: with SMTP id h2mr4115189wrt.57.1631108476698; Wed, 08 Sep 2021 06:41:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r25sm2621172wrc.26.2021.09.08.06.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 06:41:16 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 13:41:12 +0000 Subject: [PATCH 5/5] rebase: remove unused parameter Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood Now that we use reset_head() we don't need to pass orig_head around. Signed-off-by: Phillip Wood --- builtin/rebase.c | 3 +-- sequencer.c | 12 +++++------- sequencer.h | 5 ++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 12f093121d9..1520f75a491 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -377,8 +377,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) split_exec_commands(opts->cmd, &commands); ret = complete_action(the_repository, &replay, flags, shortrevisions, opts->onto_name, opts->onto, - &opts->orig_head, &commands, opts->autosquash, - &todo_list); + &commands, opts->autosquash, &todo_list); } string_list_clear(&commands, 0); diff --git a/sequencer.c b/sequencer.c index 1a9dbc70d3c..a7ea60a7a82 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4193,8 +4193,7 @@ int apply_autostash_oid(const char *stash_oid) } static int checkout_onto(struct repository *r, struct replay_opts *opts, - const char *onto_name, const struct object_id *onto, - const struct object_id *orig_head) + const char *onto_name, const struct object_id *onto) { const char *action = reflog_message(opts, "start", "checkout %s", onto_name); @@ -5567,9 +5566,8 @@ static int skip_unnecessary_picks(struct repository *r, int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, - struct commit *onto, const struct object_id *orig_head, - struct string_list *commands, unsigned autosquash, - struct todo_list *todo_list) + struct commit *onto, struct string_list *commands, + unsigned autosquash, struct todo_list *todo_list) { char shortonto[GIT_MAX_HEXSZ + 1]; const char *todo_file = rebase_path_todo(); @@ -5616,7 +5614,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla return error(_("nothing to do")); } else if (res == -4) { - checkout_onto(r, opts, onto_name, &onto->object.oid, orig_head); + checkout_onto(r, opts, onto_name, &onto->object.oid); todo_list_release(&new_todo); return -1; @@ -5644,7 +5642,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla res = -1; - if (checkout_onto(r, opts, onto_name, &oid, orig_head)) + if (checkout_onto(r, opts, onto_name, &oid)) goto cleanup; if (require_clean_work_tree(r, "rebase", "", 1, 1)) diff --git a/sequencer.h b/sequencer.h index cdeb0c6be47..352b24014bb 100644 --- a/sequencer.h +++ b/sequencer.h @@ -163,9 +163,8 @@ void todo_list_add_exec_commands(struct todo_list *todo_list, struct string_list *commands); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, - struct commit *onto, const struct object_id *orig_head, - struct string_list *commands, unsigned autosquash, - struct todo_list *todo_list); + struct commit *onto, struct string_list *commands, + unsigned autosquash, struct todo_list *todo_list); int todo_list_rearrange_squash(struct todo_list *todo_list); /*