From patchwork Fri Jun 2 10:25:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265046 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D908CC7EE29 for ; Fri, 2 Jun 2023 10:28:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235579AbjFBK2O (ORCPT ); Fri, 2 Jun 2023 06:28:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235501AbjFBK1z (ORCPT ); Fri, 2 Jun 2023 06:27:55 -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 59B6DE45 for ; Fri, 2 Jun 2023 03:26:09 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3f606912ebaso19139945e9.3 for ; Fri, 02 Jun 2023 03:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701552; x=1688293552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=18RgXSbFuZYyfYUKIIuyTGEfhKGNz7QPk5fQDftbOIo=; b=OorkxhT6WFWXlsS9VVRchvpMA2UWFeQkYGyDcDIO2ywjPV9IGT1cJWvZYilI3af1gn ghK8UKLgKJlo9lNm2U96nT1xQynfKaCewIZv8VZjm32dNuCXJ/ROyuQ67GVziaNe/iUh a9Cm2o2BiYN0rqYzUfI+mYFSHaR77XPtfTU/edfy8vwIx6I24mfmluZC/ktSZ6iukO/k r44OVSrRzpeMVaHf9EqEAMqnkIeQjfLDwApU+NiB5XpFi2AuvXEVlMCX1KgaHoMauJxe ovH+iE+sSKHMMYN2o+TkGvLNGgtOvXsVCEXt/EmALU4g7tckYXSpoaIoig5xA1LPva9Z UFZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701552; x=1688293552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=18RgXSbFuZYyfYUKIIuyTGEfhKGNz7QPk5fQDftbOIo=; b=c5e2BPskJKqPQUZPdG1npMrecwAzE7jgLAgrLV9I3o1LpNiBPlIh3vTaFWyoqUKeF+ 5mwOp6rFbwjQgdCjSuNNN4r2s8IIGDh6/sfaBtP0jUtskInUStGLKx002lRd/QOpZVZx 7fi1ZYrRSF4Fph+p2i4RBOKeSW4/IUgb01Y1U9d7DfqV4Yg8lI+byEUUZ19T+ngBEgP3 HpC9HBinNAGDHBZCWrKjGomqG9g1r6NylrZpRYupCvvvQpnbiNf5CwVrlVR27i+RQL+J fEEGa/Dm8jIItuxquMlghePYy56gaxRFw5fcw7hLlsvGD5wBSQr8MccYfO0RN30XOumr d+7Q== X-Gm-Message-State: AC+VfDwa324AulomA/ByYUAw6r/RCIzw+aOtFMuRuQmJTxwiSgJX97+C I7I4LElWMZv0K6ZOrZnp83wXQeNf/xIwHw== X-Google-Smtp-Source: ACHHUZ5o2ZO7cd0MjWn9sHtt/3Ifx7tn+iKMXbmgUrC/jrjvDhiNhMqAM6MYoO8mArh58c7w3H2ryQ== X-Received: by 2002:a7b:c395:0:b0:3f1:979f:a734 with SMTP id s21-20020a7bc395000000b003f1979fa734mr1566776wmj.11.1685701551483; Fri, 02 Jun 2023 03:25:51 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:25:51 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 01/15] t6429: remove switching aspects of fast-rebase Date: Fri, 2 Jun 2023 12:25:19 +0200 Message-ID: <20230602102533.876905-2-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren At the time t6429 was written, merge-ort was still under development, did not have quite as many tests, and certainly was not widely deployed. Since t6429 was exercising some codepaths just a little differently, we thought having them also test the "merge_switch_to_result()" bits of merge-ort was useful even though they weren't intrinsic to the real point of these tests. However, the value provided by doing extra testing of the "merge_switch_to_result()" bits has decreased a bit over time, and it's actively making it harder to refactor `test-tool fast-rebase` into `git replay`, which we are going to do in following commits. Dispense with these bits. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- t/helper/test-fast-rebase.c | 9 +-------- t/t6429-merge-sequence-rename-caching.sh | 9 +++++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c index d1d63feaa9..403bdf8e75 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -193,7 +193,7 @@ int cmd__fast_rebase(int argc, const char **argv) last_commit = create_commit(result.tree, commit, last_commit); } - merge_switch_to_result(&merge_opt, head_tree, &result, 1, !result.clean); + merge_finalize(&merge_opt, &result); if (result.clean < 0) exit(128); @@ -212,9 +212,6 @@ int cmd__fast_rebase(int argc, const char **argv) } if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0) die(_("unable to update HEAD")); - - prime_cache_tree(the_repository, the_repository->index, - result.tree); } else { fprintf(stderr, "\nAborting: Hit a conflict.\n"); strbuf_addf(&reflog_msg, "rebase progress up to %s", @@ -227,10 +224,6 @@ int cmd__fast_rebase(int argc, const char **argv) die("Failed to update %s", argv[4]); } } - if (write_locked_index(&the_index, &lock, - COMMIT_LOCK | SKIP_IF_UNCHANGED)) - die(_("unable to write %s"), get_index_file()); - ret = (result.clean == 0); cleanup: strbuf_release(&reflog_msg); diff --git a/t/t6429-merge-sequence-rename-caching.sh b/t/t6429-merge-sequence-rename-caching.sh index d02fa16614..75d3fd2dba 100755 --- a/t/t6429-merge-sequence-rename-caching.sh +++ b/t/t6429-merge-sequence-rename-caching.sh @@ -72,6 +72,7 @@ test_expect_success 'caching renames does not preclude finding new ones' ' git switch upstream && test-tool fast-rebase --onto HEAD upstream~1 topic && + git reset --hard topic && #git cherry-pick upstream~1..topic git ls-files >tracked-files && @@ -200,6 +201,7 @@ test_expect_success 'rename same file identically, then reintroduce it' ' export GIT_TRACE2_PERF && test-tool fast-rebase --onto HEAD upstream~1 topic && + git reset --hard topic && #git cherry-pick upstream~1..topic && git ls-files >tracked && @@ -277,6 +279,7 @@ test_expect_success 'rename same file identically, then add file to old dir' ' export GIT_TRACE2_PERF && test-tool fast-rebase --onto HEAD upstream~1 topic && + git reset --hard topic && #git cherry-pick upstream~1..topic && git ls-files >tracked && @@ -356,8 +359,6 @@ test_expect_success 'cached dir rename does not prevent noticing later conflict' test_must_fail test-tool fast-rebase --onto HEAD upstream~1 topic >output && #git cherry-pick upstream..topic && - grep CONFLICT..rename/rename output && - grep region_enter.*diffcore_rename trace.output >calls && test_line_count = 2 calls ) @@ -456,6 +457,7 @@ test_expect_success 'dir rename unneeded, then add new file to old dir' ' export GIT_TRACE2_PERF && test-tool fast-rebase --onto HEAD upstream~1 topic && + git reset --hard topic && #git cherry-pick upstream..topic && grep region_enter.*diffcore_rename trace.output >calls && @@ -522,6 +524,7 @@ test_expect_success 'dir rename unneeded, then rename existing file into old dir export GIT_TRACE2_PERF && test-tool fast-rebase --onto HEAD upstream~1 topic && + git reset --hard topic && #git cherry-pick upstream..topic && grep region_enter.*diffcore_rename trace.output >calls && @@ -624,6 +627,7 @@ test_expect_success 'caching renames only on upstream side, part 1' ' export GIT_TRACE2_PERF && test-tool fast-rebase --onto HEAD upstream~1 topic && + git reset --hard topic && #git cherry-pick upstream..topic && grep region_enter.*diffcore_rename trace.output >calls && @@ -682,6 +686,7 @@ test_expect_success 'caching renames only on upstream side, part 2' ' export GIT_TRACE2_PERF && test-tool fast-rebase --onto HEAD upstream~1 topic && + git reset --hard topic && #git cherry-pick upstream..topic && grep region_enter.*diffcore_rename trace.output >calls && From patchwork Fri Jun 2 10:25:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265048 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DECE3C7EE24 for ; Fri, 2 Jun 2023 10:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235595AbjFBK2T (ORCPT ); Fri, 2 Jun 2023 06:28:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235585AbjFBK14 (ORCPT ); Fri, 2 Jun 2023 06:27:56 -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 6946C1728 for ; Fri, 2 Jun 2023 03:26:12 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f70fc4682aso17794185e9.1 for ; Fri, 02 Jun 2023 03:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701553; x=1688293553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cahow9oR6UnNk1mm1m7BDXAC1t8XdaxPi86Rk7sFsPc=; b=jE4Juqz7clfJFDQPnYEVVDVsS3D4xB6U2x3Yxj03TxkMUPLJ2hYO8d/zZDWpuAZOMx dWKXLA6F4+/M2W5oY8+2LAsTAgTcrRCJ8U9OPnmbkaSINrP4gjoMve6FIbyf6qnpWidw SEZHMvF3Z2C2VEzVWd8rYo96qV6sZG+T6B1pDZ8NwMAalMnSjyhL3/a8kJ0/g/qL1GKY oYF6OU44TOicIXrjjxDTQuECgoT5s2lhOT2bmtglCkjXQT0mKIMdiAfUCOqniukXT6Of 4eZE32RZiQxrIM/JHRNdGRsAFSxrLMeB37TQOwAV3GONXmbeSwLPzmGLGUndNtkQo2AB NkCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701553; x=1688293553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cahow9oR6UnNk1mm1m7BDXAC1t8XdaxPi86Rk7sFsPc=; b=gJikcVnGe+0OuVXROr+mas03nVbzG2X8HTbHCdSEuMDfZJj2CNMQ8C4o9Z/DEu9Puv iyH6ySyG9Km0evnvr2dEG0vQGUrJaj9i5Bop/HnqGHQAEdW0JXG8jThBIUdvBLdiLRnR Kt4n/KhREmTajOU8NaqtMOZBDTYEOhBowaQMwUGPUcaXWthIQQTCFbc8pI3QUs13jcLt 3OysrX5+fm2CfCHhBesyjeGkE2CgXn0i4ZmDVaOrAaVlKQX+ZgNPbc2nX2d+i+GT3Xfj m38Dz+EjaIlP+gJij6lP7mB0DWHN/hicFGzc/154RShWfMmeb6KedISXdclJ9XWYblzT SJMQ== X-Gm-Message-State: AC+VfDyhzPKfPJi6huGhE/JKlYcS+DKXP9g+wwnnxMumt7ckJdKE9pYB 1YUd24vuYhXOfcZesMjm8fCffS+0LUGK3g== X-Google-Smtp-Source: ACHHUZ6Lwx5ihHYGchcUpmin1nvN0qTY7TZwvlWDmP41fN7+j6ExhHLSJfQQTAoDlE56XxKOMeNCNA== X-Received: by 2002:a05:600c:2114:b0:3f4:253b:92b3 with SMTP id u20-20020a05600c211400b003f4253b92b3mr1578444wml.18.1685701553468; Fri, 02 Jun 2023 03:25:53 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:25:52 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 02/15] replay: introduce new builtin Date: Fri, 2 Jun 2023 12:25:20 +0200 Message-ID: <20230602102533.876905-3-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren For now, this is just a rename from `t/helper/test-fast-rebase.c` into `builtin/replay.c` with minimal changes to make it build appropriately. Subsequent commits will flesh out its capabilities and make it a more standard regular builtin. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- .gitignore | 1 + Makefile | 2 +- builtin.h | 1 + .../test-fast-rebase.c => builtin/replay.c | 28 ++++++------------- command-list.txt | 1 + git.c | 1 + t/helper/test-tool.c | 1 - t/helper/test-tool.h | 1 - t/t6429-merge-sequence-rename-caching.sh | 27 ++++++------------ 9 files changed, 22 insertions(+), 41 deletions(-) rename t/helper/test-fast-rebase.c => builtin/replay.c (89%) diff --git a/.gitignore b/.gitignore index e875c59054..b5f025a296 100644 --- a/.gitignore +++ b/.gitignore @@ -135,6 +135,7 @@ /git-remote-ext /git-repack /git-replace +/git-replay /git-request-pull /git-rerere /git-reset diff --git a/Makefile b/Makefile index e440728c24..a6ab78840f 100644 --- a/Makefile +++ b/Makefile @@ -799,7 +799,6 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-env-helper.o TEST_BUILTINS_OBJS += test-example-decorate.o -TEST_BUILTINS_OBJS += test-fast-rebase.o TEST_BUILTINS_OBJS += test-fsmonitor-client.o TEST_BUILTINS_OBJS += test-genrandom.o TEST_BUILTINS_OBJS += test-genzeros.o @@ -1286,6 +1285,7 @@ BUILTIN_OBJS += builtin/remote-fd.o BUILTIN_OBJS += builtin/remote.o BUILTIN_OBJS += builtin/repack.o BUILTIN_OBJS += builtin/replace.o +BUILTIN_OBJS += builtin/replay.o BUILTIN_OBJS += builtin/rerere.o BUILTIN_OBJS += builtin/reset.o BUILTIN_OBJS += builtin/rev-list.o diff --git a/builtin.h b/builtin.h index cb0db67681..c3f0b56915 100644 --- a/builtin.h +++ b/builtin.h @@ -214,6 +214,7 @@ int cmd_remote(int argc, const char **argv, const char *prefix); int cmd_remote_ext(int argc, const char **argv, const char *prefix); int cmd_remote_fd(int argc, const char **argv, const char *prefix); int cmd_repack(int argc, const char **argv, const char *prefix); +int cmd_replay(int argc, const char **argv, const char *prefix); int cmd_rerere(int argc, const char **argv, const char *prefix); int cmd_reset(int argc, const char **argv, const char *prefix); int cmd_restore(int argc, const char **argv, const char *prefix); diff --git a/t/helper/test-fast-rebase.c b/builtin/replay.c similarity index 89% rename from t/helper/test-fast-rebase.c rename to builtin/replay.c index 403bdf8e75..252af62d12 100644 --- a/t/helper/test-fast-rebase.c +++ b/builtin/replay.c @@ -1,18 +1,11 @@ /* - * "git fast-rebase" builtin command - * - * FAST: Forking Any Subprocesses (is) Taboo - * - * This is meant SOLELY as a demo of what is possible. sequencer.c and - * rebase.c should be refactored to use the ideas here, rather than attempting - * to extend this file to replace those (unless Phillip or Dscho say that - * refactoring is too hard and we need a clean slate, but I'm guessing that - * refactoring is the better route). + * "git replay" builtin command */ #define USE_THE_INDEX_VARIABLE -#include "test-tool.h" -#include "cache.h" +#include "git-compat-util.h" + +#include "builtin.h" #include "cache-tree.h" #include "commit.h" #include "environment.h" @@ -26,7 +19,8 @@ #include "sequencer.h" #include "setup.h" #include "strvec.h" -#include "tree.h" +#include +#include static const char *short_commit_name(struct commit *commit) { @@ -93,7 +87,7 @@ static struct commit *create_commit(struct tree *tree, return (struct commit *)obj; } -int cmd__fast_rebase(int argc, const char **argv) +int cmd_replay(int argc, const char **argv, const char *prefix) { struct commit *onto; struct commit *last_commit = NULL, *last_picked_commit = NULL; @@ -109,12 +103,6 @@ int cmd__fast_rebase(int argc, const char **argv) struct strbuf branch_name = STRBUF_INIT; int ret = 0; - /* - * test-tool stuff doesn't set up the git directory by default; need to - * do that manually. - */ - setup_git_directory(); - if (argc == 2 && !strcmp(argv[1], "-h")) { printf("Sorry, I am not a psychiatrist; I can not give you the help you need. Oh, you meant usage...\n"); exit(129); @@ -135,7 +123,7 @@ int cmd__fast_rebase(int argc, const char **argv) if (repo_read_index(the_repository) < 0) BUG("Could not read index"); - repo_init_revisions(the_repository, &revs, NULL); + repo_init_revisions(the_repository, &revs, prefix); revs.verbose_header = 1; revs.max_parents = 1; revs.cherry_mark = 1; diff --git a/command-list.txt b/command-list.txt index 54b2a50f5f..d74836ab21 100644 --- a/command-list.txt +++ b/command-list.txt @@ -160,6 +160,7 @@ git-reflog ancillarymanipulators complete git-remote ancillarymanipulators complete git-repack ancillarymanipulators complete git-replace ancillarymanipulators complete +git-replay mainporcelain history git-request-pull foreignscminterface complete git-rerere ancillaryinterrogators git-reset mainporcelain history diff --git a/git.c b/git.c index 2f42da20f4..cf95c61813 100644 --- a/git.c +++ b/git.c @@ -593,6 +593,7 @@ static struct cmd_struct commands[] = { { "remote-fd", cmd_remote_fd, NO_PARSEOPT }, { "repack", cmd_repack, RUN_SETUP }, { "replace", cmd_replace, RUN_SETUP }, + { "replay", cmd_replay, RUN_SETUP }, { "rerere", cmd_rerere, RUN_SETUP }, { "reset", cmd_reset, RUN_SETUP }, { "restore", cmd_restore, RUN_SETUP | NEED_WORK_TREE }, diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index abe8a785eb..9ca1586de7 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -30,7 +30,6 @@ static struct test_cmd cmds[] = { { "dump-untracked-cache", cmd__dump_untracked_cache }, { "env-helper", cmd__env_helper }, { "example-decorate", cmd__example_decorate }, - { "fast-rebase", cmd__fast_rebase }, { "fsmonitor-client", cmd__fsmonitor_client }, { "genrandom", cmd__genrandom }, { "genzeros", cmd__genzeros }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index ea2672436c..a03bbfc6b2 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -24,7 +24,6 @@ int cmd__dump_untracked_cache(int argc, const char **argv); int cmd__dump_reftable(int argc, const char **argv); int cmd__env_helper(int argc, const char **argv); int cmd__example_decorate(int argc, const char **argv); -int cmd__fast_rebase(int argc, const char **argv); int cmd__fsmonitor_client(int argc, const char **argv); int cmd__genrandom(int argc, const char **argv); int cmd__genzeros(int argc, const char **argv); diff --git a/t/t6429-merge-sequence-rename-caching.sh b/t/t6429-merge-sequence-rename-caching.sh index 75d3fd2dba..7670b72008 100755 --- a/t/t6429-merge-sequence-rename-caching.sh +++ b/t/t6429-merge-sequence-rename-caching.sh @@ -71,9 +71,8 @@ test_expect_success 'caching renames does not preclude finding new ones' ' git switch upstream && - test-tool fast-rebase --onto HEAD upstream~1 topic && + git replay --onto HEAD upstream~1 topic && git reset --hard topic && - #git cherry-pick upstream~1..topic git ls-files >tracked-files && test_line_count = 2 tracked-files && @@ -141,8 +140,7 @@ test_expect_success 'cherry-pick both a commit and its immediate revert' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - test-tool fast-rebase --onto HEAD upstream~1 topic && - #git cherry-pick upstream~1..topic && + git replay --onto HEAD upstream~1 topic && grep region_enter.*diffcore_rename trace.output >calls && test_line_count = 1 calls @@ -200,9 +198,8 @@ test_expect_success 'rename same file identically, then reintroduce it' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - test-tool fast-rebase --onto HEAD upstream~1 topic && + git replay --onto HEAD upstream~1 topic && git reset --hard topic && - #git cherry-pick upstream~1..topic && git ls-files >tracked && test_line_count = 2 tracked && @@ -278,9 +275,8 @@ test_expect_success 'rename same file identically, then add file to old dir' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - test-tool fast-rebase --onto HEAD upstream~1 topic && + git replay --onto HEAD upstream~1 topic && git reset --hard topic && - #git cherry-pick upstream~1..topic && git ls-files >tracked && test_line_count = 4 tracked && @@ -356,8 +352,7 @@ test_expect_success 'cached dir rename does not prevent noticing later conflict' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - test_must_fail test-tool fast-rebase --onto HEAD upstream~1 topic >output && - #git cherry-pick upstream..topic && + test_must_fail git replay --onto HEAD upstream~1 topic >output && grep region_enter.*diffcore_rename trace.output >calls && test_line_count = 2 calls @@ -456,9 +451,8 @@ test_expect_success 'dir rename unneeded, then add new file to old dir' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - test-tool fast-rebase --onto HEAD upstream~1 topic && + git replay --onto HEAD upstream~1 topic && git reset --hard topic && - #git cherry-pick upstream..topic && grep region_enter.*diffcore_rename trace.output >calls && test_line_count = 2 calls && @@ -523,9 +517,8 @@ test_expect_success 'dir rename unneeded, then rename existing file into old dir GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - test-tool fast-rebase --onto HEAD upstream~1 topic && + git replay --onto HEAD upstream~1 topic && git reset --hard topic && - #git cherry-pick upstream..topic && grep region_enter.*diffcore_rename trace.output >calls && test_line_count = 3 calls && @@ -626,9 +619,8 @@ test_expect_success 'caching renames only on upstream side, part 1' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - test-tool fast-rebase --onto HEAD upstream~1 topic && + git replay --onto HEAD upstream~1 topic && git reset --hard topic && - #git cherry-pick upstream..topic && grep region_enter.*diffcore_rename trace.output >calls && test_line_count = 1 calls && @@ -685,9 +677,8 @@ test_expect_success 'caching renames only on upstream side, part 2' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - test-tool fast-rebase --onto HEAD upstream~1 topic && + git replay --onto HEAD upstream~1 topic && git reset --hard topic && - #git cherry-pick upstream..topic && grep region_enter.*diffcore_rename trace.output >calls && test_line_count = 2 calls && From patchwork Fri Jun 2 10:25:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09F7CC7EE29 for ; Fri, 2 Jun 2023 10:28:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235700AbjFBK21 (ORCPT ); Fri, 2 Jun 2023 06:28:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235425AbjFBK16 (ORCPT ); Fri, 2 Jun 2023 06:27:58 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EECC5268B for ; Fri, 2 Jun 2023 03:26:12 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-30ae69ef78aso2459957f8f.1 for ; Fri, 02 Jun 2023 03:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701555; x=1688293555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QHE5OnrTCyTOspyTEGRV/FXxpuPMNE2g5IzgoBIA704=; b=YxmBIl7c0Rptj8CYrQ13ZxGEGpgCRlLhduu8gZRJj3UVTp9oG3TftJ3HTdciTXKPo4 bJM5F9UIQCj6AjRYrD8yUf1GYMIzo2Javrk1iGWAbFoJ7j4RlqG/0xrFpWx4yDZ/StJh ntLdvtZOa2L0OH1Dc/xyLLMAZFTejQIEeMC5I3a/SAXRlsdsMahGmTTw7+z8o2vLixa5 JVsKefrtD50eb2QQ02DAXv3gV4MMQWPAui8VN7hgrl2AnBEUEqAwK09E1sK+oTA80jJC HFfSaZuHveCgvFwg2EeZFM5aWqB0NwR/UfaxNeLEGW/bXz4JdBdqhGoILCOW2d2n+5YY n8xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701555; x=1688293555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QHE5OnrTCyTOspyTEGRV/FXxpuPMNE2g5IzgoBIA704=; b=Y27eA5zC6sr99y2wCEtcKLVZ48gILEzOcrgRaQcKhmO8NgXuhBGNHM/VnyQjHMv4TR f00XIUVAcrShkEPkjHLW+Y7fC60g2DQVVxvy8qnB+18DBvuVAhSGTg+vunoUB2iCVh7W Xz3RQSUvN/UHLEy+YR937oc2ezVqLx0nnFva4+My8Vu58tLkKm+1Kp1rLRPJNJVa9TwN nt33bGDqotrdWqfcGckPjNoX5bpIFp9acfyVrLGIM1nKuDu5TVaQPil2rIAg7aeM7ufy FOu23MUag6F864K0VDaAN6OkEJyD4ZnRxVhwXmfhFm2BXEncQ8suMq+TWgWBmgLc3o7N /bog== X-Gm-Message-State: AC+VfDzx3HzJD6j3OGgPNK0pNopeV54evE6RD2UcnDFcFdBWbapi3uJa hvqh7hmjtYCsj/TPYz1O0/CcaykmfbLReg== X-Google-Smtp-Source: ACHHUZ6xZLfFY51t5I5loTipSqdJLg51wvQg8kv3uYPubfTmGIrNwcMRMIQeJU3Wr3bilBdtpZ8JUg== X-Received: by 2002:a5d:53d0:0:b0:30a:e63b:950 with SMTP id a16-20020a5d53d0000000b0030ae63b0950mr3829081wrw.31.1685701554976; Fri, 02 Jun 2023 03:25:54 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:25:54 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 03/15] replay: start using parse_options API Date: Fri, 2 Jun 2023 12:25:21 +0200 Message-ID: <20230602102533.876905-4-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Instead of manually parsing arguments, let's start using the parse_options API. This way this new builtin will look more standard, and in some upcoming commits will more easily be able to handle more command line options. Note that we plan to later use standard revision ranges instead of hardcoded " " arguments. When we will use standard revision ranges, it will be easier to check if there are no spurious arguments if we keep ARGV[0], so let's call parse_options() with PARSE_OPT_KEEP_ARGV0 even if we don't need ARGV[0] right now to avoid some useless code churn. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index 252af62d12..7eb05048a5 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -14,6 +14,7 @@ #include "lockfile.h" #include "merge-ort.h" #include "object-name.h" +#include "parse-options.h" #include "refs.h" #include "revision.h" #include "sequencer.h" @@ -90,6 +91,7 @@ static struct commit *create_commit(struct tree *tree, int cmd_replay(int argc, const char **argv, const char *prefix) { struct commit *onto; + const char *onto_name = NULL; struct commit *last_commit = NULL, *last_picked_commit = NULL; struct object_id head; struct lock_file lock = LOCK_INIT; @@ -103,16 +105,32 @@ int cmd_replay(int argc, const char **argv, const char *prefix) struct strbuf branch_name = STRBUF_INIT; int ret = 0; - if (argc == 2 && !strcmp(argv[1], "-h")) { - printf("Sorry, I am not a psychiatrist; I can not give you the help you need. Oh, you meant usage...\n"); - exit(129); + const char * const replay_usage[] = { + N_("git replay --onto "), + NULL + }; + struct option replay_options[] = { + OPT_STRING(0, "onto", &onto_name, + N_("revision"), + N_("replay onto given commit")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, replay_options, replay_usage, + PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT); + + if (!onto_name) { + error(_("option --onto is mandatory")); + usage_with_options(replay_usage, replay_options); } - if (argc != 5 || strcmp(argv[1], "--onto")) - die("usage: read the code, figure out how to use it, then do so"); + if (argc != 3) { + error(_("bad number of arguments")); + usage_with_options(replay_usage, replay_options); + } - onto = peel_committish(argv[2]); - strbuf_addf(&branch_name, "refs/heads/%s", argv[4]); + onto = peel_committish(onto_name); + strbuf_addf(&branch_name, "refs/heads/%s", argv[2]); /* Sanity check */ if (repo_get_oid(the_repository, "HEAD", &head)) @@ -124,6 +142,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) BUG("Could not read index"); repo_init_revisions(the_repository, &revs, prefix); + revs.verbose_header = 1; revs.max_parents = 1; revs.cherry_mark = 1; @@ -132,7 +151,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix) revs.right_only = 1; revs.sort_order = REV_SORT_IN_GRAPH_ORDER; revs.topo_order = 1; - strvec_pushl(&rev_walk_args, "", argv[4], "--not", argv[3], NULL); + + strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL); if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) { ret = error(_("unhandled options")); @@ -195,8 +215,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix) &last_commit->object.oid, &last_picked_commit->object.oid, REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) { - error(_("could not update %s"), argv[4]); - die("Failed to update %s", argv[4]); + error(_("could not update %s"), argv[2]); + die("Failed to update %s", argv[2]); } if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0) die(_("unable to update HEAD")); @@ -208,8 +228,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix) &last_commit->object.oid, &head, REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) { - error(_("could not update %s"), argv[4]); - die("Failed to update %s", argv[4]); + error(_("could not update %s"), argv[2]); + die("Failed to update %s", argv[2]); } } ret = (result.clean == 0); From patchwork Fri Jun 2 10:25:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35728C7EE29 for ; Fri, 2 Jun 2023 10:28:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235662AbjFBK2V (ORCPT ); Fri, 2 Jun 2023 06:28:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235395AbjFBK15 (ORCPT ); Fri, 2 Jun 2023 06:27:57 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6397F268E for ; Fri, 2 Jun 2023 03:26:14 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f60bc818d7so1774418e87.1 for ; Fri, 02 Jun 2023 03:26:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701557; x=1688293557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s+WAD0bNtCqZf8cEoH7eJlDDTc5MjxUTnqrq6G9eSF8=; b=Ab9v8abN41UHBInqX/30veEXBEvxP3sX21nwbHshQXdRqKyRD1XzCKyPsBz5Z148zw 7wQs21Ty8f/kLGT/q7R/xDj9hfwPjX61bPapx6R1zhDJ7GKsandcDHXfTs13CCWwhNx1 utdmKmhv7Pm57PyhRdenxM4Iu5ISRHVXefZkX7XhnwkGFZ7uOoXDkkmNLsDR5NmbuFJ2 iF+TU187XBuN9aYl5BnGRH+x0LDefwD6V7813lLgOpry1MKeX8Uy+HNUAvR7aWRBxbGB VUZt73uSojuiN/mOEv1Pj72jS0CO7AJ5Jjvw8F2fAAnjYxRH+KnDZJsshlw4TwKOT8aC DINg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701557; x=1688293557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s+WAD0bNtCqZf8cEoH7eJlDDTc5MjxUTnqrq6G9eSF8=; b=Tjq9jnOjjxRN9oR4eUKd1I51/V4l5uKtYnV/i7HO4A/j+GnB3FAn3gzMfxjQSOAQGJ qCOrWmHQXDVaELmiGDHRBOLoig6jGHc/J6MptkFgDrUzxD9TGk0rg8g/tlB4Jtbmh9Cc h056SpifonVwXc3OXzm/5ixEBUkWT0oKQL2rOlPmRdYnufRRlZz5wdPuTsAtv7lmE/wQ YWxms/8xCPA/UVj9Dl2J6V0JjCwdk1exLOxKyoBbbU+qWtfm45efF0A19vVN4oZ2gBz4 ZKrBmqRnFUfPyY9Oirnx55WELpoWcilL81fRnoJx5YaIHbLrCLewwnHIAxLx/abl3y7a Kc8w== X-Gm-Message-State: AC+VfDx0ws57X3znbgJfUVY8h0pP6tD01+6BlGT4xyGA5CgUuze6045C RZyFRcp/0zs+a+9J133m2wOvQbNCkGt4Fw== X-Google-Smtp-Source: ACHHUZ6+MOW/cZK7dC9hCzw0PSFK7ikuHSGykOLQLfqjSN0DFyKyPFq4yJfW2tqO7lWtFUK8kF3rug== X-Received: by 2002:a19:ac43:0:b0:4f3:9868:bee4 with SMTP id r3-20020a19ac43000000b004f39868bee4mr1621541lfc.32.1685701556708; Fri, 02 Jun 2023 03:25:56 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:25:56 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 04/15] replay: die() instead of failing assert() Date: Fri, 2 Jun 2023 12:25:22 +0200 Message-ID: <20230602102533.876905-5-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren It's not a good idea for regular Git commands to use an assert() to check for things that could happen but are not supported. Let's die() with an explanation of the issue instead. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/replay.c b/builtin/replay.c index 7eb05048a5..2537adbaea 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -178,7 +178,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix) fprintf(stderr, "Rebasing %s...\r", oid_to_hex(&commit->object.oid)); - assert(commit->parents && !commit->parents->next); + + if (!commit->parents) + die(_("replaying down to root commit is not supported yet!")); + if (commit->parents->next) + die(_("replaying merge commits is not supported yet!")); + base = commit->parents->item; next_tree = repo_get_commit_tree(the_repository, commit); From patchwork Fri Jun 2 10:25:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265050 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46228C7EE24 for ; Fri, 2 Jun 2023 10:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235697AbjFBK2Z (ORCPT ); Fri, 2 Jun 2023 06:28:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235577AbjFBK16 (ORCPT ); Fri, 2 Jun 2023 06:27:58 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE68A2693 for ; Fri, 2 Jun 2023 03:26:15 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3f60e730bf2so18996115e9.1 for ; Fri, 02 Jun 2023 03:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701558; x=1688293558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l59AcLLCUVroqGYZSEcJWJ80YBF7a4Xqu5LX5BrHy4M=; b=f1KIUy1AVMXjEmRmquqHOSfEBjexMypCWkO4M6m7zKXfmaig5sYqLBvqjmsIUwFNfo hvw02lEF8KJzuwhAN/Rda4dxUb/VG773UtE6GlCs5zEh/TX5HL8NRdO9d3AxsxUcSdhN GAr1RR7TpG7oxPgnRFkFUasVutXVeM6bb7BoW6T4hrbUHCo1ZGZAaMf+veCt2+hViv1G OERXzmsICis9KinKV0FrqMwkobQNKa855og1BUFtbk5Ay5e7rZRUkcrYN7P63GJhC8tc c+Q6aFPJFUrms2yN+x/sY1dikYbLAisP8p0uuYqVvGYKTVA6QX/ZBKCeIVBJOITAsLt/ VOWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701558; x=1688293558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l59AcLLCUVroqGYZSEcJWJ80YBF7a4Xqu5LX5BrHy4M=; b=F/Ba1Ab6aYkecJLDFVtCjd7fo0BOWSAugYnGFJ3HtkJavN3bdQbhq7AyNB0sYwWQWz lrABOFHryY/tCa3iAcEL1PZuIDA2iqbvyte1uw65KoQvYcB1tV6KaMkT8IzIjO5o9gbv eWuNm0tOp3o+M229dNLGALSSOQ90KJ/j2gt8kGHy1x+h7BJsB/rwSahAF3tHb+CeL34f lBIalyM2MRFLkjqhmON1IvuaU+SZBo/7koFylcfNfdSQx8WcH5+yDU7Gc7Z0XwpXWp4d Kn/QzFTFQucFg4K7SyOkCnhVIzorQMqjbKIkUT0zg1ByHQCk2GlPtGNfuC0Azy4xFHtl hGGw== X-Gm-Message-State: AC+VfDwDT5377QTrGy0gBH3iNJnlIJALCR6GdWtT1k6O9y98Q0gdPL/9 DaGOoNXBf6dL/w+7wD8vc/ORn2PtOBWoLw== X-Google-Smtp-Source: ACHHUZ4SDl8vmhhMBOoSciwy2q431ROsvn8oU9hEOmFV3PpYIhN0LwkB9blu5G0JwpdemmwpRm2NHA== X-Received: by 2002:a1c:6a15:0:b0:3f6:89e:2716 with SMTP id f21-20020a1c6a15000000b003f6089e2716mr1783519wmc.33.1685701558318; Fri, 02 Jun 2023 03:25:58 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:25:57 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 05/15] replay: introduce pick_regular_commit() Date: Fri, 2 Jun 2023 12:25:23 +0200 Message-ID: <20230602102533.876905-6-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Let's refactor the code to handle a regular commit (a commit that is neither a root commit nor a merge commit) into a single function instead of keeping it inside cmd_replay(). This is good for separation of concerns, and this will help further work in the future to replay merge commits. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 54 ++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index 2537adbaea..319020f5fd 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -88,6 +88,35 @@ static struct commit *create_commit(struct tree *tree, return (struct commit *)obj; } +static struct commit *pick_regular_commit(struct commit *pickme, + struct commit *last_commit, + struct merge_options *merge_opt, + struct merge_result *result) +{ + struct commit *base; + struct tree *pickme_tree, *base_tree; + + base = pickme->parents->item; + + pickme_tree = repo_get_commit_tree(the_repository, pickme); + base_tree = repo_get_commit_tree(the_repository, base); + + merge_opt->branch2 = short_commit_name(pickme); + merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2); + + merge_incore_nonrecursive(merge_opt, + base_tree, + result->tree, + pickme_tree, + result); + + free((char*)merge_opt->ancestor); + merge_opt->ancestor = NULL; + if (!result->clean) + return NULL; + return create_commit(result->tree, pickme, last_commit); +} + int cmd_replay(int argc, const char **argv, const char *prefix) { struct commit *onto; @@ -99,7 +128,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) struct rev_info revs; struct commit *commit; struct merge_options merge_opt; - struct tree *next_tree, *base_tree, *head_tree; + struct tree *head_tree; struct merge_result result; struct strbuf reflog_msg = STRBUF_INIT; struct strbuf branch_name = STRBUF_INIT; @@ -174,7 +203,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) result.tree = head_tree; last_commit = onto; while ((commit = get_revision(&revs))) { - struct commit *base; + struct commit *pick; fprintf(stderr, "Rebasing %s...\r", oid_to_hex(&commit->object.oid)); @@ -184,26 +213,11 @@ int cmd_replay(int argc, const char **argv, const char *prefix) if (commit->parents->next) die(_("replaying merge commits is not supported yet!")); - base = commit->parents->item; - - next_tree = repo_get_commit_tree(the_repository, commit); - base_tree = repo_get_commit_tree(the_repository, base); - - merge_opt.branch2 = short_commit_name(commit); - merge_opt.ancestor = xstrfmt("parent of %s", merge_opt.branch2); - - merge_incore_nonrecursive(&merge_opt, - base_tree, - result.tree, - next_tree, - &result); - - free((char*)merge_opt.ancestor); - merge_opt.ancestor = NULL; - if (!result.clean) + pick = pick_regular_commit(commit, last_commit, &merge_opt, &result); + if (!pick) break; + last_commit = pick; last_picked_commit = commit; - last_commit = create_commit(result.tree, commit, last_commit); } merge_finalize(&merge_opt, &result); From patchwork Fri Jun 2 10:25:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265052 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9540DC7EE29 for ; Fri, 2 Jun 2023 10:28:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235705AbjFBK2u (ORCPT ); Fri, 2 Jun 2023 06:28:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235600AbjFBK2A (ORCPT ); Fri, 2 Jun 2023 06:28:00 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEB8EE4D for ; Fri, 2 Jun 2023 03:26:19 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f603d4bc5bso18227705e9.3 for ; Fri, 02 Jun 2023 03:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701560; x=1688293560; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/oC3Plisdt966JyNz69Px1c/osGOg6I3auirVRmndbg=; b=Vrf1QwgJxi7C3jGQYQ3ePEJXalHYuZmGW+ejddv2sUsGarT25kqtIKaJmd3YEpM6AK 5rEMgX8hqxHsDzzNhncPlnRs7y3/ir9kh8+7+LHkb1kn8fFYaqJg1S6kTx/DkiGwltCh juUSUIcCC5EcchkYRBCt+Esqak0OURCjzbURFrnKWOuDpVskZRXK2AqznTQsZfGC3JcM J/yr2sgeo/EFt8/av23N4P9WM0OKfy4ByJIyX41zZex59A47O83m+0/8BJSQyF9H+7Ug 72RYurMIm9jroMricdHSYJZ1v3kU5ayPqKc536qt2lmc1Uhn54bNhTDa6AxCynV5naGw akDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701560; x=1688293560; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/oC3Plisdt966JyNz69Px1c/osGOg6I3auirVRmndbg=; b=RinuRbmMjp4192hS+idAn6m9ld3vplmDyd9Fffa0He2XB+gt0vRlgIbr7fGg3YZUej dNKkx0k1/H0VPEs8G6YitxNhGhSDwNlB9DRe7dBpfVxnrndPgwRr89W2mpje4XhIn7ie 36Y9QGulHmH3DhrtIlVEuzxTdR+Nuc/arXTPdomyRs4G0RCFRE38SgSlwFzIjMTUJsg9 H8FLAcnjik/6fBmj4uXJsuNPeYGzl7PLGC1r5zpBvdNG7yxQUnhd8uKRXMpIpQgCyX+P 52wVO7pLKWplFLe9g7AvNwhTisBQ3OrWGdMFILDyFOrAsg164Etlq0KEbHZ4do8wmJv3 GGpQ== X-Gm-Message-State: AC+VfDzHY0cND1E8ihjRQEWMvd+C1jkVLzAZW7rINB+ooO8VX6eSfddY gRkFCPmn2FQYDDl44IpBggO3lP8kTTMefQ== X-Google-Smtp-Source: ACHHUZ5Kibt0nYRZcx6tLLVsANiBnevCh4e4o37CDFkU80togBtDipKXDx9VMzO2tHkAqFVoVnXUPA== X-Received: by 2002:a7b:c8d9:0:b0:3f4:271a:8aaf with SMTP id f25-20020a7bc8d9000000b003f4271a8aafmr1793687wml.38.1685701560342; Fri, 02 Jun 2023 03:26:00 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:25:59 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 06/15] replay: don't simplify history Date: Fri, 2 Jun 2023 12:25:24 +0200 Message-ID: <20230602102533.876905-7-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Let's set the rev walking options we need after calling setup_revisions() instead of before. This makes it clearer which options we need. Also we don't want history simplification, as we want to deal with all the commits in the affected range. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index 319020f5fd..d28d468008 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -172,15 +172,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix) repo_init_revisions(the_repository, &revs, prefix); - revs.verbose_header = 1; - revs.max_parents = 1; - revs.cherry_mark = 1; - revs.limited = 1; - revs.reverse = 1; - revs.right_only = 1; - revs.sort_order = REV_SORT_IN_GRAPH_ORDER; - revs.topo_order = 1; - strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL); if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) { @@ -188,6 +179,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix) goto cleanup; } + /* requirements/overrides for revs */ + revs.reverse = 1; + revs.sort_order = REV_SORT_IN_GRAPH_ORDER; + revs.topo_order = 1; + revs.simplify_history = 0; + strvec_clear(&rev_walk_args); if (prepare_revision_walk(&revs) < 0) { From patchwork Fri Jun 2 10:25:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05AA7C7EE24 for ; Fri, 2 Jun 2023 10:28:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235711AbjFBK2w (ORCPT ); Fri, 2 Jun 2023 06:28:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235616AbjFBK2C (ORCPT ); Fri, 2 Jun 2023 06:28:02 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE5E26AA for ; Fri, 2 Jun 2023 03:26:24 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4f004cc54f4so2533738e87.3 for ; Fri, 02 Jun 2023 03:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701562; x=1688293562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=giikQtTdogrSg/BbfYz+hkhwJOgoL3VsNe1CrYfp5nc=; b=RA4yWlWhv/jC70hPUgHRvZfqSl+Et7PVorfkvyV30eiW1ypqjLOOYv2DgJqI65t8ny ykXzYOjYZKjgNw7+cXDFhVzIx0fQvVFDkzxDEMhEtY02Fek1WapU7vl5rllcj3MFt09g PzOuFlSeg9LRqavhPPbrP+OlRg3Gt9hLzNmjRminq8HJBHz36b7BFry4v2HDtbPAxdYL Zq5a/08wa+Iy38es9LUYCiyMKmS6IfzRZj1Ud3LT1Kj5OCqOn8evGgsGF973Z43nepqg DEocEAqvPKx49vv5F3/j+EX4LWmmppq9YaLpVpKLSlOfM/Pan767/gWl2hV1bh5Jaicn AtKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701562; x=1688293562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=giikQtTdogrSg/BbfYz+hkhwJOgoL3VsNe1CrYfp5nc=; b=L244Y3eW+EuWDAa/Ve4O3LFGF8ztpEJXWBXd9rBsOiCOG35fFFp+TSNvlUIOBTYzlF v5wZ6KDmzTZ+c6Wl4CVg1mVumtrfl9e3WtHwblV3kjFSiWGgOH/bnd8waACbQJ+q/nhg WGYCMcDw3BSgiNLEqY/UL+0/b9wIQ+xbrOfD9Zr4tcVfuafFBiqT/DBurDzM1CCp1mSI an6C1LerHGMkjRUD8aIznaqBlnDRO0WvDne9SMV5oSZdh+dEKOW6jTFjuw17Cz8KPwbz VpJwjpLdgAr6O6NcRbLrY69z7dP8hF+37HNk7SvE0FXoR+iaEz+RuVncE+WXiBV7eJ74 3I5w== X-Gm-Message-State: AC+VfDwbSBvZbAih7OXPSoc9az0dl5NpVjepIYiwYHcrDIatNPuTRVC5 zdULJvTmI3w6IOXeZVdFOQ9xSMOWzSszCA== X-Google-Smtp-Source: ACHHUZ764SjkTVCC7i4bLUKJRUv312HE5NydgH2P0+Fs6fflFal2zEi+iYm5v8zk1xVMqTlp6dAOjw== X-Received: by 2002:ac2:47e4:0:b0:4f3:a1db:ad4 with SMTP id b4-20020ac247e4000000b004f3a1db0ad4mr1367417lfp.66.1685701561695; Fri, 02 Jun 2023 03:26:01 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:26:01 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 07/15] replay: add an important FIXME comment about gpg signing Date: Fri, 2 Jun 2023 12:25:25 +0200 Message-ID: <20230602102533.876905-8-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren We want to be able to handle signed commits in some way in the future, but we are not ready to do it now. So for the time being let's just add a FIXME comment to remind us about it. These are different ways we could handle them: - in case of a cli user and if there was an interactive mode, we could perhaps ask if the user wants to sign again - we could add an option to just fail if there are signed commits Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/replay.c b/builtin/replay.c index d28d468008..52db8e0941 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -61,7 +61,7 @@ static struct commit *create_commit(struct tree *tree, struct object *obj; struct commit_list *parents = NULL; char *author; - char *sign_commit = NULL; + char *sign_commit = NULL; /* FIXME: cli users might want to sign again */ struct commit_extra_header *extra; struct strbuf msg = STRBUF_INIT; const char *out_enc = get_commit_output_encoding(); From patchwork Fri Jun 2 10:25:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265054 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1556BC7EE29 for ; Fri, 2 Jun 2023 10:29:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235032AbjFBK3E (ORCPT ); Fri, 2 Jun 2023 06:29:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234594AbjFBK2G (ORCPT ); Fri, 2 Jun 2023 06:28:06 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 344BE10CC for ; Fri, 2 Jun 2023 03:26:30 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4f3edc05aa5so2432374e87.3 for ; Fri, 02 Jun 2023 03:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701563; x=1688293563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kLH08/1Jj31YQZ3K0A+NRzZLpvhxie+bpVAPrS6fHA8=; b=gpe7AZ/VA+YZyWhhRCzoXa9E4+JvrIZAi+n5xofJupgFMFJ/aFTgCNvbmp9YRV9Cqk O4FIrh8/qvUaBDCqX6+Q2xieyQ2G7nh9wMpzVmhGY79Y1+/G2n8R3KXYgcp1QoD2G359 jAXe2drLF0VaFb4xFOmfo+Xk9bw2Mg8K7lL4TR6hqYanWJFx1wiA1uJow6VnmU2DLoW2 Fa5YLBMijRNSDyhKR90z2Z9Ut0L1X6QMQElfYXLTW4C9eWZtLAB0o1CXza3yze+uGE/3 ApMp4NtmvfPU6DD+ytMqraZacDijsX+ovwNG6XmQuR95QWgT+k1dFCJlkdNYHJKOOs9W n1TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701563; x=1688293563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kLH08/1Jj31YQZ3K0A+NRzZLpvhxie+bpVAPrS6fHA8=; b=k865my+E9n7/ZX4LStAzbf+r2qJvY6E/tjmbiQmshajf04O4oUIeqOKio199VMS9pg 4wzZ7mNiprlx2d4/rHVFX0S724maq7b0mfYiFGPctJ31ecRzWbGn8tql8WQrkzIXe13i 0swJQPOGMBk4c/hMaKrD2A01fbZG78R/QTb8u5ZcWPucVmDIcVI/+aBR6Ccbf599FfEd /8iXkNyZTriItKlWJ0Eu+7z38R9GyZpdA0apsLPPWnrrLW0ytrIjjoxf81M6tri8G/O2 zHMp+rO+wb7KqKHoalVteTfMLajiV6pwyWHEP8ba0k0T7IXFC/iEFFdm217DkDpI+ZKl tyZg== X-Gm-Message-State: AC+VfDx1Va5W+wzHsIL+vYVNIPtzUbjL24N/bVJ1Qix0V4hSxQcC7A7+ KaN688dFTL8drEfj1/cihNBPb7/nc6xTCQ== X-Google-Smtp-Source: ACHHUZ6dOr9k0FPNFqPzbi8kWYH2tm7dNex8/iziXWmKW6SaAFFE/IigT6lGjjzn6eOADn1dyH3g3w== X-Received: by 2002:ac2:5455:0:b0:4f1:26f5:77fb with SMTP id d21-20020ac25455000000b004f126f577fbmr1572630lfn.28.1685701563323; Fri, 02 Jun 2023 03:26:03 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:26:02 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 08/15] replay: remove progress and info output Date: Fri, 2 Jun 2023 12:25:26 +0200 Message-ID: <20230602102533.876905-9-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren The replay command will be changed in a follow up commit, so that it will not update refs directly, but instead it will print on stdout a list of commands that can be consumed by `git update-ref --stdin`. We don't want this output to be polluted by its current low value output, so let's just remove the latter. In the future, when the command gets an option to update refs by itself, it will make a lot of sense to display a progress meter, but we are not there yet. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index 52db8e0941..2ad0835c06 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -194,7 +194,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) init_merge_options(&merge_opt, the_repository); memset(&result, 0, sizeof(result)); - merge_opt.show_rename_progress = 1; + merge_opt.show_rename_progress = 0; merge_opt.branch1 = "HEAD"; head_tree = repo_get_commit_tree(the_repository, onto); result.tree = head_tree; @@ -202,9 +202,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix) while ((commit = get_revision(&revs))) { struct commit *pick; - fprintf(stderr, "Rebasing %s...\r", - oid_to_hex(&commit->object.oid)); - if (!commit->parents) die(_("replaying down to root commit is not supported yet!")); if (commit->parents->next) @@ -223,7 +220,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix) exit(128); if (result.clean) { - fprintf(stderr, "\nDone.\n"); strbuf_addf(&reflog_msg, "finish rebase %s onto %s", oid_to_hex(&last_picked_commit->object.oid), oid_to_hex(&last_commit->object.oid)); @@ -237,7 +233,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix) if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0) die(_("unable to update HEAD")); } else { - fprintf(stderr, "\nAborting: Hit a conflict.\n"); strbuf_addf(&reflog_msg, "rebase progress up to %s", oid_to_hex(&last_picked_commit->object.oid)); if (update_ref(reflog_msg.buf, "HEAD", From patchwork Fri Jun 2 10:25:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2DF7C7EE24 for ; Fri, 2 Jun 2023 10:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235536AbjFBK3H (ORCPT ); Fri, 2 Jun 2023 06:29:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235495AbjFBK2L (ORCPT ); Fri, 2 Jun 2023 06:28:11 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FD6410D2 for ; Fri, 2 Jun 2023 03:26:32 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f4b2bc1565so2482002e87.2 for ; Fri, 02 Jun 2023 03:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701565; x=1688293565; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BoyNNzaApwgD4JT070uWEaEAB0u+J2m/o9l9+cvhSns=; b=iPfOk5d9XeiDdTMZVesx3iy90TMpKY4sT1D5TuGxwGRqRxwrCubvOd7/cWIg1NhlTT 4CODQUIn9MIUjOGCVsRIX32OkhKxQsiamoxTINCf9JmKOkiAtY8PPQtv7wmcqvDqOoNP Vp9d8D6BbRxChF/Zml3O/QYC4EfCSJi895Zmy1GNDIqOvAmsc+UbKsiefPblslvA89d6 CmpVHx4SbHKYKSpraUVoYJ7O/EmWygK7Ox5NU9M1fHh+9FYlKCrHKOl5HfXYr1evfE9k VuA+SC4t3HfSc/fDL8hENIBnWi6uh95k6rA1jKAwYOE0nRTovNfBCNmbEqWGSaLhUQoz ruiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701565; x=1688293565; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BoyNNzaApwgD4JT070uWEaEAB0u+J2m/o9l9+cvhSns=; b=Ez7pmvH8tFm/zYJDEdc/lkSnIqWco2V0LZ+ISqOuJUqUvWu/CA3MXc0jzwKEwZajFc m+cV4V+b6RhubeuvFaO9l/i0WV1TttEOO3GL7sO1dJOvJqKkqqqfu4BqhfFeKSGXDMvG 3ULzS0XEThjvndpYMJP+kqss9KK7a3RFFpEFIrDPOcm5zSi2UzsJmG7lemewsxSzwqSG r1S3VRC3Q/TiiqVJGOBoNx/Yg9IPx2HGE3sRxwI7SC8Pzfq0pZiX3QmX7ZnFwRhopO1c KcEgliR8A+SuPaILLao+0RToeyeXcHtBHskCEHedj+0srrTSKdemXIE57efsPfk/EEms sV2g== X-Gm-Message-State: AC+VfDzzJrkuilRcy8RjkrkCDCu2rHWgg6+mCSIAlUmDDZXZo4HqSNnF +BAgCvhTDovjSo0lTZeRgaSOTvbNnttFyQ== X-Google-Smtp-Source: ACHHUZ5LNtLlDQlY1JIZdyg3h1VXm/obGcbD1GLihKfeYWeHIeW/WScJiRhRIlgUk7J8jyyG8yWlEg== X-Received: by 2002:ac2:4e71:0:b0:4f0:181:5a14 with SMTP id y17-20020ac24e71000000b004f001815a14mr1657697lfs.21.1685701564758; Fri, 02 Jun 2023 03:26:04 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:26:04 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 09/15] replay: remove HEAD related sanity check Date: Fri, 2 Jun 2023 12:25:27 +0200 Message-ID: <20230602102533.876905-10-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren We want replay to be a command that can be used on the server side on any branch, not just the current one, so we are going to stop updating HEAD in a future commit. A "sanity check" that makes sure we are replaying the current branch doesn't make sense anymore. Let's remove it. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index 2ad0835c06..3b86fe140f 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -122,7 +122,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix) struct commit *onto; const char *onto_name = NULL; struct commit *last_commit = NULL, *last_picked_commit = NULL; - struct object_id head; struct lock_file lock = LOCK_INIT; struct strvec rev_walk_args = STRVEC_INIT; struct rev_info revs; @@ -161,11 +160,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix) onto = peel_committish(onto_name); strbuf_addf(&branch_name, "refs/heads/%s", argv[2]); - /* Sanity check */ - if (repo_get_oid(the_repository, "HEAD", &head)) - die(_("Cannot read HEAD")); - assert(oideq(&onto->object.oid, &head)); - repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR); if (repo_read_index(the_repository) < 0) BUG("Could not read index"); @@ -237,7 +231,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) oid_to_hex(&last_picked_commit->object.oid)); if (update_ref(reflog_msg.buf, "HEAD", &last_commit->object.oid, - &head, + &onto->object.oid, REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) { error(_("could not update %s"), argv[2]); die("Failed to update %s", argv[2]); From patchwork Fri Jun 2 10:25:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45A78C7EE29 for ; Fri, 2 Jun 2023 10:29:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235487AbjFBK3Q (ORCPT ); Fri, 2 Jun 2023 06:29:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232921AbjFBK2l (ORCPT ); Fri, 2 Jun 2023 06:28:41 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19B2F1729 for ; Fri, 2 Jun 2023 03:26:41 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f6a6b9c079so17922025e9.1 for ; Fri, 02 Jun 2023 03:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701566; x=1688293566; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KxpvNFvJnRpwZpW3piDtJ/hKH98TDXtBseRPfJghvMY=; b=hcx6YuGu3eaXxbtWavdSn1yxaSabAhM/4ejH7faFoPi4oeo1fBHlhIAwBDgR927FWI gUH2uIVddrTIuU9HIqFIsJgUgq0W1eP/uHwRZ7TUb86UYHp8MuABeVFUyVqiKpuRps1E +cbcS/r/7hlsfRc/qMH2N1Z+WMb3WaI416mOAqE5h9/6r5r9pK+yl1yrp1ZihBaAE1fr LUKi05EewYUfQOBZpYnMZ5R9DcKLGk5mSvvo4YKyc7WdwgkhGhhYvXm+o50/VbPj0UeC 8IdvcIAnuvrcRyprzj0jI3Ij4XUy5wo4oF/raJ3wv8XY63wPfG+UhpIoKUA9Byn4TLXq 1ecA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701566; x=1688293566; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KxpvNFvJnRpwZpW3piDtJ/hKH98TDXtBseRPfJghvMY=; b=Ymam/TPed1jTM8TdhbwY4AWEFNGuuuIXgcCWsfb8BFSkPXXWUOyrqj4LEPGApx+838 +z319ylTwvpc5aRxirlqk4fjwD+KGSQbZar6sKOH0aVa2ZTvgk15PuWdcoiju5GZ7sks knwgtNE9j/bny2kMabojhg7hyR+A9IjfNOBh5uK/buhQx16vgNPp/io5+s5l22Oe3Lkw FBLJ7x15GVby5LphdO63I67mtLdIkfRnNXfdfhXbdIC1A1EUJvNgaSHs/oUevJHVd/Pf VPliDbkvfbrWnYWyg8sEdiFHsguE47QPsQzWWYDXPjNjzpQ5GZsS31wy3Zmfk9gnIOmV 9YBQ== X-Gm-Message-State: AC+VfDwrQzTXE/DuZgRV5DWZc/2ili2/k7PBlCGfebwqeDqSvnJDo91e SzvSXAeUX8aIZnPNg9OVjj79rdoaxANvyw== X-Google-Smtp-Source: ACHHUZ44BA5O2LKgk0XO6i8pB3qv0FxkJb6kI5KBT5Cbumd9FnRY9HOZ81YZ1xyl9k8HNX36QofV6A== X-Received: by 2002:a7b:c84f:0:b0:3f5:aa2:288b with SMTP id c15-20020a7bc84f000000b003f50aa2288bmr1521673wml.0.1685701566223; Fri, 02 Jun 2023 03:26:06 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:26:05 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 10/15] replay: make it a minimal server side command Date: Fri, 2 Jun 2023 12:25:28 +0200 Message-ID: <20230602102533.876905-11-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren We want this command to be a minimal command that just does server side picking of commits, displaying the results on stdout for higher level scripts to consume. So let's simplify it: * remove the worktree and index reading/writing, * remove the ref (and reflog) updating, * remove the assumptions tying us to HEAD, since (a) this is not a rebase and (b) we want to be able to pick commits in a bare repo, i.e. to/from branches that are not checked out and not the main branch, * remove unneeded includes, * handle rebasing multiple branches by printing on stdout the update ref commands that should be performed. The output can be piped into `git update-ref --stdin` for the ref updates to happen. In the future to make it easier for users to use this command directly maybe an option can be added to automatically pipe its output into `git update-ref`. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 78 ++++++++---------------- t/t6429-merge-sequence-rename-caching.sh | 39 +++++++----- 2 files changed, 51 insertions(+), 66 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index 3b86fe140f..9385973ffc 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -6,10 +6,7 @@ #include "git-compat-util.h" #include "builtin.h" -#include "cache-tree.h" -#include "commit.h" #include "environment.h" -#include "gettext.h" #include "hex.h" #include "lockfile.h" #include "merge-ort.h" @@ -17,8 +14,6 @@ #include "parse-options.h" #include "refs.h" #include "revision.h" -#include "sequencer.h" -#include "setup.h" #include "strvec.h" #include #include @@ -101,6 +96,7 @@ static struct commit *pick_regular_commit(struct commit *pickme, pickme_tree = repo_get_commit_tree(the_repository, pickme); base_tree = repo_get_commit_tree(the_repository, base); + merge_opt->branch1 = short_commit_name(last_commit); merge_opt->branch2 = short_commit_name(pickme); merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2); @@ -121,15 +117,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix) { struct commit *onto; const char *onto_name = NULL; - struct commit *last_commit = NULL, *last_picked_commit = NULL; - struct lock_file lock = LOCK_INIT; + struct commit *last_commit = NULL; struct strvec rev_walk_args = STRVEC_INIT; struct rev_info revs; struct commit *commit; struct merge_options merge_opt; - struct tree *head_tree; struct merge_result result; - struct strbuf reflog_msg = STRBUF_INIT; struct strbuf branch_name = STRBUF_INIT; int ret = 0; @@ -160,10 +153,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix) onto = peel_committish(onto_name); strbuf_addf(&branch_name, "refs/heads/%s", argv[2]); - repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR); - if (repo_read_index(the_repository) < 0) - BUG("Could not read index"); - repo_init_revisions(the_repository, &revs, prefix); strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL); @@ -189,58 +178,45 @@ int cmd_replay(int argc, const char **argv, const char *prefix) init_merge_options(&merge_opt, the_repository); memset(&result, 0, sizeof(result)); merge_opt.show_rename_progress = 0; - merge_opt.branch1 = "HEAD"; - head_tree = repo_get_commit_tree(the_repository, onto); - result.tree = head_tree; + result.tree = repo_get_commit_tree(the_repository, onto); last_commit = onto; while ((commit = get_revision(&revs))) { - struct commit *pick; + const struct name_decoration *decoration; if (!commit->parents) die(_("replaying down to root commit is not supported yet!")); if (commit->parents->next) die(_("replaying merge commits is not supported yet!")); - pick = pick_regular_commit(commit, last_commit, &merge_opt, &result); - if (!pick) + last_commit = pick_regular_commit(commit, last_commit, &merge_opt, &result); + if (!last_commit) break; - last_commit = pick; - last_picked_commit = commit; + + decoration = get_name_decoration(&commit->object); + if (!decoration) + continue; + + while (decoration) { + if (decoration->type == DECORATION_REF_LOCAL) { + printf("update %s %s %s\n", + decoration->name, + oid_to_hex(&last_commit->object.oid), + oid_to_hex(&commit->object.oid)); + } + decoration = decoration->next; + } } + /* Cleanup */ merge_finalize(&merge_opt, &result); + ret = result.clean; - if (result.clean < 0) - exit(128); - - if (result.clean) { - strbuf_addf(&reflog_msg, "finish rebase %s onto %s", - oid_to_hex(&last_picked_commit->object.oid), - oid_to_hex(&last_commit->object.oid)); - if (update_ref(reflog_msg.buf, branch_name.buf, - &last_commit->object.oid, - &last_picked_commit->object.oid, - REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) { - error(_("could not update %s"), argv[2]); - die("Failed to update %s", argv[2]); - } - if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0) - die(_("unable to update HEAD")); - } else { - strbuf_addf(&reflog_msg, "rebase progress up to %s", - oid_to_hex(&last_picked_commit->object.oid)); - if (update_ref(reflog_msg.buf, "HEAD", - &last_commit->object.oid, - &onto->object.oid, - REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) { - error(_("could not update %s"), argv[2]); - die("Failed to update %s", argv[2]); - } - } - ret = (result.clean == 0); cleanup: - strbuf_release(&reflog_msg); strbuf_release(&branch_name); release_revisions(&revs); - return ret; + + /* Return */ + if (ret < 0) + exit(128); + return ret ? 0 : 1; } diff --git a/t/t6429-merge-sequence-rename-caching.sh b/t/t6429-merge-sequence-rename-caching.sh index 7670b72008..099aefeffc 100755 --- a/t/t6429-merge-sequence-rename-caching.sh +++ b/t/t6429-merge-sequence-rename-caching.sh @@ -71,8 +71,9 @@ test_expect_success 'caching renames does not preclude finding new ones' ' git switch upstream && - git replay --onto HEAD upstream~1 topic && - git reset --hard topic && + git replay --onto HEAD upstream~1 topic >out && + git update-ref --stdin tracked-files && test_line_count = 2 tracked-files && @@ -140,7 +141,9 @@ test_expect_success 'cherry-pick both a commit and its immediate revert' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - git replay --onto HEAD upstream~1 topic && + git replay --onto HEAD upstream~1 topic >out && + git update-ref --stdin calls && test_line_count = 1 calls @@ -198,8 +201,9 @@ test_expect_success 'rename same file identically, then reintroduce it' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - git replay --onto HEAD upstream~1 topic && - git reset --hard topic && + git replay --onto HEAD upstream~1 topic >out && + git update-ref --stdin tracked && test_line_count = 2 tracked && @@ -275,8 +279,9 @@ test_expect_success 'rename same file identically, then add file to old dir' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - git replay --onto HEAD upstream~1 topic && - git reset --hard topic && + git replay --onto HEAD upstream~1 topic >out && + git update-ref --stdin tracked && test_line_count = 4 tracked && @@ -451,8 +456,9 @@ test_expect_success 'dir rename unneeded, then add new file to old dir' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - git replay --onto HEAD upstream~1 topic && - git reset --hard topic && + git replay --onto HEAD upstream~1 topic >out && + git update-ref --stdin calls && test_line_count = 2 calls && @@ -517,8 +523,9 @@ test_expect_success 'dir rename unneeded, then rename existing file into old dir GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - git replay --onto HEAD upstream~1 topic && - git reset --hard topic && + git replay --onto HEAD upstream~1 topic >out && + git update-ref --stdin calls && test_line_count = 3 calls && @@ -619,8 +626,9 @@ test_expect_success 'caching renames only on upstream side, part 1' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - git replay --onto HEAD upstream~1 topic && - git reset --hard topic && + git replay --onto HEAD upstream~1 topic >out && + git update-ref --stdin calls && test_line_count = 1 calls && @@ -677,8 +685,9 @@ test_expect_success 'caching renames only on upstream side, part 2' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - git replay --onto HEAD upstream~1 topic && - git reset --hard topic && + git replay --onto HEAD upstream~1 topic >out && + git update-ref --stdin calls && test_line_count = 2 calls && From patchwork Fri Jun 2 10:25:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A7B7C7EE24 for ; Fri, 2 Jun 2023 10:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235710AbjFBK31 (ORCPT ); Fri, 2 Jun 2023 06:29:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235617AbjFBK2w (ORCPT ); Fri, 2 Jun 2023 06:28:52 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 910F41735 for ; Fri, 2 Jun 2023 03:26:51 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-30aeee7c8a0so1450605f8f.1 for ; Fri, 02 Jun 2023 03:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701568; x=1688293568; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D8e2H4U5UUwV1RnmYcVFLJRUGH4b+zKLMWmbu8fM+aU=; b=e6b9jYf+8nfx+m6ON/01C8GsHU9ArkoxGT/V+B6Vtgxi/CpCgpEXegYkcrBDc9RWVG lVR8Avx4UYo4iUU16Cyj1zam+3zizC24C0d7SCd2aiyYxdEKIOJzbDdchAmrKkucSHYv AKrHbL4kDe+v4Jo+UccTlR4/MTz1M6RCgzwc10JbHDKVSkE6A2ff0CV+xHMvd3S4Lh6k fphJpnnfNwDvPj61Rhq7w68RcfHqartBaMeM8XUAYtpdRbbRXfrmpBsgSrylNwvPib6y XUz1/b0gUVOR5yqd+DjDWuJcKbxWEFrOrLeMqSYNG8wO699GCn3ygImJ3VidpQPnVuN9 QjNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701568; x=1688293568; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D8e2H4U5UUwV1RnmYcVFLJRUGH4b+zKLMWmbu8fM+aU=; b=erBHLUlAIvO0pHD5Krr7jYkTqlhW17zfb2QMBAK/o4FTBnE0DsXTcQi3Q+83zAwQvt 6S6Cxoy4M/gBCnXcK/DiBOi4pDWAU9HmLfvOvNNru8fEwSSqduBwD4BsZlfS7w+BK8HB PvSXpxvihajzYtpcved9RP9XcdVV/1EpjPfyWxW0RcmcUGoSHos4CcHH3aw9twO0lDap 4w9WlKHG3HcL8ujuAMqGt+8XD9PoOBZ/ZbrEUtXZYleN+cgSrq6TapJoxcQcfH+sfAFK C4m4kVp8gbhfh6uc4fKSYouvNTS5l7pEH54cJPUqj472HEAPKlNCXXGppHu773usOskk 5gDg== X-Gm-Message-State: AC+VfDzKsLeqzce7VHK/h288Tr6sOZi/NA5lxsYIIaHJZoj8tPwKFYQN rIE5o0/PWzB3Jo8UQ9tAYVBpSLUinn0zTg== X-Google-Smtp-Source: ACHHUZ5pRnkueLKs7Xpu1KQuWX+z8QCvEdDDiG8wIDKb4ws3tgxxc8zQH2QrKkakFBZ/9RoFD0+NLw== X-Received: by 2002:adf:e54e:0:b0:30a:f68f:9b94 with SMTP id z14-20020adfe54e000000b0030af68f9b94mr4196114wrm.21.1685701567684; Fri, 02 Jun 2023 03:26:07 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:26:07 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 11/15] replay: use standard revision ranges Date: Fri, 2 Jun 2023 12:25:29 +0200 Message-ID: <20230602102533.876905-12-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Instead of the fixed " " arguments, the replay command now accepts "..." arguments in a similar way as many other Git commands. This makes its interface more standard and more flexible. Also as the interface of the command is now mostly finalized, we can add some documentation as well as testcases to make sure the command will continue to work as designed in the future. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- Documentation/git-replay.txt | 88 ++++++++++++++++++++++++ builtin/replay.c | 21 ++---- t/t3650-replay-basics.sh | 83 ++++++++++++++++++++++ t/t6429-merge-sequence-rename-caching.sh | 18 ++--- 4 files changed, 184 insertions(+), 26 deletions(-) create mode 100644 Documentation/git-replay.txt create mode 100755 t/t3650-replay-basics.sh diff --git a/Documentation/git-replay.txt b/Documentation/git-replay.txt new file mode 100644 index 0000000000..394d7b0050 --- /dev/null +++ b/Documentation/git-replay.txt @@ -0,0 +1,88 @@ +git-replay(1) +============= + +NAME +---- +git-replay - Replay commits on a different base, without touching working tree + + +SYNOPSIS +-------- +[verse] +'git replay' --onto ... + +DESCRIPTION +----------- + +Takes a range of commits, and replays them onto a new location. Does +not touch the working tree or index, and does not update any +references. However, the output of this command is meant to be used +as input to `git update-ref --stdin`, which would update the relevant +branches. + +THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE. + +OPTIONS +------- + +--onto :: + Starting point at which to create the new commits. May be any + valid commit, and not just an existing branch name. ++ +The update-ref commands in the output will update the branch(es) +in the revision range to point at the new commits (in other +words, this mimics a rebase operation). + +:: + Range of commits to replay; see "Specifying Ranges" in + linkgit:git-rev-parse. + +OUTPUT +------ + +When there are no conflicts, the output of this command is usable as +input to `git update-ref --stdin`. It is basically of the form: + + update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH} + update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH} + update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH} + +where the number of refs updated depend on the arguments passed. + +EXIT STATUS +----------- + +For a successful, non-conflicted replay, the exit status is 0. When +the replay has conflicts, the exit status is 1. If the replay is not +able to complete (or start) due to some kind of error, the exit status +is something other than 0 or 1. + +EXAMPLES +-------- + +To simply rebase mybranch onto target: + +------------ +$ git replay --onto target origin/main..mybranch +update refs/heads/mybranch ${NEW_mybranch_HASH} ${OLD_mybranch_HASH} +------------ + +When calling `git replay`, one does not need to specify a range of +commits to replay using the syntax `A..B`; any range expression will +do: + +------------ +$ git replay --onto origin/main ^base branch1 branch2 branch3 +update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH} +update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH} +update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH} +------------ + +This will simultaneously rebase branch1, branch2, and branch3 -- all +commits they have since base, playing them on top of origin/main. +These three branches may have commits on top of base that they have in +common, but that does not need to be the case. + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/builtin/replay.c b/builtin/replay.c index 9385973ffc..c1bd72c0e5 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -14,7 +14,6 @@ #include "parse-options.h" #include "refs.h" #include "revision.h" -#include "strvec.h" #include #include @@ -118,16 +117,14 @@ int cmd_replay(int argc, const char **argv, const char *prefix) struct commit *onto; const char *onto_name = NULL; struct commit *last_commit = NULL; - struct strvec rev_walk_args = STRVEC_INIT; struct rev_info revs; struct commit *commit; struct merge_options merge_opt; struct merge_result result; - struct strbuf branch_name = STRBUF_INIT; int ret = 0; const char * const replay_usage[] = { - N_("git replay --onto "), + N_("git replay --onto ..."), NULL }; struct option replay_options[] = { @@ -145,20 +142,13 @@ int cmd_replay(int argc, const char **argv, const char *prefix) usage_with_options(replay_usage, replay_options); } - if (argc != 3) { - error(_("bad number of arguments")); - usage_with_options(replay_usage, replay_options); - } - onto = peel_committish(onto_name); - strbuf_addf(&branch_name, "refs/heads/%s", argv[2]); repo_init_revisions(the_repository, &revs, prefix); - strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL); - - if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) { - ret = error(_("unhandled options")); + argc = setup_revisions(argc, argv, &revs, NULL); + if (argc > 1) { + ret = error(_("unrecognized argument: %s"), argv[1]); goto cleanup; } @@ -168,8 +158,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix) revs.topo_order = 1; revs.simplify_history = 0; - strvec_clear(&rev_walk_args); - if (prepare_revision_walk(&revs) < 0) { ret = error(_("error preparing revisions")); goto cleanup; @@ -212,7 +200,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix) ret = result.clean; cleanup: - strbuf_release(&branch_name); release_revisions(&revs); /* Return */ diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh new file mode 100755 index 0000000000..a1da4f9ef9 --- /dev/null +++ b/t/t3650-replay-basics.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +test_description='basic git replay tests' + +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + +. ./test-lib.sh + +GIT_AUTHOR_NAME=author@name +GIT_AUTHOR_EMAIL=bogus@email@address +export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL + +test_expect_success 'setup' ' + test_commit A && + test_commit B && + + git switch -c topic1 && + test_commit C && + git switch -c topic2 && + test_commit D && + test_commit E && + git switch topic1 && + test_commit F && + git switch -c topic3 && + test_commit G && + test_commit H && + git switch -c topic4 main && + test_commit I && + test_commit J && + + git switch -c next main && + test_commit K && + git merge -m "Merge topic1" topic1 && + git merge -m "Merge topic2" topic2 && + git merge -m "Merge topic3" topic3 && + >evil && + git add evil && + git commit --amend && + git merge -m "Merge topic4" topic4 && + + git switch main && + test_commit L && + test_commit M && + + git switch -c conflict B && + test_commit C.conflict C.t conflict +' + +test_expect_success 'setup bare' ' + git clone --bare . bare +' + +test_expect_success 'using replay to rebase two branches, one on top of other' ' + git replay --onto main topic1..topic2 >result && + + test_line_count = 1 result && + + git log --format=%s $(cut -f 3 -d " " result) >actual && + test_write_lines E D M L B A >expect && + test_cmp expect actual && + + printf "update refs/heads/topic2 " >expect && + printf "%s " $(cut -f 3 -d " " result) >>expect && + git rev-parse topic2 >>expect && + + test_cmp expect result +' + +test_expect_success 'using replay on bare repo to rebase two branches, one on top of other' ' + git -C bare replay --onto main topic1..topic2 >result-bare && + test_cmp expect result-bare +' + +test_expect_success 'using replay to rebase with a conflict' ' + test_expect_code 1 git replay --onto topic1 B..conflict +' + +test_expect_success 'using replay on bare repo to rebase with a conflict' ' + test_expect_code 1 git -C bare replay --onto topic1 B..conflict +' + +test_done diff --git a/t/t6429-merge-sequence-rename-caching.sh b/t/t6429-merge-sequence-rename-caching.sh index 099aefeffc..0f39ed0d08 100755 --- a/t/t6429-merge-sequence-rename-caching.sh +++ b/t/t6429-merge-sequence-rename-caching.sh @@ -71,7 +71,7 @@ test_expect_success 'caching renames does not preclude finding new ones' ' git switch upstream && - git replay --onto HEAD upstream~1 topic >out && + git replay --onto HEAD upstream~1..topic >out && git update-ref --stdin out && + git replay --onto HEAD upstream~1..topic >out && git update-ref --stdin out && + git replay --onto HEAD upstream~1..topic >out && git update-ref --stdin out && + git replay --onto HEAD upstream~1..topic >out && git update-ref --stdin output && + test_must_fail git replay --onto HEAD upstream~1..topic >output && grep region_enter.*diffcore_rename trace.output >calls && test_line_count = 2 calls @@ -456,7 +456,7 @@ test_expect_success 'dir rename unneeded, then add new file to old dir' ' GIT_TRACE2_PERF="$(pwd)/trace.output" && export GIT_TRACE2_PERF && - git replay --onto HEAD upstream~1 topic >out && + git replay --onto HEAD upstream~1..topic >out && git update-ref --stdin out && + git replay --onto HEAD upstream~1..topic >out && git update-ref --stdin out && + git replay --onto HEAD upstream~1..topic >out && git update-ref --stdin out && + git replay --onto HEAD upstream~1..topic >out && git update-ref --stdin X-Patchwork-Id: 13265058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC6E8C7EE29 for ; Fri, 2 Jun 2023 10:29:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235543AbjFBK3k (ORCPT ); Fri, 2 Jun 2023 06:29:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235503AbjFBK3N (ORCPT ); Fri, 2 Jun 2023 06:29:13 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57B33198C for ; Fri, 2 Jun 2023 03:27:02 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f4bdcde899so2459182e87.0 for ; Fri, 02 Jun 2023 03:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701569; x=1688293569; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U0PaX3m5d7VvOT4SucyqOyF/JAl/clkYcZqYEk89yrQ=; b=edij7IpMEicCbmCReIOft6gIQ+Sjr+J9cs5rmoespgEe/yjbKR7X8+i0GRHptU0vzX Zz1bKSezbPRFGGDJsZSC9HIXtsbxE3FBAqOKmQahe1S+xE++uQBVk2SJ27CRJszuQkn6 y+5klETXIkmq+4lDSyo8HScaiwTpI8aMCWJ28l47sltk6XPyDRjN7t/WGpuPjUbg6pJ4 HuVFZcwor1S+JPnz2TNVPuy65HN5mCasOlXIjVbMKP6iUrBukShtY62gdFpBE58s72IY uU/6ZYjN1JRiyA7R9t0Ny3fPWiu5lc2IHNiUfS5+ZCMtVePLRniRIUw5/MTMnp6m4q78 cxGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701569; x=1688293569; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U0PaX3m5d7VvOT4SucyqOyF/JAl/clkYcZqYEk89yrQ=; b=NGDe+JQJD5uUVfXcEaLE+N2XNQqhEzahcmkUB7PnETH6+mDpVLbhQZEFQieQxVQ/Hx Av7LsmYVz5aJeqtKnFDUBsXN8mES82fu97S8HzFcsxss2TgZnzb4yiifFS0D+h9BHV/w x+3IV5WIqfMIiOy7pa55KLDhHa8x8A3lRM6mFRPFH5vK/8vWD1sDs35tPJUlHlfFgosy CA0MifecqCjBvXUue0X3ZCMclJEOOMREImKjIlmLxKf7QDkDh4c2SKAv8lTFtboAGrXL CLVVwA8A9sTkrpcAlblim5RM560B2SIk6V0973pAVpphxiiMbX6Cxzn7Gxbk8SDrvCWi MbKQ== X-Gm-Message-State: AC+VfDyutACmgVHwH4QBfYRl9aGBFLLRCR7sirMEJwhE8z0UfXz6Cg2M u3LvGYjh6EA+ZSzO2lsghcnQBbj7OS5o2Q== X-Google-Smtp-Source: ACHHUZ67U3c2kJAeP69WgX/dV7XkLcr4L2y2dMSAl4QBShQhlCgC3/hL2QUxTk5kfN6oKowze4/hNw== X-Received: by 2002:a05:6512:3906:b0:4f3:b97c:2d91 with SMTP id a6-20020a056512390600b004f3b97c2d91mr1334388lfu.66.1685701569128; Fri, 02 Jun 2023 03:26:09 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:26:08 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder , Christian Couder Subject: [PATCH v3 12/15] replay: disallow revision specific options and pathspecs Date: Fri, 2 Jun 2023 12:25:30 +0200 Message-ID: <20230602102533.876905-13-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A previous commit changed `git replay` to make it accept standard revision ranges using the setup_revisions() function. While this is a good thing to make this command more standard and more flexible, it has the downside of enabling many revision related options accepted and eaten by setup_revisions(). Some of these options might make sense, but others, like those generating non-contiguous history, might not. Anyway those we might want to allow should probably be tested and perhaps documented a bit, which could be done in future work. For now it is just simpler and safer to just disallow all of them, so let's do that. Other commands, like `git fast-export`, currently allow all these revision specific options even though some of them might not make sense, as these commands also use setup_revisions() but do not check the options that might be passed to this function. So a way to fix those commands as well as git replay could be to improve or refactor the setup_revisions() mechanism to let callers allow and disallow options in a relevant way for them. Such improvements are outside the scope of this work though. Pathspecs, which are also accepted and eaten by setup_revisions(), are likely to result in disconnected history. That could perhaps be useful, but that would need tests and documentation, which can be added in future work. So, while at it, let's disallow them too. Helped-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 26 +++++++++++++++++++++++++- t/t3650-replay-basics.sh | 16 ++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/builtin/replay.c b/builtin/replay.c index c1bd72c0e5..cffbf34290 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -121,7 +121,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) struct commit *commit; struct merge_options merge_opt; struct merge_result result; - int ret = 0; + int ret = 0, i; const char * const replay_usage[] = { N_("git replay --onto ..."), @@ -137,6 +137,20 @@ int cmd_replay(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, replay_options, replay_usage, PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT); + /* + * TODO: For now, we reject any unknown or invalid option, + * including revision related ones, like --not, + * --first-parent, etc that would be allowed and eaten by + * setup_revisions() below. In the future we should definitely + * accept those that make sense and add related tests and doc + * though. + */ + for (i = 0; i < argc; i++) + if (argv[i][0] == '-') { + error(_("invalid option: %s"), argv[i]); + usage_with_options(replay_usage, replay_options); + } + if (!onto_name) { error(_("option --onto is mandatory")); usage_with_options(replay_usage, replay_options); @@ -152,6 +166,16 @@ int cmd_replay(int argc, const char **argv, const char *prefix) goto cleanup; } + /* + * Reject any pathspec. (They are allowed and eaten by + * setup_revisions() above.) In the future we might accept + * them, after adding related tests and doc though. + */ + if (revs.prune_data.nr) { + error(_("invalid pathspec: %s"), revs.prune_data.items[0].match); + usage_with_options(replay_usage, replay_options); + } + /* requirements/overrides for revs */ revs.reverse = 1; revs.sort_order = REV_SORT_IN_GRAPH_ORDER; diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh index a1da4f9ef9..de6e40950e 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -80,4 +80,20 @@ test_expect_success 'using replay on bare repo to rebase with a conflict' ' test_expect_code 1 git -C bare replay --onto topic1 B..conflict ' +test_expect_success 'using replay with (for now) disallowed revision specific option --not' ' + test_must_fail git replay --onto main topic2 --not topic1 +' + +test_expect_success 'using replay on bare repo with (for now) disallowed revision specific option --first-parent' ' + test_must_fail git -C bare replay --onto main --first-parent topic1..topic2 +' + +test_expect_success 'using replay with disallowed pathspec' ' + test_must_fail git replay --onto main topic1..topic2 A.t +' + +test_expect_success 'using replay on bare repo with disallowed pathspec' ' + test_must_fail git -C bare replay --onto main topic1..topic2 -- A.t +' + test_done From patchwork Fri Jun 2 10:25:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265070 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDCF3C7EE24 for ; Fri, 2 Jun 2023 10:31:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235691AbjFBKb2 (ORCPT ); Fri, 2 Jun 2023 06:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235706AbjFBK30 (ORCPT ); Fri, 2 Jun 2023 06:29:26 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09D791718 for ; Fri, 2 Jun 2023 03:27:15 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4f4f8b94c06so2518536e87.1 for ; Fri, 02 Jun 2023 03:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701571; x=1688293571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v3gs0oBPqSPSDtXxAIn4Q4FHrFsumrFKkrw0+iopqUo=; b=IhO4t7UtTc1oneztP3lzB0AQrenlxY9BKKySRdLMHjULrfGNModeA/9VJzZrjVC7pY 3UyZyCK/o+v0bjQ1MXnvPrUzt9MxEQXpOgpivRIhZsNFlHaN0DPPbEC4DDNSnAV38SgE TWdFf/76Ik3t6s1MzEDnqGpXLJTkZikgPZJio8UPcAkUasIoQ4CNu8HRCLHdGXaz2x/r uWXY0KcL9Nbf1srn6lG0qk5Tk8tz86b5XLvt/u8CpfuamN5w6e1hRymwCfZ6vGC+3u4R k9JhjmuDYUJRZHhKVoavuljL50LpBPTkZbJli+vCF3hl+gsCxaViRfD4giQB2reiWQ/S /Fcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701571; x=1688293571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v3gs0oBPqSPSDtXxAIn4Q4FHrFsumrFKkrw0+iopqUo=; b=fSkRUDCVNFsjFDhstb8Ph2puAFEpqdrC9YLsRC651eb9d2l9l3st7S7hmj+5WSTHp+ EjGvdEjy4XDQyN+AXHO84ayQSG6Qk15dWD6eB6Jv/IunQ2Upgl0RbnvDuMLGM76ee+qF Tp2wHVHqwSEO8712nOvt1T+0yO7q10/UaObrR4s5QaPB+Ba4P6S9r85yYSnLPdCjPNUC hOyyIMtILzfJWJdvyG8QYFVotaX+82B+AQVpeI80Fec6Xrh8IITdWdKffLWhN2wWgZk7 v2zZOQL/jF+COcmLIEBInuAvdDl5e0I2tpZz/KHuoDCTtvzwpzx/+518WsvQCFqgjhcg 5T4Q== X-Gm-Message-State: AC+VfDwvcRNDOxoqe7NTH4Tkk4mqM4cW1sI5JhYrLTwHnhh3QjDjVo0H wUNgtCLmjzfBsVHXJuhWC6PEyKJw6w0LZg== X-Google-Smtp-Source: ACHHUZ5TdZmM4eYT4feAY9FQkVXWAa4Zeeh4nn0CsAYAiBz95ETCXWOjqFNlZWTnewDcVvJeqqWW3Q== X-Received: by 2002:a05:6512:376f:b0:4f4:e1f8:98e with SMTP id z15-20020a056512376f00b004f4e1f8098emr1281102lft.23.1685701571072; Fri, 02 Jun 2023 03:26:11 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:26:10 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 13/15] replay: add --advance or 'cherry-pick' mode Date: Fri, 2 Jun 2023 12:25:31 +0200 Message-ID: <20230602102533.876905-14-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren There is already a 'rebase' mode with `--onto`. Let's add an 'advance' or 'cherry-pick' mode with `--advance`. This new mode will make the target branch advance as we replay commits onto it. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- Documentation/git-replay.txt | 33 ++++++- builtin/replay.c | 185 +++++++++++++++++++++++++++++++++-- t/t3650-replay-basics.sh | 26 +++++ 3 files changed, 230 insertions(+), 14 deletions(-) diff --git a/Documentation/git-replay.txt b/Documentation/git-replay.txt index 394d7b0050..439b2f92e7 100644 --- a/Documentation/git-replay.txt +++ b/Documentation/git-replay.txt @@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree SYNOPSIS -------- [verse] -'git replay' --onto ... +'git replay' (--onto | --advance ) ... DESCRIPTION ----------- @@ -29,9 +29,17 @@ OPTIONS Starting point at which to create the new commits. May be any valid commit, and not just an existing branch name. + -The update-ref commands in the output will update the branch(es) -in the revision range to point at the new commits (in other -words, this mimics a rebase operation). +When `--onto` is specified, the update-ref command(s) in the output will +update the branch(es) in the revision range to point at the new +commits (in other words, this mimics a rebase operation). + +--advance :: + Starting point at which to create the new commits; must be a + branch name. ++ +When `--advance` is specified, the update-ref command(s) in the output +will update the branch passed as an argument to `--advance` to point at +the new commits (in other words, this mimics a cherry-pick operation). :: Range of commits to replay; see "Specifying Ranges" in @@ -47,7 +55,10 @@ input to `git update-ref --stdin`. It is basically of the form: update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH} update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH} -where the number of refs updated depend on the arguments passed. +where the number of refs updated depend on the arguments passed. When +using `--advance`, the number of refs updated is always one, but for +`--onto`, it can be one or more (rebasing multiple branches +simultaneously is supported). EXIT STATUS ----------- @@ -67,6 +78,18 @@ $ git replay --onto target origin/main..mybranch update refs/heads/mybranch ${NEW_mybranch_HASH} ${OLD_mybranch_HASH} ------------ +To cherry-pick the commits from mybranch onto target: + +------------ +$ git replay --advance target origin/main..mybranch +update refs/heads/target ${NEW_target_HASH} ${OLD_target_HASH} +------------ + +Note that the first two examples replay the exact same commits and on +top of the exact same new base, they only differ in that the first +provides instructions to make mybranch point at the new commits and +the second provides instructions to make target point at them. + When calling `git replay`, one does not need to specify a range of commits to replay using the syntax `A..B`; any range expression will do: diff --git a/builtin/replay.c b/builtin/replay.c index cffbf34290..4b64d15159 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -14,6 +14,7 @@ #include "parse-options.h" #include "refs.h" #include "revision.h" +#include "strmap.h" #include #include @@ -82,6 +83,146 @@ static struct commit *create_commit(struct tree *tree, return (struct commit *)obj; } +struct ref_info { + struct commit *onto; + struct strset positive_refs; + struct strset negative_refs; + int positive_refexprs; + int negative_refexprs; +}; + +static void get_ref_information(struct rev_cmdline_info *cmd_info, + struct ref_info *ref_info) +{ + int i; + + ref_info->onto = NULL; + strset_init(&ref_info->positive_refs); + strset_init(&ref_info->negative_refs); + ref_info->positive_refexprs = 0; + ref_info->negative_refexprs = 0; + + /* + * When the user specifies e.g. + * git replay origin/main..mybranch + * git replay ^origin/next mybranch1 mybranch2 + * we want to be able to determine where to replay the commits. In + * these examples, the branches are probably based on an old version + * of either origin/main or origin/next, so we want to replay on the + * newest version of that branch. In contrast we would want to error + * out if they ran + * git replay ^origin/master ^origin/next mybranch + * git replay mybranch~2..mybranch + * the first of those because there's no unique base to choose, and + * the second because they'd likely just be replaying commits on top + * of the same commit and not making any difference. + */ + for (i = 0; i < cmd_info->nr; i++) { + struct rev_cmdline_entry *e = cmd_info->rev + i; + struct object_id oid; + const char *refexpr = e->name; + char *fullname = NULL; + int can_uniquely_dwim = 1; + + if (*refexpr == '^') + refexpr++; + if (repo_dwim_ref(the_repository, refexpr, strlen(refexpr), &oid, &fullname, 0) != 1) + can_uniquely_dwim = 0; + + if (e->flags & BOTTOM) { + if (can_uniquely_dwim) + strset_add(&ref_info->negative_refs, fullname); + if (!ref_info->negative_refexprs) + ref_info->onto = lookup_commit_reference_gently(the_repository, + &e->item->oid, 1); + ref_info->negative_refexprs++; + } else { + if (can_uniquely_dwim) + strset_add(&ref_info->positive_refs, fullname); + ref_info->positive_refexprs++; + } + + free(fullname); + } +} + +static void determine_replay_mode(struct rev_cmdline_info *cmd_info, + const char *onto_name, + const char **advance_name, + struct commit **onto, + struct strset **update_refs) +{ + struct ref_info rinfo; + + get_ref_information(cmd_info, &rinfo); + if (!rinfo.positive_refexprs) + die(_("need some commits to replay")); + if (onto_name && *advance_name) + die(_("--onto and --advance are incompatible")); + else if (onto_name) { + *onto = peel_committish(onto_name); + if (rinfo.positive_refexprs < + strset_get_size(&rinfo.positive_refs)) + die(_("all positive revisions given must be references")); + } else if (*advance_name) { + struct object_id oid; + char *fullname = NULL; + + *onto = peel_committish(*advance_name); + if (repo_dwim_ref(the_repository, *advance_name, strlen(*advance_name), + &oid, &fullname, 0) == 1) { + *advance_name = fullname; + } else { + die(_("argument to --advance must be a reference")); + } + if (rinfo.positive_refexprs > 1) + die(_("cannot advance target with multiple source branches because ordering would be ill-defined")); + } else { + int positive_refs_complete = ( + rinfo.positive_refexprs == + strset_get_size(&rinfo.positive_refs)); + int negative_refs_complete = ( + rinfo.negative_refexprs == + strset_get_size(&rinfo.negative_refs)); + /* + * We need either positive_refs_complete or + * negative_refs_complete, but not both. + */ + if (rinfo.negative_refexprs > 0 && + positive_refs_complete == negative_refs_complete) + die(_("cannot implicitly determine whether this is an --advance or --onto operation")); + if (negative_refs_complete) { + struct hashmap_iter iter; + struct strmap_entry *entry; + + if (rinfo.negative_refexprs == 0) + die(_("all positive revisions given must be references")); + else if (rinfo.negative_refexprs > 1) + die(_("cannot implicitly determine whether this is an --advance or --onto operation")); + else if (rinfo.positive_refexprs > 1) + die(_("cannot advance target with multiple source branches because ordering would be ill-defined")); + + /* Only one entry, but we have to loop to get it */ + strset_for_each_entry(&rinfo.negative_refs, + &iter, entry) { + *advance_name = entry->key; + } + } else { /* positive_refs_complete */ + if (rinfo.negative_refexprs > 1) + die(_("cannot implicitly determine correct base for --onto")); + if (rinfo.negative_refexprs == 1) + *onto = rinfo.onto; + } + } + if (!*advance_name) { + *update_refs = xcalloc(1, sizeof(**update_refs)); + **update_refs = rinfo.positive_refs; + memset(&rinfo.positive_refs, 0, sizeof(**update_refs)); + } + strset_clear(&rinfo.negative_refs); + strset_clear(&rinfo.positive_refs); +} + static struct commit *pick_regular_commit(struct commit *pickme, struct commit *last_commit, struct merge_options *merge_opt, @@ -114,20 +255,26 @@ static struct commit *pick_regular_commit(struct commit *pickme, int cmd_replay(int argc, const char **argv, const char *prefix) { - struct commit *onto; + const char *advance_name = NULL; + struct commit *onto = NULL; const char *onto_name = NULL; - struct commit *last_commit = NULL; + struct rev_info revs; + struct commit *last_commit = NULL; struct commit *commit; struct merge_options merge_opt; struct merge_result result; + struct strset *update_refs = NULL; int ret = 0, i; const char * const replay_usage[] = { - N_("git replay --onto ..."), + N_("git replay (--onto | --advance ) ..."), NULL }; struct option replay_options[] = { + OPT_STRING(0, "advance", &advance_name, + N_("branch"), + N_("make replay advance given branch")), OPT_STRING(0, "onto", &onto_name, N_("revision"), N_("replay onto given commit")), @@ -151,13 +298,11 @@ int cmd_replay(int argc, const char **argv, const char *prefix) usage_with_options(replay_usage, replay_options); } - if (!onto_name) { - error(_("option --onto is mandatory")); + if (!onto_name && !advance_name) { + error(_("option --onto or --advance is mandatory")); usage_with_options(replay_usage, replay_options); } - onto = peel_committish(onto_name); - repo_init_revisions(the_repository, &revs, prefix); argc = setup_revisions(argc, argv, &revs, NULL); @@ -182,6 +327,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix) revs.topo_order = 1; revs.simplify_history = 0; + determine_replay_mode(&revs.cmdline, onto_name, &advance_name, + &onto, &update_refs); + + if (!onto) /* FIXME: Should handle replaying down to root commit */ + die("Replaying down to root commit is not supported yet!"); + if (prepare_revision_walk(&revs) < 0) { ret = error(_("error preparing revisions")); goto cleanup; @@ -190,6 +341,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) init_merge_options(&merge_opt, the_repository); memset(&result, 0, sizeof(result)); merge_opt.show_rename_progress = 0; + result.tree = repo_get_commit_tree(the_repository, onto); last_commit = onto; while ((commit = get_revision(&revs))) { @@ -204,12 +356,15 @@ int cmd_replay(int argc, const char **argv, const char *prefix) if (!last_commit) break; + /* Update any necessary branches */ + if (advance_name) + continue; decoration = get_name_decoration(&commit->object); if (!decoration) continue; - while (decoration) { - if (decoration->type == DECORATION_REF_LOCAL) { + if (decoration->type == DECORATION_REF_LOCAL && + strset_contains(update_refs, decoration->name)) { printf("update %s %s %s\n", decoration->name, oid_to_hex(&last_commit->object.oid), @@ -219,11 +374,23 @@ int cmd_replay(int argc, const char **argv, const char *prefix) } } + /* In --advance mode, advance the target ref */ + if (result.clean == 1 && advance_name) { + printf("update %s %s %s\n", + advance_name, + oid_to_hex(&last_commit->object.oid), + oid_to_hex(&onto->object.oid)); + } + /* Cleanup */ merge_finalize(&merge_opt, &result); ret = result.clean; cleanup: + if (update_refs) { + strset_clear(update_refs); + free(update_refs); + } release_revisions(&revs); /* Return */ diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh index de6e40950e..bca405c431 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -96,4 +96,30 @@ test_expect_success 'using replay on bare repo with disallowed pathspec' ' test_must_fail git -C bare replay --onto main topic1..topic2 -- A.t ' +test_expect_success 'using replay to perform basic cherry-pick' ' + # The differences between this test and previous ones are: + # --advance vs --onto + # 2nd field of result is refs/heads/main vs. refs/heads/topic2 + # 4th field of result is hash for main instead of hash for topic2 + + git replay --advance main topic1..topic2 >result && + + test_line_count = 1 result && + + git log --format=%s $(cut -f 3 -d " " result) >actual && + test_write_lines E D M L B A >expect && + test_cmp expect actual && + + printf "update refs/heads/main " >expect && + printf "%s " $(cut -f 3 -d " " result) >>expect && + git rev-parse main >>expect && + + test_cmp expect result +' + +test_expect_success 'using replay on bare repo to perform basic cherry-pick' ' + git -C bare replay --advance main topic1..topic2 >result-bare && + test_cmp expect result-bare +' + test_done From patchwork Fri Jun 2 10:25:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6855CC7EE29 for ; Fri, 2 Jun 2023 10:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235581AbjFBKbh (ORCPT ); Fri, 2 Jun 2023 06:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235500AbjFBK33 (ORCPT ); Fri, 2 Jun 2023 06:29:29 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51186199D for ; Fri, 2 Jun 2023 03:27:22 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4f3edc05aa5so2432585e87.3 for ; Fri, 02 Jun 2023 03:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701573; x=1688293573; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/5iobcDlK6GSIrK6NEtemfFGrUTfsyd7OyGW/DnyfiQ=; b=XTeo3tNn7b9TNzZEEo0CeyAPAzVOzNWktFkRKzu2BQJtpoU7qfduE0yUvglr9r+Zr6 GG2X6MOKB1Y0EOvtxu60jQhhjHHpWZ5t4N/xCJma+4bm0aD1jgec1/i/4Mvye/Mk+V5v grdv2ErE+vp7RGVZEIbNk62C/oQ+QtDwIi/o2gqIiTGfONtkq6AjDZ7xYYsLgdGrBOGE ytj0/IacfQP3fGcA9/Q6O7cl16xcpz5otf33e0JWIeusd21AdIbpTov4rPEXn5NlhaZ0 95sAF5QTegiwa2reQDOGvNPEHRB6CYlKHQTsWcr+MKBwwcfWH9X7FRlLJNSlVkAHreAW +tRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701573; x=1688293573; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/5iobcDlK6GSIrK6NEtemfFGrUTfsyd7OyGW/DnyfiQ=; b=g56JKn0jyjvTaFcD+eoVcKMfNaj/cLsVAmR4d+YLKkXm1bhP5M0S/JqkiBbt9YUdf8 Hfs4YT0QLcsyrdzZJy2Z3q05wFUifL5yEMaextE7O/SXalz4BV11azpt8xbQys2V9eVO /9tGioAi7YNfnjOV0o0iZTLH3fiNnsFxrlK+XMcn4u8mC+FTndOwFD0YdKd6EJHaZWJk lralnPQITt6qvN4zftH3wALTGXWJ4r3h5FqNfdsVsCtIrNKi7YdYTKDtWFj/Jvt4hEIU L9VIZ53pKOMwwYWK3CSJNIzcKT0RiuafOqXJi/z8c/LSE20tIkI66VocVs6Y3vdqwZbI UKyw== X-Gm-Message-State: AC+VfDyguGJtRR9zZy0qD5UoBUwXkqp6AMRG2LCOOMGGX+Ui87HskZVJ O+5ukmCN6vUiGoNrwiBBeMYwST+fbQR6gg== X-Google-Smtp-Source: ACHHUZ6YBly7SuDw+HtlEQ0GMdsIDlApluKLLP3nY5l4zby/VTuNK2Bez0uuZZ9tpAKz5+nEtA0YCg== X-Received: by 2002:a05:6512:1025:b0:4f1:43de:7c3 with SMTP id r5-20020a056512102500b004f143de07c3mr1189017lfr.51.1685701572613; Fri, 02 Jun 2023 03:26:12 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.26.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:26:12 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 14/15] replay: add --contained to rebase contained branches Date: Fri, 2 Jun 2023 12:25:32 +0200 Message-ID: <20230602102533.876905-15-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Let's add a `--contained` option that can be used along with `--onto` to rebase all the branches contained in the argument. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- Documentation/git-replay.txt | 12 +++++++++++- builtin/replay.c | 12 ++++++++++-- t/t3650-replay-basics.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Documentation/git-replay.txt b/Documentation/git-replay.txt index 439b2f92e7..6fcaa44ef2 100644 --- a/Documentation/git-replay.txt +++ b/Documentation/git-replay.txt @@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree SYNOPSIS -------- [verse] -'git replay' (--onto | --advance ) ... +'git replay' ([--contained] --onto | --advance ) ... DESCRIPTION ----------- @@ -90,6 +90,16 @@ top of the exact same new base, they only differ in that the first provides instructions to make mybranch point at the new commits and the second provides instructions to make target point at them. +What if you have a stack of branches, one depending upon another, and +you'd really like to rebase the whole set? + +------------ +$ git replay --contained --onto origin/main origin/main..tipbranch +update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH} +update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH} +update refs/heads/tipbranch ${NEW_tipbranch_HASH} ${OLD_tipbranch_HASH} +------------ + When calling `git replay`, one does not need to specify a range of commits to replay using the syntax `A..B`; any range expression will do: diff --git a/builtin/replay.c b/builtin/replay.c index 4b64d15159..9b182eaa90 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -258,6 +258,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) const char *advance_name = NULL; struct commit *onto = NULL; const char *onto_name = NULL; + int contained = 0; struct rev_info revs; struct commit *last_commit = NULL; @@ -268,7 +269,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) int ret = 0, i; const char * const replay_usage[] = { - N_("git replay (--onto | --advance ) ..."), + N_("git replay ([--contained] --onto | --advance ) ..."), NULL }; struct option replay_options[] = { @@ -278,6 +279,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix) OPT_STRING(0, "onto", &onto_name, N_("revision"), N_("replay onto given commit")), + OPT_BOOL(0, "contained", &contained, + N_("advance all branches contained in revision-range")), OPT_END() }; @@ -303,6 +306,10 @@ int cmd_replay(int argc, const char **argv, const char *prefix) usage_with_options(replay_usage, replay_options); } + if (advance_name && contained) + die(_("options '%s' and '%s' cannot be used together"), + "--advance", "--contained"); + repo_init_revisions(the_repository, &revs, prefix); argc = setup_revisions(argc, argv, &revs, NULL); @@ -364,7 +371,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix) continue; while (decoration) { if (decoration->type == DECORATION_REF_LOCAL && - strset_contains(update_refs, decoration->name)) { + (contained || strset_contains(update_refs, + decoration->name))) { printf("update %s %s %s\n", decoration->name, oid_to_hex(&last_commit->object.oid), diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh index bca405c431..3fb4167e69 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -122,4 +122,33 @@ test_expect_success 'using replay on bare repo to perform basic cherry-pick' ' test_cmp expect result-bare ' +test_expect_success 'using replay to also rebase a contained branch' ' + git replay --contained --onto main main..topic3 >result && + + test_line_count = 2 result && + cut -f 3 -d " " result >new-branch-tips && + + git log --format=%s $(head -n 1 new-branch-tips) >actual && + test_write_lines F C M L B A >expect && + test_cmp expect actual && + + git log --format=%s $(tail -n 1 new-branch-tips) >actual && + test_write_lines H G F C M L B A >expect && + test_cmp expect actual && + + printf "update refs/heads/topic1 " >expect && + printf "%s " $(head -n 1 new-branch-tips) >>expect && + git rev-parse topic1 >>expect && + printf "update refs/heads/topic3 " >>expect && + printf "%s " $(tail -n 1 new-branch-tips) >>expect && + git rev-parse topic3 >>expect && + + test_cmp expect result +' + +test_expect_success 'using replay on bare repo to also rebase a contained branch' ' + git -C bare replay --contained --onto main main..topic3 >result-bare && + test_cmp expect result-bare +' + test_done From patchwork Fri Jun 2 10:25:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13265071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1DA5C7EE24 for ; Fri, 2 Jun 2023 10:31:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235485AbjFBKbc (ORCPT ); Fri, 2 Jun 2023 06:31:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235623AbjFBK3a (ORCPT ); Fri, 2 Jun 2023 06:29:30 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97D7F194 for ; Fri, 2 Jun 2023 03:27:23 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f6ef9a928fso17849865e9.3 for ; Fri, 02 Jun 2023 03:27:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685701574; x=1688293574; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ajPa/7hZEf7DJsyM+tg3YsLxH55ulGSSY2NvYdm6oV4=; b=KdqNKCKwf2k/wlClR4LDe70r5hW966jm+9qmjEgug4m9sj2p8YOZumgfGLE3a5YolW dyZz8Fso3LwXsAf0msfDMVDacCLy6RNHnqBb2oQDA3JVO5GnzMxUuo3W7o3VnWtex1CV qnuRtzt5CdHmPIEWbaGeHh5ZyT3NmRd32rlpimMHFv1FXgyoT8tTIvkfekEzedSfz7gT jm+PZ5+aIyrneEAQ5tjou2dLOJ/fnkwxirX8kW6BLSWOX4WaHUOPxygZaf4ME9U9Vss5 8vS38EzDL04zcML6Prus3dtSd6ss3A3YFAB5PUgAdNFbKwGj97NaHurCIl9aprm+sKHN g43g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685701574; x=1688293574; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ajPa/7hZEf7DJsyM+tg3YsLxH55ulGSSY2NvYdm6oV4=; b=lQadLWsbsdZArUE61irkSdJdgZsNiYdfNdSLUvQjzXoOgpVq53I3nv+G/bUld4dLpu cBqo6z+nWFvKnUslJEZOc1e3pLNzZiae8fS9qWei1Hl/qAQGueMV6axQILpi3u5I8A0A XBA/OzxUJ4rdCL7lUU3IqbHyJwIYcJ5wOVVCT6JFrzqBAv8rFkM6LLAvPQ5ok3WeffHd ylTAzMvb2ReCssfMDpz4BxQfhgammWd9WhYaqf3nrRLy/NVZo/tiXoA57xEDPtHFO7y9 GqSGEa394o1juIXpTjt+RSZGBe/9RGCwBC/8EJuIPuP3DoLS7QgxzijLOzg4fq6hpfAZ eJMQ== X-Gm-Message-State: AC+VfDxKbaJ0e5fyttJXD9pYe4jMdBPtH4+ORTRX5GhZhmN1vyqKQbow dI1kCcsTHjIcrMI/Q3NlFP7HK7exlZXs2w== X-Google-Smtp-Source: ACHHUZ6KXw3Nlfvu9G5hmz/h7AiJWeirF4TUgDrtYxISRc6E9fQrI2QZ8GbN2A0UQxWXEpctDRf4pg== X-Received: by 2002:a7b:c412:0:b0:3f1:74bd:bc22 with SMTP id k18-20020a7bc412000000b003f174bdbc22mr1532186wmi.6.1685701573976; Fri, 02 Jun 2023 03:26:13 -0700 (PDT) Received: from christian-Precision-5550.. ([2a04:cec0:1169:70dc:520b:5de9:c23d:7cde]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003f601a31ca2sm1468035wmk.33.2023.06.02.03.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 03:26:13 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Felipe Contreras , Calvin Wan , Christian Couder Subject: [PATCH v3 15/15] replay: stop assuming replayed branches do not diverge Date: Fri, 2 Jun 2023 12:25:33 +0200 Message-ID: <20230602102533.876905-16-christian.couder@gmail.com> X-Mailer: git-send-email 2.41.0.15.ga6d88fc8f0 In-Reply-To: <20230602102533.876905-1-christian.couder@gmail.com> References: <20230509175347.1714141-1-christian.couder@gmail.com> <20230602102533.876905-1-christian.couder@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren The replay command is able to replay multiple branches but when some of them are based on other replayed branches, their commit should be replayed onto already replayed commits. For this purpose, let's store the replayed commit and its original commit in a key value store, so that we can easily find and reuse a replayed commit instead of the original one. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- builtin/replay.c | 44 ++++++++++++++++++++++++++-------- t/t3650-replay-basics.sh | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 10 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index 9b182eaa90..a06649fa6e 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -223,20 +223,33 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info, strset_clear(&rinfo.positive_refs); } +static struct commit *mapped_commit(kh_oid_map_t *replayed_commits, + struct commit *commit, + struct commit *fallback) +{ + khint_t pos = kh_get_oid_map(replayed_commits, commit->object.oid); + if (pos == kh_end(replayed_commits)) + return fallback; + return kh_value(replayed_commits, pos); +} + static struct commit *pick_regular_commit(struct commit *pickme, - struct commit *last_commit, + kh_oid_map_t *replayed_commits, + struct commit *onto, struct merge_options *merge_opt, struct merge_result *result) { - struct commit *base; + struct commit *base, *replayed_base; struct tree *pickme_tree, *base_tree; base = pickme->parents->item; + replayed_base = mapped_commit(replayed_commits, base, onto); + result->tree = repo_get_commit_tree(the_repository, replayed_base); pickme_tree = repo_get_commit_tree(the_repository, pickme); base_tree = repo_get_commit_tree(the_repository, base); - merge_opt->branch1 = short_commit_name(last_commit); + merge_opt->branch1 = short_commit_name(replayed_base); merge_opt->branch2 = short_commit_name(pickme); merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2); @@ -250,7 +263,7 @@ static struct commit *pick_regular_commit(struct commit *pickme, merge_opt->ancestor = NULL; if (!result->clean) return NULL; - return create_commit(result->tree, pickme, last_commit); + return create_commit(result->tree, pickme, replayed_base); } int cmd_replay(int argc, const char **argv, const char *prefix) @@ -266,6 +279,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) struct merge_options merge_opt; struct merge_result result; struct strset *update_refs = NULL; + kh_oid_map_t *replayed_commits; int ret = 0, i; const char * const replay_usage[] = { @@ -348,21 +362,30 @@ int cmd_replay(int argc, const char **argv, const char *prefix) init_merge_options(&merge_opt, the_repository); memset(&result, 0, sizeof(result)); merge_opt.show_rename_progress = 0; - - result.tree = repo_get_commit_tree(the_repository, onto); last_commit = onto; + replayed_commits = kh_init_oid_map(); while ((commit = get_revision(&revs))) { const struct name_decoration *decoration; + khint_t pos; + int hr; if (!commit->parents) die(_("replaying down to root commit is not supported yet!")); if (commit->parents->next) die(_("replaying merge commits is not supported yet!")); - last_commit = pick_regular_commit(commit, last_commit, &merge_opt, &result); + last_commit = pick_regular_commit(commit, replayed_commits, onto, + &merge_opt, &result); if (!last_commit) break; + /* Record commit -> last_commit mapping */ + pos = kh_put_oid_map(replayed_commits, commit->object.oid, &hr); + if (hr == 0) + BUG("Duplicate rewritten commit: %s\n", + oid_to_hex(&commit->object.oid)); + kh_value(replayed_commits, pos) = last_commit; + /* Update any necessary branches */ if (advance_name) continue; @@ -392,13 +415,14 @@ int cmd_replay(int argc, const char **argv, const char *prefix) /* Cleanup */ merge_finalize(&merge_opt, &result); - ret = result.clean; - -cleanup: + kh_destroy_oid_map(replayed_commits); if (update_refs) { strset_clear(update_refs); free(update_refs); } + ret = result.clean; + +cleanup: release_revisions(&revs); /* Return */ diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh index 3fb4167e69..5aafad448f 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -151,4 +151,56 @@ test_expect_success 'using replay on bare repo to also rebase a contained branch test_cmp expect result-bare ' +test_expect_success 'using replay to rebase multiple divergent branches' ' + git replay --onto main ^topic1 topic2 topic4 >result && + + test_line_count = 2 result && + cut -f 3 -d " " result >new-branch-tips && + + git log --format=%s $(head -n 1 new-branch-tips) >actual && + test_write_lines E D M L B A >expect && + test_cmp expect actual && + + git log --format=%s $(tail -n 1 new-branch-tips) >actual && + test_write_lines J I M L B A >expect && + test_cmp expect actual && + + printf "update refs/heads/topic2 " >expect && + printf "%s " $(head -n 1 new-branch-tips) >>expect && + git rev-parse topic2 >>expect && + printf "update refs/heads/topic4 " >>expect && + printf "%s " $(tail -n 1 new-branch-tips) >>expect && + git rev-parse topic4 >>expect && + + test_cmp expect result +' + +test_expect_success 'using replay on bare repo to rebase multiple divergent branches, including contained ones' ' + git -C bare replay --contained --onto main ^main topic2 topic3 topic4 >result && + + test_line_count = 4 result && + cut -f 3 -d " " result >new-branch-tips && + + >expect && + for i in 2 1 3 4 + do + printf "update refs/heads/topic$i " >>expect && + printf "%s " $(grep topic$i result | cut -f 3 -d " ") >>expect && + git -C bare rev-parse topic$i >>expect || return 1 + done && + + test_cmp expect result && + + test_write_lines F C M L B A >expect1 && + test_write_lines E D C M L B A >expect2 && + test_write_lines H G F C M L B A >expect3 && + test_write_lines J I M L B A >expect4 && + + for i in 1 2 3 4 + do + git -C bare log --format=%s $(grep topic$i result | cut -f 3 -d " ") >actual && + test_cmp expect$i actual || return 1 + done +' + test_done