From patchwork Tue Oct 10 12:38:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415339 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 15D37CD80C0 for ; Tue, 10 Oct 2023 12:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231663AbjJJMjK (ORCPT ); Tue, 10 Oct 2023 08:39:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjJJMjI (ORCPT ); Tue, 10 Oct 2023 08:39:08 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 267D3A9 for ; Tue, 10 Oct 2023 05:39:06 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4066241289bso52536965e9.0 for ; Tue, 10 Oct 2023 05:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941544; x=1697546344; 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=RdB2Sfx5tjWkyK8+Qlv7HGdfiXikWTmSCmIKvFTl0AY=; b=gtSVegxM4bv1iH8arKjKC0bzK3As6XMhKKaiP932muubxSkzZ3BzO201B/+DOHaN4g Y+2FNFjd41A6hHUUlYAgc4Oh3A+3Tl45sisIgoSISJyuu/eyULCep2GttNEfwA0oZHcd 20UzAyikbHf8lB6zZsD6LUmhKCEIHM0uTQ53P2AUVLWA0+3uhThvK3S2lrzqaBn/j4cy nVCran8bbeGAtTxp2QIy8u8DYxVHl7yFEJ8/d8C+oHGwY5nx/YTnM4dQWqQXgZrw2JgT +EOyV44KC7ACpHQAlJqVB+APh6tdQ1cQK3CZgvQ2lSZsE2L68md+pDci8WCbYSL3GFiU 21CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941544; x=1697546344; 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=RdB2Sfx5tjWkyK8+Qlv7HGdfiXikWTmSCmIKvFTl0AY=; b=asvqf0Vx/Kt5UGapnHnk48STsLY7j9RooPeOXfu4eQ/c/zAb0IGPwrsPkMzeTtMdgL pLPyeoskl5/wtxwlsCxbWx5KkpCtS+wdjRKXPJSMJO2kqbhsxvL56T3vKPslRP3TroGy gWixiQx1KQ9xSaJb53eAwE6Irx86/oXBXrT4+A063/VeYBSHrpcEdHqMRsGvdkO0nuJ5 +DcelkuvwD0l2fFx64uo3gmMfpQk9DSgjL1vb0P7TKCnIUov/aYu206oqG6j/+51KP1x PflKy5YS0wLR4sKnUHBd5/SviWagv9hdbhx0oRoUZQTWR0A1QfT20LiVnoxBRqjiCBKu ANSw== X-Gm-Message-State: AOJu0Yz6s7vnzcNlFezEyWAJvkBWFdMsP2L9kC6ZcTKIw2j/GibXpX9l CUC/awvF8+bQUW7eoUtcLu/wdzE9LNu6aQ== X-Google-Smtp-Source: AGHT+IGP2PvrVW5JDmOfmBPteCvr/o7BM8iquL7jy+m7ZSRyFHzG56VQDKntWW75XgFlcQCUuzfJDQ== X-Received: by 2002:a05:600c:c8b:b0:401:b2c7:34aa with SMTP id fj11-20020a05600c0c8b00b00401b2c734aamr16091082wmb.33.1696941543934; Tue, 10 Oct 2023 05:39:03 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:03 -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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 01/14] t6429: remove switching aspects of fast-rebase Date: Tue, 10 Oct 2023 14:38:34 +0200 Message-ID: <20231010123847.2777056-2-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 Tue Oct 10 12:38:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415342 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 13BE7CD80C1 for ; Tue, 10 Oct 2023 12:39:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231876AbjJJMjO (ORCPT ); Tue, 10 Oct 2023 08:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjJJMjK (ORCPT ); Tue, 10 Oct 2023 08:39:10 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BC769D for ; Tue, 10 Oct 2023 05:39:08 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40684f53d11so57086995e9.1 for ; Tue, 10 Oct 2023 05:39:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941546; x=1697546346; 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=tWT2tn9AECEPyoJkmXMc9sKmRafwP7GgxenQywqYvTA=; b=gnOVkWDWDcX65oD5uImGWs6HbXp1Yq9Jjxt8s0voPdjCyDV6kUilsyTFUwoeB3WXI5 BCulMX5sr/5n1NdC/FyQZ6QFQJfSA6GvISN+vIX30tH8BJSqgJZDd2R14Pntcd7uag1+ cBGNY2owHdU5ldrAaWdYImJSH5hO9YEF1TFXHeljax8CDv4UOuZ0yOvPaDtX6saxzCKK LAp16i2aT02PsoUHWjA3O75D98Dpy6JSMw2nBX0Z9/EU2Io2BMIarxPYKs9bt/pfS+VT tu9PgltXT63sfSCz5JgkKJFNj4stFJWXuZnR3Ai3wpi3T9lUyaOf/43pI4Rp7e/6x/u+ 0XMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941546; x=1697546346; 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=tWT2tn9AECEPyoJkmXMc9sKmRafwP7GgxenQywqYvTA=; b=qIY6K5U8YiroEAiyAKiEVaOIGjeF6negjnjonEXzFFlfjFHZMyueDAEYQWHKPSNTy0 YECa8rZkbmX/pjgV9G4aEfc8DjxFNDNDvz0lwe+S7aXlUiHQOv6rTds654So93wkmZwH +xjS4QOxaBnYztxuQhxJYL19n1V++WMzye/MJ1r6zea3TkuufSvi0AK96xWvctqMZ3Sa Eyzbx8JIeEIQtRmpBYc+yPKbiYo5NjFwhps05UY2/mmCXZ4tlj4zbwHOljoL/W4DxjBH n6jOQUsc6WDpQ6w/a3hudqkD96sC4jQ1BOCw8zD1zFNP/7uE8Q6985FAAzSh3qTzNkN2 Qocg== X-Gm-Message-State: AOJu0Ywjjh5ogQtatzpi6c/Fp7xtSdzIlbTCK6kjgTj0yQIpztry6mUE YLE7/kI3T+oy7R5KM4GxHUIpoFhHJu0Tgw== X-Google-Smtp-Source: AGHT+IG/fTU94Ox7dHIGGNLSNE8uxFi69uLYypw4Jiy7ZvdMW+RRMqMDa+4YLGeLJ7Ku4B+H4hANAw== X-Received: by 2002:a05:600c:22c6:b0:405:3a65:1b4c with SMTP id 6-20020a05600c22c600b004053a651b4cmr15772685wmg.6.1696941545558; Tue, 10 Oct 2023 05:39:05 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:04 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Calvin Wan , Toon Claes , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 02/14] replay: introduce new builtin Date: Tue, 10 Oct 2023 14:38:35 +0200 Message-ID: <20231010123847.2777056-3-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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. Helped-by: Johannes Schindelin 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 003e63b792..b5e3843d7f 100644 --- a/Makefile +++ b/Makefile @@ -799,7 +799,6 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-env-helper.o TEST_BUILTINS_OBJS += test-example-decorate.o -TEST_BUILTINS_OBJS += test-fast-rebase.o TEST_BUILTINS_OBJS += test-fsmonitor-client.o TEST_BUILTINS_OBJS += test-genrandom.o TEST_BUILTINS_OBJS += test-genzeros.o @@ -1286,6 +1285,7 @@ BUILTIN_OBJS += builtin/remote-fd.o BUILTIN_OBJS += builtin/remote.o BUILTIN_OBJS += builtin/repack.o BUILTIN_OBJS += builtin/replace.o +BUILTIN_OBJS += builtin/replay.o BUILTIN_OBJS += builtin/rerere.o BUILTIN_OBJS += builtin/reset.o BUILTIN_OBJS += builtin/rev-list.o diff --git a/builtin.h b/builtin.h index 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..c4cd0f352b 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 plumbingmanipulators 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 621ac3dd10..3109ba5c7a 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 a641c3a81d..d3e55c3f4e 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 Tue Oct 10 12:38:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415341 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 36D47CD80C2 for ; Tue, 10 Oct 2023 12:39:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231878AbjJJMjP (ORCPT ); Tue, 10 Oct 2023 08:39:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231751AbjJJMjM (ORCPT ); Tue, 10 Oct 2023 08:39:12 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F585A9 for ; Tue, 10 Oct 2023 05:39:10 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-50308217223so7032496e87.3 for ; Tue, 10 Oct 2023 05:39:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941548; x=1697546348; 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=jtfjEzkcsd/s2TXPrVNa45PB+Jl1suIyO2dRL8DMcbM=; b=d9jYLd1TZGogmT/xSI1TvzTFIpIRmhKySsdYXC1PLkrnpVhjnrTb9zsnAiRpXv30TO ljdTlXzQW/k7oN2Ff/xS2ytXI0q/gy0FSr+N5cL1RUiUAnz/54Iq3lpeChTlbSHQP2Ep yDGRea9d0hqBmFeG+89V/d7hWjLwsh0fonDjSUBW0BxC/cfSlypav4cruWBp6X37bWr+ F9bzqRk+o9WNLOHUWWUqf79hX2scarx0DlHppRluveRlSbYv67/rJo1BRxs/p2l5+s90 iuNbJahK2SqG5AIICvMJGYvTRiA1XuyVUmMYh3ANYfgyYw7IRfcid6Xt6Kx6oqa/MQmT 8a8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941548; x=1697546348; 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=jtfjEzkcsd/s2TXPrVNa45PB+Jl1suIyO2dRL8DMcbM=; b=ozUp1meCCnbI52i0jVWF/e8WOsJYS9++iOPqPNCibOE7HuNjWZdK+IbJT2qg+GjLSM lHUVKjbDaerNF5XnZnA5fdCq+JvQxHO/ff3qfTFbHWrNcO3J7Q0MRu+oLOp3KQJuJBwI OsNF9w8aUABxUxzcFu3/5KzYLDopC8V2FsuY+6K/FuD7qnDoIHtPOtjuX++f5nr1dSF1 yITE87C3MFCulEWQD1JHQvs1rsikUNiUjFcq/Qgpw7v5dyXLd668jv1kKVOSBiUvJWDO gZf5H54M7E4fK8Aen7e4DNfGrk7AstHDIkN7zMlQF8BzL+2HwVCa43YHz0BuzaaSUjJC uyQQ== X-Gm-Message-State: AOJu0Yy6OSIjbcBXYYrmTiJdFiXOvxaQq7viTCegqD1i8pR6DP5n7KHt B3wi5OOXv52fkRvbJQU6qYP0szvuGh3V1Q== X-Google-Smtp-Source: AGHT+IEh0l2tj+BFhuasWDX0IBu7b1BudJyl/W7XvH6HmGLiRP61FxpPQZ0iZ/hyqa0p2GLbCBDmvA== X-Received: by 2002:a05:6512:3246:b0:505:6fed:33a0 with SMTP id c6-20020a056512324600b005056fed33a0mr13295641lfr.34.1696941546525; Tue, 10 Oct 2023 05:39:06 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:06 -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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 03/14] replay: start using parse_options API Date: Tue, 10 Oct 2023 14:38:36 +0200 Message-ID: <20231010123847.2777056-4-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 Tue Oct 10 12:38:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415343 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 13956CD80C1 for ; Tue, 10 Oct 2023 12:39:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231929AbjJJMj1 (ORCPT ); Tue, 10 Oct 2023 08:39:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231894AbjJJMjP (ORCPT ); Tue, 10 Oct 2023 08:39:15 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14D02AC for ; Tue, 10 Oct 2023 05:39:12 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-405524e6768so54137525e9.2 for ; Tue, 10 Oct 2023 05:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941550; x=1697546350; 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=JNQ39VxswEN3jDWQEH+KmUcn3hK4HhGnFM8vEePDN9o=; b=PYS1zbUElq7GJJ4qBgUH3bgeroRBSGVJL3tsq9FDCYbj5TeGDDxKZrvYRowwQU9q+t jEWdf6r3gYq28gdQR4jjfPN/Om6mII4l9117dnzHISZfvYvoiMkA6S216tHDv9Jqo89m sDDPNbg7wT3bHnCpfbT4n1w/kxCRJFrVYyA9obdoHo4bIztEwJYx6cNEWhtCN+VjpFkO Lw7sHJKgBQ15EUoIIc5I6v8AGnT+E/4+E2n6J450PBgx9Io7h0Y+ey4Z1ZeOj3CxpAKE I7WhDzyZrwgjBO/o/hgY3L3xumKBUqaQquKO2gKRsuNfHX1KZp98Ymh6IZlWVqObty5b 0QEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941550; x=1697546350; 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=JNQ39VxswEN3jDWQEH+KmUcn3hK4HhGnFM8vEePDN9o=; b=t/ovOkvHLRZ4llB6l5WMBPb47q96baitu0E3SF9q5rDdxGof0Jf7jYxwSlvqsLchrL QnduMJMBsEsPaNjPMqc038Xl+WQmajHZrj6lLpp78FLM5GHgzbJMuylvt0PmL+gX2XHD wE3P+GhjUOKha2IOEpUmJFlvlqrX2GiSahAvmoRJtQ6g0cAObAr/IF8kbP4QwBJEi9rc Kv7Lh3c4qO8iuaZu6L+TfAwJbj8Z9teAxwvPtPkbugaJoadz6NP+dsjiEoO6dB2s8Dkt +9OcA33ppQZj2N05lkBmJFgyHhciuDt8g77pCJbjt1Hbnav/xwO358ECzUb3fY3y8yrG ahGg== X-Gm-Message-State: AOJu0YzzkWU0CyW+0RMFQZglgUbfmMA741Mp2p/e9/BDI34od1nHH40+ meP78GRVY3L+rKB0ab0gbv77yecpBXRa8w== X-Google-Smtp-Source: AGHT+IGWn6Bgnx2k8FwwE5Ody4l6ipoWTHVyYHiJyQLq8IRvmKJL2nAvP5N4QdrY0VdXzwBhaY8RvQ== X-Received: by 2002:a05:600c:211:b0:401:bf56:8ba6 with SMTP id 17-20020a05600c021100b00401bf568ba6mr15177609wmi.28.1696941549557; Tue, 10 Oct 2023 05:39:09 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39: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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 04/14] replay: die() instead of failing assert() Date: Tue, 10 Oct 2023 14:38:37 +0200 Message-ID: <20231010123847.2777056-5-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 Tue Oct 10 12:38:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415344 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 2DAB0CD80C0 for ; Tue, 10 Oct 2023 12:39:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232066AbjJJMja (ORCPT ); Tue, 10 Oct 2023 08:39:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbjJJMjP (ORCPT ); Tue, 10 Oct 2023 08:39:15 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B4CAF for ; Tue, 10 Oct 2023 05:39:12 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40572aeb6d0so52842225e9.1 for ; Tue, 10 Oct 2023 05:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941551; x=1697546351; 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=C7wh5OwEy8UhTyV+/y0fYzwQph084MhSujI9Va4XL0Q=; b=JEyF9XSea4+L5cvGdF42NZZql9IvDmiYNJ6umg/N/C4Lv7n9s9tK1/sSZ1x+x9leWf Z8ypDNhvg30AoqYhGmJXUvSg0yvgs+0aAUMFdywlS0NCgSY7WHO9oSbYXpqgf1xqa2PC C6PBE+Xz5a998GKjK3Mq7B7DLbhibLoJqMcELc+Ln5uJPOm0jGyhwr7Le9GSjstsarwH tJ93uvhu2nrvQQEtRT7WxcMhnHdbU/KPEhVrUctFoPkNC793aFuqQ0tzzWREbBTIJ1ag lLbMT1Iplg0Eqld4eivEtmaGsvhDYEdSMswlwsdfWUfpq+bC5LYuCgnbhtx5fxDV9N7E 5bbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941551; x=1697546351; 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=C7wh5OwEy8UhTyV+/y0fYzwQph084MhSujI9Va4XL0Q=; b=w/87WnahojeKWKjZEH+C3AcZ3YgCQJN2BjACrY+An1Tvt4mU7c1icKz1oYxh241aMG tv0a77tEkMwBux7xlDv5kZJKo/qkUG1iayqT7dvsNurKPw3duhIFjva4jfhBxZltP2tp O6czLDRP+KtI19sL7mzaheVh/6ijSitRAtZOi6suVeWdPeHpOrGoospRouD2yAxTzbvm mvejDKYp5RDGpsU2gPc/gdGon85GTgaS6bSzRra4ZAnYeWY7UwEmY4kGvIbMOW/nopF0 b1TJHPCvRy4we8xrahYa4dCbGJbhgOg7AJnDN67qkeyFfTbNHXcDW7O4NuNzsnMmJXlA vcaA== X-Gm-Message-State: AOJu0YwapDVQyAlpIDjU9enBIRz/qIc9qONwwzS3Ho5AFt8wrm1xbGe7 Yh0ILI5TUcj8AuAVBm0PGKImuGANXM07nw== X-Google-Smtp-Source: AGHT+IGoJXbs+YMxpTnqKxvAWkiIgWkLsCkN0os2Mk0E5ni2pmcUsnxszQYvAvkY3o/3Fes6QgA2tg== X-Received: by 2002:a5d:538b:0:b0:319:67ac:4191 with SMTP id d11-20020a5d538b000000b0031967ac4191mr15124083wrv.37.1696941550451; Tue, 10 Oct 2023 05:39:10 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39: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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 05/14] replay: introduce pick_regular_commit() Date: Tue, 10 Oct 2023 14:38:38 +0200 Message-ID: <20231010123847.2777056-6-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 Tue Oct 10 12:38:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415346 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 AD6D5CD80C0 for ; Tue, 10 Oct 2023 12:39:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232072AbjJJMjd (ORCPT ); Tue, 10 Oct 2023 08:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231921AbjJJMjP (ORCPT ); Tue, 10 Oct 2023 08:39:15 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3118E9D for ; Tue, 10 Oct 2023 05:39:14 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9b6559cbd74so1020823466b.1 for ; Tue, 10 Oct 2023 05:39:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941552; x=1697546352; 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=2WVQI9EjfG6xbmP0tPftS1CJm5uruGzTjG2k3MMcbxI=; b=j7lUWSJFamlU8G6MgOn7WJn5LBKJ886G47UFAHPQAwqod85FofjWfXaE4x4nT26hL+ zxrNG9VIVn7Vm5S+OxL6vKxfwreEhJF+M5mq8e4IYjx+zP+/cLXOYSHVSvptBVEbs0sG aGQTCHrxYv3feOigA2KdiV4BVnnzHK5BUkXHusDukBVIvgMWTwdIUtbgz16DZGszLzPP DbRoKgo0C1hO7AAZGBC3/T0IUlp8EWd4lwsM3FBcEHEUiRbo5R8Eexu7iNGGFRDYw7OW UbTt/Kviv3UTHwNymO603TSAie6F+MsG+v9Jvz+vUTxxVl51ejUKcco8c3s5wBHYcbN6 RVhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941552; x=1697546352; 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=2WVQI9EjfG6xbmP0tPftS1CJm5uruGzTjG2k3MMcbxI=; b=RErrgPhMCSn2Uuxdpp96H1qRYCOhbM9pSINATXy3mGJawdwL8ijIGBwQ16pqMXYmCj VANgpOaRqUc2LPXPQ617kCO68oJPwCumXgaMj1MGXjzNIjA+bc/2OxMJAy74ntqWX6kQ 9YVmwc4UBw1oCprhhtZO8PEXDQjTpTlz0TJtNvgvnTn6yhckFR2fb7e3qPkbQLjS8fcR wMgYs1o5t1aFag07U0Ych8oLctztj49N9u3WLGHJ+gFUeV6e/+LrGPbeTOhz+3n6kGJu ZwDYkIgBOWq3Y7XwwIb6CGG8dZ9KjAp0VBk08maJP6UG/57g27pkWmxA8ODl6NiUY7Un Dayg== X-Gm-Message-State: AOJu0YxDtZF26HBYfistzsR9eNgk9PnYBlGvKsQrD5W+4mcDKD0Uyqz4 kNxrOHN9vviajpIy4yoe2AhHf/VMx4OXzA== X-Google-Smtp-Source: AGHT+IFi/WpMjCqncUPx5zHY5cr+4btOZozjJrNHYItgNne9J9QhAJ0zylP1YWHDihEttSkDclPGJg== X-Received: by 2002:a17:906:10b:b0:9a9:eef6:434a with SMTP id 11-20020a170906010b00b009a9eef6434amr16733046eje.36.1696941552118; Tue, 10 Oct 2023 05:39:12 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39: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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 06/14] replay: change rev walking options Date: Tue, 10 Oct 2023 14:38:39 +0200 Message-ID: <20231010123847.2777056-7-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 enforces options we always want. We want the command to work from older commits to newer ones by default, but we are Ok with letting users reverse that, using --reverse, if that's what they really want. Also we don't want history simplification, as we want to deal with all the commits in the affected range. Helped-by: Johannes Schindelin 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..5bab89857f 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 = !revs.reverse; + 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 Tue Oct 10 12:38:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415345 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 C4418CD80C2 for ; Tue, 10 Oct 2023 12:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231962AbjJJMjc (ORCPT ); Tue, 10 Oct 2023 08:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231932AbjJJMj0 (ORCPT ); Tue, 10 Oct 2023 08:39:26 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51970C9 for ; Tue, 10 Oct 2023 05:39:15 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40537481094so52062935e9.0 for ; Tue, 10 Oct 2023 05:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941553; x=1697546353; 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=n1KT/RpPiB3ydvZP59FagJ5XhQe3osyIlL68u32k3a8=; b=evMZ41TtMz1FvAvW/PxLt9tEDbj/ltCLAYSnxJpcU7iqWr6H3B/tcmAsXmkpE3WDBx HmfajyIgMzWqu8D2JWMDmM9m+rbX12vMBWYZKHNKw+V7L2wKKH3VPkgEb/OCUWZY/NXV MzvTGtM57PsCO9PC4mYTg7wa09Wx4bB8BGbk58puroNVHqaJxD6zX9lASr9D8dkMzCod KNNfiDBFszeAZ2w1EbYl9GDalP5/FFkpW2BlP+hcL4+e8Qcu0OgEmhJRpN/kMWNh+p4/ S5IlF7e1LaCTpFXXyVPk+u9UwcGCUOkvh5PUB30sfBrSBPb2zG5DA8BWTORvtAYrCe+n 11gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941553; x=1697546353; 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=n1KT/RpPiB3ydvZP59FagJ5XhQe3osyIlL68u32k3a8=; b=gtFKGfDJCEP3AFryMOVq/5rxTKG6gHeTcetH7TFTbgikG4rpiNaDr4Rd7tBusZ1Utu aVTceOKa4MsJXmv6PLoCkdG7+UitO2v8PfW6/2suLig/LaCbSuHGB6ARqfa/pvSRbKLI fToGcsZ9F6KFN5QN9DEFcEnGc7/oLmpGZv1OCLJ8L0h3eYFn2y5bHTWiTcHy07N1R1hx PR9M+BD3OKRufZO0HtcEIOCI3vrXo7FSxgvt5rxN+vLwgmZ8UX+rMdYOt1EJ+5jK+whI 0Xmm/5paLtUKktFbjUEdat6AlWpcYsGUK6kQj/AS20eEIVLWH5IVRF5BFnZ9RrxRJjBx E0sQ== X-Gm-Message-State: AOJu0YxRTE7z3pjMq8UII26PJVd9cMjijqOu2XNdqTUZ7L8EuMKlwN1u mBkKO/vFOQPU/bhJzoT4hhZtEHbKISuEkw== X-Google-Smtp-Source: AGHT+IF3j8gcKWnmpThZItYkMZ3lUOBoBN55pva8la+EgmEHMDvFLAGT2NZeWSbsm4jU+TcoLM0aJg== X-Received: by 2002:a7b:cd0a:0:b0:405:3dbc:8821 with SMTP id f10-20020a7bcd0a000000b004053dbc8821mr15417880wmj.22.1696941553241; Tue, 10 Oct 2023 05:39:13 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:12 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Calvin Wan , Toon Claes , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 07/14] replay: add an important FIXME comment about gpg signing Date: Tue, 10 Oct 2023 14:38:40 +0200 Message-ID: <20231010123847.2777056-8-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 5bab89857f..dbadf3b9b4 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 Tue Oct 10 12:38:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415348 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 BB869CD80C1 for ; Tue, 10 Oct 2023 12:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232007AbjJJMjg (ORCPT ); Tue, 10 Oct 2023 08:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231975AbjJJMj0 (ORCPT ); Tue, 10 Oct 2023 08:39:26 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE50ADA for ; Tue, 10 Oct 2023 05:39:16 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4065dea9a33so53983295e9.3 for ; Tue, 10 Oct 2023 05:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941555; x=1697546355; 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=1jR1XyF6IYB0kqtD7JZ+p7VDCFKX9AOIuEefk+PYcg0=; b=DwgGsoqnVoyFf4//3QM6YpT3JdsjuKwSQu4VBWXwirtKyVPxm7ELrBgmKar7dkbx9H sM3qJMFGw8MyG2ZjnokU8KCHOJp3SQ0KgajED6eLhmmFMZLchJMYwio8RH85l5w8cOlu IgCuDTGioWn6uRMzgnNiZfKB7ZS8YyR6bd35kbzeKmdw6OX6kv5GQsIRbcz4/pp/2iWe Mqpkdoat1DVmbENvqKNA/GcS8rf0WuNgZ6PWcZgOBJDXPCAajVa+sl/KdYIAOU1FhQHA 3SIiYFlrprKHk07PKrS0+xlauTzBDCqHMQMws941hL/xQJL3/yXktXLR4NW6s2fbN0bA gy1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941555; x=1697546355; 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=1jR1XyF6IYB0kqtD7JZ+p7VDCFKX9AOIuEefk+PYcg0=; b=C+KUk4bY5T1L9PyJk2p1iL2nCf/hsjbL/iuairhThgrodibKilHpLMW4tEEYPc7yQ2 NDim/ErqMksx8bBh4miwcuCjkl8vEx9RGUIHECFMKKqbq1VBWUE934zJ4F3yqTtXIjy4 PFfNUxpyD557wQUTxDzWDzVzzOYnMGC5UpLIyoKlxMslY1Zl0FYTTmQRFhhrBpwq4YPT FAKF2cuDzuyUaPAhvaoNdh6vVxaXUtt/xu8gU9GIyRj2WAOdvKQGYG7LRG+TAvVKMAwA xy5w4NtrOMyFe4uw9eYzfwJ6Tq9bpqEy4C1oW0688FbUJ5eUgP1mABUoiUnsSVONde66 6WzQ== X-Gm-Message-State: AOJu0YxB5MfBd3N7nIUD+WWxdyl+4RPqKxbtSGnxO6Cz3RRbtChPUeAA mBIjcaXQbYNqLD4Y7YuNMuzRENT+4L/0Ww== X-Google-Smtp-Source: AGHT+IFpAwQBSUwZ3BRZYjnkRep9kmuL+eTxIMAIQY+Anarx8/wXxG+Q29SMN63q9aXWFHSsgHKvNA== X-Received: by 2002:a05:600c:ac7:b0:403:b6bc:d90d with SMTP id c7-20020a05600c0ac700b00403b6bcd90dmr16245464wmr.20.1696941554560; Tue, 10 Oct 2023 05:39:14 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:13 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Johannes Schindelin , Elijah Newren , John Cai , Derrick Stolee , Phillip Wood , Calvin Wan , Toon Claes , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 08/14] replay: remove progress and info output Date: Tue, 10 Oct 2023 14:38:41 +0200 Message-ID: <20231010123847.2777056-9-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 dbadf3b9b4..08a7f68420 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 Tue Oct 10 12:38:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415349 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 4F40ECD80C0 for ; Tue, 10 Oct 2023 12:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232052AbjJJMji (ORCPT ); Tue, 10 Oct 2023 08:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231980AbjJJMj0 (ORCPT ); Tue, 10 Oct 2023 08:39:26 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F0C3E9 for ; Tue, 10 Oct 2023 05:39:18 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4066692ad35so52223945e9.1 for ; Tue, 10 Oct 2023 05:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941556; x=1697546356; 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=eQ/066jZaXiQEaVtypMMC+nnWxBzeA4apy59aTDg9VI=; b=G/Li4fTeLjSfiAnSRt14fhHajtCl6FXexjQpkkE1exCPClLbTz41KFH4AgmhEUbHAT KUYLKqFkfuvfnFJxbrSCTIRjqieDGHwzxFtGawvADd2hCT3njPwfxXCuFOy2hOTDBbTD o6V2YdsohV4ctLQDzcOuHYE6IXAmfAUwdQ3DCqXGajqD0pzOX/O44NpnwnuCoTg4BBht R3/+QJDXfCZBoUyTS5H5O1Oi1FVp4pDMWc+M+GWE0MAcISXm/89CbMbsiIPhbB1RJeMC ZikVlQy/DXRAb4IF+rdO5rjTpVfCYXLFFd0mtJ9a5wvRhnaRCgHsTrTusZG8bIiQDxn0 DOmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941556; x=1697546356; 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=eQ/066jZaXiQEaVtypMMC+nnWxBzeA4apy59aTDg9VI=; b=Jhp2PCwD5+vOpHyTkrxSleFzhbPx0XT07iedAHNq8W1e23CTH9aurLGzw7Y7A8rt8E PRjs7WppHj9+yagyO1ycnz3GpRsBxnZjJLzGWgOohyPFoVW3dQKniGUIZx+bMCrAW/zL HWyJbMZOQlFFWiAvO//G0LEkmKLd78859kT45yf58YkoRhEQ6pozyp+GvfHoLKpoSX2Q UyoMDkPvlhUgqKpDeCT2dg0k08vP6EC9ZLLMpAmDN2KleHCzv6kuxQGRm4iZ6Pcf4W/w CMhP352sIP+Y/xsHP6u3a7WsucWV0BJ/czaJI6IaNl/otbUcDQ7IAP1kdb6RcaYWsjCn vqRw== X-Gm-Message-State: AOJu0Ywy4iyA+Gdu1PEH1PlyxDsS4J3SuR+btiLVOV2Z/5q40XbXTlFL icRzSa5YFy7iGGi/E15fGxIEoNsDAq8jPg== X-Google-Smtp-Source: AGHT+IFmhBovHGdzEhWvo/V56o0Xj4ahrWqfLAsAXQBvENF/69nHXnTFSRZv1Yesd/vxzlwp4CTVkw== X-Received: by 2002:a05:600c:3502:b0:406:44e6:c00d with SMTP id h2-20020a05600c350200b0040644e6c00dmr16524133wmq.2.1696941556164; Tue, 10 Oct 2023 05:39:16 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:14 -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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 09/14] replay: remove HEAD related sanity check Date: Tue, 10 Oct 2023 14:38:42 +0200 Message-ID: <20231010123847.2777056-10-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 08a7f68420..87fe655c6f 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 Tue Oct 10 12:38:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415347 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 50FDACD80C2 for ; Tue, 10 Oct 2023 12:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231941AbjJJMjf (ORCPT ); Tue, 10 Oct 2023 08:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232047AbjJJMj1 (ORCPT ); Tue, 10 Oct 2023 08:39:27 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10194F4 for ; Tue, 10 Oct 2023 05:39:20 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-405505b07dfso39441115e9.0 for ; Tue, 10 Oct 2023 05:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941558; x=1697546358; 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=7FKWWCBSdn5tfwCm6cFyoUP0rtbnqghkaVMvmji4kmw=; b=VBU9aG4J9qBnDG+c70mEEI2659ngPqlu2myZxJ+n/88poOm/QmElEbnwrpMoW5daB7 VPYQRaQEd47DAidz6vHm/xbqmiGeCVcRGrtswJGEhyGNjWsIf5tvkpawtWAkOVTfLhMh f6MwRBWP3dTiAkxRjk418KQiPS1/3AG0BqgGKo+Mq02/zctBK7bDkdCm8nJoO5U5EERU ZRUvMOzS+1WkcDZpdjehptk+MzztVmAo3jFeKww0wpy1r9Y8ObBe1FY5d1iKaKHMD4EQ +NBQWQmh6eB51pSZVjr15kw7VyGcdQYLAencQsDendrEKhTokR9l41vUedxBZgtL4JCc puoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941558; x=1697546358; 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=7FKWWCBSdn5tfwCm6cFyoUP0rtbnqghkaVMvmji4kmw=; b=JN1eSzpQRD2EkkKDwvV8ysGhmSM7L5tfECSKYibsT+A7x8GGTuuLc1yPbJljk4YQ48 XdS9ly8dA2xBq31cSsR+rmuMxdcXU/uWCLL+MgrJAX1iiptntzGJ1Frg5aBnwCF4EOSh DCQFvdjZrsHd6TzcUITsq7IrPg9g29L05KDx4ii9GpC50U3VgZ1cf3TkguxbwFyIfTrJ dwYmu2d9PevrzX8sSEeFOmq7aOPhnK6Qe5V8pPIzkLRY5zY/MyCB3+6GgVBua2pRBLSB T+horfehyY3WF+/Gof6futClQCU8AWjsX/+nUVWvSflHG3rk60bNj83ZaoaHm4jJcsYN 9zCg== X-Gm-Message-State: AOJu0Yw4C4gFOuGV2TRQnfC3UhXO8Lx8HfrQ0lIFcIfkZzqe/MCJvj7w Y9+Vl3kBnga09bfjrTnhkcrHAOGrLDC1hw== X-Google-Smtp-Source: AGHT+IHEZqSCZGSQnd/nPRdlt6bwoqVbG+7lx/Ny8CQJJrrpvKfO/ot3qqCV856G4TwdPaYykuuFHA== X-Received: by 2002:a05:600c:44d3:b0:400:140c:6083 with SMTP id f19-20020a05600c44d300b00400140c6083mr12068457wmo.2.1696941557818; Tue, 10 Oct 2023 05:39:17 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:16 -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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 10/14] replay: make it a minimal server side command Date: Tue, 10 Oct 2023 14:38:43 +0200 Message-ID: <20231010123847.2777056-11-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 87fe655c6f..ace9ac6df0 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 Tue Oct 10 12:38:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415350 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 EA313CD80C0 for ; Tue, 10 Oct 2023 12:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232130AbjJJMjk (ORCPT ); Tue, 10 Oct 2023 08:39:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231937AbjJJMj1 (ORCPT ); Tue, 10 Oct 2023 08:39:27 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8B42FB for ; Tue, 10 Oct 2023 05:39:21 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40572aeb673so54277965e9.0 for ; Tue, 10 Oct 2023 05:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941559; x=1697546359; 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=/WnV72tVPZcMUI+gcgnS1nrDKjuufUjlRcljke+jwOk=; b=jEWdl70taIKTmb3Ynrx/BO649tONzeNvWF8H6C9vtyrGMnxIpzmukTcwsni1zJAtAl Z+ezJwr2V+sHYLchjSUPHFFlXTkuh53LHkL0NKzhZwOiJ6+DqVE6zplz6hD6u2YszYc9 /8z4KBtzz5rQP5MvGCG1jWHnUr30g/agfSG4hRI3Wf2azkLdAEdmLBD8dTp1ZayQWf+t ZorJE/HobIdy+0RJWDqiR8+kSeRR1s0oBiUlHGRPhg3+pn6o518/vyDIX1Y/93pbdQYi rfgXfjE4Ebls/2+QELguTsNIQqFSGO8zVhcWOqjKVVe+R1R4N/a0h9EJySC+NJ+qGmtW C1Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941559; x=1697546359; 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=/WnV72tVPZcMUI+gcgnS1nrDKjuufUjlRcljke+jwOk=; b=dioxvquaJ7x5e2QHFMRLfDiZ516pRt133TI9SFIaWmK2FFbTNN1NnTzwDah7WU0lVN uGVgybmBe3LhUHLQ10kcM/Tn80pbrIwooX7ykRinePyIc38IcCmvc1IkMFBNbsd7REnA 6vscxawvDvBnfDdtDYWkK3ILkX0KtxklaWixWaEmswYOw06VD76H5SDaoOzRCIVP1fnA opCk5p406LEA6e1wgjO+Vw8jozbrYlf8+YceIu9qM/N5BcMD0bIZXGub8udiqSGBfv8e qZsSLg0Geuh/Y0dz9380A2Yp279mcWgSRpfrYeJCDvvH3XP6/Yj5K3lRBw2Pzcl8wQyi JYew== X-Gm-Message-State: AOJu0Yy9mKLH3uhDVTQ8a+em42pcpWNU+/SNW578k+acoBDt2xybUKMb JygomckdG+HXZOtJifu1k1yGW4tkcg05LQ== X-Google-Smtp-Source: AGHT+IF8y/2UskzeRwjQ497zurUl/bMbQdd8cWrOwWtZ+QL4QWOuHUKNUZlibosEvDkqUwykTbmHiQ== X-Received: by 2002:a05:600c:252:b0:402:f536:2d3e with SMTP id 18-20020a05600c025200b00402f5362d3emr15628385wmj.14.1696941559449; Tue, 10 Oct 2023 05:39:19 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:18 -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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 11/14] replay: use standard revision ranges Date: Tue, 10 Oct 2023 14:38:44 +0200 Message-ID: <20231010123847.2777056-12-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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. This also enables many revision related options accepted and eaten by setup_revisions(). If the replay command was a high level one or had a high level mode, it would make sense to restrict some of the possible options, like those generating non-contiguous history, as they could be confusing for most users. 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. We only document the rev-list related options among all the revision related options that are now accepted, as the rev-list related ones are probably the most useful for now. Helped-by: Dragan Simic Helped-by: Linus Arver Co-authored-by: Christian Couder Signed-off-by: Elijah Newren Signed-off-by: Christian Couder --- Documentation/git-replay.txt | 92 ++++++++++++++++++++++++ builtin/replay.c | 21 ++---- t/t3650-replay-basics.sh | 83 +++++++++++++++++++++ t/t6429-merge-sequence-rename-caching.sh | 18 ++--- 4 files changed, 188 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..86be363f9b --- /dev/null +++ b/Documentation/git-replay.txt @@ -0,0 +1,92 @@ +git-replay(1) +============= + +NAME +---- +git-replay - Replay commits on a new base, works on bare repos too + + +SYNOPSIS +-------- +[verse] +'git replay' --onto ... + +DESCRIPTION +----------- + +Takes a range of commits and replays them onto a new location. Leaves +the working tree and the index untouched, and updates no +references. The output of this command is meant to be used as input to +`git update-ref --stdin`, which would update the relevant branches +(see the OUTPUT section below). + +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 and the "Commit Limiting" options below. + +include::rev-list-options.txt[] + +OUTPUT +------ + +When there are no conflicts, the output of this command is usable as +input to `git update-ref --stdin`. It is 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 ace9ac6df0..213ac2764e 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: 13415351 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 C1119CD80C1 for ; Tue, 10 Oct 2023 12:39:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232211AbjJJMjn (ORCPT ); Tue, 10 Oct 2023 08:39:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232081AbjJJMj2 (ORCPT ); Tue, 10 Oct 2023 08:39:28 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 510CB102 for ; Tue, 10 Oct 2023 05:39:23 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40651a726acso51987705e9.1 for ; Tue, 10 Oct 2023 05:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941561; x=1697546361; 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=xOeZ42wHhZ8YSnebuuhJA0p1Nj3RcEaALwf4SMymqkQ=; b=IC8uesAHIc5gPx0Jfgr+9eSMJJy2ncB1G49UEtbqWWZ+/oxfhmK8OqaZ2FmR303IY5 qdIeUuLDHnDbjnl2wzrJ68vYAeuTGSr6RzlA1mr2+iN3TDEck0GwgwScjrTThxyTEBs4 t2uX2i+T4M5vKP8tJ1V2RklybZAxbHJRlcIrgWUeXy2mO9v2YABg1wuzL0XBzL/1AtnX i+Lzd7EskItGVLsApJGuQ7bUMyTD0MHquPQWrXY8t7lTvAZ1m87lqUw/gjD5+L+se4xu tHudA6IGLcG/F4m2lW07/7D/rRjAe9/+2lMljbFkjq1hkABXaGvx9cf6+7nX8nfwQbDT gULw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941561; x=1697546361; 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=xOeZ42wHhZ8YSnebuuhJA0p1Nj3RcEaALwf4SMymqkQ=; b=T2l8DsjjSmDc5LN2MxUMsGUjRo7zI8MYsPF5lRQa19Bf18BnCXI1Mog+Zn29vkWUsH hCJAqH1ZBTaKH1FI6A6xtIH+17C+SC/i+FEOCUOFvLS3A5zc4wA0E6Jch+ifqSnDx3Jd VlwIhf+4LuOsyHE7hnKGsUY8CDVFhB/yLGV/rfCJ0Vfn/uGFvnAOD6TRl4T439VxDB8n QhgNm/UENH7LPDduRLYsT9/OJg0yAp8rguBBdDuYd+xwXtDgcKcdFiCQYduS07TWi1bF k2ZdZ5bq8hcqfMQFc/DUGd8Aaxhw/Em39WX89wfOqrbmMgyUnu2Cf0hf7iDpm2iO8IPp S9Og== X-Gm-Message-State: AOJu0YzB1pnpQIHUQycXzV0qrUItF+ozoACIb8OknVIb+guC8O11HjVu whm3hRuM2nOqnFJXSkKgX4cn9CggJP+MyQ== X-Google-Smtp-Source: AGHT+IGxTr61Dy1edzvaCBOEpu1bj5Fu/GnapwEoi1y4coRWiw30DKIIU2tAsgH0lqM0UDr/KfBvKQ== X-Received: by 2002:a05:600c:21c2:b0:405:3d04:5f52 with SMTP id x2-20020a05600c21c200b004053d045f52mr16811133wmj.24.1696941561109; Tue, 10 Oct 2023 05:39:21 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:19 -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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 12/14] replay: add --advance or 'cherry-pick' mode Date: Tue, 10 Oct 2023 14:38:45 +0200 Message-ID: <20231010123847.2777056-13-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 | 41 ++++++-- builtin/replay.c | 185 +++++++++++++++++++++++++++++++++-- t/t3650-replay-basics.sh | 34 +++++++ 3 files changed, 243 insertions(+), 17 deletions(-) diff --git a/Documentation/git-replay.txt b/Documentation/git-replay.txt index 86be363f9b..2c09232c8f 100644 --- a/Documentation/git-replay.txt +++ b/Documentation/git-replay.txt @@ -9,7 +9,7 @@ git-replay - Replay commits on a new base, works on bare repos too SYNOPSIS -------- [verse] -'git replay' --onto ... +'git replay' (--onto | --advance ) ... DESCRIPTION ----------- @@ -29,14 +29,25 @@ 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 and the "Commit Limiting" options below. + 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 and the + "Commit Limiting" options below. include::rev-list-options.txt[] @@ -51,7 +62,9 @@ input to `git update-ref --stdin`. It is 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 ----------- @@ -71,6 +84,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 213ac2764e..d458837e9c 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; 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")), @@ -137,13 +284,11 @@ 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); - 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); @@ -158,6 +303,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; @@ -166,6 +317,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))) { @@ -180,12 +332,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), @@ -195,10 +350,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 a1da4f9ef9..68a87e7803 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -80,4 +80,38 @@ 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 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 Tue Oct 10 12:38:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415352 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 18057CD80C0 for ; Tue, 10 Oct 2023 12:39:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231975AbjJJMjp (ORCPT ); Tue, 10 Oct 2023 08:39:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232108AbjJJMj2 (ORCPT ); Tue, 10 Oct 2023 08:39:28 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF17C110 for ; Tue, 10 Oct 2023 05:39:24 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4054f790190so54666885e9.2 for ; Tue, 10 Oct 2023 05:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941563; x=1697546363; 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=3JKhnpjl5sOQBmmvXRBONT2nlbP6VD+7ya0BpBA/o80=; b=lhQ8H53n+ELUjiEbXnTfXmAe+Zfx44O2FhssrGRv/jN3utoWHS0Y4ZuUrteFjeaBQL DAaaPLoqgWLHyRVBHMcei+9RIsBtqBcmBp5iWMcnVy3MExWGDZTgoO6ECfnVwL9Et8gw /yPOM2G1O2CrEnQfiGhBe+3JdobFGx4LxtVXzS1o68gn75sJ2X8KlutpydckBD8q5Uq/ NDJzfzHAtt9eDoucb5cBKf0/hOmdRmj6gIu91KGCxWMVKZREHiMAxPX6pFInVIAC3iPD XiIbwKZsUd48qakPoL0GywIiiq/fbxQB1j3MEtPoIAmRwSaeUeRQ7Sv5VYpdV0mE7LRh xrIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941563; x=1697546363; 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=3JKhnpjl5sOQBmmvXRBONT2nlbP6VD+7ya0BpBA/o80=; b=A3EvTb0MOjGltPjP1wGdXZefWgXCdM8LPn9jT9pIGEs7H6LVH7BbPJBVXqvxBNcYG1 VXPb+ebta35882UfktLUWXxPCtLPmA0Z/9ggjY2FtrrsMkzy1gsYd7gg/DUL3ncPxPaD tFjqOvvaZjw6+NR13AejM1d59i4SfMZGaBukYPEBpeYbHacS/xzVs/XUoNtdgLXd1X0l HjjqbkaAWlyw2TQ2ieh3k7dTzse6yeFlPb0UEdmSeH+HodTKeaqQRIZaO/Gp2j3m15+4 ziALsDQmFu683pWX70F/Mac3JK9kpZ+XWyr8oWCCWisgqcUChk71TE6YLhnTbW+lLRi9 d7iA== X-Gm-Message-State: AOJu0Yz354GgKQVQrR4AFEB7CbBe+QlN4CTsORBj29AwH8al6ybxnAm2 uJcXPTdypKs+tyz0/DBUq5GDl5RKQonRMw== X-Google-Smtp-Source: AGHT+IFoSoeo2wBWo416yoKwe8LEc4t9qITD6JYFR9AxpOmXBWGPBUSGEQ1yImPFUnTuEx2cHkBA8A== X-Received: by 2002:a05:600c:2150:b0:402:8c7e:ba5 with SMTP id v16-20020a05600c215000b004028c7e0ba5mr14800534wml.18.1696941562693; Tue, 10 Oct 2023 05:39:22 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39:21 -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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 13/14] replay: add --contained to rebase contained branches Date: Tue, 10 Oct 2023 14:38:46 +0200 Message-ID: <20231010123847.2777056-14-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 2c09232c8f..e9697fcfb6 100644 --- a/Documentation/git-replay.txt +++ b/Documentation/git-replay.txt @@ -9,7 +9,7 @@ git-replay - Replay commits on a new base, works on bare repos too SYNOPSIS -------- [verse] -'git replay' (--onto | --advance ) ... +'git replay' ([--contained] --onto | --advance ) ... DESCRIPTION ----------- @@ -96,6 +96,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 d458837e9c..12689f1c89 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; 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() }; @@ -289,6 +292,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); @@ -340,7 +347,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 68a87e7803..d6286f9580 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -114,4 +114,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 Tue Oct 10 12:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13415353 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 34FEDCD80C0 for ; Tue, 10 Oct 2023 12:39:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232243AbjJJMjr (ORCPT ); Tue, 10 Oct 2023 08:39:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbjJJMj3 (ORCPT ); Tue, 10 Oct 2023 08:39:29 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DF3BB0 for ; Tue, 10 Oct 2023 05:39:26 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40666aa674fso52899755e9.0 for ; Tue, 10 Oct 2023 05:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696941564; x=1697546364; 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=FG9uFhIZYBAT1cYlYWjhUFiG33889dMAk/xw90vmX04=; b=PAC43qNUkNIxG5azNSGjuyztw7N/VQSmHkrZzt9WlAN7nuop9dBrLPVl0MzMUOqKwi eAATmtAOYPsL3r4OSxzZo6O6saXaPFkq5tTkvB4Y9HyXfajbzNmfTJJDY7Y8UTKLnh1g 67vtF0M1oXab7CZHMKfBCZjO++Y+lAcdnZyrMVTRNDZ3HtUELWd8J7VE6X1YXRFvN+EL bU+vGdtLabLrFxVs5M5MlA36TKoO+rdLihVcUKDCrKsZ9herITNbpp2QtF/wmGFxQ3To Xr+/FMpslgh/YRK1M6CpzdL5wwiIWvUhUH5HZTcGpFjIXYOQEXFfvL9hHrv08X2koZR7 NZQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696941564; x=1697546364; 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=FG9uFhIZYBAT1cYlYWjhUFiG33889dMAk/xw90vmX04=; b=mHXEZqYwNZ9mgKMrkRM7nXunhkqSw/avlgzVDTwhJBXipnVPt/Qt3/KQ2vtfe6KXrk ozP19QaaJFZTATx/ZhLuA9x5UTjLhtM3xKYcazENJDQdDOlidxoPtsH/pdSqreKGXa0l V9uNbosgg+zMWJ2oaiSqoIgkd7EoMOWfd6VapNRZOiTpdrA0Lu75B7hrWQWttqi3dtQQ PX0Uy74Ovvl2cuYeOyX6VOPCWgVhZOkL+O2RD9E8friW4vE0oq0bTRbZ/YKqN+Sb+biZ FGtfJci593PS594H8DAjZzx1HmKSxQLA+lFwUh/YBZRGSir3di75+f2H5I+olvEi5ris b6MA== X-Gm-Message-State: AOJu0Yxse88+2O3Beoh+c7kxFDqeXOzL1oXMf+qzD8qCbDt6VTv8dL9f Zerdbn65R8k6ks0jEhEtTBlD+Ka1i1426Q== X-Google-Smtp-Source: AGHT+IGQQIFHXmePHRPv65VykYu2TvmMfY3yDxNCocx6kCSXjZJEpwzPhMT4ImmUBQZKPysLLvfTRQ== X-Received: by 2002:a7b:c8c8:0:b0:404:7462:1f6f with SMTP id f8-20020a7bc8c8000000b0040474621f6fmr15581631wml.8.1696941564223; Tue, 10 Oct 2023 05:39:24 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3f04:7ca0:516d:299b:cbff:be05]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcc8f000000b003fee6e170f9sm14071689wma.45.2023.10.10.05.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 05:39: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 , Dragan Simic , Linus Arver , Christian Couder Subject: [PATCH v5 14/14] replay: stop assuming replayed branches do not diverge Date: Tue, 10 Oct 2023 14:38:47 +0200 Message-ID: <20231010123847.2777056-15-christian.couder@gmail.com> X-Mailer: git-send-email 2.42.0.339.g663cbc8ab1 In-Reply-To: <20231010123847.2777056-1-christian.couder@gmail.com> References: <20230907092521.733746-1-christian.couder@gmail.com> <20231010123847.2777056-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 12689f1c89..f74261b75e 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; const char * const replay_usage[] = { @@ -324,21 +338,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; @@ -367,13 +390,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 d6286f9580..389670262e 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -143,4 +143,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