From patchwork Thu Sep 7 09:25:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376647 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 613B9EC873E for ; Thu, 7 Sep 2023 16:49:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243319AbjIGQth (ORCPT ); Thu, 7 Sep 2023 12:49:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243361AbjIGQtf (ORCPT ); Thu, 7 Sep 2023 12:49:35 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3753B1BC9 for ; Thu, 7 Sep 2023 09:49:11 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2bd0a5a5abbso20759671fa.0 for ; Thu, 07 Sep 2023 09:49:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694105285; x=1694710085; darn=vger.kernel.org; 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=RLXvhxvAcTubTLZoUT0um1y8VxTvyJPDq+F3ZZGAb2A=; b=GOHv/HMu7z3/tCBb5JYMYTMllllzW5TMDQpZfr2i9iHE14+EqrO6fIWZZhA911I4qi AxLgc6UOHqXGIjZKpyagYOp+17Y+K61/aMajoRSc+Jh01XbiuM6wp6ld4voQf9Sp4Fh4 lJPD07FJRzPtJSusLdYnucxc6bVhXvlr8B0on/PrZH0lmoa78PCAOzKX/Wu9h31+XRUv K9Ce0FKp1YgrXaETezaBDHR5EVH3kUoHYrrrTRzqlixAGAY87DTkAtsAQBhGxCFpLoge njkHP/8f8BIArS9bOGNLhOZmyRr7PXyi5p7q6H7EaTvxVWwVjVh9zYu8k6KqG7raMZcH BJqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694105285; x=1694710085; 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=RLXvhxvAcTubTLZoUT0um1y8VxTvyJPDq+F3ZZGAb2A=; b=Pw5fQThuxMuh2fNs97VXscqpTq0IfEz/sFV8sOAD+fzivosnyA6xt1SRLFyv8cz5p8 /lA5ldhuGMSGs7R2/DjmBGjQZyoLjjHnNZGmzXOQmoGeHISGFaWbYtEnp3SEkHafP1tO bjSDLuUNO8USZPQHKkKgxXNSMR3PtMP2sZHpuWmHWiFQclP6+CiEJ1pq39witLtPLPv7 UrstvuGDYLcmV4+4lZSBquEtiCdsm73B6cE5UYydbRsp+0g+mvszbd5ErmoNsX7UBNbo mbZQ/BsA1CaTM6vU8ygwuukALOZje+xCGfM0W+4BzKnfUX05JB20D5aBOpLfUwnACNlt fS1Q== X-Gm-Message-State: AOJu0YzxAbgJvn2WEYRmjxW4e8KF1SVR/YrskURJoTlheQ1/yJx6tcQg I3tH++qNWq2+rKHJ0yyCZQFxAYNrKYA= X-Google-Smtp-Source: AGHT+IGAZOilvgLi/Z/EGWtqKTBeWm5+oI8p6m/oHdBIJfZR1QLljx/EmyF2eSmGIDRW4Onab9/rLw== X-Received: by 2002:a5d:4a4a:0:b0:31a:d2f9:7372 with SMTP id v10-20020a5d4a4a000000b0031ad2f97372mr4272313wrs.29.1694078771131; Thu, 07 Sep 2023 02:26:11 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02: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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 01/15] t6429: remove switching aspects of fast-rebase Date: Thu, 7 Sep 2023 11:25:07 +0200 Message-ID: <20230907092521.733746-2-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 cac20a72b3..2bfab66b1b 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -194,7 +194,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); @@ -213,9 +213,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", @@ -228,10 +225,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 Thu Sep 7 09:25:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376775 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 E53BDEC8726 for ; Thu, 7 Sep 2023 18:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235856AbjIGSRR (ORCPT ); Thu, 7 Sep 2023 14:17:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235691AbjIGSRQ (ORCPT ); Thu, 7 Sep 2023 14:17:16 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A51F91A8 for ; Thu, 7 Sep 2023 11:16:50 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-52bcb8b199aso1717780a12.3 for ; Thu, 07 Sep 2023 11:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694110597; x=1694715397; darn=vger.kernel.org; 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=gfNxmz/ybTqRxTj0jMppVWmWYoHRR6t83zfdM8frOBU=; b=lqJvBxRY7SY1zSH85uIlGlq8Kq0ONWIwGtDl69bRlFekusEEz+TqMiFML4ue58heQz PVQEThKwsKlDn1ZdMLUxWxhCJ9VP94KvuaEDbqj5HJwWto6tzv6RcV5sEARiPw5JciBW embeO5E4uAIUQiur2Kj5DGiCSuF/uv26RFW/3kHVhLk+X1WEgk299oB4B644iBxyAf/r 7IMg/pKrXgMc3z38EIXQB/eBIIKvtT4GhEtysS0ZXhVASYdznWJ8NT/LforUmqexm6BA xwZ2CdslNyo8u/gBArXyQEOZY5Z5vIzvg4BPWhYdUCCcrp1ibO6djgipuOlErl5YChL1 bBCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694110597; x=1694715397; 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=gfNxmz/ybTqRxTj0jMppVWmWYoHRR6t83zfdM8frOBU=; b=UmRntQt8m5tFLcSHe7Uydoo1lBdELPQlZkhbbFIyS90lpBr+sbt1ZoGBdxyEgqogbN 7rxmn5JX1x2rcbpJ+aYyH+x4necyJ7m2jDZsbswct2lOq3XPNzvxpZzccOxGErVwe3AB /jqtLsvpT32dDHZumjpNgThyDo2zaJaz6kZHR6o8GoL7GHWN3bZ86K2kcApXjUD8+qyB yAcrbLJTrIhQcl8CdA3o4ncTEny3ZD3TXNn5RnVo1LaI7HXX1QSBZ/S60eDgr6g9vvAo /EOOMPZnd5LTOQKX9sLhN+cU1mKgpBKHpK5JFhTk7V8UU645cDxDuUR5Cz2fIQjs+ZUR 75uQ== X-Gm-Message-State: AOJu0YxRrzpgad2CyKuDh4yAvEp9ZJGy7W+ye0vxci2qiUGXsXy34uTd AcZil+a2b5Addkn91MN+ZZ/BH/IngMQ= X-Google-Smtp-Source: AGHT+IFt0FOTw5iQ85Q0pxxxy0hx0Z5/tAdDIUheic3Ad4wb6xGHYxWFTA0Bt0SxKwWv1lqKYir8gQ== X-Received: by 2002:a5d:4a4d:0:b0:317:5eb8:b1c4 with SMTP id v13-20020a5d4a4d000000b003175eb8b1c4mr4308255wrs.2.1694078785098; Thu, 07 Sep 2023 02:26:25 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.26.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:26:24 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 02/15] replay: introduce new builtin Date: Thu, 7 Sep 2023 11:25:08 +0200 Message-ID: <20230907092521.733746-3-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 | 27 ++++++------------- 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(+), 40 deletions(-) rename t/helper/test-fast-rebase.c => builtin/replay.c (89%) diff --git a/.gitignore b/.gitignore index 5e56e471b3..612c0f6a0f 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 5776309365..05a504dc28 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 @@ -1287,6 +1286,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 d560baa661..28280636da 100644 --- a/builtin.h +++ b/builtin.h @@ -211,6 +211,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 2bfab66b1b..e102749ab6 100644 --- a/t/helper/test-fast-rebase.c +++ b/builtin/replay.c @@ -1,17 +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 "git-compat-util.h" + +#include "builtin.h" #include "cache-tree.h" #include "commit.h" #include "environment.h" @@ -27,7 +21,8 @@ #include "sequencer.h" #include "setup.h" #include "strvec.h" -#include "tree.h" +#include +#include static const char *short_commit_name(struct commit *commit) { @@ -94,7 +89,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; @@ -110,12 +105,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); @@ -136,7 +125,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 c67e44dd82..7068a184b0 100644 --- a/git.c +++ b/git.c @@ -594,6 +594,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 Thu Sep 7 09:25:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376708 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 D4FA0EC874C for ; Thu, 7 Sep 2023 17:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242888AbjIGRSs (ORCPT ); Thu, 7 Sep 2023 13:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242882AbjIGRSo (ORCPT ); Thu, 7 Sep 2023 13:18:44 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C7A91FE5 for ; Thu, 7 Sep 2023 10:18:21 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31dca134c83so1129039f8f.3 for ; Thu, 07 Sep 2023 10:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694107038; x=1694711838; darn=vger.kernel.org; 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=WE8CWPu3mKNRmlD8NSJkLx+RsB8YQ1QcZnq8i2OeuH4=; b=Yc5Hl/VOUvzUZ5kJ5DTHmE2TpHEOoFgtqvcRgUv4wan3duxo23aCHJUu8yRIbFA3nr S+fbcemxkOAYgCXIUAnT8wquI/s8AP1xaK7dmZWhnhaGjL4QNYVDLffzws3eguml8gJv i5axtVDM6b0wV2nhonMFv1PKPrccqZ8Dcb2fdewXOvB5Glbr+iBAelJ2cGPnUtJJJOzu cJN0XHT0A/1ZHnnVp5yug1Mb0tsqO3rHMBj4hpoYeyKy7ZDSB4779nb3rI40iqxb/hUe wc4Wv7HGhtWfd5AHT/YPjEPevE60Bm5VAA4Qg3xHwCvBVQr77s4zQd96GjX2QJrSwSkP zeZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694107038; x=1694711838; 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=WE8CWPu3mKNRmlD8NSJkLx+RsB8YQ1QcZnq8i2OeuH4=; b=T/cMmMUF6Er0qC/NLxDkfZdsckugpku2WwZzGTo6jtwB+Xjkk/T5lRDuOFFVD7H31B zV7F/iWvIyuqmBWHLFU7NoboYfEA/yePATAFKf3em7MAYAeI8AeNVCV1pnjonN8FP3bV hEhBwNH4/v7I1iz/LK6EJJk2BoOx+3bFNMbTPtdB0WpNr9xouV9CDinRlST3U8Z5XuSl /61LG7kgrQ91d/XLQ+06bAcAT3H4ehV0HQfg6yIBI8xBaaljcs7DYeBrI2YQfs9yOYDX 0RbWxnv2Q2M/PvYwG2kK9yfUbrttySllPjUWAFGPQVJAX12tQuaEpTn8MkyNEYVgkt61 xcwA== X-Gm-Message-State: AOJu0YznpuRh26CweSUL14OJhCmpvCwedsXMtD8V0eFC+SJVCuyKEpED rcFXXxLJR650V4oAkDUYUWX4Rcskk0c= X-Google-Smtp-Source: AGHT+IHCOX7l6MDdZNG8UWHPd5vMcXj5u4xbA01f3gnCO2AqWQf4yEK0z9tSAlfd3T3K8OxIIErcYw== X-Received: by 2002:a2e:870d:0:b0:2bc:b9c7:7ba8 with SMTP id m13-20020a2e870d000000b002bcb9c77ba8mr4241648lji.43.1694078800122; Thu, 07 Sep 2023 02:26:40 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:26:39 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 03/15] replay: start using parse_options API Date: Thu, 7 Sep 2023 11:25:09 +0200 Message-ID: <20230907092521.733746-4-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index e102749ab6..d6dec7c866 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -15,7 +15,7 @@ #include "lockfile.h" #include "merge-ort.h" #include "object-name.h" -#include "read-cache-ll.h" +#include "parse-options.h" #include "refs.h" #include "revision.h" #include "sequencer.h" @@ -92,6 +92,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; @@ -105,16 +106,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)) @@ -126,6 +143,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; @@ -134,7 +152,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")); @@ -197,8 +216,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")); @@ -210,8 +229,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 Thu Sep 7 09:25:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376575 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 419CFEC8742 for ; Thu, 7 Sep 2023 15:51:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235871AbjIGPrp (ORCPT ); Thu, 7 Sep 2023 11:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344179AbjIGPci (ORCPT ); Thu, 7 Sep 2023 11:32:38 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DB03CE7 for ; Thu, 7 Sep 2023 08:32:09 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-501be2d45e0so1790094e87.3 for ; Thu, 07 Sep 2023 08:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694100674; x=1694705474; darn=vger.kernel.org; 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=8Cbku0d5FhZ8o4lNqUvCu77IIGuA+U2HqkGrXEHTDBA=; b=AYyvMJMbdKAOY0IuEdrWE0ifNE0QB7YXArNSrF3sj1e/WIk1rt9tpKJ+BlCsCUSFvO jOqEibPqcSkMH0T9gh50q8ACK3Qs58PuiCqmWsyOx07CcMjrdpdEEFCvG0MErzGUrHnh 8a82MyceVqZKAJF9XhSaKbAE6fRI4CogBCTpZcxD8faE3RHpVI0XClThbZeIsfOBzpP5 1oTqR2ffuWwMmh2H+qSBVKmwyYzBQHKm3GmP+Wz7qnwkBc0+q/s1JuXrClGPOKyK6Jay tFIuRPSXvgt91aQaV61iy/CBq7WUrywRBUFaNeoPFVmNB21tHSvSJDnrOG2iDsOS+F4s 0AhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694100674; x=1694705474; 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=8Cbku0d5FhZ8o4lNqUvCu77IIGuA+U2HqkGrXEHTDBA=; b=htXG/pRwY75I44kbSBxwI19HCPHeH8ydG2Eu20vo43MoJygyG7mC1FlayoHVTc63jL yDfDaKoMqCpus/V6rfGtlFHEU1+EsLMaBTXPo+5F2TwvcYMSnUTxg5dWJZUB6rh0V1Vu aqcSEm/f/sBWttWZ0GUgksVMCDU01oczK42POXoBdnvHDwTga0jUlKLu87ckboEQ/jm2 Ijp2SS0vlqByLABAIiVyrwnywvNDgOc9xQiGekgxs2lCki/pkRs9ZzRQcva0lq+0ye0F SFYBIcMzLgl6BZi7RyulgG5/FL33XdkkVg64s7i382mAdwLRi5UPIw3wHGXzZ+A+IyW+ dyZw== X-Gm-Message-State: AOJu0YxGW8QpMJ6q1EGYgaATTSL3Cx9rqbEvXPlV93L37k0EREAAw7QB MbeMF/VXVLl5NVA6taHkgYhhPttsZ+Y= X-Google-Smtp-Source: AGHT+IG4ZX6Z53W7V+8yM6VSWkRUIJI8WPjbtLeKvU873Lt9CxHaCFvd0xbsimtN9LIY0gleFnZqlA== X-Received: by 2002:a5d:5911:0:b0:317:7af4:5294 with SMTP id v17-20020a5d5911000000b003177af45294mr3785192wrd.44.1694078815181; Thu, 07 Sep 2023 02:26:55 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:26: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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 04/15] replay: die() instead of failing assert() Date: Thu, 7 Sep 2023 11:25:10 +0200 Message-ID: <20230907092521.733746-5-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 d6dec7c866..f3fdbe48c9 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -179,7 +179,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 Thu Sep 7 09:25:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376765 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 493EBEC874B for ; Thu, 7 Sep 2023 18:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343583AbjIGSIR (ORCPT ); Thu, 7 Sep 2023 14:08:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343820AbjIGSIM (ORCPT ); Thu, 7 Sep 2023 14:08:12 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F13141FF5 for ; Thu, 7 Sep 2023 11:07:49 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-52a250aa012so1700138a12.3 for ; Thu, 07 Sep 2023 11:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694110067; x=1694714867; darn=vger.kernel.org; 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=lv7GiXQdh1VNlUx7vsDCS8ejSwSZoYuJnQcoYwDHgdc=; b=VQY5/RcHUnntvC+sOaumYE+1rB4SrRh0EHfknMMhljPjEMbGpG1AUeU4HkPWsz6NtM 70FXrAhqKLtimmeAvYDVcKwztYzpHv8/vGUZXMXqbfdyqRQ7i2BInY4AbEkF8wsQsNa2 y+pBJQB9MXngIjCR1BzSCax2D06/gcoFJVJX3C906544yKvNLEc/TsS7LmOXJY9OvKjR 3CZQQ06bvehqcAAjq6055MGT2eBaR7Bf5NZ1Z/q7ln8j0aqgpVQToKHaRgGs3dVrhA10 ZjM6Qru9Sm9fnxlVtmCVOJ2INcSPdv6Fo9LdgtFN7zYZv128DcA/iAWLawhUHooc/iSv p4ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694110067; x=1694714867; 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=lv7GiXQdh1VNlUx7vsDCS8ejSwSZoYuJnQcoYwDHgdc=; b=tBl3+FHICOMOWI5YM4Lx/KQ5WmmLSVLOrMtZAW8F858/Lf4TeLT07TnwiBfmTiZ4c7 Az1MaBewKfi5TBg3npS5qPmn+QcsiqttEh4ewEBrKaPN7CwwlwOSjkuUwLwreH72we+s JH6Ij+E2Y/lIcVh17RkFEKwbY+3/mL/JLzUlBUtaYJzt45fF8xrN8tnCSXmei3wrE0F9 qiLcl87Y5DGEVycdWLb8WZXBMg6MNolkGmpNY9zmYNRYDLmfX3K96oB5kDCwpoC6CfxT ry4hBYmXfje39uZmSTqZsayh9VbJj7tQGU6BVU2lx4YcTECQkr/YM58shzOXkVQnnuzk YKTA== X-Gm-Message-State: AOJu0YxaMG+UoGIEKWbDwppeZNyV8xbaNLjpr2HV4TWnnpByXHpf86Y+ 5Dpu4jD1fb45C/LkxoejbdxtHwhZQ+k= X-Google-Smtp-Source: AGHT+IHDEISlyeiIkbbgFBBN6yCw5NMFg9CyoPnsTxdqYj3hsoLlEjxBP2SKkHiFQDGjay3djduwhA== X-Received: by 2002:a5d:4b87:0:b0:319:6d91:28bf with SMTP id b7-20020a5d4b87000000b003196d9128bfmr3966526wrt.60.1694078830332; Thu, 07 Sep 2023 02:27:10 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:27:09 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 05/15] replay: introduce pick_regular_commit() Date: Thu, 7 Sep 2023 11:25:11 +0200 Message-ID: <20230907092521.733746-6-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 f3fdbe48c9..c66888679b 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -89,6 +89,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; @@ -100,7 +129,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; @@ -175,7 +204,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)); @@ -185,26 +214,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 Thu Sep 7 09:25:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376506 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 0B40DEC873B for ; Thu, 7 Sep 2023 15:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230233AbjIGPYd (ORCPT ); Thu, 7 Sep 2023 11:24:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231597AbjIGPVs (ORCPT ); Thu, 7 Sep 2023 11:21:48 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A32DACE7 for ; Thu, 7 Sep 2023 08:21:22 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9a9d6b98845so340629066b.0 for ; Thu, 07 Sep 2023 08:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694100081; x=1694704881; darn=vger.kernel.org; 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=dwMKgStb0gtvCSRexFYqFykdGSWjbsq8NCIRN6CDTsY=; b=XbpNsfTEjFNzUUq02MBav3ktPQCVTF/bI0fdg/j1sPxPoU0QHGI37b3O8UPfKzbUek MPvZEXDWmSP8iF7RGYLH8XTAnuz6s6j7/WrDiWqvuoSTxFpPMaEuwFHxt0qUMMsrruEf tbL3Wp30fPf7QU5TjlcT/5/ik+5Arzk53mmnp7gxrkhq7x/utMenVdWMLR6Ssbpnkjo3 sU0Zd2lyP1AGelvfMnWrZBgJFTWLpZAerNQHybgAU+uUTZstyUe/3uyHzeWqkxf0NRsL UMDpolsWxFFNmB6rMLXpTnKUcobpCkvodKNVCkgT81+lDM2Imlevxdb40jYuGmgV/ZIl hUog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694100081; x=1694704881; 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=dwMKgStb0gtvCSRexFYqFykdGSWjbsq8NCIRN6CDTsY=; b=eXuSOe6BJdSWeivsa9eY9660AriRXiKbrD+UW0Vi1yO7v5uL7eysjZTkk1Az12hOG3 B6z2TQOGxLDwPcoz2zj1uKNVGBHV3H0bkV+i4pM70hIFTH7BPtSZGrqU0lzrf/NbNO8u grP0Ongxn4t0LqSONebrcqif9JjZt4EALhzfEsOKvUKeN+y6c8gznRUMUaC+v+tC2TxI o79EtmwxRhJ20SSgSvCJuNSAce9gB8N38wYATTyIqKRzlVwVAlPxxX/yHro3xCSPDwBG CAtU1N7CovLgrTiQ4BzrlUp6pfv9h06FMf7FkKKnUMQGNssLw2MAsM5dREESK+KO93Uo NPsw== X-Gm-Message-State: AOJu0Yy99Jn6XX41L0j20Py6T/wTtQwaVaCeqDuZJQFVmdBwCOS+5zYL 9XOlLw6yMNADab8jrd996lIufLtyuBY= X-Google-Smtp-Source: AGHT+IE7GXLuvXJRB0xPye6DFSSzD49cWrjf8xjglMYcBJCD7hVUP8TfhXFYGuRtp9qkglfy36cm3w== X-Received: by 2002:a5d:6852:0:b0:319:6e9e:bbdc with SMTP id o18-20020a5d6852000000b003196e9ebbdcmr1550198wrw.32.1694078844322; Thu, 07 Sep 2023 02:27:24 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:27:23 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 06/15] replay: don't simplify history Date: Thu, 7 Sep 2023 11:25:12 +0200 Message-ID: <20230907092521.733746-7-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 c66888679b..4b1e501595 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -173,15 +173,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) { @@ -189,6 +180,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 Thu Sep 7 09:25:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376507 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 84AFCEC873F for ; Thu, 7 Sep 2023 15:26:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238874AbjIGPYf (ORCPT ); Thu, 7 Sep 2023 11:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238017AbjIGPXo (ORCPT ); Thu, 7 Sep 2023 11:23:44 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24AF5CA for ; Thu, 7 Sep 2023 08:23:39 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2bcb0b973a5so18768121fa.3 for ; Thu, 07 Sep 2023 08:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694100217; x=1694705017; darn=vger.kernel.org; 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=kycl7eo8JkvIoN6yTGIme6lpNri20fB4MA/DAHFXLMs=; b=XnrqjhQzf69wXyYCGcbA3+0gZylZDZ+3PFRaT1UE3rnkZQ0f/qTF9HDJT9s1pFT4GY LKMwhLz6/rwjvoEQYXqVFX9Yhir5OQjsYGVu8fH6ADILOR4tM/L+52Jj+3kf8KnFMHbH VpHTzINXWZcP6k7az7rZUcIavCN5pkmeE2yr1llp3TJlTmnFFLvRITJ7p+KE3oux2Oe5 XAG8OmMXaOQz9H/QvgYkaW7T6/ZOa0k4CHjBRAo5gzSQTE1aIuvZC2ljnxLRuUEke3xG xRzkpn947mJDxI6dKYQH4yuoQY6nc0VeqtML9HgEFNZV07dggJrsGyJUfWQ/oOnQj9IY kaHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694100217; x=1694705017; 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=kycl7eo8JkvIoN6yTGIme6lpNri20fB4MA/DAHFXLMs=; b=Yx+TkH9n/6RfSoraotYV+G92tsTlmKP5MLjLIYug2Qho47Hc5L5EaQVlMw/xSVqBE0 GQGREts9gRNP4d3SPgxZp+DUXe2sOOqs52/fEH/AQDfg685WvJfqziG0AgSSlnHRRNXl moh/EWmForLl56WcTBAhC49XG4+fYlGEy2p4JM1btvJEYGMaAfYnQOudBLamj554mKa+ lsM3X+DZHNFPBjpWST8FN07OkG/OEftsJcCSKuGO1WL5E/ZioVBMc3OBNkgz+N1wzJnp TethB2IXpiML14/o+ERDIEyw6LGvZQLJ6z8728+FyTkCLeh4PWW+mrcSlO1vUMcZPRzr iLuA== X-Gm-Message-State: AOJu0Yzu5iQL4UDBZXLnnfLA3tu1Pd6w4UVBlYNKY+/e0gvskFos9l+X bhbFm0xATqjrx88w8K60O3BGeaSnHCo= X-Google-Smtp-Source: AGHT+IE4/yG4a1646qmymRpZ3XhM+jm6ghyxTnEE5X3OcOXzYdbsQZVHziSd1YyczqdoYsMbyxlV7g== X-Received: by 2002:a05:600c:2285:b0:401:5443:5598 with SMTP id 5-20020a05600c228500b0040154435598mr4233433wmf.25.1694078859602; Thu, 07 Sep 2023 02:27:39 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:27:38 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 07/15] replay: add an important FIXME comment about gpg signing Date: Thu, 7 Sep 2023 11:25:13 +0200 Message-ID: <20230907092521.733746-8-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 4b1e501595..47d695df93 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -62,7 +62,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 Thu Sep 7 09:25:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376679 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 65D6BEC8743 for ; Thu, 7 Sep 2023 17:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236765AbjIGRNd (ORCPT ); Thu, 7 Sep 2023 13:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231859AbjIGRNc (ORCPT ); Thu, 7 Sep 2023 13:13:32 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F05110CA for ; Thu, 7 Sep 2023 10:13:08 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-986d8332f50so155393566b.0 for ; Thu, 07 Sep 2023 10:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694106705; x=1694711505; darn=vger.kernel.org; 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=+/YweAa+/Xk3ac1g6f3K8q9nTvgdPe2k2YZfxUWpgTI=; b=cnzez44UdscFiNl2hRbF7JSrTU5//eszzSVNVgk24ELR2fsG6KEyl7XMaYctiohXmo fMMw2yNjD0R9gNy29lmbga5Dalt88YEoDKoGlQANtRvs8J2RJKtXImGXakBlgy78cqQx 5ZdgYqWMaeQ4YEmpZMFP2KlDPqMD8IzpOToRY204VzoXPvzZxKsmsSR8+DiVjGXlqgsN aT8rFxFxavqS0szu0nIx3Secx4wfScHyZw3pFvV72eGZaNk77h2/bTLVcVNNWjCZJPd+ VLzquKWjbUMFgW4TSQqRf/8Bopa5DoURTDUN39L3YS3PPZVvtRySVLaenwtFsOuMSlRH I4ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694106705; x=1694711505; 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=+/YweAa+/Xk3ac1g6f3K8q9nTvgdPe2k2YZfxUWpgTI=; b=EnIVl8oKjNs+kuNcY90g9WKjoBcfBFAZ5bA5Ng9eV5sCRQ7qNd2D8FtghYM8lh9PlJ HEiuuxBL8I5av9nLaHC5T9VYBAH0gCmDJj7+ueb0mlDBbUOYy0ND9qhfGk0Q8jdxwiP8 C2bE1mh8DQ7R3SOx1D19SZotP22u6gwHQUd43qmxVwqYlNijorueKafJOc/r8pA2rC9r TEcuRlPGhlCcBCcpbnBP+RKSabiprKoMPY2oMWcuQZIhlELfdhZUT6g70GaeNph+K4U2 hFEd2uyKgn3+vX1VL7Pb34v2kesgfg+XGZkcNvnq9+NDl9BVuXdao+t5ANIjyNVss9CW ApRA== X-Gm-Message-State: AOJu0Yy56qe8FD6XNzf4UlNpdeuoqEbmcdnACMSkbfN68gMIUVPfDN8d nuU732mZk+T2d386FcYKHBi5Pqd9jY4= X-Google-Smtp-Source: AGHT+IEwPvHzh/iZMJLFATe2kQxhlPFRdzpf8/wvGO2c2XWNzjbBivnAox3XKiEjH3vAlkBfTw+iYg== X-Received: by 2002:a7b:c7c7:0:b0:401:b2c7:34aa with SMTP id z7-20020a7bc7c7000000b00401b2c734aamr4138891wmk.33.1694078874481; Thu, 07 Sep 2023 02:27:54 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:27:53 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 08/15] replay: remove progress and info output Date: Thu, 7 Sep 2023 11:25:14 +0200 Message-ID: <20230907092521.733746-9-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 47d695df93..b5c854c686 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -195,7 +195,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; @@ -203,9 +203,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) @@ -224,7 +221,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)); @@ -238,7 +234,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 Thu Sep 7 09:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376715 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 CD02EEC8743 for ; Thu, 7 Sep 2023 17:25:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231625AbjIGRZO (ORCPT ); Thu, 7 Sep 2023 13:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242562AbjIGRZN (ORCPT ); Thu, 7 Sep 2023 13:25:13 -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 2E1DCB2 for ; Thu, 7 Sep 2023 10:24:49 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fef56f7248so12980595e9.3 for ; Thu, 07 Sep 2023 10:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694107435; x=1694712235; darn=vger.kernel.org; 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=OjOFbkb8q2Pa07AlZR+/OvQvqJ19nYTd8Je4qQv9qCw=; b=WQWuiBf1aWYmtP/0jB6wjuCPE3hhZMg4GKDMHA+X+uwggcyoKf/DJH4NGpq6BSONY9 MGz1Jna7YE3aCKA+12JqScok0/Z687kOyEw+EByEIc8bT7jw2EgqqP6q/p1arQYSFFD2 SOR5dPAh2dZ1tnLfzUfwexPu4tI4DYmczM6thxiE1OH/Y8cSg5NZucPYZE2SJuvT1VHI 0DsRqbvFBCW4PLraaJ0ofwKIU3Qd005nN0yzPVL7UG5NyQnoLmU2D0UOZ5M+xu2wYJ8C KFbplM9RdiMdCJaRxo8X+nEwDcObwJBg8dDc0hT9hpWF43YeOSMPUVJfZ58rnysI0kaG WgKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694107435; x=1694712235; 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=OjOFbkb8q2Pa07AlZR+/OvQvqJ19nYTd8Je4qQv9qCw=; b=NW6KnzTuSpybY0r2iVCkAhAnCSctBx0gL8FG8IbRTw9J2RvWelF8cFaEoapRQTt4J6 qEfzIE1vj2fqnzs3VqiiM7GraobRYfL62HjcIVfFnzmtQoJBvY+sWQBQpOLTzD38DZNj EEcuupYYe1CHT/957f7JVJGt9eKaZDWeoVRZg1jkeNfLVKRrnl+FAqU1g1//LluSleoz t+BWHe0rH8V/2JKqRlYW9nnqlxE/UUqCGkkF/spaxRed2TmVtxxW7FcH3n5vPP9A4Bw1 uWYbAC3Wmg+lYEeA3SnSKN6igIx1g1c2TGOKAaaovUDTpsBJRPZeRNUvT1kSKl2rJ/ro fqrA== X-Gm-Message-State: AOJu0Ywjp+mslm07/m/4HkTVcyqC3LHtqLPpE/Y5WtL49XZMoYeMB3G9 ACEP4x1+IXzFDqTnbeLaHZf3i7XSR2I= X-Google-Smtp-Source: AGHT+IG8qtmtLWzncUEP6VB60JOkNOm53TZHbuT/QO6ux7SLyyCgfY1QVvK9SKN54iHqdppEK0cQ5Q== X-Received: by 2002:a5d:4a4d:0:b0:317:5eb8:b1c4 with SMTP id v13-20020a5d4a4d000000b003175eb8b1c4mr4311103wrs.2.1694078889596; Thu, 07 Sep 2023 02:28:09 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:28: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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 09/15] replay: remove HEAD related sanity check Date: Thu, 7 Sep 2023 11:25:15 +0200 Message-ID: <20230907092521.733746-10-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 b5c854c686..a2636fbdcc 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -123,7 +123,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; @@ -162,11 +161,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"); @@ -238,7 +232,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 Thu Sep 7 09:25:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376615 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 9E2AEEC8743 for ; Thu, 7 Sep 2023 16:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232200AbjIGQfK (ORCPT ); Thu, 7 Sep 2023 12:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbjIGQfI (ORCPT ); Thu, 7 Sep 2023 12:35:08 -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 32D5C3C04 for ; Thu, 7 Sep 2023 09:34:40 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5029740cfd2so775720e87.1 for ; Thu, 07 Sep 2023 09:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694104417; x=1694709217; darn=vger.kernel.org; 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=qi9+HyN1lKSgcEhyhb3bm3DWDRvpTUHb9RSykj4q6IE=; b=V2ThirvGaTZBRuIUG8p2jZaycsn081k3KsfeQXI1Kp0jp7jFXpepIvHSv7YT7QQqoO yMfIipANi2Znm0hnAg2pS3VtMWu+tsl3siZOgGcvNwbKYOCcu8lWzB9v+/6yL8wSK/gb fbq8KMhlPmMLfv6zjW8QSAYrW7owcshuBdvZN+KGXw/oWMvzRFhgNApSs6aUXKbJJV0i rGBE+IC45Bmpb3bRNnK6FVYpKB+PqCtDfC+eve7KufMKOn1iTVemvIKWRXrVjhBue8WK TAakiok8iV0s+Nre1J9DNKTo35RAfYQs+VzTYKTU5KRWJLz0KzeJ+IZjKa93dm0eWoMu nCQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694104417; x=1694709217; 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=qi9+HyN1lKSgcEhyhb3bm3DWDRvpTUHb9RSykj4q6IE=; b=lWjwszKnOcsniJxuzl3WUjlVF4q7e0beFxo171VNoSqZNl6PowmqlWeMPcZP5YC8jr kjEn7o2/XC4RQ4MovLXBSgr7yzemBJgKBHjOkpG7rhLcwZW64Ul/ubhM8aiM5np7g3w9 Etc4BxVprY2eEhPWl73ZzEqz35ehLsUTYKfmvT2IdrWNa2yuA467p2O1Fp/wdV2DV5yt 14sSdW/ksVxV3aypcm/fG/STqFRQw+VnPud8ZrM0YhKlqjqnF5QwyefaL0HmTR5UaBoC 8rmpZY2D9z7Vsj3WU8Klhc8xa+PyXa7pBenhLGpVtx76fdOyuqks2Oc1rpHhUJHaJ378 H41A== X-Gm-Message-State: AOJu0Yw+WmzdPaWIwR87md3BvvVAEtanCMyTZnykbTnaQziD5WNlFewe UC7Wjul6l+gGS8J4cb/gPsPrzp1hZXw= X-Google-Smtp-Source: AGHT+IFndZwPh6yJLdjY1R7nnZzRbyD1MptcLc78pnpJmOPxOv3oRVqEv7fm5+mWrXyHR3m3t1o4fQ== X-Received: by 2002:a5d:6d4d:0:b0:313:e953:65d0 with SMTP id k13-20020a5d6d4d000000b00313e95365d0mr4481640wri.28.1694078904497; Thu, 07 Sep 2023 02:28:24 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:28:23 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 10/15] replay: make it a minimal server side command Date: Thu, 7 Sep 2023 11:25:16 +0200 Message-ID: <20230907092521.733746-11-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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, 50 insertions(+), 67 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index a2636fbdcc..e45cd59da1 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -6,11 +6,7 @@ #include "git-compat-util.h" #include "builtin.h" -#include "cache-tree.h" -#include "commit.h" #include "environment.h" -#include "gettext.h" -#include "hash.h" #include "hex.h" #include "lockfile.h" #include "merge-ort.h" @@ -18,8 +14,6 @@ #include "parse-options.h" #include "refs.h" #include "revision.h" -#include "sequencer.h" -#include "setup.h" #include "strvec.h" #include #include @@ -102,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); @@ -122,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; @@ -161,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); @@ -190,58 +178,44 @@ 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; + } } 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 Thu Sep 7 09:25:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13376663 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 4B219EC873E for ; Thu, 7 Sep 2023 16:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238118AbjIGQ7e (ORCPT ); Thu, 7 Sep 2023 12:59:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243954AbjIGQnF (ORCPT ); Thu, 7 Sep 2023 12:43:05 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 866C11FD9 for ; Thu, 7 Sep 2023 09:42:05 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-31aeee69de0so1092014f8f.2 for ; Thu, 07 Sep 2023 09:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694104863; x=1694709663; darn=vger.kernel.org; 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=OWEEjwhBhppAwOn5cBv/21wjqd0zxJmgP2WSGEHnFsU=; b=Or1rc55+SFSTu7ss1/iMf0PgthbnbWfoQsitaMGn51x3yg6dHZa447YlYkrY2i1toF ODZt/f5g0l45wPuerJIEicQAZJM+oGriyS7fdK0SIOuNrJdv/Uu6P8TxJQPWp1mug123 IS3W0Kq/kgn9ocl0zE0VDegs7kLmza+QSt5udwR1xX3/BJgttpO7amJw7UyIFCkUxgjy TvglEbCu9Vir0bjiaGmt285+2NKMHTc646yfmeRDBf4svp9MDyS3tNNvhSx8BPlzkBZ6 Nb4vJyw1rAXmyA8/1IFXmvB0g16y3ExG1pwW2lk93Rkd0rxWWX/WlsOIp/Hj9NuWrHph +9hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694104863; x=1694709663; 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=OWEEjwhBhppAwOn5cBv/21wjqd0zxJmgP2WSGEHnFsU=; b=V1wEwYQyrgffxUCvzfNt4zB2B5H3/WqxQhHaCpQX6Z2GCHrBNRvdBSrTrNVAeooIwf wfla1hGlL7p2Jx0R3WmZkSr/my73xLrgdFTiE0TReT6uk1Hx4pqyeCchPtWDe5mbPcDQ NT64SIOmT8Il5pvFzv3yfyzfwWamrbf+t82XBgwteJYRMFh6gTx8W4YA+dnOsTwAlEi3 hsyllZUOSp6+7uLn+uQGxIArX6mJW78TnyqAqr3CUPjc7JW4Lq9i2effU+5AUtK2+muz Q3ffPAuPDbHSNG4+MrAvauyttOP5EOxpqimqY7eDPckak0HiUOBONwUQmKZRddrkDyK2 HIrA== X-Gm-Message-State: AOJu0Yw2k2pUZ2wJMchhM5sbCzvZl3txktR7+73rmJ/Ltmw3+kdpaspX J/U3x6Y1lfqca3+r5ffNHTCSGedxgRw= X-Google-Smtp-Source: AGHT+IHAHNTHc+f0Oyp0+HRo1zyOa8vJqVbAZwzNMcO6zqjbp53bjhijd7IllqBVxTZmUtyi/JDmqw== X-Received: by 2002:a5d:5911:0:b0:317:7af4:5294 with SMTP id v17-20020a5d5911000000b003177af45294mr3787818wrd.44.1694078919616; Thu, 07 Sep 2023 02:28:39 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:28:39 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 11/15] replay: use standard revision ranges Date: Thu, 7 Sep 2023 11:25:17 +0200 Message-ID: <20230907092521.733746-12-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 | 90 ++++++++++++++++++++++++ builtin/replay.c | 21 ++---- t/t3650-replay-basics.sh | 83 ++++++++++++++++++++++ t/t6429-merge-sequence-rename-caching.sh | 18 ++--- 4 files changed, 186 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..9a2087b01a --- /dev/null +++ b/Documentation/git-replay.txt @@ -0,0 +1,90 @@ +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 command(s) in the output will update the branch(es) in +the revision range to point at the new commits, similar to the way how +`git rebase --update-refs` updates multiple branches in the affected +range. + +:: + 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 depends on the arguments passed and +the shape of the history being replayed. + +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 e45cd59da1..de2ddeae3e 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; @@ -211,7 +199,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: 13376648 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 666EEEC873E for ; Thu, 7 Sep 2023 16:50:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243590AbjIGQur (ORCPT ); Thu, 7 Sep 2023 12:50:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243038AbjIGQuq (ORCPT ); Thu, 7 Sep 2023 12:50:46 -0400 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F25DD171C for ; Thu, 7 Sep 2023 09:50:19 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-99c3d3c3db9so148532666b.3 for ; Thu, 07 Sep 2023 09:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694105027; x=1694709827; darn=vger.kernel.org; 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=CudVLzGFJgo4zZ4d2+8qJM8WR7188itEz7HYc1E4dLE=; b=cPne/t3IFv7HJkS1kPOUyDgb0TPicYbmUbEKOoKw/HV+ZP+994gn9R5B6711ghI/qd 16fxUYK9vF2DzbfiaqpxvHP3qgkKOX+s4sj3KCSNoX7xZc3DzpetM1OauQm0Px2UNhGZ AS2fAEt+4GBRddclUPhnnO6JXtNOq61IjyRkxDVf7s+f2Zrbn4vLGaKgiI1ALzFkapU6 eJJtf2L0vyalW33/oUGY/Y4C72FJ5rAttB17CCe2WIy1OCB613x5b6LqnHInIXfbf5VY Bn/O3vqKsxShhvik6CN059f4LoC8Kp/dRdtR+8idmNOuUKLIwXFs0NhxN8x8NoVkrTXu dtrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694105027; x=1694709827; 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=CudVLzGFJgo4zZ4d2+8qJM8WR7188itEz7HYc1E4dLE=; b=O/N3iykwT1DgRcISCiI5/QSg08O1w5TRCJh1cUWeWUYex80qsiUQ5aqxM7DeYy4x/L ENyxQEXRzRpylZmd3+qrOu9iLSdzYjQ0lnXwGpj1goF5qGhu0gZ1zwxzuvIDgJDVih/I 22XAVrx0r44Qe+pSOyIvmZGC+j8ewPscXs8By1qqoao9HnaQv8xVvNa10/dHBDwlF19x XM3rTn+DNZcqz7fONv+UJh91fquXpDlrV3COtYnh9Yxq1iJH9kn1WiY2Rv5XPeOrxUj+ TVYTmxc7BR0c8aLCVjEGrSCJU7QcsmCDkjHsCmZZGjv2Su+8om4TIK3oQZ2qH8CDUjqX 2EWQ== X-Gm-Message-State: AOJu0YyRgnv38zZpr8rNjhD3w5i5v+onzJucykwfKXCq353yOoOIHqli H8t9SIN+uFk3u+aYM57mcC6vsKg0IsQ= X-Google-Smtp-Source: AGHT+IFqc7I0JuU8pKNofJPkCjijygPm29THxWJcLstGus38EDysfYwWEGtxUGTIMDdOV2aw15xuAg== X-Received: by 2002:adf:f38e:0:b0:315:8a13:ef17 with SMTP id m14-20020adff38e000000b003158a13ef17mr4474149wro.65.1694078935600; Thu, 07 Sep 2023 02:28:55 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:28:55 -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 , Calvin Wan , Toon Claes , Christian Couder , Christian Couder Subject: [PATCH v4 12/15] replay: disallow revision specific options and pathspecs Date: Thu, 7 Sep 2023 11:25:18 +0200 Message-ID: <20230907092521.733746-13-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 de2ddeae3e..60abdaee9e 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(_("no pathspec is allowed: '%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 Thu Sep 7 09: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: 13376655 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 5BDC8EC8748 for ; Thu, 7 Sep 2023 16:55:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238248AbjIGQzl (ORCPT ); Thu, 7 Sep 2023 12:55:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbjIGQzd (ORCPT ); Thu, 7 Sep 2023 12:55:33 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 192C71BE4 for ; Thu, 7 Sep 2023 09:55:09 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-501be2d45e0so1943998e87.3 for ; Thu, 07 Sep 2023 09:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694105647; x=1694710447; darn=vger.kernel.org; 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=Jx8a78kSeIAviuV/vuA4G6UNVTFx+KKhZ3+hsqXQs60=; b=heNprYVG8YZ/zY++OEFeNbHQ0psbYmTLsPxZ9nf60HfJl2xf7H9tcjb+RfU7DHiMoj CrYO62iAJIAEf0OrZ438a/Yc+LmP6/vODefhKnRU4EQ1S0Y0ROYY6CTUzrCngpmXZz05 kutZkSxy7VKV2HLcALYwBXRx9LhSGdK4/V9VxZzlQ7C6ZrOraqJjucJcN1gV29wupn+Q ZN/0juE5mVFxKvIXd224TNwoK1XuaQV+09yjV3dySknooN10FlR3+pnRgTRQPNq2Sv5G ABpuRlFeNhTgOs0KHi6rWRXPuXn7C2eTSS1G+0PlnQdNgvQmp2bNrLhsLsAP5jBj4OTJ XLEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694105647; x=1694710447; 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=Jx8a78kSeIAviuV/vuA4G6UNVTFx+KKhZ3+hsqXQs60=; b=R+N4itZxTabC/gjuAhMH/yJxsvaARoo1KzaKyUHJW5a9IV03Ekcjwz717lGtoVSdr6 2MVN3t/eAtw/8bbzNMXX8N01V9manrTw0ahDZLaDFsJVP26QN8rKMbGuYZgaQualPkNh 7nbHpIANSywiuvcAX7tUYtR486cBni94roeIZODzWUc3fCQmCHomAkh08GiC8NXyep00 7ueOSXUxIDgMxvFn1M1vADRZTfsG/9gSEVo+GKko3mO99kZnkItmr2+q5uq2vMeqaVsp ZocozMZijQnqf865loH8zb+6PxQavtSSUpwLDPlxeIXJEJy80LPKXz+7xaoWeEsW2kmB nt1w== X-Gm-Message-State: AOJu0YwPkZyHn+jbR0zUDZL/8Hi+nnVOgoN2MyQaZs5avgjEFMexPx32 NPKQ2ama26VtneDgl2c2f8fdGe4PnmA= X-Google-Smtp-Source: AGHT+IEOuYRozGg3i8R8enO2bQwj23tsJqwmDiTamv0syGq/al4GR62OfVhm4ZNAuA5VYENT8c2fNg== X-Received: by 2002:adf:f6c7:0:b0:319:5e0d:9b0f with SMTP id y7-20020adff6c7000000b003195e0d9b0fmr4217174wrp.33.1694078950721; Thu, 07 Sep 2023 02:29:10 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:29: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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 13/15] replay: add --advance or 'cherry-pick' mode Date: Thu, 7 Sep 2023 11:25:19 +0200 Message-ID: <20230907092521.733746-14-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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. The replayed commits should have a single tip, so that it's clear where the target branch should be advanced. If they have more than one tip, this new mode will error out. Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- Documentation/git-replay.txt | 40 ++++++-- builtin/replay.c | 185 +++++++++++++++++++++++++++++++++-- t/t3650-replay-basics.sh | 34 +++++++ 3 files changed, 242 insertions(+), 17 deletions(-) diff --git a/Documentation/git-replay.txt b/Documentation/git-replay.txt index 9a2087b01a..5c5c15237d 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,14 +29,24 @@ 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 command(s) in the output will update the branch(es) in -the revision range to point at the new commits, similar to the way how -`git rebase --update-refs` updates multiple branches in the affected -range. +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, similar to the way how `git rebase --update-refs` updates +multiple branches in the affected range. + +--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 - linkgit:git-rev-parse. + Range of commits to replay. More than one can + be passed, but in `--advance ` mode, they should have + a single tip, so that it's clear where should point + to. See "Specifying Ranges" in linkgit:git-rev-parse. OUTPUT ------ @@ -49,7 +59,9 @@ input to `git update-ref --stdin`. It is basically of the form: update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH} where the number of refs updated depends on the arguments passed and -the shape of the history being replayed. +the shape of the history being replayed. 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 ----------- @@ -69,6 +81,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 60abdaee9e..6b89964be9 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 sources 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,10 +374,22 @@ 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)); + } + 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..1919f7d5d1 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -96,4 +96,38 @@ 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_expect_success 'replay on bare repo fails with both --advance and --onto' ' + test_must_fail git -C bare replay --advance main --onto main topic1..topic2 >result-bare +' + +test_expect_success 'replay fails when both --advance and --onto are omitted' ' + test_must_fail git replay topic1..topic2 >result +' + test_done From patchwork Thu Sep 7 09: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: 13376616 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 0C335EC873D for ; Thu, 7 Sep 2023 16:38:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241560AbjIGQhl (ORCPT ); Thu, 7 Sep 2023 12:37:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241495AbjIGQhO (ORCPT ); Thu, 7 Sep 2023 12:37:14 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D552BE4F for ; Thu, 7 Sep 2023 09:28:28 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-501cef42bc9so1921267e87.0 for ; Thu, 07 Sep 2023 09:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694104046; x=1694708846; darn=vger.kernel.org; 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=qEwUmNrS0BKhHHzzGjTQecxqyzmmDDSLK21otX6KA40=; b=sY3FJCewKE9xzslyHiVZcvhITdQl85NLnj3ZeZPh5oZKxVUat5SqcXHDlr6ppcuR6C JJDQ65tjWcvZLp6zs+oUCYmSrgUtVIP1M27Ewf1/K1aBlQnWLSD7jMlghocoAfk9J/78 2fH2dvXX75Jf0lUnh9gtvZGHQ9BBL9XsVvKEUxmIhqfQg3zMDBUW1EpqWGUjzLwRQtH5 VANRz0gVDCOYYfBovQ38r0N8LO38Po651MMPzEpUjiaxhsH5B/xo+DDWC7kY7czTXTrx Le5YmP5kTRtm3h3w4TohKXWZqhSiHSSop5tx/O6LcqFKrKvUPnSrqXxFYuItiPbpMXg/ yMCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694104046; x=1694708846; 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=qEwUmNrS0BKhHHzzGjTQecxqyzmmDDSLK21otX6KA40=; b=dW3zEcSJRNd5jVcdh9bA5CPzV7kcU8Qyu3Rzq/RdTuhnusPeuQO9lm04tFPzh5VlUx O6jKcPDVoEr3NKVeqfTZfk0w8L9YJNI/QSDINRiQKNtrnhkTZLv4hOLfQDoh1lHEKyFe a5zg/kH79YohdJC5/DpFPkQPJPwQ97STCt0zpUKeAZyqpRPiHdUxwidihFHemEHNcuaM EXMKgP6JQbCtb9E8jAXqq9BnqgRxaMzGWCeTvrM3K8zUOsEbnrKEJ6fNOsZ3Hsbw/iiZ yB+7c/+6EX0bGY7ItyPlaDpnyTYEYwrsIcbYHrJ2R/R9tP1sjFSVxMbPlC1EPqmc1Jdc 88jw== X-Gm-Message-State: AOJu0Yx6aB2ExKr7TrR7caciM2lT4VGJdJjo7p908OisBxgu7niR6Xwn h8JUrxeSIyX4plTH4ZHRdemzuc4E594= X-Google-Smtp-Source: AGHT+IGIK1OO0sELtBe3YN7q0fLVrANzQRhy4A5YtXGiSQw2FeIVGHRTAot9UrwroYbunYBMN9VD7Q== X-Received: by 2002:adf:ed8f:0:b0:318:8ad:f9f with SMTP id c15-20020adfed8f000000b0031808ad0f9fmr4274358wro.24.1694078964676; Thu, 07 Sep 2023 02:29:24 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:29:24 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 14/15] replay: add --contained to rebase contained branches Date: Thu, 7 Sep 2023 11:25:20 +0200 Message-ID: <20230907092521.733746-15-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 5c5c15237d..b94c39b161 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 ----------- @@ -93,6 +93,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 6b89964be9..a7d36a639c 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 1919f7d5d1..57d2ef9ea4 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -130,4 +130,33 @@ test_expect_success 'replay fails when both --advance and --onto are omitted' ' test_must_fail git replay topic1..topic2 >result ' +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 Thu Sep 7 09: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: 13376782 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 D13EAEC874B for ; Thu, 7 Sep 2023 18:20:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235585AbjIGSUx (ORCPT ); Thu, 7 Sep 2023 14:20:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbjIGSUw (ORCPT ); Thu, 7 Sep 2023 14:20:52 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A1E2A1 for ; Thu, 7 Sep 2023 11:20:46 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-52683da3f5cso1693705a12.3 for ; Thu, 07 Sep 2023 11:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694110845; x=1694715645; darn=vger.kernel.org; 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=rJrJWQDU2m/w6E3SJI2I77wg3wEKZd/lVjpGH3femMg=; b=TUdSGPnkv6Gk+3ZmRQhiiBM1me/Hp3AWW8O0hy0z1weMx1nD0Q/44N5UiYG47mPbgt JsrF06azCjf5+wufX45uQsAE44kg07xybX3vWf3PQ7S5uHLkZ5nx06dd6XhWUKzI2SDO dKiFh0NEUzcupYScl+fWfYppyl4rASHH1Tdfvp1mRqdlLwLOB/TcS+/6VUDMenUUON3n qfEj7n274x9C631YJQHjWbeU7jo9p0ZaXG+J/C7MhB9/ECA1WZytGP0lFwVubOhtRcFX GM67+KcrXLpTYB6kNjI9ss0bFnJAx0+86pUVJDI3zjm6H64Rq74SuSvHdKx0HIangvi3 sHqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694110845; x=1694715645; 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=rJrJWQDU2m/w6E3SJI2I77wg3wEKZd/lVjpGH3femMg=; b=qh5opwAcY1jVWB2XUvlU5JLK/op3YPjOZpnc4z5+ct4HSTAO8Pvaa0ZgA5EHu3eBOV JPEOea1xpcGymQIoX6adVQ2Dlf4tEoEWNt4LMDAFoeHIW2nGQqcMv7doQJNuvfeHBpFA PAcp7g0TlzzP5iZkBDZdE6n2t19BTYW8d0vuoIqcQ4wmnntjC0N3BYoAYg63QjukDTfv YLhgdyIq5pfpmg4me3TnAIPqiK40ptg3ptOU6sWXX7ZboXpKNCVTjkc7rCVl1sBdH15C XHhT7QH5KrJA8qR1lNgs+af/a4s6kl5uXOpWNjrk2X8qq/WN+WuNFP9mjFk/TMFwjcUH aVcw== X-Gm-Message-State: AOJu0YyZEm9Vt/r5/5EwsIskBO6SkxBTD4//m9PvUqHgz9vO+ZFgtOMi ahmiFUnu88lC/z2aPU4+Vvs1huiD1uM= X-Google-Smtp-Source: AGHT+IGyRTMh/iiNkDZCrz/RmNESnCaA6Hp/HGPwSmCE5gGDfEN++aiQRxYTPtIzbsVOT1cU4FMfiw== X-Received: by 2002:a5d:650c:0:b0:317:5e5e:60e0 with SMTP id x12-20020a5d650c000000b003175e5e60e0mr4397640wru.28.1694078979788; Thu, 07 Sep 2023 02:29:39 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:3385:ce2d:69dd:303e]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b00317c742ca9asm22491522wro.43.2023.09.07.02.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 02:29:39 -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 , Calvin Wan , Toon Claes , Christian Couder Subject: [PATCH v4 15/15] replay: stop assuming replayed branches do not diverge Date: Thu, 7 Sep 2023 11:25:21 +0200 Message-ID: <20230907092521.733746-16-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.126.gcf8c984877 In-Reply-To: <20230907092521.733746-1-christian.couder@gmail.com> References: <20230602102533.876905-1-christian.couder@gmail.com> <20230907092521.733746-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 a7d36a639c..5479406863 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; @@ -391,13 +414,14 @@ int cmd_replay(int argc, const char **argv, const char *prefix) } 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 57d2ef9ea4..fe5ae0391d 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -159,4 +159,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