Skip to contentSkip to conversation

Introduce new `git replay` command

PATCH Superseded Christian Couder 10 participants 208 messages Apr 7, 2023 – Nov 25, 2023 Page 1 of 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Introduce new `git replay` command

# Intro

git replay has initially been developed entirely by Elijah Newren mostly between June and July 2022 at:

https://github.com/newren/git/commits/replay

I took over a few months ago to polish and upstream it as GitLab is interested in replacing libgit2, and for that purpose needs a command to do server side (so without using a worktree) rebases, cherry-picks and reverts.

I reduced the number of commits and features in this first patch series, compared to what Elijah already developed. Especially I stopped short of replaying merge commits and replaying interactively. These and other features might be upstreamed in the future after this patch series has graduated.

Thanks to Elijah, Patrick Steinhardt and Dscho for early reviews and discussions.

Based on ae73b2c8f1 (The seventh batch, 2023-04-04)

# Quick Overview (from Elijah)

git replay, at a basic level, can perhaps be thought of as a "default-to-dry-run rebase" -- meaning no updates to the working tree, or to the index, or to any references. However, it differs from rebase in that it:

* Works for branches that aren't checked out
* Works in a bare repository
* Can replay multiple branches simultaneously (with or without common history in the range being replayed)
* Preserves relative topology by default (merges are replayed too)
* Focuses on performance
* Has several altered defaults as a result of the above

I sometimes think of git replay as "fast-replay", a patch-based analogue to the snapshot-based fast-export & fast-import tools.

# Reasons for diverging from cherry-pick & rebase (from Elijah)

There are multiple reasons to diverge from the defaults in cherry-pick and rebase.

* Server side needs

* Both cherry-pick and rebase, via the sequencer, are heavily tied to updating the working tree, index, some refs, and a lot of control files with every commit replayed, and invoke a mess of hooks[1] that might be hard to avoid for backward compatibility reasons (at least, that's been brought up a few times on the list).

* cherry-pick and rebase both fork various subprocesses unnecessarily, but somewhat intrinsically in part to ensure the same hooks are called that old scripted implementations would have called.

* "Dry run" behavior, where there are no updates to worktree, index, or even refs might be important.

* Should not assume users only want to operate on HEAD (see next section)

* Decapitate HEAD-centric assumptions

* cherry-pick forces commits to be played on top of HEAD; inflexible.

* rebase assumes the range of commits to be replayed is upstream..HEAD by default, though it allows one to replay upstream..otherbranch -- but it still forcibly and needlessly checks out otherbranch before starting to replay things.

* Assuming HEAD is involved severely limits replaying multiple (possibly divergent) branches.

* Once you stop assuming HEAD has a certain meaning, there's not much reason to have two separate commands anymore (except for the funny extra not-necessarily-compatible options both have gained over time).

* (Micro issue: Assuming HEAD is involved also makes it harder for new users to learn what rebase means and does; it makes command lines hard to parse. Not sure I want to harp on this too much, as I have a suspicion I might be creating a tool for experts with complicated use cases, but it's a minor quibble.)

* Performance

* jj is slaughtering us on rebase speed[2]. I would like us to become competitive. (I dropped a few comments in the link at [2] about why git is currently so bad.)

* From [3], there was a simple 4-patch series in linux.git that took 53 seconds to rebase. Switching to ort dropped it to 16 seconds. While that sounds great, only 11 *milliseconds* were needed to do the actual merges. That means almost *all* the time (>99%) was overhead! Big offenders:

* --reapply-cherry-picks should be the default

* can_fast_forward() should be ripped out, and perhaps other extraneous revision walks

* avoid updating working tree, index, refs, reflogs, and control structures except when needed (e.g. hitting a conflict, or operation finished)

* Other performance ideas:

* single-file control structures instead of directory of files

* avoid forking subprocesses unless explicitly requested (e.g. --exec, --strategy, --run-hooks). For example, definitely do not invoke git commit or git merge.

* Sanitize hooks:

* dispense with all per-commit hooks for sure (pre-commit, post-commit, post-checkout).

* pre-rebase also seems to assume exactly 1 ref is written, and invoking it repeatedly would be stupid. Plus, it's specific to "rebase". So...ignore? (Stolee's --ref-update option for rebase probably broke the pre-rebase assumptions already...)

* post-rewrite hook might make sense, but fast-import got exempted, and I think of replay like a patch-based analogue to the snapshot-based fast-import.

* When not running server side, resolve conflicts in a sparse-cone sparse-index worktree to reduce number of files written to a working tree. (See below as well)

* [High risk of possible premature optimization] Avoid large numbers of newly created loose objects, when replaying large numbers of commits. Two possibilities: (1) Consider using tmp-objdir and pack objects from the tmp-objdir at end of exercise, (2) Lift code from git-fast-import to immediately stuff new objects into a pack?

* Multiple branches and non-checked out branches

* The ability to operate on non-checked out branches also implies that we should generally be able to replay when in a dirty working tree (exception being when we expect to update HEAD and any of the dirty files is one that needs to be updated by the replay).

* Also, if we are operating locally on a non-checked out branch and hit a conflict, we should have a way to resolve the conflict without messing with the user's work on their current branch.

* Idea: new worktree with sparse cone + sparse index checkout, containing only files in the root directory, and whatever is necessary to get the conflicts

* Companion to above idea: control structures should be written to $GIT_COMMON_DIR/replay-${worktree}, so users can have multiple replay sessions, and so we know which worktrees are associated with which replay operations.

- [1] https://lore.kernel.org/git/[email protected]/
- [2] https://github.com/martinvonz/jj/discussions/49
- [3] https://lore.kernel.org/git/CABPp-BE48=97k_3tnNqXPjSEfA163F8hoE+HY0Zvz1SWB2B8EA@mail.gmail.com/

# Important limitations

* The code die()s if there are any conflict. No resumability. No nice output. No interactivity.

* No replaying merges, nor root commits. Only regular commits.

* Signed commits are not properly handled. It's not clear what to do to such commits when replaying on the server side.

# Commit overview

* 1/14 replay: introduce new builtin

This creates a minimal git replay command by moving the code from the fast-rebase test helper from t/helper/ into builtin/ and doing some renames and a few other needed changes.

* - 2/14 replay: start using parse_options API
- 3/14 replay: die() instead of failing assert()
- 4/14 replay: introduce pick_regular_commit()
- 5/14 replay: don't simplify history
- 6/14 replay: add an important FIXME comment about gpg signing
- 7/14 replay: remove progress and info output
- 8/14 replay: remove HEAD related sanity check

These slowly change the command to make it behave more like a regular commands and to start cleaning up its output.

* 9/14 replay: very coarse worktree updating

Make it handle conflicts in a very coarse way. This might not work on bare repos, but it allows existing tests to pass and it's nice to help cli users a bit when they get conflicts.

* 10/14 replay: make it a minimal server side command

After the cleaning up in previous ommits, it's now time to radically change the way it works by stopping it to do ref updates, to update the index and worktree, to consider HEAD as special. Instead just make it output commands that should be passed to git update-ref --stdin.

* - 11/14 replay: use standard revision ranges
- 12/14 replay: introduce guess_new_base()
- 13/14 replay: add different modes
- 14/14 replay: stop assuming replayed branches do not diverge

These finish the clean up and add new interesting features at the same time, as well as related documentation and tests.

# Note about tests and documentation

Note that the fast-rebase test helper was used before this series in

t6429-merge-sequence-rename-caching.sh

So when git replay is created from fast-rebase in patch 1/14, this test script is also converted to use git replay. This ensures that git replay doesn't break too badly during the first 10 patches in this patch series.

Tests and documentation are introduced specifically for git replay only in 11/14 and later patches as it doesn't make much sense to document and test behavior that we know is going to change soon. So it's only when the command is crystalizing towards its final form that we start documenting and testing it.

# Possibly controversial issues

* bare or not bare: this series works towards a command with the end goal of it being usable and used on bare repos, contrary to existing commands like git rebase and git cherry-pick, but the tests currently don't check that, and in case of conflicts it won't currently work on bare repos. One reason for that is that existing tests in t6429 should continue to work, and one of these tests requires some output in case of conflict. And it's nice for users to get some help in case of conflict. It's also nice for users if commands that should work on both bare and non bare repos work well on non bare repos first as they are less likely to use them on bare repos. So let's have a command that works well on non-bare repos first, even if its end goal is to work fine on bare repos too. We plan to improve things for bare repos soon after this first patch series graduates.

* exit status: a successful, non-conflicted replay exits with code
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. It has been suggested in an internal review that conflicts might want to get a more specific error code as an error code of 1 might be quite easy to return by accident. It doesn't seem to me from their docs (which might want to be improved, I didn't look at the code) that other commands like git merge and git rebase exit with a special error code in case of conflict.

* to guess or not to guess: commit 12/14 introduces the guess_new_base() function which tries to find a base to rebase onto when the --onto option is not provided, making this option actually optional instead of mandatory. Given that it's an heuristic and the command end goal is to be used on server side, we might want to introduce this as an iterative improvement later. I still think it's interesting to have it in for now though, as it shows that --onto and --advance (which is introduced in the following commit) should indeed be options. If --onto was always mandatory in the series, people could argue that it shouldn't be an option and its argument should always be the first (unconditional) argument of the command.

* make worktree and index changes optional: commit 10/14 stops updating the index and worktree, but it might be better especially for cli users to make that optional. The issue is that this would make the command more complex while we are developing a number of important features. It seems to me that this should rather be done in an iterative improvement after the important features have landed.

* when and where to add tests and docs: although t6429 has tests that are changed to use the new command instead of the fast-rebase test-tool command as soon as the former is introduced, there is no specific test script and no doc for the new command until commit 11/14 when standard revision ranges are used. This is done to avoid churn in tests and docs while the final form of the command hasn't crystalized enough. Adding tests and doc at this point makes this commit quite big and possibly more difficult to review than if they were in separate commits though. On the other hand when tests and docs are added in specific commits some reviewers say it would be better to introduce them when the related changes are made.

* --advance and --contained: these two advanced options might not belong to this first series and could perhaps be added in a followup series in separate commits. On the other hand the code for --contained seems involved with the code of --advance and it's nice to see soon that git replay can indeed do cherry-picking and rebase many refs at once, and this way fullfil these parts of its promise.

* replaying diverging branches: 14/14 the last patch in the series, which allow replaying diverging branches, can be seen as a fundamental fix or alternatively as adding an interesting feature. So it's debatable if it should be in its own patch along with its own tests as in this series, or if it should be merged into a previous patch and which one.

* only 2 patches: this patch series can be seen from a high level point of view as 1) introducing the new git replay command, and 2) using git replay to replace, and get rid of, the fast-rebase test-tool command. The fact that not much of the original fast-rebase code and interface is left would agree with that point of view. On the other hand, fast-rebase can also be seen as a first iteration towards git replay. So it can also make sense to see how git replay evolved from it.

Elijah Newren (14):
replay: introduce new builtin
replay: start using parse_options API
replay: die() instead of failing assert()
replay: introduce pick_regular_commit()
replay: don't simplify history
replay: add an important FIXME comment about gpg signing
replay: remove progress and info output
replay: remove HEAD related sanity check
replay: very coarse worktree updating
replay: make it a minimal server side command
replay: use standard revision ranges
replay: introduce guess_new_base()
replay: add different modes
replay: stop assuming replayed branches do not diverge

 .gitignore                               |   1 +
 Documentation/git-replay.txt             | 130 +++++++
 Makefile                                 |   2 +-
 builtin.h                                |   1 +
 builtin/replay.c                         | 419 +++++++++++++++++++++++
 command-list.txt                         |   1 +
 git.c                                    |   1 +
 t/helper/test-fast-rebase.c              | 233 -------------
 t/helper/test-tool.c                     |   1 -
 t/helper/test-tool.h                     |   1 -
 t/t3650-replay-basics.sh                 | 160 +++++++++
 t/t6429-merge-sequence-rename-caching.sh |  43 ++-
 12 files changed, 739 insertions(+), 254 deletions(-)
 create mode 100644 Documentation/git-replay.txt
 create mode 100644 builtin/replay.c
 delete mode 100644 t/helper/test-fast-rebase.c
 create mode 100755 t/t3650-replay-basics.sh
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#1 lore raw

PATCH 1/14 replay: introduce new builtin

From: Elijah Newren <[email protected]>

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.

---
 .gitignore                                    |  1 +
 Makefile                                      |  2 +-
 builtin.h                                     |  1 +
 .../test-fast-rebase.c => builtin/replay.c    | 23 ++++------------
 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, 19 insertions(+), 39 deletions(-)
 rename t/helper/test-fast-rebase.c => builtin/replay.c (89%)
.gitignore +1 -0
index e875c59054..b5f025a296 100644
@@ -135,6 +135,7 @@
 /git-remote-ext
 /git-repack
 /git-replace
+/git-replay
 /git-request-pull
 /git-rerere
 /git-reset
Makefile +1 -1
index 60ab1a8b4f..44546f74dc 100644
@@ -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
builtin.h +1 -0
index 46cc789789..6ad9efd6cd 100644
@@ -204,6 +204,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);
builtin/replay.c renamed from t/helper/test-fast-rebase.c +5 -18
similarity index 89%
rename from t/helper/test-fast-rebase.c
rename to builtin/replay.c
index b1edb92a03..154a976ca6 100644
@@ -1,18 +1,11 @@
 /*
- * "git fast-rebase" builtin command
- *
- * FAST: Forking Any Subprocesses (is) Taboo
- *
- * This is meant SOLELY as a demo of what is possible.  sequencer.c and
- * rebase.c should be refactored to use the ideas here, rather than attempting
- * to extend this file to replace those (unless Phillip or Dscho say that
- * refactoring is too hard and we need a clean slate, but I'm guessing that
- * refactoring is the better route).
+ * "git replay" builtin command
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "test-tool.h"
+#include "git-compat-util.h"
 
+#include "builtin.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "hex.h"
@@ -86,7 +79,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;
@@ -102,12 +95,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);
@@ -128,7 +115,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;
command-list.txt +1 -0
index 54b2a50f5f..d74836ab21 100644
@@ -160,6 +160,7 @@ git-reflog                              ancillarymanipulators           complete
 git-remote                              ancillarymanipulators           complete
 git-repack                              ancillarymanipulators           complete
 git-replace                             ancillarymanipulators           complete
+git-replay                              mainporcelain           history
 git-request-pull                        foreignscminterface             complete
 git-rerere                              ancillaryinterrogators
 git-reset                               mainporcelain           history
git.c +1 -0
index ae2134f29a..e4ce39fd4d 100644
@@ -571,6 +571,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 },
t/helper/test-tool.c +0 -1
index abe8a785eb..9ca1586de7 100644
@@ -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 },
t/helper/test-tool.h +0 -1
index ea2672436c..a03bbfc6b2 100644
@@ -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);
t/t6429-merge-sequence-rename-caching.sh +9 -18
index d02fa16614..40505c9054 100755
@@ -71,8 +71,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 cherry-pick upstream~1..topic
+		git replay --onto HEAD upstream~1 topic &&
 
 		git ls-files >tracked-files &&
 		test_line_count = 2 tracked-files &&
@@ -140,8 +139,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
@@ -199,8 +197,7 @@ 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 cherry-pick upstream~1..topic &&
+		git replay --onto HEAD upstream~1 topic &&
 
 		git ls-files >tracked &&
 		test_line_count = 2 tracked &&
@@ -276,8 +273,7 @@ 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 cherry-pick upstream~1..topic &&
+		git replay --onto HEAD upstream~1 topic &&
 
 		git ls-files >tracked &&
 		test_line_count = 4 tracked &&
@@ -353,8 +349,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 CONFLICT..rename/rename output &&
 
@@ -455,8 +450,7 @@ 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 cherry-pick upstream..topic &&
+		git replay --onto HEAD upstream~1 topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 2 calls &&
@@ -521,8 +515,7 @@ 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 cherry-pick upstream..topic &&
+		git replay --onto HEAD upstream~1 topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 3 calls &&
@@ -623,8 +616,7 @@ 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 cherry-pick upstream..topic &&
+		git replay --onto HEAD upstream~1 topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 1 calls &&
@@ -681,8 +673,7 @@ 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 cherry-pick upstream..topic &&
+		git replay --onto HEAD upstream~1 topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 2 calls &&
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#2 lore raw

PATCH 2/14 replay: start using parse_options API

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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 "<oldbase> <branch>" 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.

---
 builtin/replay.c | 44 ++++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)
builtin/replay.c +32 -12
index 154a976ca6..ca931dee41 100644
@@ -11,6 +11,7 @@
 #include "hex.h"
 #include "lockfile.h"
 #include "merge-ort.h"
+#include "parse-options.h"
 #include "refs.h"
 #include "revision.h"
 #include "sequencer.h"
@@ -82,6 +83,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;
@@ -95,16 +97,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 <newbase> <oldbase> <branch>"),
+		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 (get_oid("HEAD", &head))
@@ -116,6 +134,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;
@@ -124,7 +143,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"));
@@ -187,8 +207,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"));
@@ -203,8 +223,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]);
 		}
 	}
 	if (write_locked_index(&the_index, &lock,
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#3 lore raw

PATCH 3/14 replay: die() instead of failing assert()

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
builtin/replay.c +6 -1
index ca931dee41..16efac11ab 100644
@@ -170,7 +170,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 = get_commit_tree(commit);
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#4 lore raw

PATCH 4/14 replay: introduce pick_regular_commit()

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 54 ++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 20 deletions(-)
builtin/replay.c +34 -20
index 16efac11ab..ea12d4c8fe 100644
@@ -80,6 +80,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 = get_commit_tree(pickme);
+	base_tree = get_commit_tree(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;
@@ -91,7 +120,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;
@@ -166,7 +195,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));
@@ -176,26 +205,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 = get_commit_tree(commit);
-		base_tree = get_commit_tree(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_switch_to_result(&merge_opt, head_tree, &result, 1, !result.clean);
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#5 lore raw

PATCH 5/14 replay: don't simplify history

In reply to Christian Couder

From: Elijah Newren <[email protected]>

Let's set the rev walking options we need after calling setup_revisions() instead of before. This makes it clearer which options we need.

Also we don't want history simplification, as we want to deal with all the commits in the affected range.

---
 builtin/replay.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
builtin/replay.c +6 -9
index ea12d4c8fe..59ebbc3b8f 100644
@@ -164,15 +164,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) {
@@ -180,6 +171,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		goto cleanup;
 	}
 
+	/* requirements/overrides for revs */
+	revs.reverse = 1;
+	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
+	revs.topo_order = 1;
+	revs.simplify_history = 0;
+
 	strvec_clear(&rev_walk_args);
 
 	if (prepare_revision_walk(&revs) < 0) {
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#6 lore raw

PATCH 6/14 replay: add an important FIXME comment about gpg signing

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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

---
 builtin/replay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/replay.c +1 -1
index 59ebbc3b8f..ffd7ce1fde 100644
@@ -54,7 +54,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();
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#7 lore raw

PATCH 7/14 replay: remove progress and info output

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
builtin/replay.c +1 -6
index ffd7ce1fde..0a23ea70dc 100644
@@ -186,7 +186,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 = get_commit_tree(onto);
 	result.tree = head_tree;
@@ -194,9 +194,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)
@@ -215,7 +212,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));
@@ -232,7 +228,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		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",
 			    oid_to_hex(&last_picked_commit->object.oid));
 		if (update_ref(reflog_msg.buf, "HEAD",
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#8 lore raw

PATCH 8/14 replay: remove HEAD related sanity check

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
builtin/replay.c +1 -7
index 0a23ea70dc..a331887d12 100644
@@ -114,7 +114,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;
@@ -153,11 +152,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 (get_oid("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");
@@ -232,7 +226,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]);
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#9 lore raw

PATCH 9/14 replay: very coarse worktree updating

In reply to Christian Couder

From: Elijah Newren <[email protected]>

In case of conflict, let's just update the worktree and index. And then let's just die() as this command doesn't have ways to handle conflicts yet.

Note that we might want to improve this behavior in the case of a bare repository in a future commit.

We also have to lock the index only after all the commits have been picked, so that in case of conflict the index is not already locked. Note that this locking of the index will be removed in a following commit as we will not want to modify it anymore.

---
 builtin/replay.c | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)
builtin/replay.c +29 -6
index a331887d12..9c795c05a7 100644
@@ -152,10 +152,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);
@@ -194,12 +190,39 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 			die(_("replaying merge commits is not supported yet!"));
 
 		pick = pick_regular_commit(commit, last_commit, &merge_opt, &result);
-		if (!pick)
-			break;
+		if (!pick) {
+			/* TODO: handle conflicts in sparse worktree instead */
+			struct object_id head;
+			struct tree *head_tree;
+			struct lock_file lock = LOCK_INIT;
+
+			repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
+			if (repo_read_index(the_repository) < 0)
+				BUG("Could not read index");
+
+			get_oid("HEAD", &head);
+			head_tree = parse_tree_indirect(&head);
+			printf("Switching from %s to %s.\n",
+			       oid_to_hex(&head_tree->object.oid),
+			       oid_to_hex(&result.tree->object.oid));
+			merge_switch_to_result(&merge_opt, head_tree, &result,
+					       1, 1);
+			if (write_locked_index(&the_index, &lock,
+					       COMMIT_LOCK | SKIP_IF_UNCHANGED))
+				die(_("unable to write %s"), get_index_file());
+
+			die(_("failure to pick %s; cannot handle conflicts yet"),
+			    oid_to_hex(&commit->object.oid));
+		}
+
 		last_commit = pick;
 		last_picked_commit = commit;
 	}
 
+	repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
+	if (repo_read_index(the_repository) < 0)
+		BUG("Could not read index");
+
 	merge_switch_to_result(&merge_opt, head_tree, &result, 1, !result.clean);
 
 	if (result.clean < 0)
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#10 lore raw

PATCH 10/14 replay: make it a minimal server side command

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c                         | 86 ++++++++----------------
 t/t6429-merge-sequence-rename-caching.sh | 32 ++++++---
 2 files changed, 52 insertions(+), 66 deletions(-)
builtin/replay.c +28 -58
index 9c795c05a7..119cfecfe7 100644
@@ -6,17 +6,13 @@
 #include "git-compat-util.h"
 
 #include "builtin.h"
-#include "cache-tree.h"
-#include "commit.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge-ort.h"
 #include "parse-options.h"
 #include "refs.h"
 #include "revision.h"
-#include "sequencer.h"
 #include "strvec.h"
-#include "tree.h"
 
 static const char *short_commit_name(struct commit *commit)
 {
@@ -93,6 +89,7 @@ static struct commit *pick_regular_commit(struct commit *pickme,
 	pickme_tree = get_commit_tree(pickme);
 	base_tree = get_commit_tree(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);
 
@@ -113,15 +110,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;
 
@@ -177,20 +171,19 @@ 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 = get_commit_tree(onto);
-	result.tree = head_tree;
+	result.tree = get_commit_tree(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) {
 			/* TODO: handle conflicts in sparse worktree instead */
 			struct object_id head;
 			struct tree *head_tree;
@@ -215,54 +208,31 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 			    oid_to_hex(&commit->object.oid));
 		}
 
-		last_commit = pick;
-		last_picked_commit = commit;
-	}
-
-	repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
-	if (repo_read_index(the_repository) < 0)
-		BUG("Could not read index");
-
-	merge_switch_to_result(&merge_opt, head_tree, &result, 1, !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"));
-
-		prime_cache_tree(the_repository, the_repository->index,
-				 result.tree);
-	} 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]);
+		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;
 		}
 	}
-	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 */
+	merge_finalize(&merge_opt, &result);
+	ret = result.clean;
+
 cleanup:
-	strbuf_release(&reflog_msg);
 	strbuf_release(&branch_name);
 	release_revisions(&revs);
-	return ret;
+
+	/* Return */
+	if (ret < 0)
+		exit(128);
+	return ret ? 0 : 1;
 }
t/t6429-merge-sequence-rename-caching.sh +24 -8
index 40505c9054..bfdf7f30b3 100755
@@ -71,7 +71,9 @@ test_expect_success 'caching renames does not preclude finding new ones' '
 
 		git switch upstream &&
 
-		git replay --onto HEAD upstream~1 topic &&
+		git replay --onto HEAD upstream~1 topic >out &&
+		git update-ref --stdin <out &&
+		git checkout topic &&
 
 		git ls-files >tracked-files &&
 		test_line_count = 2 tracked-files &&
@@ -139,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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 1 calls
@@ -197,7 +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 replay --onto HEAD upstream~1 topic >out &&
+		git update-ref --stdin <out &&
+		git checkout topic &&
 
 		git ls-files >tracked &&
 		test_line_count = 2 tracked &&
@@ -273,7 +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 replay --onto HEAD upstream~1 topic >out &&
+		git update-ref --stdin <out &&
+		git checkout topic &&
 
 		git ls-files >tracked &&
 		test_line_count = 4 tracked &&
@@ -450,7 +458,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 replay --onto HEAD upstream~1 topic >out &&
+		git update-ref --stdin <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 2 calls &&
@@ -515,7 +525,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 replay --onto HEAD upstream~1 topic >out &&
+		git update-ref --stdin <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 3 calls &&
@@ -616,7 +628,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 replay --onto HEAD upstream~1 topic >out &&
+		git update-ref --stdin <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 1 calls &&
@@ -673,7 +687,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 replay --onto HEAD upstream~1 topic >out &&
+		git update-ref --stdin <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 2 calls &&
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#11 lore raw

PATCH 11/14 replay: use standard revision ranges

In reply to Christian Couder

From: Elijah Newren <[email protected]>

Instead of the fixed "<oldbase> <branch>" arguments, the replay command now accepts "<revision-range>..." arguments in a similar way as many other Git commands. This makes its interface more standard and more flexible.

Also as the interface of the command is now mostly finalized, we can add some documentation as well as testcases to make sure the command will continue to work as designed in the future.

---
 Documentation/git-replay.txt             | 86 ++++++++++++++++++++++++
 builtin/replay.c                         | 21 ++----
 t/t3650-replay-basics.sh                 | 63 +++++++++++++++++
 t/t6429-merge-sequence-rename-caching.sh | 18 ++---
 4 files changed, 162 insertions(+), 26 deletions(-)
 create mode 100644 Documentation/git-replay.txt
 create mode 100755 t/t3650-replay-basics.sh
Documentation/git-replay.txt new file +86 -0
new file mode 100644
index 0000000000..7a83f70343
@@ -0,0 +1,86 @@
+git-replay(1)
+=============
+
+NAME
+----
+git-replay - Replay commits on a different base, without touching working tree
+
+
+SYNOPSIS
+--------
+[verse]
+'git replay' --onto <newbase> <revision-range>...
+
+DESCRIPTION
+-----------
+
+Takes a range of commits, and replays them onto a new location.  Does
+not touch the working tree or index, and does not update any
+references.  However, the output of this command is meant to be used
+as input to `git update-ref --stdin`, which would update the relevant
+branches.
+
+OPTIONS
+-------
+
+--onto <newbase>::
+	Starting point at which to create the new commits.  May be any
+	valid commit, and not just an existing branch name.
++
+The update-ref commands in the output will update the branch(es)
+in the revision range to point at the new commits (in other
+words, this mimics a rebase operation).
+
+<revision-range>::
+	Range of commits to replay; see "Specifying Ranges" in
+	linkgit:git-rev-parse.
+
+OUTPUT
+------
+
+When there are no conflicts, the output of this command is usable as
+input to `git update-ref --stdin`.  It is basically of the form:
+
+	update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH}
+	update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
+	update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
+
+where the number of refs updated depend on the arguments passed.
+
+EXIT STATUS
+-----------
+
+For a successful, non-conflicted replay, the exit status is 0.  When
+the replay has conflicts, the exit status is 1.  If the replay is not
+able to complete (or start) due to some kind of error, the exit status
+is something other than 0 or 1.
+
+EXAMPLES
+--------
+
+To simply rebase mybranch onto target:
+
+------------
+$ git replay --onto target origin/main..mybranch
+update refs/heads/mybranch ${NEW_mybranch_HASH} ${OLD_mybranch_HASH}
+------------
+
+When calling `git replay`, one does not need to specify a range of
+commits to replay using the syntax `A..B`; any range expression will
+do:
+
+------------
+$ git replay --onto origin/main ^base branch1 branch2 branch3
+update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH}
+update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
+update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
+------------
+
+This will simultaneously rebase branch1, branch2, and branch3 -- all
+commits they have since base, playing them on top of origin/main.
+These three branches may have commits on top of base that they have in
+common, but that does not need to be the case.
+
+GIT
+---
+Part of the linkgit:git[1] suite
builtin/replay.c +4 -17
index 119cfecfe7..63513ea6f1 100644
@@ -12,7 +12,6 @@
 #include "parse-options.h"
 #include "refs.h"
 #include "revision.h"
-#include "strvec.h"
 
 static const char *short_commit_name(struct commit *commit)
 {
@@ -111,16 +110,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 <newbase> <oldbase> <branch>"),
+		N_("git replay --onto <newbase> <revision-range>..."),
 		NULL
 	};
 	struct option replay_options[] = {
@@ -138,20 +135,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;
 	}
 
@@ -161,8 +151,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;
@@ -228,7 +216,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	ret = result.clean;
 
 cleanup:
-	strbuf_release(&branch_name);
 	release_revisions(&revs);
 
 	/* Return */
t/t3650-replay-basics.sh new file +63 -0

63 lines not on this page · raw message

t/t6429-merge-sequence-rename-caching.sh +9 -9
index bfdf7f30b3..8f3c394f0e 100755
@@ -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 checkout topic &&
 
@@ -141,7 +141,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -201,7 +201,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -279,7 +279,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -357,7 +357,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 git replay --onto HEAD upstream~1 topic >output &&
+		test_must_fail git replay --onto HEAD upstream~1..topic >output &&
 
 		grep CONFLICT..rename/rename output &&
 
@@ -458,7 +458,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 checkout topic &&
 
@@ -525,7 +525,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -628,7 +628,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -687,7 +687,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
Signature · 1 line
2.40.0.228.gb2eb5bb98e
#12 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 6 lines · Christian Couder

From: Elijah Newren <[email protected]>

Instead of the fixed "<oldbase> <branch>" arguments, the replay command now accepts "<revision-range>..." arguments in a similar way as many other Git commands. This makes its interface more standard and more flexible.

Unfortunately, while doing this, you have broken the --onto logic:

 $ git replay --onto HEAD~2 HEAD~1 HEAD
 fatal: replaying down to root commit is not supported yet!

The rev-walk you are supplying by this line...

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 142

Quoted 1 line
builtin/replay.c +1 -0
+	argc = setup_revisions(argc, argv, &revs, NULL);

is taking the remaining arguments and using them as tips to walk. We need to be able to recognize that --onto A B C means that A is the new base and our walk is B..C.

I'm not sure if there might be a way to use a callback for the --onto option and pull out the next three options into 'new-base', 'old-base', 'tip' values or something.

Overall, I don't think being flexible in the CLI is of high value for this command. Let's be as prescriptive as possible.

Something like:

'git replay [options] <base> <tip>' This mode means to rebase <tip> onto <base>, detecting the range of commits to rewrite.

'git replay [options] <new-base> <old-base> <tip>' This mode means to rebase the range <old-base>..<tip> onto <new-base>.

We don't even need "--onto" for these positional arguments.

Thanks,
-Stolee

#13 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 14 lines · Derrick Stolee
Quoted 6 lines · Christian Couder

From: Elijah Newren <[email protected]>

Instead of the fixed "<oldbase> <branch>" arguments, the replay command now accepts "<revision-range>..." arguments in a similar way as many other Git commands. This makes its interface more standard and more flexible.

Unfortunately, while doing this, you have broken the --onto logic:

 $ git replay --onto HEAD~2 HEAD~1 HEAD
 fatal: replaying down to root commit is not supported yet!
Quoted 7 lines

The rev-walk you are supplying by this line...

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 142

Quoted 1 line
builtin/replay.c +1 -0
+	argc = setup_revisions(argc, argv, &revs, NULL);

is taking the remaining arguments and using them as tips to walk. We need to be able to recognize that --onto A B C means that A is the new base and our walk is B..C.

I'm realizing after hitting "send" that this change is intentional (based on your test updates). I don't agree with it, though.

Sending arbitrary command-line arguments to setup_revisions() creates an opportunity for behavior you are not expecting.

For instance, can users pass multiple ranges? Can users supply --first-parent? What happens if they add an --author filter?

(I was able to get a segfault by rebasing this series with --author=stolee because the commit list became empty. Something to watch for.)

Quoted 9 lines

Something like:

'git replay [options] <base> <tip>' This mode means to rebase <tip> onto <base>, detecting the range of commits to rewrite.

'git replay [options] <new-base> <old-base> <tip>' This mode means to rebase the range <old-base>..<tip> onto <new-base>.

For that reason, I think we should be using explicit argument parsing in the builtin and only transform arguments we understand into the setup_revisions() (by building a strvec).

Thanks,
-Stolee

#14 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 24 lines · Derrick Stolee
Quoted 14 lines · Derrick Stolee
Quoted 6 lines · Christian Couder

From: Elijah Newren <[email protected]>

Instead of the fixed "<oldbase> <branch>" arguments, the replay command now accepts "<revision-range>..." arguments in a similar way as many other Git commands. This makes its interface more standard and more flexible.

Unfortunately, while doing this, you have broken the --onto logic:

 $ git replay --onto HEAD~2 HEAD~1 HEAD
 fatal: replaying down to root commit is not supported yet!
Quoted 7 lines

The rev-walk you are supplying by this line...

Quoted 1 line

+ argc = setup_revisions(argc, argv, &revs, NULL);

is taking the remaining arguments and using them as tips to walk. We need to be able to recognize that --onto A B C means that A is the new base and our walk is B..C.

Quoted 6 lines

I'm realizing after hitting "send" that this change is intentional (based on your test updates). I don't agree with it, though.

Sending arbitrary command-line arguments to setup_revisions() creates an opportunity for behavior you are not expecting.

Note that fast-export has always accepted the full range of setup_revisions() flags, even though many options make no sense. Perhaps we could tighten up the parsing for fast-export, but limiting fast-export to three commits in order to avoid other nonsensical combinations would destroy its utility.

You may think I've gone on a tangent, but I think it's an important comparison point here. I think limiting replay to three commits does the same: destroys its intended utility. replay is a patch-based analogue to fast-export, and we need a wide range of the revision ranges for it to work.

(There are other interesting comparisons here too. For example, if someone specifies commits rather than branches to fast-export, then things break down: new commits may be written but nothing takes advantage of them so they merely become garbage to be gc'ed later. Likely not what the user wanted. The exact same issue existed for replay. However, in replay's case I tried to add some sanity checking for it -- perhaps that sanity checking would be useful to copy to fast-export?)

Quoted 1 line

For instance, can users pass multiple ranges?

There's no such thing as multiple ranges for most commands (see f302c1e4aa0 ("revisions(7): clarify that most commands take a single revision range", 2021-05-18))

However, users should absolutely be allowed to specify something like

  $ git replay --onto new-base master..my-topic some-base..other-topic

which is one revision range, and I'd expect replay to take commits in the history of either my-topic or other-topic, which are not in the history of either master or some-base, and replay them. It'd be equivalent, in most cases, to the separate commands:

   $ git replay --onto new-base ^master ^some-base my-topic
   $ git replay --onto new-base ^master ^some-base other-topic

The first of the two commands above, for example, would replay the commits in my-topic back to nearer of (master, some-base) and do the replaying on top of new-base. The second command is similar, but with my-topic replaced by other-topic.

Notice, though, that I said most cases. There's an important case where the single command is different from the two commands: when my-topic and other-topic share common commits (which is not also shared by master and some-base), we want the replayed common history to remain common. If you do two separate commands, the replayed common history is no longer common (those commits will instead be duplicated with separate committer dates). So, supporting the single command form is an intrinsic design consideration for git-replay.

Quoted 1 line

Can users supply --first-parent?

Absolutely, and it might be a useful replacement for or supplement to --[no-]rebase-cousins.

Also, we definitely want to allow --ancestry-path and --ancestry-path=<commit>, the latter of which was specifically written for use in git-replay.

In fact, --first-parent sometimes might be equivalent to a particular specialization of --ancestry-path=<commit>, so yeah, I definitely want to allow it.

Quoted 1 line

What happens if they add an --author filter?

git fast-export accepts full revision ranges, including ones that make no sense like this. We could add patches to exclude such options, to both replay and fast-export. Or just document that they make no sense.

To answer the question as asked, though, let me first provide a little
background: for a commit A with parent B, git-replay checks whether the parent of the current commit (i.e. for A that'd be B) has been replayed (as B'). If so, it will make the parent of A' be B'. If there is no B' (e.g. because B was part of "upstream" and thus wasn't replayed), it makes the parent of A' be whatever is passed to --onto. This allows git-replay to not only rebase/replay a linear set of patches, but a partially or even fully divergent set of branches.

Now, with that background, if someone passes --author, there will be a lot of parent commits that aren't replayed, resulting in each new "first" commit being rebased on top of --onto, and only the final one(s) being referenced by the updated ref commands. In other words, it'll leave lots of orphaned commits behind and only keep the "newest" contiguous ones belonging to the author. In simpler terms, passing --author to git-replay would "make a really big mess of things" from the user perspective, but an implementationally well-defined mess. This, again, is similar to passing --author to fast-export -- that tool has very different primitives involved causing it to make a completely different big mess of things (and perhaps even bigger mess of things), but the mess is at least implementationally well-defined to those that understand the data structures and implementation. (And yes, I thought of this exact case while developing the tool, for what it's worth.)

Does that mean I want to allow people to pass --author to fast-export or replay? I'd be perfectly happy with patches that prohibit it in both tools. But I'm also not worried about people off-roading and trying it and getting non-sense. A documentation patch stating that using options that "disconnect" history make no sense with either replay or fast-export might be the easiest (and most future-proof) solution.

Quoted 1 line

[unstated: and what about other similar options?]

I'd really rather not have an allowlist of which revision options should be allowed for use by git-replay. A denylist might be okay, if also implemented for fast-export, but I'm more of the opinion that we just document that both commands only make sense with "contiguous" history.

Most importantly, though, at a minimum I do absolutely want to allow several negative revisions to be specified, several positive revisions to be specified, and special flags like --ancestry-path or --first-parent to be specified. There may well be additional flags, both current and future, that should be allowed too.

In short, I don't want another limited rebase; I want a more generic tool.

Hope that helps,
Elijah

#15 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

On Sat, Apr 15, 2023 at 12:07 PM Elijah Newren <[email protected]> wrote:
<snip>

Quoted 7 lines
Quoted 1 line

What happens if they add an --author filter?

git fast-export accepts full revision ranges, including ones that make no sense like this. We could add patches to exclude such options, to both replay and fast-export. Or just document that they make no sense.

Quoted 8 lines

To answer the question as asked, though, let me first provide a little
background: for a commit A with parent B, git-replay checks whether the parent of the current commit (i.e. for A that'd be B) has been replayed (as B'). If so, it will make the parent of A' be B'. If there is no B' (e.g. because B was part of "upstream" and thus wasn't replayed), it makes the parent of A' be whatever is passed to --onto. This allows git-replay to not only rebase/replay a linear set of patches, but a partially or even fully divergent set of branches.

A small clarification, which only matters to future work and not this particular series: the above description where ONTO is the fallback for a lack of B', is for first parent only. For a second (or later) parent of A, which we'll refer to as C, if C has not been replayed as part of this operation, then we simply use the unmodified C as the second (or later) parent of A'.

#16 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

In reply to Elijah Newren
Quoted 13 lines · Elijah Newren
Quoted 4 lines · Derrick Stolee

Sending arbitrary command-line arguments to setup_revisions() creates an opportunity for behavior you are not expecting.

[unstated: and what about other similar options?]

I'd really rather not have an allowlist of which revision options should be allowed for use by git-replay. A denylist might be okay, if also implemented for fast-export, but I'm more of the opinion that we just document that both commands only make sense with "contiguous" history.

Quoted 7 lines

Most importantly, though, at a minimum I do absolutely want to allow several negative revisions to be specified, several positive revisions to be specified, and special flags like --ancestry-path or --first-parent to be specified. There may well be additional flags, both current and future, that should be allowed too.

In short, I don't want another limited rebase; I want a more generic tool.

The primary value of git-replay (to me) is that we can do "simple" rebases without a worktree or user interaction. To me, simple rebases mean apply a linear sequence of commits from a single branch onto another branch (and specifying an "old base" is simple enough to include here). It also means that we abort completely if there is a conflict (and handle conflict resolution in later changes).

The sooner we can deliver that, the better we can deliver on its potential (and expand its functionality to be more generic).

And this is generally my preference, but we shouldn't get functionality "by accident" but instead do it with full intention and strong testing.

I will always think that certain shortcuts should not be used. This includes passing arguments directly to setup_revisions() and using pathspec parsing when a path string will work just fine.

If we have a need for a feature, then we should add it explicitly and carefully. The surface area of setup_revisions() is far too large to have confidence that we are not exposing bugs for users to trip on later.

Thanks,
-Stolee

#17 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 30 lines · Derrick Stolee
Quoted 13 lines · Elijah Newren
Quoted 4 lines · Derrick Stolee

Sending arbitrary command-line arguments to setup_revisions() creates an opportunity for behavior you are not expecting.

[unstated: and what about other similar options?]

I'd really rather not have an allowlist of which revision options should be allowed for use by git-replay. A denylist might be okay, if also implemented for fast-export, but I'm more of the opinion that we just document that both commands only make sense with "contiguous" history.

Quoted 7 lines

Most importantly, though, at a minimum I do absolutely want to allow several negative revisions to be specified, several positive revisions to be specified, and special flags like --ancestry-path or --first-parent to be specified. There may well be additional flags, both current and future, that should be allowed too.

In short, I don't want another limited rebase; I want a more generic tool.

The primary value of git-replay (to me) is that we can do "simple" rebases without a worktree or user interaction. To me, simple rebases mean apply a linear sequence of commits from a single branch onto another branch (and specifying an "old base" is simple enough to include here). It also means that we abort completely if there is a conflict (and handle conflict resolution in later changes).

Quoted 2 lines

The sooner we can deliver that, the better we can deliver on its potential (and expand its functionality to be more generic).

Limiting the initial scope of this tool to a smaller set of features is okay (and, in fact, Christian has already done that), but we really need to avoid painting ourselves into a corner if we change the design as part of that limiting. As I stated previously[1], I'm worried this is happening.

[1] https://lore.kernel.org/git/CABPp-BH7ZPBtV5Hu_-_yVdqVmiydW7_s_LYAtwbPuYSbRQiuQw@mail.gmail.com/,
under "from my view"

Quoted 2 lines

And this is generally my preference, but we shouldn't get functionality "by accident"

All of the specific flags and cases you brought up so far were ones I already carefully considered over a year ago, so the "by accident" comment seems a little unfair.

Quoted 1 line

but instead do it with full intention

The intention is listed in the subject of the commit message of this patch. I've also explicitly stated my desire on this list to make a tool which replays based on a general range expression multiple times[2][3][4][5]. And there are tests for general range expressions in this series being reviewed. I don't understand why you might think I didn't intend to use general range expressions.

[2] https://lore.kernel.org/git/CABPp-BEAqP7maTVw82Qr8mn-sxPzXmHnE_mTKf2pg6hVYAJSUw@mail.gmail.com/
[3] https://lore.kernel.org/git/CABPp-BHmj+QCBFDrH77iNfEU41V=UDu7nhBYkAbCsbXhshJzzw@mail.gmail.com/
[4] https://lore.kernel.org/git/CABPp-BHARfYcsEM7Daeb7+vYxeB9Awo8=qbrOMXG6BQ0gX1RiA@mail.gmail.com/
[5] https://lore.kernel.org/git/CABPp-BEOV53oBoBp4YjiRfksZMmAADanZUUemhxwn7Wor=m-nA@mail.gmail.com/

Quoted 1 line

and strong testing.

The series as it stands already has some good testing for multiple divergent branches, which already takes it beyond the simplistic cases you were focusing on.

Yes, there should obviously be tests for even more cases, and yes I did leave this series in a work-in-progress state nearly a year ago. My Git time has been limited, and so I have tended to only work on things that needed short bursts of attention, like responding to the list, or the cache.h refactoring...

But I'm kind of at a loss trying to understand this paragraph. Am I misinterpreting what you are saying?

Quoted 7 lines

I will always think that certain shortcuts should not be used. This includes passing arguments directly to setup_revisions() and using pathspec parsing when a path string will work just fine.

If we have a need for a feature, then we should add it explicitly and carefully. The surface area of setup_revisions() is far too large to have confidence that we are not exposing bugs for users to trip on later.

My original plan was to just extend rebase rather than create a new command. While it'd be an extraordinary amount of work to change rebase to work without touching the working tree or index, it didn't look completely insurmountable. The first thing I found that did look completely insurmountable was extending it to handle rebasing several divergent branches possibly sharing some common history. Since handling possibly-divergent branches was one of my primary motivating goals, I'm really rather unwilling to accept the suggestion that we should strip the tool and copy rebase's broken design, since that would prevent the tool from ever being extended to do what I want and what I *already* implemented. There may be some kind of middle ground we can find, but the suggestion elsewhere in this thread (to make git-replay take three commits as positional arguments, with one an assumed negative ref) is copying that exact inflexible design flaw.

If you want to move git-replay away from setup_revisions(), at a minimum I think we need a proposal that can be extended to the cases I highlighted previously:
* allow specifying several negative revisions (or maybe even zero of them)
* allow specifying several positive revisions
* allow standard basic range syntax, i.e. A..B
* allow --first-parent
* allow --ancestry-path[=<commit>]
I think it should also be able to eventually support
* --branches[=<pattern>]
* --not
* --tags[=<pattern>]
* --remotes[=<pattern>]
* --glob=<pattern>
* --exclude=<glob-pattern>
* --all
There may well be others I missed in glancing over the list.

That's a long list of things to parse, which setup_revisions() happens to handle nicely. You are right that setup_revisions() also has lots of options for generating non-contiguous history that may make little or no sense for replay (and makes no sense for fast-export either). So, I am willing to consider other solutions if anyone has one, but only alternative solutions which can eventually handle the above requirements. In particular, "three commits as positional arguments" (with one implicitly being considered a negative ref) conflicts with the first three bullet points above.

#18 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 32 lines · Elijah Newren
Quoted 12 lines · Derrick Stolee
Quoted 1 line · Elijah Newren

In short, I don't want another limited rebase; I want a more generic tool.

The primary value of git-replay (to me) is that we can do "simple" rebases without a worktree or user interaction. To me, simple rebases mean apply a linear sequence of commits from a single branch onto another branch (and specifying an "old base" is simple enough to include here). It also means that we abort completely if there is a conflict (and handle conflict resolution in later changes).

Quoted 2 lines

The sooner we can deliver that, the better we can deliver on its potential (and expand its functionality to be more generic).

Limiting the initial scope of this tool to a smaller set of features is okay (and, in fact, Christian has already done that), but we really need to avoid painting ourselves into a corner if we change the design as part of that limiting. As I stated previously[1], I'm worried this is happening.

[1] https://lore.kernel.org/git/CABPp-BH7ZPBtV5Hu_-_yVdqVmiydW7_s_LYAtwbPuYSbRQiuQw@mail.gmail.com/,
under "from my view"

Quoted 2 lines

And this is generally my preference, but we shouldn't get functionality "by accident"

All of the specific flags and cases you brought up so far were ones I already carefully considered over a year ago, so the "by accident" comment seems a little unfair.

Quoted 8 lines
Quoted 1 line

but instead do it with full intention

The intention is listed in the subject of the commit message of this patch. I've also explicitly stated my desire on this list to make a tool which replays based on a general range expression multiple times[2][3][4][5]. And there are tests for general range expressions in this series being reviewed. I don't understand why you might think I didn't intend to use general range expressions.

It's one thing to describe commit ranges, and another to include every possible rev-list option.

Quoted 6 lines

If you want to move git-replay away from setup_revisions(), at a minimum I think we need a proposal that can be extended to the cases I highlighted previously:
* allow specifying several negative revisions (or maybe even zero of them)
* allow specifying several positive revisions
* allow standard basic range syntax, i.e. A..B

I think supporting these descriptive ranges is nice, but doesn't _need_ to be in v1 of the tool. If we need to bake them into the CLI from v1 in order to ensure compatibility, then I understand that.

Quoted 10 lines

* allow --first-parent
* allow --ancestry-path[=<commit>]
I think it should also be able to eventually support
* --branches[=<pattern>]
* --not
* --tags[=<pattern>]
* --remotes[=<pattern>]
* --glob=<pattern>
* --exclude=<glob-pattern>
* --all

However, I think very few of these should be generally supported, and if there are reasons to include some then they should be motivated by a specific use case and tested directly.

As it is, these tags do something in this v1, but we can't really be sure that they work because we're not testing them. That is my primary complaint. And testing each individually isn't enough, because they can combine in all sorts of ways.

Quoted 9 lines

That's a long list of things to parse, which setup_revisions() happens to handle nicely. You are right that setup_revisions() also has lots of options for generating non-contiguous history that may make little or no sense for replay (and makes no sense for fast-export either). So, I am willing to consider other solutions if anyone has one, but only alternative solutions which can eventually handle the above requirements. In particular, "three commits as positional arguments" (with one implicitly being considered a negative ref) conflicts with the first three bullet points above.

The only way I can see using setup_revisions() safely is if you make sure to reject any arguments that start with "--" (or perhaps "-" because some of those options may have single-character versions). This could be extended to an allowlist if we find a motivation to include other options (I see "--not" as being a likely candidate) in patches that test that interaction.

Or, could we extract the portion of setup_revisions() that parses just the revision ranges in to a new setup_revision_ranges() method? It could reject any options that are not directly about revision ranges. This option makes less sense if we are going the allowlist approach.

Thanks,
-Stolee

#19 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 43 lines · Derrick Stolee
Quoted 32 lines · Elijah Newren
Quoted 12 lines · Derrick Stolee
Quoted 1 line · Elijah Newren

In short, I don't want another limited rebase; I want a more generic tool.

The primary value of git-replay (to me) is that we can do "simple" rebases without a worktree or user interaction. To me, simple rebases mean apply a linear sequence of commits from a single branch onto another branch (and specifying an "old base" is simple enough to include here). It also means that we abort completely if there is a conflict (and handle conflict resolution in later changes).

Quoted 2 lines

The sooner we can deliver that, the better we can deliver on its potential (and expand its functionality to be more generic).

Limiting the initial scope of this tool to a smaller set of features is okay (and, in fact, Christian has already done that), but we really need to avoid painting ourselves into a corner if we change the design as part of that limiting. As I stated previously[1], I'm worried this is happening.

[1] https://lore.kernel.org/git/CABPp-BH7ZPBtV5Hu_-_yVdqVmiydW7_s_LYAtwbPuYSbRQiuQw@mail.gmail.com/,
under "from my view"

Quoted 2 lines

And this is generally my preference, but we shouldn't get functionality "by accident"

All of the specific flags and cases you brought up so far were ones I already carefully considered over a year ago, so the "by accident" comment seems a little unfair.

Quoted 8 lines
Quoted 1 line

but instead do it with full intention

The intention is listed in the subject of the commit message of this patch. I've also explicitly stated my desire on this list to make a tool which replays based on a general range expression multiple times[2][3][4][5]. And there are tests for general range expressions in this series being reviewed. I don't understand why you might think I didn't intend to use general range expressions.

Quoted 2 lines

It's one thing to describe commit ranges, and another to include every possible rev-list option.

Yes, agreed. So clearly there is room for some middle ground. :-)

Quoted 10 lines
Quoted 6 lines

If you want to move git-replay away from setup_revisions(), at a minimum I think we need a proposal that can be extended to the cases I highlighted previously:
* allow specifying several negative revisions (or maybe even zero of them)
* allow specifying several positive revisions
* allow standard basic range syntax, i.e. A..B

I think supporting these descriptive ranges is nice, but doesn't _need_ to be in v1 of the tool. If we need to bake them into the CLI from v1 in order to ensure compatibility, then I understand that.

Wahoo, we're moving towards middle ground.

I personally think baking them into the CLI in v1 is the easiest way to ensure compatibility. They're part of the long term goal anyway, and they are already implemented and tested. (Well, at least the 2nd and 3rd items. We also have tests with a negative revision, but could add ones with more than one. Having zero negative revisions means replaying a root commit onto something else, which the code does not yet support.)

Quoted 11 lines
Quoted 10 lines

* allow --first-parent
* allow --ancestry-path[=<commit>]
I think it should also be able to eventually support
* --branches[=<pattern>]
* --not
* --tags[=<pattern>]
* --remotes[=<pattern>]
* --glob=<pattern>
* --exclude=<glob-pattern>
* --all

Quoted 3 lines

However, I think very few of these should be generally supported, and if there are reasons to include some then they should be motivated by a specific use case and tested directly.

None of these need to be in v1. Some aren't even useful yet without other changes that Christian excluded in this initial version.

But can I take a step back and ask if you are saying few of these should be generally supported _in v1_ (which I'm fine with) or _ever_ (which puts us at total loggerheads)? It reads to me like you're saying the latter, but I can't fathom why. While I totally understand the apprehension with "every possible rev-list option", this is far from that extreme and I don't see why flags selecting contiguous revision ranges should be of any concern. They all have usecases, and I've even pointed out multiple already. Going slightly out of order:

* --ancestry-path=<commit>:

I don't see why this option is getting pushback at all. It was invented specifically and almost exclusively for use in git-replay. I've pointed that out already and linked to the detailed usecase explanation for using this option in git-replay twice so far in this thread, but there's another interesting twist that may be relevant
here: to my knowledge, there are still no known usecases for this option outside of git-replay; Junio and I at least could not imagine any others[6].

Granted, this option is not of much use until we also support replaying of merges, so leaving it out of v1 is no big deal.

[6] See the quoted comment of Junio including "solution in search of a problem", found right before I give my usecase in
https://lore.kernel.org/git/CABPp-BHmj+QCBFDrH77iNfEU41V=UDu7nhBYkAbCsbXhshJzzw@mail.gmail.com/

* --first-parent:

This option was already referenced with a usecase in the link "[5]" from my last email. I also listed two other usecases in my replay-design-notes file[7].

Granted, this option isn't yet useful since Christian has removed the pick_merge_commit() function for v1. But considering that it was part of my original design, I've listed multiple usecases, and I have already written code for git-replay specifically designed to be used with both --ancestry-path[=<commit>] and --first-parent (just not included in this v1), it is also one where I'm struggling to understand pushback for eventual support.

[7] https://github.com/newren/git/blob/2a621020863c0b867293e020fec0954b43818789/replay-design-notes.txt#L113-L124

* all the others (which can be summarized as shorthands options for various sets of multiple positive refs or multiple negative refs):

I think that supporting multiple positive and negative revisions likely leads to users wanting these shorthand versions. For example, say a user has a dozen different branches in their repository (possibly intertwined), all based on various topics in main and next. They go on vacation (or work on some other project) for a few weeks, during which time everything in next has graduated to main (and next has not been rewound), and the user wants to replay all of their branches on an updated main. They could do so via:

   $ git fetch origin
   $ git checkout --detach HEAD   # Detach HEAD so it doesn't prevent
any ref updates
   $ git replay --onto origin/main --branches --not --remotes=origin |
git update-ref --stdin

That's something I would like to have available for my use. (And, again, N separate rebases/replays does not achieve the same effect since the commits in those branches being replayed may be partially or fully contained in some of the other branches being replayed.)

Quoted 3 lines

As it is, these tags do something in this v1, but we can't really be sure that they work because we're not testing them. That is my primary complaint.

Lack of testing for some of these options is a totally fair complaint.

I'm fine with these options being left out of v1, so long as there isn't a design change that will impose backward compatibility constraints that precludes them from being added in the future. That is my primary complaint.

Quoted 1 line

And testing each individually isn't enough, because they can combine in all sorts of ways.

That's kind of the point, though, right? Letting people select a range of (contiguous) revisions using capabilities they are familiar with and which they have used elsewhere in Git (and which have been tested elsewhere in Git).

Quoted 10 lines
Quoted 9 lines

That's a long list of things to parse, which setup_revisions() happens to handle nicely. You are right that setup_revisions() also has lots of options for generating non-contiguous history that may make little or no sense for replay (and makes no sense for fast-export either). So, I am willing to consider other solutions if anyone has one, but only alternative solutions which can eventually handle the above requirements. In particular, "three commits as positional arguments" (with one implicitly being considered a negative ref) conflicts with the first three bullet points above.

Quoted 3 lines

The only way I can see using setup_revisions() safely is if you make sure to reject any arguments that start with "--" (or perhaps "-" because some of those options may have single-character versions).

Ooh, single dash. I wonder if people might find doing an interactive replay with e.g. --keep-base -5 ${OTHER_BRANCH} handy.

Granted, that's basically the same as ${OTHER_BRANCH}~5..${OTHER_BRANCH} in most cases, and I'm not sure if I'd personally use it, but it might be a nice touch to allow folks who have long branch names to get by with less typing.

Anyway, I could see employing this reject-dashed-arguments scheme for v1, since v1 doesn't need any of the dashed options, but only if accompanied with a code comment that it's a hack not intended to be kept in the future.

Quoted 3 lines

This could be extended to an allowlist if we find a motivation to include other options (I see "--not" as being a likely candidate) in patches that test that interaction.

"if we find a motivation"??

I find this is a bit frustrating. Several things in the merge-ort machinery were designed with these kinds of capabilities in mind. git-merge-tree, on my end, was designed, written, submitted, iterated, and improved (taking 9+ months) almost solely as a feedback gathering mechanism for this tool (it has much simpler design and conflict handling needed). I've been working on the usecases for this tool for years, and have put quite a bit of time into this tool already, with specific usecases in mind driving how the tool is being written. And I'm specifically motivated by things that rebase cannot do.

I've linked to several of those usecases multiple times in this thread already. Many were also in the cover letter in this series. (And more are in my replay-design-notes.txt file on my replay branch.)

I feel like you're brushing aside those repeated attempts to point out those usecases as though they don't exist or don't matter, with some separate new motivation needed for these options to be allowed? And perhaps saying those usecases should all be *ruled out* apriori, because you're concerned the implementation *might* also allow other unintended uses?

Something isn't working here.

Quoted 5 lines

Or, could we extract the portion of setup_revisions() that parses just the revision ranges in to a new setup_revision_ranges() method? It could reject any options that are not directly about revision ranges. This option makes less sense if we are going the allowlist approach.

Ooh, that's interesting. However, would the name lead people to think that e.g. --reflog, --walk-reflogs, --author, --committer, --grep, --min-parents, --max-parents, --cherry-pick are relevant? Should we perhaps use a name like setup_contiguous_revision_ranges() so it's clear these flags are disallowed, while things like A, ^B, C..D, --first-parent, --ancestry-path, --branches, --remotes, are allowed?

Is it worth refactoring setup_revision() into more divisible chunks, so that callers can make use of just the relevant parts of it? We have numerous other tools looking for revision ranges, which currently accept full rev-list options and pass along user-supplied command-line arguments to them. Beyond rev-list/log/shortlog, these seem to include at least:
* fast-export
* blame
* cherry-pick
* revert
* format-patch
* bisect (at least the skip subcommand)
* stash (at least the show subcommand)
* filter-branch (actually, as a horrible shell script, it'll
continue accepting all rev-list options anyway)

Some of these could probably get away with non-contiguous revision ranges, but most wouldn't find any benefit from:
* tree/blob/packing options (e.g. --objects*, --unpacked, --filter*,
--verify-objects, --in-commit-order)
* anything dealing with reflogs (e.g. --reflog, --walk-reflogs)
* various forms of history simplification (e.g. --simplify-merges,
--simplify-by-decoration, --sparse, --show-pulls)
* flags related to display (e.g. --pretty, --graph,
--show-signature, --early-output, --disk-usage, --abbrev-commit, --relative-date, --log-size, --left-right, --cherry-mark)
* flags related to file contents (e.g. <pathspecs>, --merge,
--follow, --full-diff, --remove-empty)

Here's a fun and valid (and innocuous) command. Guess which flags are ignored and which aren't:

  $ git stash show --graph --relative-date --min-parents=3
--simplify-merges --cherry --show-pulls --unpacked -v -t -8
--format=oneline --abbrev=12 --pretty=fuller --show-notes
--encode-email-headers --always --branches --indexed-objects stash@{0}

That all said, while I like the idea of someone dividing setup_revisions() into divisible chunks so tools can just use the bits that are relevant, and doing so sounds like it'd avoid weird surprises from use of unintended flags, I'm surprised that the solution to the "setup_revisions() is scary" problem isn't to provide easy-to-use API that allows selecting the relevant subsets for each command, but to instead expect every one that comes along to do some heavy lifting and special whitelisting. We have half a dozen users in the tree already facing these problems, so shouldn't these be fixed and the API made to be easy to use more safely so that this problem is solved more generally rather than just putting it on each future functionality implementor who comes along to work around it in their particular situation?

#20 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 54 lines · Elijah Newren
Quoted 11 lines · Derrick Stolee
Quoted 6 lines · Elijah Newren

The intention is listed in the subject of the commit message of this patch. I've also explicitly stated my desire on this list to make a tool which replays based on a general range expression multiple times[2][3][4][5]. And there are tests for general range expressions in this series being reviewed. I don't understand why you might think I didn't intend to use general range expressions.

It's one thing to describe commit ranges, and another to include every possible rev-list option.

Yes, agreed. So clearly there is room for some middle ground. :-)

Quoted 10 lines
Quoted 6 lines

If you want to move git-replay away from setup_revisions(), at a minimum I think we need a proposal that can be extended to the cases I highlighted previously:
* allow specifying several negative revisions (or maybe even zero of them)
* allow specifying several positive revisions
* allow standard basic range syntax, i.e. A..B

I think supporting these descriptive ranges is nice, but doesn't _need_ to be in v1 of the tool. If we need to bake them into the CLI from v1 in order to ensure compatibility, then I understand that.

Wahoo, we're moving towards middle ground.

I personally think baking them into the CLI in v1 is the easiest way to ensure compatibility. They're part of the long term goal anyway, and they are already implemented and tested. (Well, at least the 2nd and 3rd items. We also have tests with a negative revision, but could add ones with more than one. Having zero negative revisions means replaying a root commit onto something else, which the code does not yet support.)

Quoted 11 lines
Quoted 10 lines

* allow --first-parent
* allow --ancestry-path[=<commit>]
I think it should also be able to eventually support
* --branches[=<pattern>]
* --not
* --tags[=<pattern>]
* --remotes[=<pattern>]
* --glob=<pattern>
* --exclude=<glob-pattern>
* --all

Quoted 3 lines

However, I think very few of these should be generally supported, and if there are reasons to include some then they should be motivated by a specific use case and tested directly.

None of these need to be in v1. Some aren't even useful yet without other changes that Christian excluded in this initial version.

Quoted 8 lines

But can I take a step back and ask if you are saying few of these should be generally supported _in v1_ (which I'm fine with) or _ever_ (which puts us at total loggerheads)? It reads to me like you're saying the latter, but I can't fathom why. While I totally understand the apprehension with "every possible rev-list option", this is far from that extreme and I don't see why flags selecting contiguous revision ranges should be of any concern. They all have usecases, and I've even pointed out multiple already. Going slightly out of order:

(going more out of order)

Quoted 5 lines

* --first-parent:

This option was already referenced with a usecase in the link "[5]" from my last email. I also listed two other usecases in my replay-design-notes file[7].

I agree on this one.

Quoted 4 lines

* --ancestry-path=<commit>:

I don't see why this option is getting pushback at all. It was invented specifically and almost exclusively for use in git-replay.

(Edited out your explanation.)

I'm still not super convinced that this solves a common user problem, but you've documented your use case well (in other places). The problem I see is that the current patch brings it in without having any of that context.

Quoted 2 lines

* all the others (which can be summarized as shorthands options for various sets of multiple positive refs or multiple negative refs):

I think you're over-simplifying here, because...

Quoted 6 lines
Quoted 5 lines

Or, could we extract the portion of setup_revisions() that parses just the revision ranges in to a new setup_revision_ranges() method? It could reject any options that are not directly about revision ranges. This option makes less sense if we are going the allowlist approach.

Quoted 6 lines

However, would the name lead people to think
that e.g. --reflog, --walk-reflogs, --author, --committer, --grep, --min-parents, --max-parents, --cherry-pick are relevant? Should we perhaps use a name like setup_contiguous_revision_ranges() so it's clear these flags are disallowed, while things like A, ^B, C..D, --first-parent, --ancestry-path, --branches, --remotes, are allowed?

I think one thing that might help bridge the divide here is a different split when I think of "revision range" and "rev-list options".

We have several categories of rev-list options, and we need to find the right set to care about and the ones that aren't useful for git-replay:

1. (What I call revision ranges) a collection of starting revisions, each marked as an "include" or "exclude" (A..B includes B, excludes A). The --not option helps with defining these starting points.

2. (Walk options) Modifications to how we walk commits, such as --first-parent, --ancestry-path. These are so far the kind of options you have motivated with use cases.

3. (Ordering options) Modifications to how those commits are ordered, such as --topo-order, --date-order, and --reverse. These seem to be overridden by git-replay (although, --reverse probably causes some confusion right now).

4. (Filtering options) A post-walk filter on a per-commit basis. This includes --(max|min)-parents, --author, --grep.

note: at this point I'm not sure into which of these categories we should put time-based options like --since.

My main objection to the generic rev-list options come from allowing categories (3) and (4), since this is more likely to cause user confusion rather than actually be of any use to the feature.

While I was not considering (2) to be included in setup_revision_ranges(), I could see it being valid to include both (1) and (2) in those options.

I would like to see tests for options in category (2) to demonstrate these use cases and solidify them in our supported scenarios.

Quoted 16 lines

"if we find a motivation"??

I find this is a bit frustrating. Several things in the merge-ort machinery were designed with these kinds of capabilities in mind. git-merge-tree, on my end, was designed, written, submitted, iterated, and improved (taking 9+ months) almost solely as a feedback gathering mechanism for this tool (it has much simpler design and conflict handling needed). I've been working on the usecases for this tool for years, and have put quite a bit of time into this tool already, with specific usecases in mind driving how the tool is being written. And I'm specifically motivated by things that rebase cannot do.

I've linked to several of those usecases multiple times in this thread already. Many were also in the cover letter in this series. (And more are in my replay-design-notes.txt file on my replay branch.)

Quoted 8 lines

I feel like you're brushing aside those repeated attempts to point out those usecases as though they don't exist or don't matter, with some separate new motivation needed for these options to be allowed? And perhaps saying those usecases should all be *ruled out* apriori, because you're concerned the implementation *might* also allow other unintended uses?

Something isn't working here.

I'm trying to read the patches and make sense of what is written there.

The current patch especially is far too lightly documented for what it is actually implementing.

Even its documentation states this:

+<revision-range>::
+ Range of commits to replay; see "Specifying Ranges" in
+ linkgit:git-rev-parse.

This "Specifying Ranges" section describes exactly category (1) of what I was talking about, but really the patch enables everything in "Commit Limiting" from git-rev-list.

Based on what I see in the patch, I can't help but think that the extra options are an accident.

And _even with the extra context linked elsewhere_ I will still hold that using something as generic as setup_revisions() isn't a good practice for software development. It adds too may things that all at once, some of which I don't think match the purpose of git-replay. You've convinced me to expand my understanding of what fits in that category, but I still think we need to test this more. Tests can demonstrate use cases much better than anything else.

Quoted 29 lines

Is it worth refactoring setup_revision() into more divisible chunks, so that callers can make use of just the relevant parts of it? We have numerous other tools looking for revision ranges, which currently accept full rev-list options and pass along user-supplied command-line arguments to them. Beyond rev-list/log/shortlog, these seem to include at least:
* fast-export
* blame
* cherry-pick
* revert
* format-patch
* bisect (at least the skip subcommand)
* stash (at least the show subcommand)
* filter-branch (actually, as a horrible shell script, it'll
continue accepting all rev-list options anyway)

Some of these could probably get away with non-contiguous revision ranges, but most wouldn't find any benefit from:
* tree/blob/packing options (e.g. --objects*, --unpacked, --filter*,
--verify-objects, --in-commit-order)
* anything dealing with reflogs (e.g. --reflog, --walk-reflogs)
* various forms of history simplification (e.g. --simplify-merges,
--simplify-by-decoration, --sparse, --show-pulls)
* flags related to display (e.g. --pretty, --graph,
--show-signature, --early-output, --disk-usage, --abbrev-commit, --relative-date, --log-size, --left-right, --cherry-mark)
* flags related to file contents (e.g. <pathspecs>, --merge,
--follow, --full-diff, --remove-empty)

Quoted 7 lines

Here's a fun and valid (and innocuous) command. Guess which flags are ignored and which aren't:

  $ git stash show --graph --relative-date --min-parents=3
--simplify-merges --cherry --show-pulls --unpacked -v -t -8
--format=oneline --abbrev=12 --pretty=fuller --show-notes
--encode-email-headers --always --branches --indexed-objects stash@{0}

This investigation is exactly why I'm concerned about using the generic setup_revisions(). I've already noticed its use elsewhere and been disappointed. But I wasn't around when those were written, so you get the short straw and become the reason I bring it up.

Quoted 5 lines

That all said, while I like the idea of someone dividing setup_revisions() into divisible chunks so tools can just use the bits that are relevant, and doing so sounds like it'd avoid weird surprises from use of unintended flags, I'm surprised that the solution to the "setup_revisions() is scary" problem isn't to provide easy-to-use API

Quoted 8 lines

that allows selecting the relevant subsets for each command, but to instead expect every one that comes along to do some heavy lifting and special whitelisting. We have half a dozen users in the tree already facing these problems, so shouldn't these be fixed and the API made to be easy to use more safely so that this problem is solved more generally rather than just putting it on each future functionality implementor who comes along to work around it in their particular situation?

I think a better API is a great idea! Splitting into multiple methods or providing option flags for "categories" of options allowed would also work.

But back to my original suggestion: you can also do something simpler for v1 of git-replay (say, very limited revision parsing such as one A..B range) so your progress here isn't blocked on refactoring the revisions API.

Thanks,
-Stolee

#21 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 5 lines · Derrick Stolee
Quoted 3 lines · Elijah Newren
Quoted 2 lines · Derrick Stolee

On 4/18/2023 1:54 AM, Elijah Newren wrote:

[...]

Quoted 29 lines
Quoted 18 lines
Quoted 11 lines
Quoted 10 lines

* allow --first-parent
* allow --ancestry-path[=<commit>]
I think it should also be able to eventually support
* --branches[=<pattern>]
* --not
* --tags[=<pattern>]
* --remotes[=<pattern>]
* --glob=<pattern>
* --exclude=<glob-pattern>
* --all

Quoted 3 lines

However, I think very few of these should be generally supported, and if there are reasons to include some then they should be motivated by a specific use case and tested directly.

None of these need to be in v1. Some aren't even useful yet without other changes that Christian excluded in this initial version.

Quoted 8 lines

But can I take a step back and ask if you are saying few of these should be generally supported _in v1_ (which I'm fine with) or _ever_ (which puts us at total loggerheads)? It reads to me like you're saying the latter, but I can't fathom why. While I totally understand the apprehension with "every possible rev-list option", this is far from that extreme and I don't see why flags selecting contiguous revision ranges should be of any concern. They all have usecases, and I've even pointed out multiple already. Going slightly out of order:

(going more out of order)

Quoted 7 lines
Quoted 5 lines

* --first-parent:

This option was already referenced with a usecase in the link "[5]" from my last email. I also listed two other usecases in my replay-design-notes file[7].

I agree on this one.

:-)

Quoted 8 lines
Quoted 4 lines

* --ancestry-path=<commit>:

I don't see why this option is getting pushback at all. It was invented specifically and almost exclusively for use in git-replay.

(Edited out your explanation.)

I'm still not super convinced that this solves a common user problem,

Why does it have to be common? I said I wanted to be able to do things that I cannot do with existing tooling, which usually implies less common usecases.

Quoted 4 lines
Quoted 2 lines

* all the others (which can be summarized as shorthand options for various sets of multiple positive refs or multiple negative refs):

I think you're over-simplifying here, because...

I don't think so. Was the context lost? I suspect it was, because right after this you started talking about completely unrelated options (though in a very useful manner, so it's all good in the end.)

Since I was responding to "few of these should be generally supported", and the first two of those had been discussed above, "all the others" here refers to exactly these 7 flags:
* --branches[=<pattern>]
* --not
* --tags[=<pattern>]
* --remotes[=<pattern>]
* --glob=<pattern>
* --exclude=<glob-pattern>
* --all

All I did was read our own documentation for these options and categorize exactly what they share in common. That yields my statement that these "can be summarized as shorthand options for various sets of multiple positive refs or multiple negative refs".

Quoted 16 lines
Quoted 6 lines
Quoted 5 lines

Or, could we extract the portion of setup_revisions() that parses just the revision ranges in to a new setup_revision_ranges() method? It could reject any options that are not directly about revision ranges. This option makes less sense if we are going the allowlist approach.

Quoted 6 lines

However, would the name lead people to think
that e.g. --reflog, --walk-reflogs, --author, --committer, --grep, --min-parents, --max-parents, --cherry-pick are relevant? Should we perhaps use a name like setup_contiguous_revision_ranges() so it's clear these flags are disallowed, while things like A, ^B, C..D, --first-parent, --ancestry-path, --branches, --remotes, are allowed?

I think one thing that might help bridge the divide here is a different split when I think of "revision range" and "rev-list options".

Quoted 7 lines

We have several categories of rev-list options, and we need to find the right set to care about and the ones that aren't useful for git-replay:

1. (What I call revision ranges) a collection of starting revisions, each marked as an "include" or "exclude" (A..B includes B, excludes A). The --not option helps with defining these starting points.

There are also shorthands for building up these collections of starting revisions, so that instead of saying e.g. maint main next seen mytopic, one can just use --branches. Thus, options like --branches[=<pattern>], --tags[=<pattern>], --exclude=<pattern>, etc. also belong in this category.

Quoted 3 lines

2. (Walk options) Modifications to how we walk commits, such as --first-parent, --ancestry-path. These are so far the kind of options you have motivated with use cases.

I think I also motivated category 1 with use cases. Since you acquiesced on including that category first, I think you may have meant this last sentence to refer to both of these categories?

Quoted 4 lines

3. (Ordering options) Modifications to how those commits are ordered, such as --topo-order, --date-order, and --reverse. These seem to be overridden by git-replay (although, --reverse probably causes some confusion right now).

Yep, intentionally overridden.

Could you elaborate on what you mean by --reverse causing confusion?

Quoted 2 lines

4. (Filtering options) A post-walk filter on a per-commit basis. This includes --(max|min)-parents, --author, --grep.

I think pathspecs are an additional example that is worth specifically calling out as belonging in category 4.

This is a reasonable splitting of categories, if a bit incomplete. (However, other categories I can think of matter less to git-replay than these four.)

Quoted 2 lines

note: at this point I'm not sure into which of these categories we should put time-based options like --since.

Fair enough, there were also some options I was unsure of. And there are some that look like a can of worms. (Which I'd rather not get into, but I'll obliquely note that I would place --since and --until in separate categories.)

Quoted 3 lines

My main objection to the generic rev-list options come from allowing categories (3) and (4), since this is more likely to cause user confusion rather than actually be of any use to the feature.

That is a reasonable objection; I wish what you had stated earlier looked more like this.

I might disagree with you on the severity of the issue, or the relative necessity/importance of cleaning up the widely-used existing code as a pre-requisite to using it in another place, but it's a totally fair review comment to bring up. Further, I agree with you that the options in these two categories would not be of any use to git-replay.

Quoted 2 lines

While I was not considering (2) to be included in setup_revision_ranges(), I could see it being valid to include both (1) and (2) in those options.

Awesome, I think this provides me with what I need. Note that categories (1) and (2) include every single option in my previous "at a minimum" list:

* several negative revisions (or maybe even zero of them)
* several positive revisions
* standard basic range syntax, i.e. A..B
* --first-parent
* --ancestry-path[=<commit>]
* --branches[=<pattern>]
* --not
* --tags[=<pattern>]
* --remotes[=<pattern>]
* --glob=<pattern>
* --exclude=<glob-pattern>
* --all

There may also be additional options that fit within categories (1) and (2).

Quoted 2 lines

I would like to see tests for options in category (2) to demonstrate these use cases and solidify them in our supported scenarios.

Yup, totally fair. Probably not as part of this initial patchset, though, since Christian and Dscho are only interested in a small subset of usecases and are the ones pushing these patches early. (Whereas I'm focused on answering questions, and making sure that whatever happens doesn't make my goals for the tool impossible.)

Quoted 36 lines
Quoted 16 lines

"if we find a motivation"??

I find this is a bit frustrating. Several things in the merge-ort machinery were designed with these kinds of capabilities in mind. git-merge-tree, on my end, was designed, written, submitted, iterated, and improved (taking 9+ months) almost solely as a feedback gathering mechanism for this tool (it has much simpler design and conflict handling needed). I've been working on the usecases for this tool for years, and have put quite a bit of time into this tool already, with specific usecases in mind driving how the tool is being written. And I'm specifically motivated by things that rebase cannot do.

I've linked to several of those usecases multiple times in this thread already. Many were also in the cover letter in this series. (And more are in my replay-design-notes.txt file on my replay branch.)

Quoted 8 lines

I feel like you're brushing aside those repeated attempts to point out those usecases as though they don't exist or don't matter, with some separate new motivation needed for these options to be allowed? And perhaps saying those usecases should all be *ruled out* apriori, because you're concerned the implementation *might* also allow other unintended uses?

Something isn't working here.

I'm trying to read the patches and make sense of what is written there.

The current patch especially is far too lightly documented for what it is actually implementing.

Even its documentation states this:

+<revision-range>::

(quoted diff) +2 -0
+       Range of commits to replay; see "Specifying Ranges" in
+       linkgit:git-rev-parse.
Quoted 6 lines

This "Specifying Ranges" section describes exactly category (1) of what I was talking about, but really the patch enables everything in "Commit Limiting" from git-rev-list.

Based on what I see in the patch, I can't help but think that the extra options are an accident.

This all would be a fine review comment, if you had said that. Instead, you stated that setup_revisions() shouldn't be used (which might have been fine as an initial comment), and when I pointed out exact options and flags that were needed at a minimum you still said they shouldn't generally be supported, and after pointing out usecases, multiple times, you responded with "if we can find a motivation".

There are two reasons I found that problematic:

Sometimes it makes sense to say that a usecase shouldn't be supported. But, when there's months of effort so far put into implementing those usecases, I would expect strong statements about ruling out usecases to be accompanied with really good explanations of why those exact cases are deemed "bad" and the best possible alternative solutions that should instead be implemented to solve something close to the proposer's stated desires. I didn't see that.

Similarly, there are times when a reviewer should say that code should not be implemented a certain way. But when the person responds with some alternatives and their _minimum_ needs trying to find some common ground, and has put months of efforts into this wider goal, I would expect that ruling out certain methods and their follow up alternatives to be accompanied with alternative solutions of your own that can solve the proposer's goals; not merely attempting to veto suggestions immediately with seemingly no path forward.

It was an unfortunate set of examples that seemed far below your typically excellent reviews. In contrast, this latest email of yours is another high quality response in line with your emails prior to this thread.

Quoted 7 lines

And _even with the extra context linked elsewhere_ I will still hold that using something as generic as setup_revisions() isn't a good practice for software development. It adds too may things that all at once, some of which I don't think match the purpose of git-replay. You've convinced me to expand my understanding of what fits in that category, but I still think we need to test this more. Tests can demonstrate use cases much better than anything else.

Yaay on the convincing bit. :-)

The rest is all fair, but I'd like to point out that there are a few problems here:

* Tests should generally be passing before submitting upstream, so
all the code to implement them needs to be sent too
* Submitted patch series have to be digestible sizes; not everything
can be submitted at once
* Christian and Dscho wanted some of what I had implemented despite
other parts not being ready

Importantly, the first two issues in particular mean that when the first series comes:

* If you insist on (or even just suggest) certain changes that
happen to break capabilities in the pipeline, especially in a fashion that cannot backward-compatibly be fixed, then I think the only path forward (other than dropping your suggestions) is to engage in discussions about those usecases & design *without* the testcases and code being available yet.

Quoted 56 lines
Quoted 29 lines

Is it worth refactoring setup_revision() into more divisible chunks, so that callers can make use of just the relevant parts of it? We have numerous other tools looking for revision ranges, which currently accept full rev-list options and pass along user-supplied command-line arguments to them. Beyond rev-list/log/shortlog, these seem to include at least:
* fast-export
* blame
* cherry-pick
* revert
* format-patch
* bisect (at least the skip subcommand)
* stash (at least the show subcommand)
* filter-branch (actually, as a horrible shell script, it'll
continue accepting all rev-list options anyway)

Some of these could probably get away with non-contiguous revision ranges, but most wouldn't find any benefit from:
* tree/blob/packing options (e.g. --objects*, --unpacked, --filter*,
--verify-objects, --in-commit-order)
* anything dealing with reflogs (e.g. --reflog, --walk-reflogs)
* various forms of history simplification (e.g. --simplify-merges,
--simplify-by-decoration, --sparse, --show-pulls)
* flags related to display (e.g. --pretty, --graph,
--show-signature, --early-output, --disk-usage, --abbrev-commit, --relative-date, --log-size, --left-right, --cherry-mark)
* flags related to file contents (e.g. <pathspecs>, --merge,
--follow, --full-diff, --remove-empty)

Quoted 7 lines

Here's a fun and valid (and innocuous) command. Guess which flags are ignored and which aren't:

  $ git stash show --graph --relative-date --min-parents=3
--simplify-merges --cherry --show-pulls --unpacked -v -t -8
--format=oneline --abbrev=12 --pretty=fuller --show-notes
--encode-email-headers --always --branches --indexed-objects stash@{0}

This investigation is exactly why I'm concerned about using the generic setup_revisions(). I've already noticed its use elsewhere and been disappointed. But I wasn't around when those were written, so you get the short straw and become the reason I bring it up.

Quoted 5 lines

That all said, while I like the idea of someone dividing setup_revisions() into divisible chunks so tools can just use the bits that are relevant, and doing so sounds like it'd avoid weird surprises from use of unintended flags, I'm surprised that the solution to the "setup_revisions() is scary" problem isn't to provide easy-to-use API

Quoted 8 lines

that allows selecting the relevant subsets for each command, but to instead expect every one that comes along to do some heavy lifting and special whitelisting. We have half a dozen users in the tree already facing these problems, so shouldn't these be fixed and the API made to be easy to use more safely so that this problem is solved more generally rather than just putting it on each future functionality implementor who comes along to work around it in their particular situation?

Quoted 6 lines

I think a better API is a great idea! Splitting into multiple methods or providing option flags for "categories" of options allowed would also work.

But back to my original suggestion: you can also do something simpler for v1 of git-replay

That's workable.

Quoted 1 line

(say, very limited revision parsing such as one A..B range)

I'm not fine with that, though. We already have tests of multiple positive refs, so there's no reason to exclude those. In fact, keeping them in is especially important as a means of avoiding having other reviewers make suggestions to copy rebase's broken design (namely, being limited to a couple commits passed as positional arguments with one implicitly being an exclude).

Quoted 2 lines

so your progress here isn't blocked on refactoring the revisions API.

Is that a positive or a negative? That question may surprise you, so let me explain.

I have a conflict of interest of sorts. When Christian and Dscho (separately) approached me earlier this year and pointed out that git-replay had the functionality they wanted, I was happy that others liked it, and gave some pointers here and there, but I was _very_ worried that upstreaming it would result in something getting backward-incompatibly locked into place that prevents the pieces that are still in progress from getting implemented. And I was concerned that my plans to create a tool people could experiment with, and that we could get usability feedback on (as I suggested at the Git contributors summit last year) might be in jeopardy as pieces of its functionality get locked into place before it's even ready for usability testing. I was silently hoping they'd lose steam on rebasing and cleaning up my patches or choose to just delay until I could get real time to work on it with them. (Since then, the one person who had ever advocated for my Git work at $DAYJOB, the best manager I had ever worked under, became not-a-manager. I was blindsided by that in February. Also, I have been transferred to a different team and am spinning up there. And so, to my dismay, I'm worried my little sliver of Git time at work may evaporate entirely rather than return to previous healthier levels.) Anyway, I've been fretting about things getting "locked-in" for a few months.

They didn't lose steam, as I found out when these patches were submitted. But, uh, I'm silently torn because I want to help Christian and Dscho get what they want, but having them be blocked on progress would reduce my stress. A lot.

Is there any chance people would be willing to accept a "NO BACKWARD COMPATIBILITY GUARANTEES" disclaimer on this command for a (long?) while, like Victoria suggested at Review club? That might be an alternate solution that would lower my worries.

#22 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 5 lines · Elijah Newren
Quoted 3 lines · Derrick Stolee
Quoted 1 line · Elijah Newren

On Tue, Apr 18, 2023 at 6:10 AM Derrick Stolee <[email protected]> wrote:

Quoted 8 lines
Quoted 4 lines

3. (Ordering options) Modifications to how those commits are ordered, such as --topo-order, --date-order, and --reverse. These seem to be overridden by git-replay (although, --reverse probably causes some confusion right now).

Yep, intentionally overridden.

Could you elaborate on what you mean by --reverse causing confusion?

It's very unlikely that a list of patches will successfully apply when applied in the reverse order. If we allow the argument, then someone will try it thinking they can flip their commits. Then they might be surprised when there are a bunch of conflicts on every commit.

Basically, I'm not super thrilled about exposing options that are unlikely to be valuable to users and instead are more likely to cause confusion due to changes that won't successfully apply.

Quoted 54 lines
Quoted 20 lines
Quoted 8 lines

I feel like you're brushing aside those repeated attempts to point out those usecases as though they don't exist or don't matter, with some separate new motivation needed for these options to be allowed? And perhaps saying those usecases should all be *ruled out* apriori, because you're concerned the implementation *might* also allow other unintended uses?

Something isn't working here.

I'm trying to read the patches and make sense of what is written there.

The current patch especially is far too lightly documented for what it is actually implementing.

Even its documentation states this:

+<revision-range>::

(quoted diff) +2 -0
+       Range of commits to replay; see "Specifying Ranges" in
+       linkgit:git-rev-parse.
Quoted 6 lines

This "Specifying Ranges" section describes exactly category (1) of what I was talking about, but really the patch enables everything in "Commit Limiting" from git-rev-list.

Based on what I see in the patch, I can't help but think that the extra options are an accident.

This all would be a fine review comment, if you had said that. Instead, you stated that setup_revisions() shouldn't be used (which might have been fine as an initial comment), and when I pointed out exact options and flags that were needed at a minimum you still said they shouldn't generally be supported, and after pointing out usecases, multiple times, you responded with "if we can find a motivation".

There are two reasons I found that problematic:

Sometimes it makes sense to say that a usecase shouldn't be supported. But, when there's months of effort so far put into implementing those usecases, I would expect strong statements about ruling out usecases to be accompanied with really good explanations of why those exact cases are deemed "bad" and the best possible alternative solutions that should instead be implemented to solve something close to the proposer's stated desires. I didn't see that.

Similarly, there are times when a reviewer should say that code should not be implemented a certain way. But when the person responds with some alternatives and their _minimum_ needs trying to find some common ground, and has put months of efforts into this wider goal, I would expect that ruling out certain methods and their follow up alternatives to be accompanied with alternative solutions of your own that can solve the proposer's goals; not merely attempting to veto suggestions immediately with seemingly no path forward.

Quoted 3 lines

It was an unfortunate set of examples that seemed far below your typically excellent reviews. In contrast, this latest email of yours is another high quality response in line with your emails prior to this thread.

I'm sorry I didn't read the prior work linked in the cover letter. Since cover letters and their external links are not recorded in our commit history, I have a habit of ignoring them other than getting some basic context of the series.

I also was less specific about my complaints because I thought that saying "things like --author" was enough to point out that setup_revisions() is too generic. Didn't seem like context that was required until you showed it was required.

Quoted 9 lines

The rest is all fair, but I'd like to point out that there are a few problems here:

* Tests should generally be passing before submitting upstream, so
all the code to implement them needs to be sent too
* Submitted patch series have to be digestible sizes; not everything
can be submitted at once
* Christian and Dscho wanted some of what I had implemented despite
other parts not being ready

Outside of my first response (using positional arguments, recommended before you provided the extra context I was missing) I have not suggested implementing something that can't be forward compatible. Note that I've used A..B notation in those replies. I'm suggesting that we focus on a critical core of functionality that can be carefully tested while the rest of the system is being worked out. Then, those more advanced bits can be added carefully with test cases.

When we get to that point, there are creative ways to prepare tests in advance of a code change such that they make reviewable patches, instead of creating test debt to be left for later.

Quoted 9 lines

Importantly, the first two issues in particular mean that when the first series comes:

* If you insist on (or even just suggest) certain changes that
happen to break capabilities in the pipeline, especially in a fashion that cannot backward-compatibly be fixed, then I think the only path forward (other than dropping your suggestions) is to engage in discussions about those usecases & design *without* the testcases and code being available yet.

This sounds a lot like your arguments are focused on reducing the amount of rework you'd need to do on your pipeline of work that hasn't been submitted for review. I find that to be an expected risk of working so far ahead of reviewed patches, and am familiar with that pain. I don't find that to be a convincing argument.

Quoted 5 lines
Quoted 2 lines

But back to my original suggestion: you can also do something simpler for v1 of git-replay

That's workable.

Quoted 8 lines
Quoted 1 line

(say, very limited revision parsing such as one A..B range)

I'm not fine with that, though. We already have tests of multiple positive refs, so there's no reason to exclude those. In fact, keeping them in is especially important as a means of avoiding having other reviewers make suggestions to copy rebase's broken design (namely, being limited to a couple commits passed as positional arguments with one implicitly being an exclude).

I'm just making one suggestion about where to limit the parsing. If multiple ranges are doable before refactoring setup_revisions(), then by all means go ahead. And whatever parsing is accepted in this v1, we can make sure it works with those future plans.

Focusing on the revisions as described by 'git rev-parse' pointed to in the 'git replay' docs in this patch would be a great place to start.

Quoted 19 lines
Quoted 2 lines

so your progress here isn't blocked on refactoring the revisions API.

Is that a positive or a negative? That question may surprise you, so let me explain.

I have a conflict of interest of sorts. When Christian and Dscho (separately) approached me earlier this year and pointed out that git-replay had the functionality they wanted, I was happy that others liked it, and gave some pointers here and there, but I was _very_ worried that upstreaming it would result in something getting backward-incompatibly locked into place that prevents the pieces that are still in progress from getting implemented. And I was concerned that my plans to create a tool people could experiment with, and that we could get usability feedback on (as I suggested at the Git contributors summit last year) might be in jeopardy as pieces of its functionality get locked into place before it's even ready for usability testing. I was silently hoping they'd lose steam on rebasing and cleaning up my patches or choose to just delay until I

Quoted 8 lines

could get real time to work on it with them. (Since then, the one person who had ever advocated for my Git work at $DAYJOB, the best manager I had ever worked under, became not-a-manager. I was blindsided by that in February. Also, I have been transferred to a different team and am spinning up there. And so, to my dismay, I'm worried my little sliver of Git time at work may evaporate entirely rather than return to previous healthier levels.) Anyway, I've been fretting about things getting "locked-in" for a few months.

I'm also upset that you have been disrupted like this.

Quoted 4 lines

They didn't lose steam, as I found out when these patches were submitted. But, uh, I'm silently torn because I want to help Christian and Dscho get what they want, but having them be blocked on progress would reduce my stress. A lot.

From my perspective, git-replay's most important use is being able to generate rebases without a worktree or an interactive user. For now, I don't even care if that includes conflict resolution. That's enough of a lift that has enough unknowns that adding a complex CLI at this early stage seems like a hasty decision to me. I'm voicing my opinion that we should avoid backwards-compatibility issues by implementing only the essentials.

That said, I also want to make sure that you eventually get the super-flexible command that you want, but only when the framework is ready for that kind of flexibility.

Quoted 4 lines

Is there any chance people would be willing to accept a "NO BACKWARD COMPATIBILITY GUARANTEES" disclaimer on this command for a (long?) while, like Victoria suggested at Review club? That might be an alternate solution that would lower my worries.

I'm not crazy about this idea, especially when it is easy to do something simpler and avoid the need for it. But I'm just one voice and one opinion.

Thanks,
-Stolee

#23 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 22 lines · Derrick Stolee
Quoted 5 lines · Elijah Newren
Quoted 3 lines · Derrick Stolee
Quoted 1 line · Elijah Newren

On Tue, Apr 18, 2023 at 6:10 AM Derrick Stolee <[email protected]> wrote:

Quoted 8 lines
Quoted 4 lines

3. (Ordering options) Modifications to how those commits are ordered, such as --topo-order, --date-order, and --reverse. These seem to be overridden by git-replay (although, --reverse probably causes some confusion right now).

Yep, intentionally overridden.

Could you elaborate on what you mean by --reverse causing confusion?

It's very unlikely that a list of patches will successfully apply when applied in the reverse order. If we allow the argument, then someone will try it thinking they can flip their commits. Then they might be surprised when there are a bunch of conflicts on every commit.

Quoted 3 lines

Basically, I'm not super thrilled about exposing options that are unlikely to be valuable to users and instead are more likely to cause confusion due to changes that won't successfully apply.

Oh, I got thrown by the "right now" portion of your comment; I couldn't see how time or future changes would affect anything to make it less (or more) confusing for users.

Quick clarification, though: while you correctly point out the type of confusion the user would experience without my overriding, my overriding of rev.reverse (after setup_revisions() returns, not before it is called) precludes that experience. The override means none of the above happens, and they would instead just wonder why their option is being ignored.

[...]

Quoted 10 lines
Quoted 9 lines

The rest is all fair, but I'd like to point out that there are a few problems here:

* Tests should generally be passing before submitting upstream, so
all the code to implement them needs to be sent too
* Submitted patch series have to be digestible sizes; not everything
can be submitted at once
* Christian and Dscho wanted some of what I had implemented despite
other parts not being ready

Quoted 3 lines

Outside of my first response (using positional arguments, recommended before you provided the extra context I was missing) I have not suggested implementing something that can't be forward compatible.

True, and maybe I was misunderstanding, but I thought you were trying to make it forward compatible to only slight deviations while ruling out most potential future changes, including ones I was specifically highlighting as minimum eventual requirements. While it was clear that _some_ of the limitations you were trying to impose were only on v1, it sounded like you were also trying to rule out a wide swath of things permanently. That's where things really concerned me, and why I specifically asked which you were trying to do.

To be honest, I'm still unsure what your original intent was. But it probably doesn't matter now, as it sounds like you've shifted. I _think_ an accurate summary of where we are now at the end of this thread is:
* I am predominantly concerned about flexibility/potential for
git-replay in the future (what goes in v1 doesn't matter *if* it doesn't affect the future, but that's a huge "if").
* You are predominantly concerned about v1 and only including the
portions of functionality that have associated tests

I think there's enough wiggle room to mostly satisfy both viewpoints.

You helped with my concern by stating that categories (1) and (2) should be fine for git-replay in the future. (It at least handles the forms of potential lock-in that I already know about, though I'm worried there are others.)

I believe we can give you what you want via a tweak to the hack you previously suggested for v1 only: rule out passing any options with a leading dash to setup_revisions(), *and* throw an error if revs->prune_data.nr is nonzero after calling setup_revisions(). But I'd want us to include a comment pointing out that it's a hack, and include in that note that in the future we want to allow all options in categories (1) and (2) to be passed to setup_revisions() (or passed to a suitable refactoring thereof).

[...]

Quoted 28 lines
Quoted 19 lines
Quoted 2 lines

so your progress here isn't blocked on refactoring the revisions API.

Is that a positive or a negative? That question may surprise you, so let me explain.

I have a conflict of interest of sorts. When Christian and Dscho (separately) approached me earlier this year and pointed out that git-replay had the functionality they wanted, I was happy that others liked it, and gave some pointers here and there, but I was _very_ worried that upstreaming it would result in something getting backward-incompatibly locked into place that prevents the pieces that are still in progress from getting implemented. And I was concerned that my plans to create a tool people could experiment with, and that we could get usability feedback on (as I suggested at the Git contributors summit last year) might be in jeopardy as pieces of its functionality get locked into place before it's even ready for usability testing. I was silently hoping they'd lose steam on rebasing and cleaning up my patches or choose to just delay until I

Quoted 8 lines

could get real time to work on it with them. (Since then, the one person who had ever advocated for my Git work at $DAYJOB, the best manager I had ever worked under, became not-a-manager. I was blindsided by that in February. Also, I have been transferred to a different team and am spinning up there. And so, to my dismay, I'm worried my little sliver of Git time at work may evaporate entirely rather than return to previous healthier levels.) Anyway, I've been fretting about things getting "locked-in" for a few months.

Quoted 1 line

I'm also upset that you have been disrupted like this.

Thanks.

Quoted 5 lines
Quoted 4 lines

They didn't lose steam, as I found out when these patches were submitted. But, uh, I'm silently torn because I want to help Christian and Dscho get what they want, but having them be blocked on progress would reduce my stress. A lot.

Quoted 7 lines

From my perspective, git-replay's most important use is being able to generate rebases without a worktree or an interactive user. For now, I don't even care if that includes conflict resolution. That's enough of a lift that has enough unknowns that adding a complex CLI at this early stage seems like a hasty decision to me. I'm voicing my opinion that we should avoid backwards-compatibility issues by implementing only the essentials.

That comment is mostly reasonable, but I'd like to nit-pick the last
sentence: while limiting the series further for now is okay, I don't believe that only implementing the essentials is any kind of guarantee against backwards-compatibility issues. More on that below.

Quoted 3 lines

That said, I also want to make sure that you eventually get the super-flexible command that you want, but only when the framework is ready for that kind of flexibility.

Yaay!!!

Quoted 8 lines
Quoted 4 lines

Is there any chance people would be willing to accept a "NO BACKWARD COMPATIBILITY GUARANTEES" disclaimer on this command for a (long?) while, like Victoria suggested at Review club? That might be an alternate solution that would lower my worries.

I'm not crazy about this idea, especially when it is easy to do something simpler and avoid the need for it. But I'm just one voice and one opinion.

Sorry I wasn't clear. I wasn't suggesting this as a way of avoiding something simpler; I was suggesting it as an addition to doing something simpler, because it's not clear to me that doing something simpler is sufficient.

Actually, I think it goes a bit further than that. Most of my objections to various forms of simplifying are due to the fact that I think that simplifying greatly increases the risks of accidental backward compatibility issues.

Part of the reason why I feel that way is that simplifying has to go through future rounds of review and people may well respond with, "oh, that'd be easier if you just did <X> instead of <Y>" with an implicit assumption that there's no difference between them if <simplification Z> is being presented as all we need, since <X> and <Y> handle that simplification equally well. It's kind of hard to guess in advance all the forms that <X>, <Y>, and <Z> combined can take, and I also have no idea if I'll have time to respond to upcoming reviews in a timely fashion given current conditions, especially as I'm not the one submitting the patches, so simplifying is a *big* risk in my book. And this clearly isn't just theoretical, as this thread started precisely with a simplification suggestion that would have broken everything. But even more importantly, I didn't start git-replay until I found too many backward compatibility issues in rebase that just couldn't be resolved, and yet I know that when folks review patches they will make suggestions in line with what they are familiar with, likely meaning rebase-like behavior. So, "limiting to the essentials" sounds like "increase the risk of future problems" to me...unless we include a backward-compatibility-explicitly-not-guaranteed-right-now disclaimer from the beginning.

#24 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Hi Elijah & Stolee,

Quoted 31 lines · Elijah Newren
Quoted 22 lines · Derrick Stolee
Quoted 5 lines · Elijah Newren
Quoted 3 lines · Derrick Stolee
Quoted 1 line · Elijah Newren

On Tue, Apr 18, 2023 at 6:10 AM Derrick Stolee <[email protected]> wrote:

Quoted 8 lines
Quoted 4 lines

3. (Ordering options) Modifications to how those commits are ordered, such as --topo-order, --date-order, and --reverse. These seem to be overridden by git-replay (although, --reverse probably causes some confusion right now).

Yep, intentionally overridden.

Could you elaborate on what you mean by --reverse causing confusion?

It's very unlikely that a list of patches will successfully apply when applied in the reverse order. If we allow the argument, then someone will try it thinking they can flip their commits. Then they might be surprised when there are a bunch of conflicts on every commit.

Quoted 3 lines

Basically, I'm not super thrilled about exposing options that are unlikely to be valuable to users and instead are more likely to cause confusion due to changes that won't successfully apply.

Oh, I got thrown by the "right now" portion of your comment; I couldn't see how time or future changes would affect anything to make it less (or more) confusing for users.

Quoted 6 lines

Quick clarification, though: while you correctly point out the type of confusion the user would experience without my overriding, my overriding of rev.reverse (after setup_revisions() returns, not before it is called) precludes that experience. The override means none of the above happens, and they would instead just wonder why their option is being ignored.

FWIW here is my view on the matter: git replay, at least in its current incarnation, is a really low-level tool. As such, I actually do not want to worry much about protecting users from nonsensical invocations.

In that light, I would like to see that code rejecting all revision options except --diff-algorithm be dropped. Should we ever decide to add a non-low-level mode to git replay, we can easily add some user-friendly sanity check of the options then, and only for that non-low-level code. For now, I feel that it's just complicating things, and git replay is in the experimental phase anyway.

And further, I would even like to see that --reverse override go, and turn it into revs.reverse = !revs.reverse instead. (And yes, I can easily think of instances where I would have wanted to reverse a series of patches...).

Ciao,
Johannes

#25 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Hi Dscho,

Quoted 26 lines · Johannes Schindelin

Hi Elijah & Stolee,

Quoted 10 lines · Elijah Newren
Quoted 3 lines · Derrick Stolee

Basically, I'm not super thrilled about exposing options that are unlikely to be valuable to users and instead are more likely to cause confusion due to changes that won't successfully apply.

Oh, I got thrown by the "right now" portion of your comment; I couldn't see how time or future changes would affect anything to make it less (or more) confusing for users.

Quoted 6 lines

Quick clarification, though: while you correctly point out the type of confusion the user would experience without my overriding, my overriding of rev.reverse (after setup_revisions() returns, not before it is called) precludes that experience. The override means none of the above happens, and they would instead just wonder why their option is being ignored.

FWIW here is my view on the matter: git replay, at least in its current incarnation, is a really low-level tool. As such, I actually do not want to worry much about protecting users from nonsensical invocations.

Quoted 6 lines

In that light, I would like to see that code rejecting all revision options except --diff-algorithm be dropped. Should we ever decide to add a non-low-level mode to git replay, we can easily add some user-friendly sanity check of the options then, and only for that non-low-level code. For now, I feel that it's just complicating things, and git replay is in the experimental phase anyway.

I would be Ok with removing the patch (called "replay: disallow revision specific options and pathspecs")
that rejects all revision options and pathspecs if there is a consensus for that. It might not simplify things too much if there is still an exception for --diff-algorithm though. Also it's not clear if you are Ok with allowing pathspecs or not.

The idea with disallowing all of them was to later add back those that make sense along with tests and maybe docs to explain them in the context of this command. It was not to disallow them permanently. So I would think the best path forward would be a patch series on top of this one that would revert the patch disallowing these options and maybe pathspecs, and instead allow most of them and document and test things a bit.

Quoted 4 lines

And further, I would even like to see that --reverse override go, and turn it into revs.reverse = !revs.reverse instead. (And yes, I can easily think of instances where I would have wanted to reverse a series of patches...).

I think this might deserve docs and tests too, so it might want to be part of a separate patch series once the existing one has graduated.

At this point I don't think it's worth delaying this patch series for relatively small issues like this. There are many different ways this new command can be polished and improved. The important thing is that it looks like we all agree that the new command makes sense and should have roughly the basic set of features that Elijah originally implemented, so let's go with this, and then we can improve and iterate on top of this.

#26 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Hi Christian,

Quoted 33 lines · Christian Couder
Quoted 24 lines · Johannes Schindelin
Quoted 10 lines · Elijah Newren
Quoted 3 lines · Derrick Stolee

Basically, I'm not super thrilled about exposing options that are unlikely to be valuable to users and instead are more likely to cause confusion due to changes that won't successfully apply.

Oh, I got thrown by the "right now" portion of your comment; I couldn't see how time or future changes would affect anything to make it less (or more) confusing for users.

Quoted 6 lines

Quick clarification, though: while you correctly point out the type of confusion the user would experience without my overriding, my overriding of rev.reverse (after setup_revisions() returns, not before it is called) precludes that experience. The override means none of the above happens, and they would instead just wonder why their option is being ignored.

FWIW here is my view on the matter: git replay, at least in its current incarnation, is a really low-level tool. As such, I actually do not want to worry much about protecting users from nonsensical invocations.

Quoted 6 lines

In that light, I would like to see that code rejecting all revision options except --diff-algorithm be dropped. Should we ever decide to add a non-low-level mode to git replay, we can easily add some user-friendly sanity check of the options then, and only for that non-low-level code. For now, I feel that it's just complicating things, and git replay is in the experimental phase anyway.

Quoted 4 lines

I would be Ok with removing the patch (called "replay: disallow revision specific options and pathspecs")
that rejects all revision options and pathspecs if there is a consensus for that.

Well, since you talk about "consensus" and I already made my strong preference known, how about you add yours?

Quoted 3 lines

It might not simplify things too much if there is still an exception for --diff-algorithm though. Also it's not clear if you are Ok with allowing pathspecs or not.

I want to remove all the rev-list-option-disallowing code. Including the pathspec one.

Quoted 7 lines

The idea with disallowing all of them was to later add back those that make sense along with tests and maybe docs to explain them in the context of this command. It was not to disallow them permanently. So I would think the best path forward would be a patch series on top of this one that would revert the patch disallowing these options and maybe pathspecs, and instead allow most of them and document and test things a bit.

I understand that that was the reasoning.

What I would like to suggest is that we should treat git replay as a low-level (or: "plumbing" in Git Speak) command.

That would allow us to leave the option for stricter command-line parameter validation to an _additional_ option, to be added later (or never), and to stop worrying about this tool being used in ways that make no sense (or make no sense _to us_, _now_).

Quoted 6 lines
Quoted 4 lines

And further, I would even like to see that --reverse override go, and turn it into revs.reverse = !revs.reverse instead. (And yes, I can easily think of instances where I would have wanted to reverse a series of patches...).

I think this might deserve docs and tests too,

I agree.

Quoted 2 lines

so it might want to be part of a separate patch series once the existing one has graduated.

Here, I disagree. This is a bug, from my perspective, and needs to be fixed before graduating.

Quoted 7 lines

At this point I don't think it's worth delaying this patch series for relatively small issues like this. There are many different ways this new command can be polished and improved. The important thing is that it looks like we all agree that the new command makes sense and should have roughly the basic set of features that Elijah originally implemented, so let's go with this, and then we can improve and iterate on top of this.

If it were for a small issue such as a typo, sure.

But it is a bug that --no-reverse is hard-coded (in a confusing manner so because the reverse attribute is set), and the --no-reverse/--reverse options are ignored, silently so.

Ciao,
Johannes

#27 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

In reply to Elijah Newren
Quoted 6 lines · Elijah Newren
Quoted 1 line

For instance, can users pass multiple ranges?

There's no such thing as multiple ranges for most commands (see f302c1e4aa0 ("revisions(7): clarify that most commands take a single revision range", 2021-05-18))

Quoted 7 lines

However, users should absolutely be allowed to specify something like

  $ git replay --onto new-base master..my-topic some-base..other-topic

which is one revision range, and I'd expect replay to take commits in the history of either my-topic or other-topic, which are not in the history of either master or some-base, and replay them.

It is one revision range "^master ^some-base my-topic other-topic" if we let traditional revision parser to work on them, and in many topologies, it would mean something unexpected for users who thought that the user gave two ranges. E.g. some-base may be an ancestor of master, in which case commits in the "some-base..master" range is not included in the result. Or some-base may be able to reach my-topic, in which case no commits from master..my-topic range appears in the result, etc.

But should we be forever limited by the "A..B is always equivalent to ^A B"?

Shouldn't replaying master..my-topic and some-base..other-topic, when some-base is an ancestor of master, replay two overlapping range, possibly recreating some commits twice (when some-base falls in between master..my-topic, for example), if the user is willing to accept the consequences?

We can still keep the "so called 'range' is just commits that are reachable from a positive end and are not reachable from any negative end, and by definition there is no such thing as multiple ranges" as an option for advanced users and trigger the semantics when one negative end is written explicitly with ^A notation, but in applications like cherry-pick where it is convenient to work on multiple ranges, we may want to extend our worldview to allow A..B C..D (especially when these two are distinct ranges---imagine the case where B is an ancestor of C) to mean "we have two ranges, and we mean the union of the commits in these two ranges".

We'd need to design carefully what should happen for trickier cases like A..B C (does it mean the traditional "a single range of commits that are reachable from either B or C, but never reachable from A", or does it mean "the union of commits A..B that are reachable from B but not from A and commits C that are reachable from C all the way down to root"?), though.

#28 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

Quoted 35 lines · Junio C Hamano
Quoted 6 lines · Elijah Newren
Quoted 1 line

For instance, can users pass multiple ranges?

There's no such thing as multiple ranges for most commands (see f302c1e4aa0 ("revisions(7): clarify that most commands take a single revision range", 2021-05-18))

Quoted 7 lines

However, users should absolutely be allowed to specify something like

  $ git replay --onto new-base master..my-topic some-base..other-topic

which is one revision range, and I'd expect replay to take commits in the history of either my-topic or other-topic, which are not in the history of either master or some-base, and replay them.

It is one revision range "^master ^some-base my-topic other-topic" if we let traditional revision parser to work on them, and in many topologies, it would mean something unexpected for users who thought that the user gave two ranges. E.g. some-base may be an ancestor of master, in which case commits in the "some-base..master" range is not included in the result. Or some-base may be able to reach my-topic, in which case no commits from master..my-topic range appears in the result, etc.

But should we be forever limited by the "A..B is always equivalent to ^A B"?

Shouldn't replaying master..my-topic and some-base..other-topic, when some-base is an ancestor of master, replay two overlapping range, possibly recreating some commits twice (when some-base falls in between master..my-topic, for example), if the user is willing to accept the consequences?

Quoted 10 lines

We can still keep the "so called 'range' is just commits that are reachable from a positive end and are not reachable from any negative end, and by definition there is no such thing as multiple ranges" as an option for advanced users and trigger the semantics when one negative end is written explicitly with ^A notation, but in applications like cherry-pick where it is convenient to work on multiple ranges, we may want to extend our worldview to allow A..B C..D (especially when these two are distinct ranges---imagine the case where B is an ancestor of C) to mean "we have two ranges, and we mean the union of the commits in these two ranges".

Ooh, interesting.

That could also be of use in rebase-like operations (i.e. it'd serve as a way for the user to rebase while dropping the commits between B and C).

One thing to be careful about is that I think we would also need parent rewriting or some other hint that B was an ancestor of C for this to correctly work. Otherwise, this construction would just be mistaken for separate branches that are both being replayed. That may even matter for the cherry-pick case, since cherry-picking merge commits is part of the intended scope, preventing us from just assuming a fully linear range of commits to handle.

Quoted 6 lines

We'd need to design carefully what should happen for trickier cases like A..B C (does it mean the traditional "a single range of commits that are reachable from either B or C, but never reachable from A", or does it mean "the union of commits A..B that are reachable from B but not from A and commits C that are reachable from C all the way down to root"?), though.

Yes, and in things like "^D A..B C", we'd have to not only worry about whether A limits C, but also whether ^D limits A..B.

Thanks for the interesting food for thought.

#29 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

In reply to Derrick Stolee
Quoted 11 lines · Derrick Stolee

(I was able to get a segfault by rebasing this series with --author=stolee because the commit list became empty. Something to watch for.)

Quoted 6 lines

Something like:

'git replay [options] <base> <tip>' This mode means to rebase <tip> onto <base>, detecting the range of commits to rewrite.

Quoted 7 lines
Quoted 3 lines

'git replay [options] <new-base> <old-base> <tip>' This mode means to rebase the range <old-base>..<tip> onto <new-base>.

For that reason, I think we should be using explicit argument parsing in the builtin and only transform arguments we understand into the setup_revisions() (by building a strvec).

So, it turns out that this suggested solution wouldn't have helped prevent the segfault you found. If someone merely passed <old-base> == <tip>, they'd see the same segfault. In fact, I think you found a latent bug in merge-ort. In particular, cmd_replay() has

    struct merge_options merge_opt;
    struct merge_result result;

    init_merge_options(&merge_opt, the_repository);
    memset(&result, 0, sizeof(result));

    <do N merges, for some value of N>

    merge_finalize(&merge_opt, &result);

This code segfaults if N is 0, because merge_finalize() doesn't return early when result->priv is NULL.

We never triggered this before, because this is the very first code example we've had where someone has tried to call merge_finalize() without first performing a merge. Anyway, nice find and thanks for reporting!

#30 lore raw

Re: [PATCH 11/14] replay: use standard revision ranges

In reply to Derrick Stolee
Quoted 9 lines · Derrick Stolee
Quoted 6 lines · Christian Couder

From: Elijah Newren <[email protected]>

Instead of the fixed "<oldbase> <branch>" arguments, the replay command now accepts "<revision-range>..." arguments in a similar way as many other Git commands. This makes its interface more standard and more flexible.

Quoted 5 lines

Unfortunately, while doing this, you have broken the --onto logic:

 $ git replay --onto HEAD~2 HEAD~1 HEAD
 fatal: replaying down to root commit is not supported yet!

One of the things Christian asked/proposed a while ago was instead of modifying fast-rebase into git-replay, just build git-replay from the ground up. I argued for using fast-rebase as a starting point, but I think you've perhaps given an example for why I may have been wrong to do so. It has caused confusion, because fast-rebase used a very rigid syntax and specification (because it was a simple test script designed to handle exactly one simple setup) that is completely against what we want here.

In particular, you are probably thinking of

    $ git replay --onto HEAD~2 HEAD~1 HEAD
as meaning replay the commits in the range HEAD~1..HEAD (i.e. just
HEAD) with the new base of HEAD~2.  That's the inflexible way
fast-rebase worked.  We are dispensing with that here, though; your
command means replay the commits in the history of either HEAD~1 or
HEAD (all the way to the root since you had no negative references) on
top of HEAD~2.  If you had instead said:
    $ git replay --onto HEAD~2 HEAD~1..HEAD
then I think `git replay` handles it just fine.  Christian did cover
this in the commit message, but it's perhaps subtle and easily missed.

Anyway, at no point in this series does git replay support rebasing commits back to the root, so the error message is what I'd expect. The problem was we weren't clear enough about a different syntax being expected.

Quoted 21 lines

The rev-walk you are supplying by this line...

Quoted 1 line

+ argc = setup_revisions(argc, argv, &revs, NULL);

is taking the remaining arguments and using them as tips to walk. We need to be able to recognize that --onto A B C means that A is the new base and our walk is B..C.

I'm not sure if there might be a way to use a callback for the --onto option and pull out the next three options into 'new-base', 'old-base', 'tip' values or something.

Overall, I don't think being flexible in the CLI is of high value for this command. Let's be as prescriptive as possible.

Something like:

'git replay [options] <base> <tip>' This mode means to rebase <tip> onto <base>, detecting the range of commits to rewrite.

Quoted 5 lines

'git replay [options] <new-base> <old-base> <tip>' This mode means to rebase the range <old-base>..<tip> onto <new-base>.

We don't even need "--onto" for these positional arguments.

So, from my view, the problem with this alternative design is that it inflexibly hardcodes a linear range of commits, in a way that likely precludes future extension. In particular it:

* precludes handling multiple divergent branches, which I think was
a core design requirement
* seems problematic for extending this to handle replaying of merges
(where being able to select what to replay needs more control)
* more generally from the above two, this precludes the opportunity
to specify both multiple positive and negative refs
* precludes things like using --ancestry-path=<commit> which was
specifically designed for use with git-replay[1]
* may not work well with --first-parent, which I think should be
allowed (in fact, --first-parent in some instances is a specialization of --ancestry-path=<commit>)
* seems to presume that rebasing is the only thing we want to do,
possibly precluding supporting cherry-pick-like commands

[1] See https://lore.kernel.org/git/CABPp-BHmj+QCBFDrH77iNfEU41V=UDu7nhBYkAbCsbXhshJzzw@mail.gmail.com/,
look for "Here's my usecase"

And on a minor note, it also copies the positional argument UI design from rebase that I've always considered to be an annoying UI design flaw. (Not sure if others agree with me on that, but it's always bothered me.)

Since you followed up on this, I'll add more detail in response to your other email.

#31 lore raw

PATCH 12/14 replay: introduce guess_new_base()

In reply to Christian Couder

From: Elijah Newren <[email protected]>

In many cases the --onto option is not necessary as we can guess the branch we would like to replay onto.

So let's introduce guess_new_base() for that purpose and make --onto optional.

---
 Documentation/git-replay.txt |  8 ++++-
 builtin/replay.c             | 61 +++++++++++++++++++++++++++++++-----
 2 files changed, 61 insertions(+), 8 deletions(-)
Documentation/git-replay.txt +7 -1
index 7a83f70343..ce2cafc42e 100644
@@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree
 SYNOPSIS
 --------
 [verse]
-'git replay' --onto <newbase> <revision-range>...
+'git replay' [--onto <newbase>] <revision-range>...
 
 DESCRIPTION
 -----------
@@ -20,6 +20,12 @@ references.  However, the output of this command is meant to be used
 as input to `git update-ref --stdin`, which would update the relevant
 branches.
 
+When the `--onto <newbase>` option is not passed, the commits will be
+replayed onto a base guessed from the `<revision-range>`.  For example
+if the `<revision-range>` is `origin/main..mybranch` then `mybranch`
+was probably based on an old version of `origin/main`, so we will
+replay it on the newest version of that branch.
+
 OPTIONS
 -------
 
builtin/replay.c +54 -7

85 lines not on this page · raw message

Signature · 1 line
2.40.0.228.gb2eb5bb98e
#32 lore raw

PATCH 13/14 replay: add different modes

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

While at it, let's also add a --contained that can be used along with --onto to rebase all the branches contained in the <revision-range> argument.

---
 Documentation/git-replay.txt |  58 +++++++++--
 builtin/replay.c             | 185 +++++++++++++++++++++++++++++------
 t/t3650-replay-basics.sh     |  45 +++++++++
 3 files changed, 247 insertions(+), 41 deletions(-)
Documentation/git-replay.txt +48 -10
index ce2cafc42e..d714c72188 100644
@@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree
 SYNOPSIS
 --------
 [verse]
-'git replay' [--onto <newbase>] <revision-range>...
+'git replay' [--contained] [--onto <newbase> | --advance <branch>] <revision-range>...
 
 DESCRIPTION
 -----------
@@ -20,11 +20,12 @@ references.  However, the output of this command is meant to be used
 as input to `git update-ref --stdin`, which would update the relevant
 branches.
 
-When the `--onto <newbase>` option is not passed, the commits will be
-replayed onto a base guessed from the `<revision-range>`.  For example
-if the `<revision-range>` is `origin/main..mybranch` then `mybranch`
-was probably based on an old version of `origin/main`, so we will
-replay it on the newest version of that branch.
+When neither the `--onto <newbase>` option nor the
+`--advance <branch>` option are passed, the commits will be replayed
+onto a base guessed from the `<revision-range>`.  For example if the
+`<revision-range>` is `origin/main..mybranch` then `mybranch` was
+probably based on an old version of `origin/main`, so we will replay
+it on the newest version of that branch.
 
 OPTIONS
 -------
@@ -33,9 +34,17 @@ OPTIONS
 	Starting point at which to create the new commits.  May be any
 	valid commit, and not just an existing branch name.
 +
-The update-ref commands in the output will update the branch(es)
-in the revision range to point at the new commits (in other
-words, this mimics a rebase operation).
+When `--onto` is specified, the update-ref command(s) in the output will
+update the branch(es) in the revision range to point at the new
+commits (in other words, this mimics a rebase operation).
+
+--advance <branch>::
+	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).
 
 <revision-range>::
 	Range of commits to replay; see "Specifying Ranges" in
@@ -51,7 +60,10 @@ input to `git update-ref --stdin`.  It is basically of the form:
 	update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
 	update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
 
-where the number of refs updated depend on the arguments passed.
+where the number of refs updated depend on the arguments passed.  When
+using `--advance`, the number of refs updated is always one, but for
+`--onto`, it can be one or more (rebasing multiple branches
+simultaneously is supported).
 
 EXIT STATUS
 -----------
@@ -71,6 +83,32 @@ $ 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.
+
+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}
+------------
+
+In contrast, trying to do this with rebase would require 3 separate
+rebases, eacho of which involves a different <ONTO> and <UPSTREAM> and
+forces you to first check out each branch in turn.
+
 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:
builtin/replay.c +154 -31

270 lines not on this page · raw message

t/t3650-replay-basics.sh +45 -0

49 lines not on this page · raw message

Signature · 1 line
2.40.0.228.gb2eb5bb98e
#33 lore raw

PATCH 14/14 replay: stop assuming replayed branches do not diverge

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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 reused a replayed commit instead of the original one.

---
 builtin/replay.c         | 44 ++++++++++++++++++++++++++--------
 t/t3650-replay-basics.sh | 52 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 10 deletions(-)
builtin/replay.c +34 -10
index 63b3ad518e..71815d5ca3 100644
@@ -216,20 +216,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 = get_commit_tree(replayed_base);
 	pickme_tree = get_commit_tree(pickme);
 	base_tree = get_commit_tree(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);
 
@@ -243,7 +256,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)
@@ -259,6 +272,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[] = {
@@ -312,18 +326,20 @@ 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 = get_commit_tree(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) {
 			/* TODO: handle conflicts in sparse worktree instead */
@@ -350,6 +366,13 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 			    oid_to_hex(&commit->object.oid));
 		}
 
+		/* 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;
@@ -379,13 +402,14 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 
 	/* Cleanup */
 	merge_finalize(&merge_opt, &result);
-	ret = result.clean;
-
-cleanup:
+	kh_destroy_oid_map(replayed_commits);
 	if (update_refs) {
 		strset_clear(update_refs);
 		free(update_refs);
 	}
+	ret = result.clean;
+
+cleanup:
 	release_revisions(&revs);
 
 	/* Return */
t/t3650-replay-basics.sh +52 -0

56 lines not on this page · raw message

Signature · 1 line
2.40.0.228.gb2eb5bb98e
#34 lore raw
In reply to Christian Couder

Hi Christian and Elijah

Quoted 18 lines · Christian Couder

# Intro

git replay has initially been developed entirely by Elijah Newren mostly between June and July 2022 at:

https://github.com/newren/git/commits/replay

I took over a few months ago to polish and upstream it as GitLab is interested in replacing libgit2, and for that purpose needs a command to do server side (so without using a worktree) rebases, cherry-picks and reverts.

I reduced the number of commits and features in this first patch series, compared to what Elijah already developed. Especially I stopped short of replaying merge commits and replaying interactively. These and other features might be upstreamed in the future after this patch series has graduated.

Quoted 4 lines

Thanks to Elijah, Patrick Steinhardt and Dscho for early reviews and discussions.

Based on ae73b2c8f1 (The seventh batch, 2023-04-04)

Thanks to both of you for working on this it looks very interesting. I've had a quick read over the patches and I ended up slightly confused as to exactly what the aim of this series is. My main confusion is whether "replay" is intended to be a plumbing command or a porcelain command. The use case above suggests plumbing and there are patches that take it in that direction by removing any diagnostic output and stopping it update any refs. But then it is marked as porcelain in command-list.txt and there are patches that do things like unconditionally updating the index and worktree when there are conflicts that stop it working in bare repositories. I've left some comments below

Quoted 32 lines

# Quick Overview (from Elijah)

git replay, at a basic level, can perhaps be thought of as a "default-to-dry-run rebase" -- meaning no updates to the working tree, or to the index, or to any references. However, it differs from rebase in that it:

* Works for branches that aren't checked out
* Works in a bare repository
* Can replay multiple branches simultaneously (with or without common history in the range being replayed)
* Preserves relative topology by default (merges are replayed too)
* Focuses on performance
* Has several altered defaults as a result of the above

I sometimes think of git replay as "fast-replay", a patch-based analogue to the snapshot-based fast-export & fast-import tools.

# Reasons for diverging from cherry-pick & rebase (from Elijah)

There are multiple reasons to diverge from the defaults in cherry-pick and rebase.

* Server side needs

* Both cherry-pick and rebase, via the sequencer, are heavily tied to updating the working tree, index, some refs, and a lot of control files with every commit replayed, and invoke a mess of hooks[1] that might be hard to avoid for backward compatibility reasons (at least, that's been brought up a few times on the list).

Quoted 4 lines

* cherry-pick and rebase both fork various subprocesses unnecessarily, but somewhat intrinsically in part to ensure the same hooks are called that old scripted implementations would have called.

To clarify, since 356ee4659bb (sequencer: try to commit without forking 'git commit', 2017-11-24) cherry-pick and rebase do not fork subprocesses other than hooks for the cases covered by this patch series (i.e. they do not fork "git commit" for simple picks).

Quoted 6 lines

* "Dry run" behavior, where there are no updates to worktree, index, or even refs might be important.

* Should not assume users only want to operate on HEAD (see next section)

Quoted 8 lines

* Decapitate HEAD-centric assumptions

* cherry-pick forces commits to be played on top of HEAD; inflexible.

* rebase assumes the range of commits to be replayed is upstream..HEAD by default, though it allows one to replay upstream..otherbranch -- but it still forcibly and needlessly checks out otherbranch before starting to replay things.

I agree it would be nice to be able to restrict the range of commits replayed, especially when replaying merges. The comment about checking out other branch is out of date since 767a9c417eb (rebase -i: stop checking out the tip of the branch to rebase, 2020-01-24)

Quoted 2 lines

* Assuming HEAD is involved severely limits replaying multiple (possibly divergent) branches.

I'm not sure how true this is anymore, since 89fc0b53fdb (rebase: update refs from 'update-ref' commands, 2022-07-19) the sequencer can update multiple branches. The issue with divergent branch is with command line arguments and the todo list generation rather than the capabilities of the sequencer.

Quoted 4 lines

* Once you stop assuming HEAD has a certain meaning, there's not much reason to have two separate commands anymore (except for the funny extra not-necessarily-compatible options both have gained over time).

I agree having a unified command at the plumbing level certainly makes sense.

Quoted 3 lines

* (Micro issue: Assuming HEAD is involved also makes it harder for new users to learn what rebase means and does; it makes command lines hard to parse.

That's an interesting point, I wonder if operating on branches that are not checked out is potentially confusing for new user though.

Quoted 10 lines

Not sure I want to harp on this too much, as
I have a suspicion I might be creating a tool for experts with complicated use cases, but it's a minor quibble.)

* Performance

* jj is slaughtering us on rebase speed[2]. I would like us to become competitive. (I dropped a few comments in the link at [2] about why git is currently so bad.)

Quoted 7 lines

* From [3], there was a simple 4-patch series in linux.git that took 53 seconds to rebase. Switching to ort dropped it to 16 seconds. While that sounds great, only 11 *milliseconds* were needed to do the actual merges. That means almost *all* the time (>99%) was overhead! Big offenders:

* --reapply-cherry-picks should be the default

I agree that can be a performance hit if there are a lot of upstream commits, but it is also a usability feature as it means we don't stop and ask the user what to do with the commits that have been upstreamed which wastes more of their time. I think maybe we want different defaults for the server use case than the user replaying commits or perhaps default to dropping commits that become empty.

Quoted 2 lines

* can_fast_forward() should be ripped out, and perhaps other extraneous revision walks

We should look at doing that at least for the merge backend which has skip_unnecessary_picks(). I think it is useful to tell the user that the branch was not updated by the rebase though.

Quoted 3 lines

* avoid updating working tree, index, refs, reflogs, and control structures except when needed (e.g. hitting a conflict, or operation finished)

Not writing to disc unless we need to is sensible. Having said that for interactive rebases I do find having HEAD's reflog record all the picks useful to unpick what went wrong if mess something up.

Quoted 3 lines

* Other performance ideas:

* single-file control structures instead of directory of files

I like the idea as it should make it easier to keep the on disc state consistent, but I'm not sure how much of an issue that is in practice as we only read/write the files once each time git is run. The bigger slow down is writing the author script, commit message, list of rewritten commits, todo list and done files with each pick.

Quoted 3 lines

* avoid forking subprocesses unless explicitly requested (e.g. --exec, --strategy, --run-hooks). For example, definitely do not invoke git commit or git merge.

Good, that matches what the sequencer does for non-merge commits when we're not editing the commit message.

Quoted 4 lines

* Sanitize hooks:

* dispense with all per-commit hooks for sure (pre-commit, post-commit, post-checkout).

I agree we should not be running those (we don't run the pre-commit hook anyway). However we had a bug report when cherry-pick stopped running the "prepare-commit-msg" hook (see https://lore.kernel.org/git/CAKdAkRQuj1hfKeckjuR2oP+8C1i+ZR36O-+aRYif4ufaS_zs+w@mail.gmail.com/). That shouldn't matter for the server but we should bear it in mind when it comes to other use cases.

Quoted 4 lines

* pre-rebase also seems to assume exactly 1 ref is written, and invoking it repeatedly would be stupid. Plus, it's specific to "rebase". So...ignore? (Stolee's --ref-update option for rebase probably broke the pre-rebase assumptions already...)

If replay is a plumbing command then skipping the pre-rebase hook makes sense as scripts can call it themselves if they want to. For a porcelain command keeping a hook that can prevent it from rewriting commits that are already upstream (which I think is one of the main uses of the pre-rebase hook) would be good.

Quoted 3 lines

* post-rewrite hook might make sense, but fast-import got exempted, and I think of replay like a patch-based analogue to the snapshot-based fast-import.

If we don't call the hook it would be good to have a option that outputs that information so scripts can request it if they want. Also we should think about if/when we want to update the notes associated with replayed commits.

Quoted 13 lines

* When not running server side, resolve conflicts in a sparse-cone sparse-index worktree to reduce number of files written to a working tree. (See below as well)

* [High risk of possible premature optimization] Avoid large numbers of newly created loose objects, when replaying large numbers of commits. Two possibilities: (1) Consider using tmp-objdir and pack objects from the tmp-objdir at end of exercise, (2) Lift code from git-fast-import to immediately stuff new objects into a pack?

* Multiple branches and non-checked out branches

Quoted 8 lines

* The ability to operate on non-checked out branches also implies that we should generally be able to replay when in a dirty working tree (exception being when we expect to update HEAD and any of the dirty files is one that needs to be updated by the replay).

* Also, if we are operating locally on a non-checked out branch and hit a conflict, we should have a way to resolve the conflict without messing with the user's work on their current branch.

That sounds tricky to do in a user friendly way.

Quoted 3 lines

* Idea: new worktree with sparse cone + sparse index checkout, containing only files in the root directory, and whatever is necessary to get the conflicts

If the user has not asked for a sparse checkout then this could be surprising. Sometimes I find it helpful to be able to poke about in other source files when resolving a conflict. I also often build and test after resolving a conflict which requires more than just the conflict to be checked out.

Quoted 4 lines

* Companion to above idea: control structures should be written to $GIT_COMMON_DIR/replay-${worktree}, so users can have multiple replay sessions, and so we know which worktrees are associated with which replay operations.

We certainly want some way of making sure we only update a given ref in one replay session, and have checks to for whether the ref is checked out anywhere as we do now for rebase --update-refs. That seems to be lacking in the patches adding ref updating in this series.

Quoted 8 lines

- [1] https://lore.kernel.org/git/[email protected]/
- [2] https://github.com/martinvonz/jj/discussions/49
- [3] https://lore.kernel.org/git/CABPp-BE48=97k_3tnNqXPjSEfA163F8hoE+HY0Zvz1SWB2B8EA@mail.gmail.com/

# Important limitations

* The code die()s if there are any conflict. No resumability. No nice output. No interactivity.

I can see that on a server you might not want any output, but if I run it locally it would be nice to have a message saying which paths have conflicts. Maybe we could add a --quiet flag for the server rather than removing the existing messages?

Quoted 1 line

* No replaying merges, nor root commits. Only regular commits.

That is a reasonable place to start.

Quoted 2 lines

* Signed commits are not properly handled. It's not clear what to do to such commits when replaying on the server side.

Yes on the server where you don't have access to the signing key there is not much need for replay to have a signing option.

Quoted 75 lines

# Commit overview

* 1/14 replay: introduce new builtin

This creates a minimal git replay command by moving the code from the fast-rebase test helper from t/helper/ into builtin/ and doing some renames and a few other needed changes.

* - 2/14 replay: start using parse_options API
- 3/14 replay: die() instead of failing assert()
- 4/14 replay: introduce pick_regular_commit()
- 5/14 replay: don't simplify history
- 6/14 replay: add an important FIXME comment about gpg signing
- 7/14 replay: remove progress and info output
- 8/14 replay: remove HEAD related sanity check

These slowly change the command to make it behave more like a regular commands and to start cleaning up its output.

* 9/14 replay: very coarse worktree updating

Make it handle conflicts in a very coarse way. This might not work on bare repos, but it allows existing tests to pass and it's nice to help cli users a bit when they get conflicts.

* 10/14 replay: make it a minimal server side command

After the cleaning up in previous ommits, it's now time to radically change the way it works by stopping it to do ref updates, to update the index and worktree, to consider HEAD as special. Instead just make it output commands that should be passed to git update-ref --stdin.

* - 11/14 replay: use standard revision ranges
- 12/14 replay: introduce guess_new_base()
- 13/14 replay: add different modes
- 14/14 replay: stop assuming replayed branches do not diverge

These finish the clean up and add new interesting features at the same time, as well as related documentation and tests.

# Note about tests and documentation

Note that the fast-rebase test helper was used before this series in

t6429-merge-sequence-rename-caching.sh

So when git replay is created from fast-rebase in patch 1/14, this test script is also converted to use git replay. This ensures that git replay doesn't break too badly during the first 10 patches in this patch series.

Tests and documentation are introduced specifically for git replay only in 11/14 and later patches as it doesn't make much sense to document and test behavior that we know is going to change soon. So it's only when the command is crystalizing towards its final form that we start documenting and testing it.

# Possibly controversial issues

* bare or not bare: this series works towards a command with the end goal of it being usable and used on bare repos, contrary to existing commands like git rebase and git cherry-pick, but the tests currently don't check that, and in case of conflicts it won't currently work on bare repos. One reason for that is that existing tests in t6429 should continue to work, and one of these tests requires some output in case of conflict. And it's nice for users to get some help in case of conflict. It's also nice for users if commands that should work on both bare and non bare repos work well on non bare repos first as they are less likely to use them on bare repos. So let's have a command that works well on non-bare repos first, even if its end goal is to work fine on bare repos too. We plan to improve things for bare repos soon after this first patch series graduates.

Quoted 10 lines

* exit status: a successful, non-conflicted replay exits with code
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. It has been suggested in an internal review that conflicts might want to get a more specific error code as an error code of 1 might be quite easy to return by accident. It doesn't seem to me from their docs (which might want to be improved, I didn't look at the code) that other commands like git merge and git rebase exit with a special error code in case of conflict.

I don't think we've ever had a special "conflict" error code but it would be useful for scripts if replay had one. Does replay return a different exit code for "merge conflicts" and "cannot merge because it would overwrite an untracked file"? Does it have an exit code for "the commit becomes empty" or are those patches unconditionally dropped?

Quoted 11 lines

* to guess or not to guess: commit 12/14 introduces the guess_new_base() function which tries to find a base to rebase onto when the --onto option is not provided, making this option actually optional instead of mandatory. Given that it's an heuristic and the command end goal is to be used on server side, we might want to introduce this as an iterative improvement later. I still think it's interesting to have it in for now though, as it shows that --onto and --advance (which is introduced in the following commit) should indeed be options. If --onto was always mandatory in the series, people could argue that it shouldn't be an option and its argument should always be the first (unconditional) argument of the command.

I think it comes down to "what's the aim of this series?" is it focused on the bare repository server use case or is it trying to add a general purpose cli tool.

Quoted 7 lines

* make worktree and index changes optional: commit 10/14 stops updating the index and worktree, but it might be better especially for cli users to make that optional. The issue is that this would make the command more complex while we are developing a number of important features. It seems to me that this should rather be done in an iterative improvement after the important features have landed.

I'm confused by this as patch 9 seems to start updating the index and worktree when there are conflicts but patch 10 stops updating the index and worktree if the replay is successful.

Quoted 12 lines

* when and where to add tests and docs: although t6429 has tests that are changed to use the new command instead of the fast-rebase test-tool command as soon as the former is introduced, there is no specific test script and no doc for the new command until commit 11/14 when standard revision ranges are used. This is done to avoid churn in tests and docs while the final form of the command hasn't crystalized enough. Adding tests and doc at this point makes this commit quite big and possibly more difficult to review than if they were in separate commits though. On the other hand when tests and docs are added in specific commits some reviewers say it would be better to introduce them when the related changes are made.

Quoted 6 lines

* --advance and --contained: these two advanced options might not belong to this first series and could perhaps be added in a followup series in separate commits. On the other hand the code for --contained seems involved with the code of --advance and it's nice to see soon that git replay can indeed do cherry-picking and rebase many refs at once, and this way fullfil these parts of its promise.

Once I understood what these options did the names made sense, but I could not tell from the names what they were going to do. For me "--cherry-pick" and "--update-refs" would have been clearer. It might be worth splitting this patch so the individual options are added separately.

Quoted 6 lines

* replaying diverging branches: 14/14 the last patch in the series, which allow replaying diverging branches, can be seen as a fundamental fix or alternatively as adding an interesting feature. So it's debatable if it should be in its own patch along with its own tests as in this series, or if it should be merged into a previous patch and which one.

It might make sense to add this in the same patch as you add --contained.

Quoted 8 lines

* only 2 patches: this patch series can be seen from a high level point of view as 1) introducing the new git replay command, and 2) using git replay to replace, and get rid of, the fast-rebase test-tool command. The fact that not much of the original fast-rebase code and interface is left would agree with that point of view. On the other hand, fast-rebase can also be seen as a first iteration towards git replay. So it can also make sense to see how git replay evolved from it.

Starting with fast-rebase means one has to checkout the first patch to see what code we're adding to replay.c and to make sense of the later patches that remove code. It would be interesting to compare this series to one that started from scratch but I guess that would be quite a bit of work.

Thanks for working on this, I'm interested to see where it goes

Best Wishes

Phillip

Quoted 35 lines

Elijah Newren (14):
replay: introduce new builtin
replay: start using parse_options API
replay: die() instead of failing assert()
replay: introduce pick_regular_commit()
replay: don't simplify history
replay: add an important FIXME comment about gpg signing
replay: remove progress and info output
replay: remove HEAD related sanity check
replay: very coarse worktree updating
replay: make it a minimal server side command
replay: use standard revision ranges
replay: introduce guess_new_base()
replay: add different modes
replay: stop assuming replayed branches do not diverge

  .gitignore                               |   1 +
  Documentation/git-replay.txt             | 130 +++++++
  Makefile                                 |   2 +-
  builtin.h                                |   1 +
  builtin/replay.c                         | 419 +++++++++++++++++++++++
  command-list.txt                         |   1 +
  git.c                                    |   1 +
  t/helper/test-fast-rebase.c              | 233 -------------
  t/helper/test-tool.c                     |   1 -
  t/helper/test-tool.h                     |   1 -
  t/t3650-replay-basics.sh                 | 160 +++++++++
  t/t6429-merge-sequence-rename-caching.sh |  43 ++-
  12 files changed, 739 insertions(+), 254 deletions(-)

create mode 100644 Documentation/git-replay.txt
create mode 100644 builtin/replay.c
delete mode 100644 t/helper/test-fast-rebase.c
create mode 100755 t/t3650-replay-basics.sh

#35 lore raw

Hi Phillip,

Quoted 27 lines · Phillip Wood

Hi Christian and Elijah

Quoted 18 lines · Christian Couder

# Intro

git replay has initially been developed entirely by Elijah Newren mostly between June and July 2022 at:

https://github.com/newren/git/commits/replay

I took over a few months ago to polish and upstream it as GitLab is interested in replacing libgit2, and for that purpose needs a command to do server side (so without using a worktree) rebases, cherry-picks and reverts.

I reduced the number of commits and features in this first patch series, compared to what Elijah already developed. Especially I stopped short of replaying merge commits and replaying interactively. These and other features might be upstreamed in the future after this patch series has graduated.

Quoted 4 lines

Thanks to Elijah, Patrick Steinhardt and Dscho for early reviews and discussions.

Based on ae73b2c8f1 (The seventh batch, 2023-04-04)

Quoted 10 lines

Thanks to both of you for working on this it looks very interesting. I've had a quick read over the patches and I ended up slightly confused as to exactly what the aim of this series is. My main confusion is whether "replay" is intended to be a plumbing command or a porcelain command. The use case above suggests plumbing and there are patches that take it in that direction by removing any diagnostic output and stopping it update any refs. But then it is marked as porcelain in command-list.txt and there are patches that do things like unconditionally updating the index and worktree when there are conflicts that stop it working in bare repositories. I've left some comments below

Yeah, that's fair. It was totally unclear in my work-in-progress patches, as I had ideas taking it in both directions. Then Christian and Dscho came along and said they wanted to use it for server-side rebasing & cherry-picking. Christian did some good cleanup of my patches, but I think your comment here is just reflecting that there's still a bit more to do.

I'd say for now that we should expunge the worktree & index updating, any conflict handling beyond exit status, mark it as plumbing, and focus strictly on server-side use for now.

Quoted 37 lines
Quoted 32 lines

# Quick Overview (from Elijah)

git replay, at a basic level, can perhaps be thought of as a "default-to-dry-run rebase" -- meaning no updates to the working tree, or to the index, or to any references. However, it differs from rebase in that it:

* Works for branches that aren't checked out
* Works in a bare repository
* Can replay multiple branches simultaneously (with or without common history in the range being replayed)
* Preserves relative topology by default (merges are replayed too)
* Focuses on performance
* Has several altered defaults as a result of the above

I sometimes think of git replay as "fast-replay", a patch-based analogue to the snapshot-based fast-export & fast-import tools.

# Reasons for diverging from cherry-pick & rebase (from Elijah)

There are multiple reasons to diverge from the defaults in cherry-pick and rebase.

* Server side needs

* Both cherry-pick and rebase, via the sequencer, are heavily tied to updating the working tree, index, some refs, and a lot of control files with every commit replayed, and invoke a mess of hooks[1] that might be hard to avoid for backward compatibility reasons (at least, that's been brought up a few times on the list).

Quoted 4 lines

* cherry-pick and rebase both fork various subprocesses unnecessarily, but somewhat intrinsically in part to ensure the same hooks are called that old scripted implementations would have called.

Quoted 4 lines

To clarify, since 356ee4659bb (sequencer: try to commit without forking 'git commit', 2017-11-24) cherry-pick and rebase do not fork subprocesses other than hooks for the cases covered by this patch series (i.e. they do not fork "git commit" for simple picks).

Thanks for the clarification.

Let me also add a clarification about this text you're responding to:
the document that Christian copied into this portion of the cover letter wasn't talking about this particular series he submitted, but about the broader design goals I was working on. I don't want a run_git_commit() function within replay.c, even for commit message editing, for picking merge commits, or for handling staged changes after resuming from an interactive rebase. I'd even say I don't want it for failure handling, either, though that one is less important.

Quoted 15 lines
Quoted 6 lines

* "Dry run" behavior, where there are no updates to worktree, index, or even refs might be important.

* Should not assume users only want to operate on HEAD (see next section)

Quoted 8 lines

* Decapitate HEAD-centric assumptions

* cherry-pick forces commits to be played on top of HEAD; inflexible.

* rebase assumes the range of commits to be replayed is upstream..HEAD by default, though it allows one to replay upstream..otherbranch -- but it still forcibly and needlessly checks out otherbranch before starting to replay things.

Quoted 4 lines

I agree it would be nice to be able to restrict the range of commits replayed, especially when replaying merges. The comment about checking out other branch is out of date since 767a9c417eb (rebase -i: stop checking out the tip of the branch to rebase, 2020-01-24)

Guess how many years I've been gathering my ideas for git-replay. ;-)

One thing to note here, though, is the checkout handling still isn't fully fixed, and it may be impossible to fix at this point. In particular, git rebase --abort doesn't return people to the original branch when otherbranch is specified, which is problematic in conjunction with other options (see e.g.
https://lore.kernel.org/git/[email protected]/).

Quoted 8 lines
Quoted 2 lines

* Assuming HEAD is involved severely limits replaying multiple (possibly divergent) branches.

I'm not sure how true this is anymore, since 89fc0b53fdb (rebase: update refs from 'update-ref' commands, 2022-07-19) the sequencer can update multiple branches. The issue with divergent branch is with command line arguments and the todo list generation rather than the capabilities of the sequencer.

Yeah, this particular paragraph I suspect is from about 18 months ago. (See also where I responded to the update-refs series about this
https://lore.kernel.org/git/CABPp-BEOV53oBoBp4YjiRfksZMmAADanZUUemhxwn7Wor=m-nA@mail.gmail.com/).

However, I'd still say the statement is true, it just needs to be focused on the divergent branches. The use of HEAD (or more generally exactly 3 commitish-es), as done in rebase, is going to make it really awkward to introduce any kind of command line UI for handling rebasing of multiple divergent branches. I'm not sure it even makes sense. git-replay has done it for over a year, and I think it makes sense specifically because it got rid of the problematic assumptions hard-wired into the command line UI.

Quoted 7 lines
Quoted 4 lines

* Once you stop assuming HEAD has a certain meaning, there's not much reason to have two separate commands anymore (except for the funny extra not-necessarily-compatible options both have gained over time).

I agree having a unified command at the plumbing level certainly makes sense.

:-)

Quoted 6 lines
Quoted 3 lines

* (Micro issue: Assuming HEAD is involved also makes it harder for new users to learn what rebase means and does; it makes command lines hard to parse.

That's an interesting point, I wonder if operating on branches that are not checked out is potentially confusing for new user though.

Yes, absolutely. Especially since I'm very focused on having operations be O(changes), not O(size-of-repo). The amount of work people go through to avoid backporting because checking out other branches is too expensive is impressive. But designing things for the user that needs scaling to big repos isn't always the friendliest to new users. And I admittedly am focused on performance above other aspects, and in some cases that might leave new users behind.

Quoted 3 lines
Quoted 3 lines

Not sure I want to harp on this too much, as
I have a suspicion I might be creating a tool for experts with complicated use cases, but it's a minor quibble.)

Oh, heh. I guess I knew at the time I wrote this that people might point out ways I was not being newbie friendly. :-)

Quoted 12 lines
Quoted 12 lines

* Performance

* jj is slaughtering us on rebase speed[2]. I would like us to become competitive. (I dropped a few comments in the link at [2] about why git is currently so bad.)

* From [3], there was a simple 4-patch series in linux.git that took 53 seconds to rebase. Switching to ort dropped it to 16 seconds. While that sounds great, only 11 *milliseconds* were needed to do the actual merges. That means almost *all* the time (>99%) was overhead! Big offenders:

Quoted 8 lines
Quoted 1 line

* --reapply-cherry-picks should be the default

I agree that can be a performance hit if there are a lot of upstream commits, but it is also a usability feature as it means we don't stop and ask the user what to do with the commits that have been upstreamed which wastes more of their time. I think maybe we want different defaults for the server use case than the user replaying commits or perhaps default to dropping commits that become empty.

Oh, sure, there are people who will like different options and configurations. Non-performant features can certainly be options, I was mostly harping on the defaults for git-replay. It should default to fast, even if/when it moves beyond server-side only.

Quoted 6 lines
Quoted 2 lines

* can_fast_forward() should be ripped out, and perhaps other extraneous revision walks

We should look at doing that at least for the merge backend which has skip_unnecessary_picks(). I think it is useful to tell the user that the branch was not updated by the rebase though.

Which could be done as a very simple post-operation check: do pre- and post- hashes match? No need for a bunch of logic to check what's going to happen that'll result in slow startup in large repositories. Default should be fast and scale to large repos.

Quoted 7 lines
Quoted 3 lines

* avoid updating working tree, index, refs, reflogs, and control structures except when needed (e.g. hitting a conflict, or operation finished)

Not writing to disc unless we need to is sensible. Having said that for interactive rebases I do find having HEAD's reflog record all the picks useful to unpick what went wrong if mess something up.

Adding an option for writing HEAD's reflog at every step along the way might be reasonable. But I specifically was designing a new command with speed as priority number 1. Updating some external file with every commit thus should not be the default for this new command. I know that's incompatible with how git-rebase works, but this isn't rebase.

Actually, there's a second problem as well. git-replay shouldn't update _anything_ (other than adding new un-referenced blobs/trees/commits), until it is entirely done. In fact, even when it's done, it doesn't update any refs by default; it simply prints out some "update-ref" instructions for git update-ref --stdin (though I was thinking of adding a flag that would make git-replay also do the ref updates, as the very final thing the program did).

And there's a third problem. HEAD isn't being updated in many cases, so why should its reflog be?

Quoted 9 lines
Quoted 3 lines

* Other performance ideas:

* single-file control structures instead of directory of files

I like the idea as it should make it easier to keep the on disc state consistent, but I'm not sure how much of an issue that is in practice as we only read/write the files once each time git is run. The bigger slow down is writing the author script, commit message, list of rewritten commits, todo list and done files with each pick.

The author script, commit message, list of rewritten commits, todo list and done files are all control structures that are part of that directory of files I was complaining about. As far as I can tell, you said it's not an issue, but then immediately said the opposite. What did you take the "directory of files" control structures to mean? ...and is there some other way I could word this that would be better?

Also, if we speed up the other stuff enough, the writing of the control files becomes much more important. See the example elsewhere where I mentioned that for a cherry-pick of a single commit that took a minute under git-rebase, that actually creating the new toplevel tree only required like 11 milliseconds. If we can speed things up dramatically enough, then all the stuff that used to just not matter, suddenly starts mattering a lot. (This happened a lot when I was rewriting the merge machinery and optimizing it.) And, I think that writing one file is going to be faster than writing N files (especially on spinny disks, and yes my laptop has a spinny disk).

Also, single file control structures are easier to make safe against an ill-timed Ctrl-C, though I suspect that's so rarely a problem that it may not be worth worrying much about.

Quoted 6 lines
Quoted 3 lines

* avoid forking subprocesses unless explicitly requested (e.g. --exec, --strategy, --run-hooks). For example, definitely do not invoke git commit or git merge.

Good, that matches what the sequencer does for non-merge commits when we're not editing the commit message.

...and when not committing staged changes after a stopped interactive rebase, and when not trying to ensure identical error messages when an issue is hit. :-)

This is good; sequencer is always improving. If it could just stop calling git commit in these four extra cases, we'd be rid of the git-commit forking for good.

Quoted 7 lines
Quoted 4 lines

* Sanitize hooks:

* dispense with all per-commit hooks for sure (pre-commit, post-commit, post-checkout).

I agree we should not be running those (we don't run the pre-commit hook anyway).

...unless picking a merge commit or editing the commit message or... :-)

Quoted 5 lines

However we had a bug report when cherry-pick stopped running the "prepare-commit-msg" hook (see
https://lore.kernel.org/git/CAKdAkRQuj1hfKeckjuR2oP+8C1i+ZR36O-+aRYif4ufaS_zs+w@mail.gmail.com/).
That shouldn't matter for the server but we should bear it in mind when it comes to other use cases.

git-fast-export and git-fast-import do not run hooks, in part for speed. I don't think git-fast-patch, i.e. git-replay should either, at least not by default. I'm well aware that it's impossible to make that kind of change to git-rebase, but I'm not trying to design another rebase.

Another thing that might horrify you that I don't think I wrote down is that when interactivity is added, I don't want replay to pre-parse and validate the script, much like fast-import doesn't pre-parse and validate its input. Not validating would be anathema to how rebase operates (because rebase muddies things as it goes -- the worktree and the index AND refs AND reflogs, and it's slow, so you don't want to start down that path until you're confident that people didn't make simple mistakes). As such, this is a change that I'd never even consider suggesting for rebase, but it's exactly the kind of thing I want for replay.

Quoted 10 lines
Quoted 4 lines

* pre-rebase also seems to assume exactly 1 ref is written, and invoking it repeatedly would be stupid. Plus, it's specific to "rebase". So...ignore? (Stolee's --ref-update option for rebase probably broke the pre-rebase assumptions already...)

If replay is a plumbing command then skipping the pre-rebase hook makes sense as scripts can call it themselves if they want to. For a porcelain command keeping a hook that can prevent it from rewriting commits that are already upstream (which I think is one of the main uses of the pre-rebase hook) would be good.

pre-rebase has a broken design; it already doesn't work correctly with Stolee's --ref-update option. So, even if we wanted to support this kind of functionality, it certainly wouldn't be that script.

Also, the name is pre-rebase, not pre-cherry-pick, and doesn't apply to both commands. That means there's a second reason the design is broken. So, even if we wanted to support this kind of functionality, it'd have to be a differently named script with a different design.

But, perhaps more importantly than either of the above, is that replay doesn't change any refs, so why do we need a hook to prevent it from changing refs?

Quoted 6 lines
Quoted 3 lines

* post-rewrite hook might make sense, but fast-import got exempted, and I think of replay like a patch-based analogue to the snapshot-based fast-import.

If we don't call the hook it would be good to have a option that outputs that information so scripts can request it if they want.

Good point, although the fact that replay doesn't update refs probably means I didn't even need to mention these hooks.

Quoted 3 lines

Also we should
think about if/when we want to update the notes associated with replayed commits.

_Very_ good point. There should definitely be an option for that, maybe even a config option.

Quoted 13 lines
Quoted 13 lines

* When not running server side, resolve conflicts in a sparse-cone sparse-index worktree to reduce number of files written to a working tree. (See below as well)

* [High risk of possible premature optimization] Avoid large numbers of newly created loose objects, when replaying large numbers of commits. Two possibilities: (1) Consider using tmp-objdir and pack objects from the tmp-objdir at end of exercise, (2) Lift code from git-fast-import to immediately stuff new objects into a pack?

* Multiple branches and non-checked out branches

Quoted 8 lines
Quoted 8 lines

* The ability to operate on non-checked out branches also implies that we should generally be able to replay when in a dirty working tree (exception being when we expect to update HEAD and any of the dirty files is one that needs to be updated by the replay).

* Also, if we are operating locally on a non-checked out branch and hit a conflict, we should have a way to resolve the conflict without messing with the user's work on their current branch.

This stuff really shouldn't have been in the cover letter for this series, but since it is...

Quoted 1 line

That sounds tricky to do in a user friendly way.

Yep, totally agreed.

But, I really, really want a command that operates in O(changes) rather than O(repo size), and which can operate on non-checked-out branches, and even if the user has a dirty working tree.

There are other choices too -- e.g. if replay is fast enough, just fail if the user has a dirty working tree and tell them to re-issue the command after first cleaning it up, allowing us to use their working tree for conflict resolution. However, the level of IDE thrashing that happens when people check out other branches (and the subsequent loss of productivity they experience after resolving the simple conflict and switching back) means I'm not willing to have the only option be resolving conflicts in the current working tree. I think something very different than how git-rebase and git-cherry-pick behave currently are needed, at least as an option.

Quoted 9 lines
Quoted 3 lines

* Idea: new worktree with sparse cone + sparse index checkout, containing only files in the root directory, and whatever is necessary to get the conflicts

If the user has not asked for a sparse checkout then this could be surprising. Sometimes I find it helpful to be able to poke about in other source files when resolving a conflict. I also often build and test after resolving a conflict which requires more than just the conflict to be checked out.

Sure, some people may need an option to have conflicts be resolved in the current working tree, or perhaps even in a separate full tree. But both are such performance killers that an O(changes) option that doesn't mess with the current working tree is very much needed for some usecases.

But again, that's **way** outside the scope of this series.

Quoted 9 lines
Quoted 4 lines

* Companion to above idea: control structures should be written to $GIT_COMMON_DIR/replay-${worktree}, so users can have multiple replay sessions, and so we know which worktrees are associated with which replay operations.

We certainly want some way of making sure we only update a given ref in one replay session, and have checks to for whether the ref is checked out anywhere as we do now for rebase --update-refs. That seems to be lacking in the patches adding ref updating in this series.

Yeah, that was in patch 9. It should be dropped or have patch 10 squashed into it.

At that point, this series won't contain any ref updating, but will only have instructions that can be passed to git update-ref --stdin. At that point, no such checks will be necessary for this series (as it all belongs in git update-ref --stdin instead).

Quoted 7 lines
Quoted 2 lines

* The code die()s if there are any conflict. No resumability. No nice output. No interactivity.

I can see that on a server you might not want any output, but if I run it locally it would be nice to have a message saying which paths have conflicts. Maybe we could add a --quiet flag for the server rather than removing the existing messages?

I think the choice of what to do for conflicts becomes really complex, really quick. Just look at git-merge-tree, which is a much simpler case, and those kinds of questions blocked the series from progressing for like half a year last year.

I don't think we're ready to answer these questions. In fact, that's precisely why I never submitted this series, even though I've had the bits that Christian is pushing in a working state for about 9 months now.

I think we should defer all conflict handling other than exit status until later (or continue deferring this series until conflict handling is ready, but that may be a long time).

Quoted 5 lines
Quoted 2 lines

* Signed commits are not properly handled. It's not clear what to do to such commits when replaying on the server side.

Yes on the server where you don't have access to the signing key there is not much need for replay to have a signing option.

And on the client side, it's the one place where I'm almost certainly going to be forced to accept forking a subprocess, though rest assured that I'll grumble about it incessantly. :-)

Quoted 11 lines
Quoted 10 lines

* exit status: a successful, non-conflicted replay exits with code
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. It has been suggested in an internal review that conflicts might want to get a more specific error code as an error code of 1 might be quite easy to return by accident. It doesn't seem to me from their docs (which might want to be improved, I didn't look at the code) that other commands like git merge and git rebase exit with a special error code in case of conflict.

Quoted 5 lines

I don't think we've ever had a special "conflict" error code but it would be useful for scripts if replay had one. Does replay return a different exit code for "merge conflicts" and "cannot merge because it would overwrite an untracked file"? Does it have an exit code for "the commit becomes empty" or are those patches unconditionally dropped?

I'm not sure what Christian meant here, but as you say there's certainly no different special codes in the merge machinery.

Quoted 11 lines
Quoted 6 lines

* --advance and --contained: these two advanced options might not belong to this first series and could perhaps be added in a followup series in separate commits. On the other hand the code for --contained seems involved with the code of --advance and it's nice to see soon that git replay can indeed do cherry-picking and rebase many refs at once, and this way fullfil these parts of its promise.

Once I understood what these options did the names made sense, but I could not tell from the names what they were going to do. For me "--cherry-pick" and "--update-refs" would have been clearer. It might be worth splitting this patch so the individual options are added separately.

The output of git replay, with or without these options, is meant to be passed as input to git update-refs --stdin. As such, naming an option --update-refs for this command just seems inherently confusing.

I also feel like --update-refs is a name coded more around implementation details than end-user description of behavior (and as far as implementation details are concerned, this options is not tied to an interactive backend the way the --update-refs options in rebase is).

In contrast, --cherry-pick might be reasonable. But I worry it'll be read backwards by people. I want:

   git replay --OPTION branch upstream..commit

to make sense and I worry that OPTION==cherry-pick will cause users to think branch is being cherry-picked rather than upstream..commit. What this command does is advance branch by cherry-picking upstream..commit onto it.

Quoted 9 lines
Quoted 8 lines

* only 2 patches: this patch series can be seen from a high level point of view as 1) introducing the new git replay command, and 2) using git replay to replace, and get rid of, the fast-rebase test-tool command. The fact that not much of the original fast-rebase code and interface is left would agree with that point of view. On the other hand, fast-rebase can also be seen as a first iteration towards git replay. So it can also make sense to see how git replay evolved from it.

Quoted 5 lines

Starting with fast-rebase means one has to checkout the first patch to see what code we're adding to replay.c and to make sense of the later patches that remove code. It would be interesting to compare this series to one that started from scratch but I guess that would be quite a bit of work.

Yeah, I was probably wrong to suggest to Christian to use fast-rebase as the starting point. That is how I started my series, and multiple people had reviewed it and it seemed like it'd be useful to leverage that past review, but the reviews of these series so far suggest I may have made the wrong recommendation to Christian.

#36 lore raw
In reply to Christian Couder
Quoted 5 lines · Christian Couder

# Quick Overview (from Elijah)

git replay, at a basic level, can perhaps be thought of as a "default-to-dry-run rebase" -- meaning no updates to the working tree, or to the index, or to any references.

Interesting, I just ran into this problem trying to cleanup my personal git branches.

Simply checking which branches can be cleanly rebased on top of master takes a significant amount of time without any tricks, and using git merge-tree still takes some time.

But the biggest offender is checking which patches have not yet been merged into master, which takes 52 seconds on my machine which is by no means old.

Quoted 3 lines

# Reasons for diverging from cherry-pick & rebase (from Elijah)

* Server side needs

I personally don't care about the server side, but...

Quoted 6 lines

* Both cherry-pick and rebase, via the sequencer, are heavily tied to updating the working tree, index, some refs, and a lot of control files with every commit replayed, and invoke a mess of hooks[1] that might be hard to avoid for backward compatibility reasons (at least, that's been brought up a few times on the list).

This is important as an end user as well.

Since day 1 one of the important selling points of git was that operations that could be done in milliseconds did take milliseconds.

If it can be done faster, why wouldn't I want it to be done faster?

Quoted 1 line

* Decapitate HEAD-centric assumptions

That's good, but not particularly important at the moment IMO.

Quoted 5 lines

* Performance

* jj is slaughtering us on rebase speed[2]. I would like us to become competitive. (I dropped a few comments in the link at [2] about why git is currently so bad.)

Indeed.

Quoted 2 lines

* From [3], there was a simple 4-patch series in linux.git that took 53 seconds to rebase.

I did participate in that discussion, but Uwe Kleine-König never responded back.

In [1] he clearly noticed the problem was *before* attempting to apply any patch. Other people mentioned the fork-point detection, but I don't think that was the issue, my guess was that checking for the possibility of a fast-forward was the issue.

The code was clearly doing the wrong thing for that case, but I believe it should have been fixed by d42c9ffa0f (rebase: factor out branch_base calculation, 2022-10-17).

It would be interesting to see if this issue can be reproduced somehow.

Quoted 1 line

Switching to ort dropped it to 16 seconds.

No, it dropped to 16 seconds it for Elijah, not Uwe. Uwe (who had the real repository) noticed a big reduction of around 70%, but the discrepancy of using --onto versus not always remained.

Quoted 8 lines

While that sounds great, only 11 *milliseconds* were needed to do the actual merges. That means almost *all* the time (>99%) was overhead! Big offenders:

* --reapply-cherry-picks should be the default

* can_fast_forward() should be ripped out, and perhaps other extraneous revision walks

Doesn't d42c9ffa0f (rebase: factor out branch_base calculation, 2022-10-17) deal with that?

---

I think something like this is defeinitely needed, when I rewrote git rebase to use git cherry-pick I noticed many areas of improvement, and I'm of the opinion that git rebase should be rewritten from scratch.

But precisely because git focuses too much on backwards compatibility (and often in the wrong areas), I think git replay should be thoroughly discussed before accepting something we could quickly realize can be substantially improved.

Cheers.

[1] https://lore.kernel.org/git/[email protected]/

Signature · 1 line
Felipe Contreras
#37 lore raw
In reply to Christian Couder
Quoted 5 lines · Christian Couder

# Intro

git replay has initially been developed entirely by Elijah Newren mostly between June and July 2022 at:

(Sidenote: actually, there was a good chunk in Jan & Feb 2022 as well, and various design and idea work preceding that over a long time, some in the form of the fast-rebase test-tool...)

Quoted 7 lines

https://github.com/newren/git/commits/replay

I took over a few months ago to polish and upstream it as GitLab is interested in replacing libgit2, and for that purpose needs a command to do server side (so without using a worktree) rebases, cherry-picks and reverts.

Quoted 5 lines

I reduced the number of commits and features in this first patch series, compared to what Elijah already developed. Especially I stopped short of replaying merge commits and replaying interactively. These and other features might be upstreamed in the future after this patch series has graduated.

...and also cleaned up my commits which were in a WIP state. Thanks! :-)

Quoted 6 lines

Thanks to Elijah, Patrick Steinhardt and Dscho for early reviews and discussions.

Based on ae73b2c8f1 (The seventh batch, 2023-04-04)

# Quick Overview (from Elijah)

In particular, this comes from the replay-design-notes.txt file on the replay branch, up until the footnote links.

<snip>

My replay branch involved a whole bunch of aspirational ideas, work in progress, and some things that worked. As noted above, you've taken this portion of the cover letter from my replay-design-notes.txt file on that branch, but that file involved my in-progress thought processes on all these ideas. For this series, we should probably just focus on the server-side usecases since other aspects just weren't complete enough for use. (I also thought the server-side aspects of git-replay weren't good enough for use either because I thought we'd need some conflict-related handling similar to what git-merge-tree does, but both you and Dscho have said you aren't worried about that, and are fine with just a simple non-zero exit status.)

Anyway, deleting the forward-looking stuff and concentrating on the server-side replaying of commits would mean that we can at least delete the portion of this cover letter starting from here...

Quoted 44 lines

* Other performance ideas:

* single-file control structures instead of directory of files

* avoid forking subprocesses unless explicitly requested (e.g. --exec, --strategy, --run-hooks). For example, definitely do not invoke git commit or git merge.

* Sanitize hooks:

* dispense with all per-commit hooks for sure (pre-commit, post-commit, post-checkout).

* pre-rebase also seems to assume exactly 1 ref is written, and invoking it repeatedly would be stupid. Plus, it's specific to "rebase". So...ignore? (Stolee's --ref-update option for rebase probably broke the pre-rebase assumptions already...)

* post-rewrite hook might make sense, but fast-import got exempted, and I think of replay like a patch-based analogue to the snapshot-based fast-import.

* When not running server side, resolve conflicts in a sparse-cone sparse-index worktree to reduce number of files written to a working tree. (See below as well)

* [High risk of possible premature optimization] Avoid large numbers of newly created loose objects, when replaying large numbers of commits. Two possibilities: (1) Consider using tmp-objdir and pack objects from the tmp-objdir at end of exercise, (2) Lift code from git-fast-import to immediately stuff new objects into a pack?

* Multiple branches and non-checked out branches

* The ability to operate on non-checked out branches also implies that we should generally be able to replay when in a dirty working tree (exception being when we expect to update HEAD and any of the dirty files is one that needs to be updated by the replay).

* Also, if we are operating locally on a non-checked out branch and hit a conflict, we should have a way to resolve the conflict without messing with the user's work on their current branch.

Quoted 8 lines

* Idea: new worktree with sparse cone + sparse index checkout, containing only files in the root directory, and whatever is necessary to get the conflicts

* Companion to above idea: control structures should be written to $GIT_COMMON_DIR/replay-${worktree}, so users can have multiple replay sessions, and so we know which worktrees are associated with which replay operations.

...up to here. Some of the other stuff could perhaps be trimmed as well, though I suspect at least some of it is useful from the perspective of letting others know of additional usecases we'd like to support (so that design suggestions don't curtail those additional future usecases).

Quoted 3 lines

- [1] https://lore.kernel.org/git/[email protected]/
- [2] https://github.com/martinvonz/jj/discussions/49
- [3] https://lore.kernel.org/git/CABPp-BE48=97k_3tnNqXPjSEfA163F8hoE+HY0Zvz1SWB2B8EA@mail.gmail.com/

This appears to be the end of the part you copied from replay-design-notes.txt

<snip>

Quoted 5 lines

* 9/14 replay: very coarse worktree updating

Make it handle conflicts in a very coarse way. This might not work on bare repos, but it allows existing tests to pass and it's nice to help cli users a bit when they get conflicts.

I had the coarse working updating in git-replay mostly because it came from fast-rebase. I did also use it to poke and prod early ideas, even though I knew that its current implementation might well be incompatible with some of the other ideas I had.

I don't think this helps the server-side use though, and since it potentially conflicts with some of the other goals, I'd be inclined to say we should just drop this patch (and/or squash the next patch into this one.)

Quoted 7 lines

* 10/14 replay: make it a minimal server side command

After the cleaning up in previous ommits, it's now time to radically change the way it works by stopping it to do ref updates, to update the index and worktree, to consider HEAD as special. Instead just make it output commands that should be passed to git update-ref --stdin.

A squashed 9 & 10 would thus be similar to patch 8 in the sense that its purpose was to get rid of something that made sense for fast-rebase but which doesn't align with the current goals of this command.

<snip>

Quoted 16 lines

# Possibly controversial issues

* bare or not bare: this series works towards a command with the end goal of it being usable and used on bare repos, contrary to existing commands like git rebase and git cherry-pick, but the tests currently don't check that, and in case of conflicts it won't currently work on bare repos. One reason for that is that existing tests in t6429 should continue to work, and one of these tests requires some output in case of conflict. And it's nice for users to get some help in case of conflict. It's also nice for users if commands that should work on both bare and non bare repos work well on non bare repos first as they are less likely to use them on bare repos. So let's have a command that works well on non-bare repos first, even if its end goal is to work fine on bare repos too. We plan to improve things for bare repos soon after this first patch series graduates.

I think there's a lot of work to do for conflict handling, and if we want to submit this for inclusion then we should just exclude conflict handling entirely and adjust the tests accordingly.

Quoted 10 lines

* exit status: a successful, non-conflicted replay exits with code
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. It has been suggested in an internal review that conflicts might want to get a more specific error code as an error code of 1 might be quite easy to return by accident. It doesn't seem to me from their docs (which might want to be improved, I didn't look at the code) that other commands like git merge and git rebase exit with a special error code in case of conflict.

The merge backend does not provide any granularity finer than "had conflicts" for its return code. This is somewhat cemented by the git-merge API as well, where it mandates that the return code of merge backends be 1 for conflicts:

/*
* The backend exits with 1 when conflicts are
* left to be resolved, with 2 when it does not
* handle the given merge at all.
*/

Because of this, all of git-merge-resolve, git-merge-octopus, git-merge-recursive, and git-merge-ort return 1 for conflicts.

Of course, we do not have to use the return code of the merge backend as the exit status for git replay. We could inspect the conflicts, somewhat like git-merge-tree does, except that instead of printing information about those conflicts, we could also let it guide us to choose a new exit status. I'm not sure we'd want to do that, but we could.

Since an exit status of 1 is pretty thoroughly baked in elsewhere for everything merge related, including git-merge-tree, I'd be inclined to leave this series as-is and have an exit status of 1 for conflicts.

Quoted 11 lines

* to guess or not to guess: commit 12/14 introduces the guess_new_base() function which tries to find a base to rebase onto when the --onto option is not provided, making this option actually optional instead of mandatory. Given that it's an heuristic and the command end goal is to be used on server side, we might want to introduce this as an iterative improvement later. I still think it's interesting to have it in for now though, as it shows that --onto and --advance (which is introduced in the following commit) should indeed be options. If --onto was always mandatory in the series, people could argue that it shouldn't be an option and its argument should always be the first (unconditional) argument of the command.

I do not want a positional argument for <onto>; rebase's use of positional arguments is an example to avoid, IMO.

I also don't want people thinking this is just rebase. Rebase is perhaps used more than cherry-pick and as such a lot of the documentation and design goals talk about it more, but I designed this command very deliberately to be about handling both cherry-pick and rebase functionality in the same command.

All that said, I remember spending a fair amount of time on the heuristic, but don't remember if I felt I had gotten it good enough or not. If folks want to leave it out for a future series, that'd be fine, so long as it doesn't lead people to suggestions that'd conflict with the above points.

Quoted 7 lines

* make worktree and index changes optional: commit 10/14 stops updating the index and worktree, but it might be better especially for cli users to make that optional. The issue is that this would make the command more complex while we are developing a number of important features. It seems to me that this should rather be done in an iterative improvement after the important features have landed.

I don't think worktree and index changes should be included in this series, even as an option. The related code as currently written is incompatible with some other ideas expressed in the cover letter. Granted, those ideas might change, even dramatically, but I don't want us limiting the design space and I don't think the worktree or index updates in this series are ready for users to use yet. (And there aren't any patches available, to my knowledge, that make them ready. Those still need to be written.)

Quoted 11 lines

* when and where to add tests and docs: although t6429 has tests that are changed to use the new command instead of the fast-rebase test-tool command as soon as the former is introduced, there is no specific test script and no doc for the new command until commit 11/14 when standard revision ranges are used. This is done to avoid churn in tests and docs while the final form of the command hasn't crystalized enough. Adding tests and doc at this point makes this commit quite big and possibly more difficult to review than if they were in separate commits though. On the other hand when tests and docs are added in specific commits some reviewers say it would be better to introduce them when the related changes are made.

I don't have opinions on this one. Maybe I will after reading through this cleaned up series more carefully.

Quoted 6 lines

* --advance and --contained: these two advanced options might not belong to this first series and could perhaps be added in a followup series in separate commits. On the other hand the code for --contained seems involved with the code of --advance and it's nice to see soon that git replay can indeed do cherry-picking and rebase many refs at once, and this way fullfil these parts of its promise.

--advance is the one option I thought I had a chance of getting my company to use server-side in the near term...

Also, without --advance, I worry reviewers will make rebase-centric assumptions that preclude handling cherry-picks, so I'm really leery of deferring it based on that.

I understand that --contained isn't as likely to be useful server-side, but it was the one piece that I really enjoyed using cli-side (especially since it pre-dated rebase --update-refs). But yeah, it's utility is somewhat limited until there's some kind of conflict resolution mechanism provided.

Quoted 6 lines

* replaying diverging branches: 14/14 the last patch in the series, which allow replaying diverging branches, can be seen as a fundamental fix or alternatively as adding an interesting feature. So it's debatable if it should be in its own patch along with its own tests as in this series, or if it should be merged into a previous patch and which one.

I don't have opinions on this either. Maybe I will after reading through the series?

Quoted 8 lines

* only 2 patches: this patch series can be seen from a high level point of view as 1) introducing the new git replay command, and 2) using git replay to replace, and get rid of, the fast-rebase test-tool command. The fact that not much of the original fast-rebase code and interface is left would agree with that point of view. On the other hand, fast-rebase can also be seen as a first iteration towards git replay. So it can also make sense to see how git replay evolved from it.

I preferred the angle of starting from fast-rebase, but I don't feel too strongly about it. Mostly I just thought it'd make it easier for me, and for the few other people who already reviewed fast-rebase (and yes, I got review comments on it from a few different people back when it was proposed). If dividing up the patches some other way makes it easier for others to reason about, and you want to switch it around, go for it.

#38 lore raw

v2 cover Introduce new `git replay` command

In reply to Christian Couder

# Intro

git replay has initially been developed entirely by Elijah Newren mostly last year (2022) at:

https://github.com/newren/git/commits/replay

I took over a few months ago to polish and upstream it as GitLab is interested in replacing libgit2, and for that purpose needs a command to do server side (so without using a worktree) rebases, cherry-picks and reverts.

I reduced the number of commits and features in this first patch series, compared to what Elijah already developed. Especially I stopped short of replaying merge commits and replaying interactively. These and other features might be upstreamed in the future after this patch series has graduated.

The focus in this series is to make it a good plumbing command that can already be used server side and that replaces the "fast-rebase" test-tool command. So things to make it easier to use on the command line, and more advanced features (like replaying merges) are left out.

# Content of this cover letter

The "Quick Overview" and "Reasons for diverging from cherry-pick & rebase" sections just below are describing the purpose of the new command in the big scheme of things. They are taken from Elijah's design notes
(https://github.com/newren/git/blob/replay/replay-design-notes.txt)
and describe what we want this command to become and the reasons for that, not what the command is after only this patch series. Also these design notes were written at least one year ago, so parts of those 2 sections are not true anymore. I have added Phillip Wood's or Felipe Contreras' notes (thanks to them) where that's the case, but some now flawed parts may have missed.

After these two sections, starting with the "Important limitations" section, you will find sections describing what is actually in this patch series.

More interesting material is available in Elijah's design notes like an "Intro via examples"
(https://github.com/newren/git/blob/replay/replay-design-notes.txt#L37-L132),
a discussion about "Preserving topology, replaying merges"
(https://github.com/newren/git/blob/replay/replay-design-notes.txt#L264-L341)
and a "Current status" section describing Elijah's work
(https://github.com/newren/git/blob/replay/replay-design-notes.txt#L344-L392)
before I started working on upstreaming it.

I have not included this material here though, as the documentation added by this patch series for the git replay command already includes an "EXAMPLES" section, and other sections of Elijah's design notes might not be interesting for now. Also this cover letter is already pretty long. But reviewers can refer to the links above if they think it can help.

# Quick Overview (from Elijah's design notes)

git replay, at a basic level, can perhaps be thought of as a "default-to-dry-run rebase" -- meaning no updates to the working tree, or to the index, or to any references. However, it differs from rebase in that it:

* Works for branches that aren't checked out

* Works in a bare repository

* Can replay multiple branches simultaneously (with or without common history in the range being replayed)

* Preserves relative topology by default (merges are replayed too in Elijah's original work, not in this series)

* Focuses on performance

* Has several altered defaults as a result of the above

I sometimes think of git replay as "fast-replay", a patch-based analogue to the snapshot-based fast-export & fast-import tools.

# Reasons for diverging from cherry-pick & rebase (from Elijah's
design notes)

There are multiple reasons to diverge from the defaults in cherry-pick and rebase.

* Server side needs

* Both cherry-pick and rebase, via the sequencer, are heavily tied to updating the working tree, index, some refs, and a lot of control files with every commit replayed, and invoke a mess of hooks[1] that might be hard to avoid for backward compatibility reasons (at least, that's been brought up a few times on the list).

* cherry-pick and rebase both fork various subprocesses unnecessarily, but somewhat intrinsically in part to ensure the same hooks are called that old scripted implementations would have called.

Note: since 356ee4659bb (sequencer: try to commit without forking 'git commit', 2017-11-24) cherry-pick and rebase do not fork subprocesses other than hooks for the cases covered by this patch series (i.e. they do not fork "git commit" for simple picks).

* "Dry run" behavior, where there are no updates to worktree, index, or even refs might be important.

* Should not assume users only want to operate on HEAD (see next section)

* Decapitate HEAD-centric assumptions

* cherry-pick forces commits to be played on top of HEAD; inflexible.

* rebase assumes the range of commits to be replayed is upstream..HEAD by default, though it allows one to replay upstream..otherbranch -- but it still forcibly and needlessly checks out 'otherbranch' before starting to replay things.

Note: since 767a9c417eb (rebase -i: stop checking out the tip of the branch to rebase, 2020-01-24) it's not true that rebase forcibly and needlessly checks out 'otherbranch'.

* Assuming HEAD is involved severely limits replaying multiple (possibly divergent) branches.

Note: since 89fc0b53fdb (rebase: update refs from 'update-ref' commands, 2022-07-19) the sequencer can update multiple branches. The issue with divergent branch is with command line arguments and the todo list generation rather than the capabilities of the sequencer.

* Once you stop assuming HEAD has a certain meaning, there's not much reason to have two separate commands anymore (except for the funny extra not-necessarily-compatible options both have gained over time).

* (Micro issue: Assuming HEAD is involved also makes it harder for new users to learn what rebase means and does; it makes command lines hard to parse. Not sure I want to harp on this too much, as I have a suspicion I might be creating a tool for experts with complicated use cases, but it's a minor quibble.)

* Performance

* jj is slaughtering us on rebase speed[2]. I would like us to become competitive. (I dropped a few comments in the link at [2] about why git is currently so bad.)

* From [3], there was a simple 4-patch series in linux.git that took 53 seconds to rebase. Switching to ort dropped it to 16 seconds. While that sounds great, only 11 *milliseconds* were needed to do the actual merges. That means almost *all* the time (>99%) was overhead! Big offenders:

* --reapply-cherry-picks should be the default

* can_fast_forward() should be ripped out, and perhaps other extraneous revision walks

Note: d42c9ffa0f (rebase: factor out branch_base calculation, 2022-10-17) might already deal with that (according to Felipe Contreras).

* avoid updating working tree, index, refs, reflogs, and control structures except when needed (e.g. hitting a conflict, or operation finished)

* Other performance ideas (mostly for future work, not in this series)

* single-file control structures instead of directory of files (when doing interactive things which is in Elijah's original work, but not in this series)

* avoid forking subprocesses unless explicitly requested (e.g. --exec, --strategy, --run-hooks). For example, definitely do not invoke git commit or git merge.

* Sanitize hooks:

* dispense with all per-commit hooks for sure (pre-commit, post-commit, post-checkout).

* pre-rebase also seems to assume exactly 1 ref is written, and invoking it repeatedly would be stupid. Plus, it's specific to "rebase". So...ignore? (Stolee's --ref-update option for rebase probably broke the pre-rebase assumptions already...)

* post-rewrite hook might make sense, but fast-import got exempted, and I think of replay like a patch-based analogue to the snapshot-based fast-import.

* When not running server side, resolve conflicts in a sparse-cone sparse-index worktree to reduce number of files written to a working tree. (See below as well.)

* [High risk of possible premature optimization] Avoid large numbers of newly created loose objects, when replaying large numbers of commits. Two possibilities: (1) Consider using tmp-objdir and pack objects from the tmp-objdir at end of exercise, (2) Lift code from git-fast-import to immediately stuff new objects into a pack?

* Multiple branches and non-checked out branches

* The ability to operate on non-checked out branches also implies that we should generally be able to replay when in a dirty working tree (exception being when we expect to update HEAD and any of the dirty files is one that needs to be updated by the replay).

* Also, if we are operating locally on a non-checked out branch and hit a conflict, we should have a way to resolve the conflict without messing with the user's work on their current branch. (This is not is this patch series though.)

* Idea: new worktree with sparse cone + sparse index checkout, containing only files in the root directory, and whatever is necessary to get the conflicts

* Companion to above idea: control structures should be written to $GIT_COMMON_DIR/replay-${worktree}, so users can have multiple replay sessions, and so we know which worktrees are associated with which replay operations.

- [1] https://lore.kernel.org/git/[email protected]/
- [2] https://github.com/martinvonz/jj/discussions/49
- [3] https://lore.kernel.org/git/CABPp-BE48=97k_3tnNqXPjSEfA163F8hoE+HY0Zvz1SWB2B8EA@mail.gmail.com/

# Important limitations

* The code exits with code 1 if there are any conflict. No resumability. No nice output. No interactivity. No special exit code depending on the reason.

* When a commit becomes empty as it is replayed, it is still replayed as an empty commit, instead of being dropped.

* No replaying merges, nor root commits. Only regular commits.

* Signed commits are not properly handled. It's not clear what to do to such commits when replaying on the server side.

* Notes associated with replayed commits are not updated nor duplicated. (Thanks to Phillip Wood for noticing.)

# Commit overview

* 1/15 t6429: remove switching aspects of fast-rebase

New preparatory commit to make it easier to later replace the fast-rebase test-tool by git replay without breaking existing tests.

* 2/15 replay: introduce new builtin

This creates a minimal git replay command by moving the code from the fast-rebase test helper from t/helper/ into builtin/ and doing some renames and a few other needed changes. (No change on this commit since v1.)

* - 3/15 replay: start using parse_options API
- 4/15 replay: die() instead of failing assert()
- 5/15 replay: introduce pick_regular_commit()
- 6/15 replay: don't simplify history
- 7/15 replay: add an important FIXME comment about gpg signing
- 8/15 replay: remove progress and info output
- 9/15 replay: remove HEAD related sanity check

These slowly change the command to make it behave more like a regular commands and to start cleaning up its output. (No change on these commits since v1.)

* 10/15 replay: make it a minimal server side command

After the cleaning up in previous commits, it's now time to radically change the way it works by stopping it to do ref updates, to update the index and worktree, to consider HEAD as special. Instead just make it output commands that should be passed to git update-ref --stdin. (No change on this commit since v1.)

* 11/15 replay: use standard revision ranges

Start addind new interesting features and also documentation and tests, as the interface of the command is cristalizing into its final form.

Since v1, new tests to check that the command works well on bare repo and exits with code 1 in case of conflict have been added. The doc also now says that the new command is experimental.

* 12/15 replay: disallow revision specific options and pathspecs

New commit to disallow for now revision specific options and pathspecs that are allowed and eaten by setup_revisions(), as it's not clear if all of these extra features are really needed, and anyway they would require tests and doc. So we leave them for future improvements.

* - 13/15 replay: add --advance or 'cherry-pick' mode
- 14/15 replay: add --contained to rebase contained branches

New commits, but extracted from a previous commit (that added both --advance and --contained at the same time) without any code change except that a few test cases for bare repos were added.

* 15/15 replay: stop assuming replayed branches do not diverge

This adds another interesting feature, as well as related documentation and tests. (Since v1 a few test cases for bare repos were added.)

# Notes about fast-rebase, tests and documentation

The fast-rebase test-tool helper was developed by Elijah to experiment with a rebasing tool that would be developed from scratch based on his merge-ort work, could be used to test that merge-ort work, and would not have the speed and interface limitations of git rebase or git cherry-pick.

This fast-rebase helper was used before this series in:

t6429-merge-sequence-rename-caching.sh

So when git replay is created from fast-rebase in patch 2/15, the t6429 test script is also converted to use git replay. This ensures that git replay doesn't break too badly during the first 10 patches in this patch series.

Tests and documentation are introduced specifically for git replay only in 11/15 and later patches as it doesn't make much sense to document and test behavior that we know is going to change soon. So it's only when the command is crystalizing towards its final form that we start documenting and testing it.

# Possibly controversial issues

* bare or not bare: this series works towards a plumbing command with the end goal of it being usable and used first on bare repos, contrary to existing commands like git rebase and git cherry-pick. The tests check that the command works on both bare and non-bare repo though.

* exit status: a successful, non-conflicted replay exits with code
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. There are a few tests checking that. It has been suggested in an internal review that conflicts might want to get a more specific error code as an error code of 1 might be quite easy to return by accident. It doesn't seem to me from their docs (which might want to be improved, I didn't look at the code) that other commands like git merge and git rebase exit with a special error code in case of conflict.

* make worktree and index changes optional: commit 10/15 stops updating the index and worktree, but it might be better especially for cli users to make that optional. The issue is that this would make the command more complex while we are developing a number of important features so that the command can be used on bare repos. It seems that this should rather be done in an iterative improvement after the important features have landed.

* when and where to add tests and docs: although t6429 has tests that are changed to use the new command instead of the fast-rebase test-tool command as soon as the former is introduced, there is no specific test script and no doc for the new command until commit 11/15 when standard revision ranges are used. This is done to avoid churn in tests and docs while the final form of the command hasn't crystalized enough. Adding tests and doc at this point makes this commit quite big and possibly more difficult to review than if they were in separate commits though. On the other hand when tests and docs are added in specific commits some reviewers say it would be better to introduce them when the related changes are made.

* --advance and --contained: these two advanced options might not belong to this first series and could perhaps be added in a followup series in separate commits. On the other hand the code for --contained seems involved with the code of --advance and it's nice to see soon that git replay can indeed do cherry-picking and rebase many refs at once, and this way fullfil these parts of its promise.

* replaying diverging branches: 15/15 the last patch in the series, which allow replaying diverging branches, can be seen as a fundamental fix or alternatively as adding an interesting feature. So it's debatable if it should be in its own patch along with its own tests as in this series, or if it should be merged into a previous patch and which one.

* only 2 patches: this patch series can be seen from a high level point of view as 1) introducing the new git replay command, and 2) using git replay to replace, and get rid of, the fast-rebase test-tool command. The fact that not much of the original fast-rebase code and interface is left would agree with that point of view. On the other hand, fast-rebase can also be seen as a first iteration towards git replay. So it can also make sense to see how git replay evolved from it.

# Changes between v1 and v2

Thanks to all the reviewers on the mailing list or during a Review Club! Especially, thanks to Elijah, Dscho, Phillip Wood, Derrick Stolee, Patrick Steinhardt, Junio, Felipe Contreras, Calvin Wan and all the Review Club participants.

The Review Club notes (see those on 2023-04-18) are available on:

https://docs.google.com/document/d/14L8BAumGTpsXpjDY8VzZ4rRtpAjuGrFSRqn3stCuS_w/

Now the changes between v1 and v2 are:

* The patch series has been rebased on top of current master, so that conflicts with master are resolved. This required replacing calls to functions like get_oid() with repo_get_oid(), as well as changing some #include "*.h" to use different header files. This unfortunately makes the range-diff between v1 and v2 a bit more difficult to read than we would like.

* Patch 1/15 is a new patch. It has been introduced to rework t6429, so that this test script doesn't break when conflict output is removed later in the series. This allowed us to remove the old 9/14 patch ("replay: very coarse worktree updating").

* The old 9/14 patch ("replay: very coarse worktree updating") was removed. This is to make sure that the new command can be used on bare repos. This enables us to focus first on making sure the new command a good plumbing command that works well on bare repos.

* The old 12/14 patch ("replay: introduce guess_new_base()") was removed. This is also to focus first on making sure the new command is a good plumbing command.

* The old 13/14 patch ("replay: add different modes") has been split into 2 patches: patch 13/15 ("replay: add --advance or 'cherry-pick' mode") and patch 14/15 ("replay: add --contained to rebase contained branches").

* Patch 12/15 ("replay: disallow revision specific options and pathspecs") is a new patch that disallow using revision specific options that would be allowed and eaten by setup_revisions(). Even if it would be very nice to have some of these options in the future, not all these options make sense for the new command, and it might require improving the setup_revisions() mechanism (as well as adding tests and doc) to cleanly allow those we want, but that is outside the scope of this first patch series.

While at it, this patch also disallow pathspecs too. It would be nice to have them in the future, but for now it is not necessary and would require work (at least for tests and doc) that can be done later.

* Patches 11/15 to 15/15 include a number of new tests to check that the command works well on bare repos, and in case of 11/15 to check that exit code in case of conflict is 1.

* Patch 11/15, in which the doc for the git replay command is introduced, now says that the new command is experimental.

* Note that a segfault that was found by Derrick Stolee in the v1 is fixed by 000c4ceca7 (merge-ort: fix calling merge_finalize() with no intermediate merge, 2023-04-22) merged to master by 3927312601 (Merge branch 'en/ort-finalize-after-0-merges-fix', 2023-05-02).

Christian Couder (1):
replay: disallow revision specific options and pathspecs

Elijah Newren (14):
t6429: remove switching aspects of fast-rebase
replay: introduce new builtin
replay: start using parse_options API
replay: die() instead of failing assert()
replay: introduce pick_regular_commit()
replay: don't simplify history
replay: add an important FIXME comment about gpg signing
replay: remove progress and info output
replay: remove HEAD related sanity check
replay: make it a minimal server side command
replay: use standard revision ranges
replay: add --advance or 'cherry-pick' mode
replay: add --contained to rebase contained branches
replay: stop assuming replayed branches do not diverge

 .gitignore                               |   1 +
 Documentation/git-replay.txt             | 125 +++++++
 Makefile                                 |   2 +-
 builtin.h                                |   1 +
 builtin/replay.c                         | 431 +++++++++++++++++++++++
 command-list.txt                         |   1 +
 git.c                                    |   1 +
 t/helper/test-fast-rebase.c              | 240 -------------
 t/helper/test-tool.c                     |   1 -
 t/helper/test-tool.h                     |   1 -
 t/t3650-replay-basics.sh                 | 206 +++++++++++
 t/t6429-merge-sequence-rename-caching.sh |  45 +--
 12 files changed, 792 insertions(+), 263 deletions(-)
 create mode 100644 Documentation/git-replay.txt
 create mode 100644 builtin/replay.c
 delete mode 100644 t/helper/test-fast-rebase.c
 create mode 100755 t/t3650-replay-basics.sh
Signature · 1 line
2.40.1.491.gdff9a222ea
#39 lore raw

PATCH v2 1/15 t6429: remove switching aspects of fast-rebase

From: Elijah Newren <[email protected]>

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.

---
 t/helper/test-fast-rebase.c              | 9 +--------
 t/t6429-merge-sequence-rename-caching.sh | 9 +++++++--
 2 files changed, 8 insertions(+), 10 deletions(-)
t/helper/test-fast-rebase.c +1 -8
index d1d63feaa9..403bdf8e75 100644
@@ -193,7 +193,7 @@ int cmd__fast_rebase(int argc, const char **argv)
 		last_commit = create_commit(result.tree, commit, last_commit);
 	}
 
-	merge_switch_to_result(&merge_opt, head_tree, &result, 1, !result.clean);
+	merge_finalize(&merge_opt, &result);
 
 	if (result.clean < 0)
 		exit(128);
@@ -212,9 +212,6 @@ int cmd__fast_rebase(int argc, const char **argv)
 		}
 		if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0)
 			die(_("unable to update HEAD"));
-
-		prime_cache_tree(the_repository, the_repository->index,
-				 result.tree);
 	} else {
 		fprintf(stderr, "\nAborting: Hit a conflict.\n");
 		strbuf_addf(&reflog_msg, "rebase progress up to %s",
@@ -227,10 +224,6 @@ int cmd__fast_rebase(int argc, const char **argv)
 			die("Failed to update %s", argv[4]);
 		}
 	}
-	if (write_locked_index(&the_index, &lock,
-			       COMMIT_LOCK | SKIP_IF_UNCHANGED))
-		die(_("unable to write %s"), get_index_file());
-
 	ret = (result.clean == 0);
 cleanup:
 	strbuf_release(&reflog_msg);
t/t6429-merge-sequence-rename-caching.sh +7 -2
index d02fa16614..75d3fd2dba 100755
@@ -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 &&
Signature · 1 line
2.40.1.491.gdff9a222ea
#40 lore raw

PATCH v2 2/15 replay: introduce new builtin

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 .gitignore                                    |  1 +
 Makefile                                      |  2 +-
 builtin.h                                     |  1 +
 .../test-fast-rebase.c => builtin/replay.c    | 25 +++++------------
 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, 20 insertions(+), 40 deletions(-)
 rename t/helper/test-fast-rebase.c => builtin/replay.c (89%)
.gitignore +1 -0
index e875c59054..b5f025a296 100644
@@ -135,6 +135,7 @@
 /git-remote-ext
 /git-repack
 /git-replace
+/git-replay
 /git-request-pull
 /git-rerere
 /git-reset
Makefile +1 -1
index e440728c24..a6ab78840f 100644
@@ -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
builtin.h +1 -0
index cb0db67681..c3f0b56915 100644
@@ -214,6 +214,7 @@ int cmd_remote(int argc, const char **argv, const char *prefix);
 int cmd_remote_ext(int argc, const char **argv, const char *prefix);
 int cmd_remote_fd(int argc, const char **argv, const char *prefix);
 int cmd_repack(int argc, const char **argv, const char *prefix);
+int cmd_replay(int argc, const char **argv, const char *prefix);
 int cmd_rerere(int argc, const char **argv, const char *prefix);
 int cmd_reset(int argc, const char **argv, const char *prefix);
 int cmd_restore(int argc, const char **argv, const char *prefix);
builtin/replay.c renamed from t/helper/test-fast-rebase.c +6 -19
similarity index 89%
rename from t/helper/test-fast-rebase.c
rename to builtin/replay.c
index 403bdf8e75..9637c31da2 100644
@@ -1,18 +1,11 @@
 /*
- * "git fast-rebase" builtin command
- *
- * FAST: Forking Any Subprocesses (is) Taboo
- *
- * This is meant SOLELY as a demo of what is possible.  sequencer.c and
- * rebase.c should be refactored to use the ideas here, rather than attempting
- * to extend this file to replace those (unless Phillip or Dscho say that
- * refactoring is too hard and we need a clean slate, but I'm guessing that
- * refactoring is the better route).
+ * "git replay" builtin command
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "test-tool.h"
-#include "cache.h"
+#include "git-compat-util.h"
+
+#include "builtin.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "environment.h"
@@ -93,7 +86,7 @@ static struct commit *create_commit(struct tree *tree,
 	return (struct commit *)obj;
 }
 
-int cmd__fast_rebase(int argc, const char **argv)
+int cmd_replay(int argc, const char **argv, const char *prefix)
 {
 	struct commit *onto;
 	struct commit *last_commit = NULL, *last_picked_commit = NULL;
@@ -109,12 +102,6 @@ int cmd__fast_rebase(int argc, const char **argv)
 	struct strbuf branch_name = STRBUF_INIT;
 	int ret = 0;
 
-	/*
-	 * test-tool stuff doesn't set up the git directory by default; need to
-	 * do that manually.
-	 */
-	setup_git_directory();
-
 	if (argc == 2 && !strcmp(argv[1], "-h")) {
 		printf("Sorry, I am not a psychiatrist; I can not give you the help you need.  Oh, you meant usage...\n");
 		exit(129);
@@ -135,7 +122,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;
command-list.txt +1 -0
index 54b2a50f5f..d74836ab21 100644
@@ -160,6 +160,7 @@ git-reflog                              ancillarymanipulators           complete
 git-remote                              ancillarymanipulators           complete
 git-repack                              ancillarymanipulators           complete
 git-replace                             ancillarymanipulators           complete
+git-replay                              mainporcelain           history
 git-request-pull                        foreignscminterface             complete
 git-rerere                              ancillaryinterrogators
 git-reset                               mainporcelain           history
git.c +1 -0
index 45899be826..a1252e4cd3 100644
@@ -577,6 +577,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 },
t/helper/test-tool.c +0 -1
index abe8a785eb..9ca1586de7 100644
@@ -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 },
t/helper/test-tool.h +0 -1
index ea2672436c..a03bbfc6b2 100644
@@ -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);
t/t6429-merge-sequence-rename-caching.sh +9 -18
index 75d3fd2dba..7670b72008 100755
@@ -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 &&
Signature · 1 line
2.40.1.491.gdff9a222ea
#41 lore raw

PATCH v2 3/15 replay: start using parse_options API

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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 "<oldbase> <branch>" 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.

---
 builtin/replay.c | 44 ++++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)
builtin/replay.c +32 -12
index 9637c31da2..4644bee3cf 100644
@@ -14,6 +14,7 @@
 #include "lockfile.h"
 #include "merge-ort.h"
 #include "object-name.h"
+#include "parse-options.h"
 #include "refs.h"
 #include "revision.h"
 #include "sequencer.h"
@@ -89,6 +90,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;
@@ -102,16 +104,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 <newbase> <oldbase> <branch>"),
+		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))
@@ -123,6 +141,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;
@@ -131,7 +150,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"));
@@ -194,8 +214,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"));
@@ -207,8 +227,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);
Signature · 1 line
2.40.1.491.gdff9a222ea
#42 lore raw

PATCH v2 4/15 replay: die() instead of failing assert()

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
builtin/replay.c +6 -1
index 4644bee3cf..366ea8ef08 100644
@@ -177,7 +177,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);
Signature · 1 line
2.40.1.491.gdff9a222ea
#43 lore raw

PATCH v2 5/15 replay: introduce pick_regular_commit()

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 54 ++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 20 deletions(-)
builtin/replay.c +34 -20
index 366ea8ef08..f087d97353 100644
@@ -87,6 +87,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;
@@ -98,7 +127,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;
@@ -173,7 +202,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));
@@ -183,26 +212,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);
Signature · 1 line
2.40.1.491.gdff9a222ea
#44 lore raw

PATCH v2 6/15 replay: don't simplify history

In reply to Christian Couder

From: Elijah Newren <[email protected]>

Let's set the rev walking options we need after calling setup_revisions() instead of before. This makes it clearer which options we need.

Also we don't want history simplification, as we want to deal with all the commits in the affected range.

---
 builtin/replay.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
builtin/replay.c +6 -9
index f087d97353..9f6cca2972 100644
@@ -171,15 +171,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) {
@@ -187,6 +178,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		goto cleanup;
 	}
 
+	/* requirements/overrides for revs */
+	revs.reverse = 1;
+	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
+	revs.topo_order = 1;
+	revs.simplify_history = 0;
+
 	strvec_clear(&rev_walk_args);
 
 	if (prepare_revision_walk(&revs) < 0) {
Signature · 1 line
2.40.1.491.gdff9a222ea
#45 lore raw

PATCH v2 7/15 replay: add an important FIXME comment about gpg signing

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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

---
 builtin/replay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/replay.c +1 -1
index 9f6cca2972..a9d88ac6df 100644
@@ -60,7 +60,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();
Signature · 1 line
2.40.1.491.gdff9a222ea
#46 lore raw

PATCH v2 8/15 replay: remove progress and info output

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
builtin/replay.c +1 -6
index a9d88ac6df..ccbef6552a 100644
@@ -193,7 +193,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;
@@ -201,9 +201,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)
@@ -222,7 +219,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));
@@ -236,7 +232,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",
Signature · 1 line
2.40.1.491.gdff9a222ea
#47 lore raw

PATCH v2 9/15 replay: remove HEAD related sanity check

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
builtin/replay.c +1 -7
index ccbef6552a..6437633724 100644
@@ -121,7 +121,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;
@@ -160,11 +159,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");
@@ -236,7 +230,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]);
Signature · 1 line
2.40.1.491.gdff9a222ea
#48 lore raw

PATCH v2 10/15 replay: make it a minimal server side command

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c                         | 79 ++++++++----------------
 t/t6429-merge-sequence-rename-caching.sh | 39 +++++++-----
 2 files changed, 51 insertions(+), 67 deletions(-)
builtin/replay.c +27 -52
index 6437633724..46f00a2d71 100644
@@ -6,10 +6,7 @@
 #include "git-compat-util.h"
 
 #include "builtin.h"
-#include "cache-tree.h"
-#include "commit.h"
 #include "environment.h"
-#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge-ort.h"
@@ -17,10 +14,7 @@
 #include "parse-options.h"
 #include "refs.h"
 #include "revision.h"
-#include "sequencer.h"
-#include "setup.h"
 #include "strvec.h"
-#include "tree.h"
 
 static const char *short_commit_name(struct commit *commit)
 {
@@ -100,6 +94,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);
 
@@ -120,15 +115,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;
 
@@ -159,10 +151,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);
@@ -188,58 +176,45 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	init_merge_options(&merge_opt, the_repository);
 	memset(&result, 0, sizeof(result));
 	merge_opt.show_rename_progress = 0;
-	merge_opt.branch1 = "HEAD";
-	head_tree = repo_get_commit_tree(the_repository, onto);
-	result.tree = head_tree;
+	result.tree = repo_get_commit_tree(the_repository, onto);
 	last_commit = onto;
 	while ((commit = get_revision(&revs))) {
-		struct commit *pick;
+		const struct name_decoration *decoration;
 
 		if (!commit->parents)
 			die(_("replaying down to root commit is not supported yet!"));
 		if (commit->parents->next)
 			die(_("replaying merge commits is not supported yet!"));
 
-		pick = pick_regular_commit(commit, last_commit, &merge_opt, &result);
-		if (!pick)
+		last_commit = pick_regular_commit(commit, last_commit, &merge_opt, &result);
+		if (!last_commit)
 			break;
-		last_commit = pick;
-		last_picked_commit = commit;
+
+		decoration = get_name_decoration(&commit->object);
+		if (!decoration)
+			continue;
+
+		while (decoration) {
+			if (decoration->type == DECORATION_REF_LOCAL) {
+				printf("update %s %s %s\n",
+				       decoration->name,
+				       oid_to_hex(&last_commit->object.oid),
+				       oid_to_hex(&commit->object.oid));
+			}
+			decoration = decoration->next;
+		}
 	}
 
+	/* Cleanup */
 	merge_finalize(&merge_opt, &result);
+	ret = result.clean;
 
-	if (result.clean < 0)
-		exit(128);
-
-	if (result.clean) {
-		strbuf_addf(&reflog_msg, "finish rebase %s onto %s",
-			    oid_to_hex(&last_picked_commit->object.oid),
-			    oid_to_hex(&last_commit->object.oid));
-		if (update_ref(reflog_msg.buf, branch_name.buf,
-			       &last_commit->object.oid,
-			       &last_picked_commit->object.oid,
-			       REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
-			error(_("could not update %s"), argv[2]);
-			die("Failed to update %s", argv[2]);
-		}
-		if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0)
-			die(_("unable to update HEAD"));
-	} else {
-		strbuf_addf(&reflog_msg, "rebase progress up to %s",
-			    oid_to_hex(&last_picked_commit->object.oid));
-		if (update_ref(reflog_msg.buf, "HEAD",
-			       &last_commit->object.oid,
-			       &onto->object.oid,
-			       REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
-			error(_("could not update %s"), argv[2]);
-			die("Failed to update %s", argv[2]);
-		}
-	}
-	ret = (result.clean == 0);
 cleanup:
-	strbuf_release(&reflog_msg);
 	strbuf_release(&branch_name);
 	release_revisions(&revs);
-	return ret;
+
+	/* Return */
+	if (ret < 0)
+		exit(128);
+	return ret ? 0 : 1;
 }
t/t6429-merge-sequence-rename-caching.sh +24 -15
index 7670b72008..099aefeffc 100755
@@ -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 <out &&
+		git checkout topic &&
 
 		git ls-files >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >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 <out &&
+		git checkout topic &&
 
 		git ls-files >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 <out &&
+		git checkout topic &&
 
 		git ls-files >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 2 calls &&
Signature · 1 line
2.40.1.491.gdff9a222ea
#49 lore raw

PATCH v2 11/15 replay: use standard revision ranges

In reply to Christian Couder

From: Elijah Newren <[email protected]>

Instead of the fixed "<oldbase> <branch>" arguments, the replay command now accepts "<revision-range>..." arguments in a similar way as many other Git commands. This makes its interface more standard and more flexible.

Also as the interface of the command is now mostly finalized, we can add some documentation as well as testcases to make sure the command will continue to work as designed in the future.

---
 Documentation/git-replay.txt             | 88 ++++++++++++++++++++++++
 builtin/replay.c                         | 21 ++----
 t/t3650-replay-basics.sh                 | 83 ++++++++++++++++++++++
 t/t6429-merge-sequence-rename-caching.sh | 18 ++---
 4 files changed, 184 insertions(+), 26 deletions(-)
 create mode 100644 Documentation/git-replay.txt
 create mode 100755 t/t3650-replay-basics.sh
Documentation/git-replay.txt new file +88 -0
new file mode 100644
index 0000000000..394d7b0050
@@ -0,0 +1,88 @@
+git-replay(1)
+=============
+
+NAME
+----
+git-replay - Replay commits on a different base, without touching working tree
+
+
+SYNOPSIS
+--------
+[verse]
+'git replay' --onto <newbase> <revision-range>...
+
+DESCRIPTION
+-----------
+
+Takes a range of commits, and replays them onto a new location.  Does
+not touch the working tree or index, and does not update any
+references.  However, the output of this command is meant to be used
+as input to `git update-ref --stdin`, which would update the relevant
+branches.
+
+THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
+
+OPTIONS
+-------
+
+--onto <newbase>::
+	Starting point at which to create the new commits.  May be any
+	valid commit, and not just an existing branch name.
++
+The update-ref commands in the output will update the branch(es)
+in the revision range to point at the new commits (in other
+words, this mimics a rebase operation).
+
+<revision-range>::
+	Range of commits to replay; see "Specifying Ranges" in
+	linkgit:git-rev-parse.
+
+OUTPUT
+------
+
+When there are no conflicts, the output of this command is usable as
+input to `git update-ref --stdin`.  It is basically of the form:
+
+	update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH}
+	update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
+	update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
+
+where the number of refs updated depend on the arguments passed.
+
+EXIT STATUS
+-----------
+
+For a successful, non-conflicted replay, the exit status is 0.  When
+the replay has conflicts, the exit status is 1.  If the replay is not
+able to complete (or start) due to some kind of error, the exit status
+is something other than 0 or 1.
+
+EXAMPLES
+--------
+
+To simply rebase mybranch onto target:
+
+------------
+$ git replay --onto target origin/main..mybranch
+update refs/heads/mybranch ${NEW_mybranch_HASH} ${OLD_mybranch_HASH}
+------------
+
+When calling `git replay`, one does not need to specify a range of
+commits to replay using the syntax `A..B`; any range expression will
+do:
+
+------------
+$ git replay --onto origin/main ^base branch1 branch2 branch3
+update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH}
+update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
+update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
+------------
+
+This will simultaneously rebase branch1, branch2, and branch3 -- all
+commits they have since base, playing them on top of origin/main.
+These three branches may have commits on top of base that they have in
+common, but that does not need to be the case.
+
+GIT
+---
+Part of the linkgit:git[1] suite
builtin/replay.c +4 -17
index 46f00a2d71..c855e1a128 100644
@@ -14,7 +14,6 @@
 #include "parse-options.h"
 #include "refs.h"
 #include "revision.h"
-#include "strvec.h"
 
 static const char *short_commit_name(struct commit *commit)
 {
@@ -116,16 +115,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 <newbase> <oldbase> <branch>"),
+		N_("git replay --onto <newbase> <revision-range>..."),
 		NULL
 	};
 	struct option replay_options[] = {
@@ -143,20 +140,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;
 	}
 
@@ -166,8 +156,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;
@@ -210,7 +198,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	ret = result.clean;
 
 cleanup:
-	strbuf_release(&branch_name);
 	release_revisions(&revs);
 
 	/* Return */
t/t3650-replay-basics.sh new file +83 -0

83 lines not on this page · raw message

t/t6429-merge-sequence-rename-caching.sh +9 -9
index 099aefeffc..0f39ed0d08 100755
@@ -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 checkout topic &&
 
@@ -141,7 +141,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -201,7 +201,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -279,7 +279,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -357,7 +357,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 git replay --onto HEAD upstream~1 topic >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 checkout topic &&
 
@@ -523,7 +523,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -626,7 +626,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -685,7 +685,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
Signature · 1 line
2.40.1.491.gdff9a222ea
#50 lore raw

PATCH v2 12/15 replay: disallow revision specific options and pathspecs

In reply to Christian Couder

A previous commit changed git replay to make it accept standard revision ranges using the setup_revisions() function. While this is good thing to make this command more standard and more flexible, it has the downside of enabling many revision related options accepted and eaten by setup_revisions().

Some of these options might make sense, but others, like those generating non-contiguous history, might not. Anyway those we might want to allow should probably be tested and perhaps documented a bit, which could be done in future work.

For now it is just simpler and safer to just disallow all of them, so let's do that.

Other commands, like git fast-export, currently allow all these revision specific options even though some of them might not make sense, as these commands also use setup_revisions() but do not check the options that might be passed to this function.

So a way to fix those commands as well as git replay could be to improve or refactor the setup_revisions() mechanism to let callers allow and disallow options in a relevant way for them. Such improvements are outside the scope of this work though.

Pathspecs, which are also accepted and eaten by setup_revisions(), are likely to result in disconnected history. That could perhaps be useful, but that would need tests and documentation, which can be added in future work. So, while at it, let's disallow them too.

---
 builtin/replay.c         | 27 ++++++++++++++++++++++++++-
 t/t3650-replay-basics.sh | 16 ++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)
builtin/replay.c +26 -1
index c855e1a128..7b3c0f2bc4 100644
@@ -119,7 +119,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	struct commit *commit;
 	struct merge_options merge_opt;
 	struct merge_result result;
-	int ret = 0;
+	int ret = 0, i;
 
 	const char * const replay_usage[] = {
 		N_("git replay --onto <newbase> <revision-range>..."),
@@ -135,6 +135,20 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, replay_options, replay_usage,
 			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);
 
+	/*
+	 * TODO: For now, we reject any unknown or invalid option,
+	 * including revision related ones, like --not,
+	 * --first-parent, etc that would be allowed and eaten by
+	 * setup_revisions() below. In the future we should definitely
+	 * accept those that make sense and add related tests and doc
+	 * though.
+	 */
+	for (i = 0; i < argc; i++)
+		if (argv[i][0] == '-') {
+			error(_("invalid option: %s"), argv[i]);
+			usage_with_options(replay_usage, replay_options);
+		}
+
 	if (!onto_name) {
 		error(_("option --onto is mandatory"));
 		usage_with_options(replay_usage, replay_options);
@@ -150,6 +164,17 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		goto cleanup;
 	}
 
+	/*
+	 * TODO: For now, we reject any pathspec. (They are allowed
+	 * and eaten by setup_revisions() above.) In the future we
+	 * should definitely accept them and add related tests and doc
+	 * though.
+	 */
+	if (revs.prune_data.nr) {
+		error(_("invalid pathspec: %s"), revs.prune_data.items[0].match);
+		usage_with_options(replay_usage, replay_options);
+	}
+
 	/* requirements/overrides for revs */
 	revs.reverse = 1;
 	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
t/t3650-replay-basics.sh +16 -0
index a1da4f9ef9..de6e40950e 100755
@@ -80,4 +80,20 @@ test_expect_success 'using replay on bare repo to rebase with a conflict' '
 	test_expect_code 1 git -C bare replay --onto topic1 B..conflict
 '
 
+test_expect_success 'using replay with (for now) disallowed revision specific option --not' '
+	test_must_fail git replay --onto main topic2 --not topic1
+'
+
+test_expect_success 'using replay on bare repo with (for now) disallowed revision specific option --first-parent' '
+	test_must_fail git -C bare replay --onto main --first-parent topic1..topic2
+'
+
+test_expect_success 'using replay with disallowed pathspec' '
+	test_must_fail git replay --onto main topic1..topic2 A.t
+'
+
+test_expect_success 'using replay on bare repo with disallowed pathspec' '
+	test_must_fail git -C bare replay --onto main topic1..topic2 -- A.t
+'
+
 test_done
Signature · 1 line
2.40.1.491.gdff9a222ea
#51 lore raw

Re: [PATCH v2 12/15] replay: disallow revision specific options and pathspecs

Quoted 3 lines · Christian Couder

A previous commit changed git replay to make it accept standard revision ranges using the setup_revisions() function. While this is good

s/is good/is a good/

Quoted 3 lines

thing to make this command more standard and more flexible, it has the downside of enabling many revision related options accepted and eaten by setup_revisions().

[...]

Quoted 22 lines
builtin/replay.c +14 -0
@@ -135,6 +135,20 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, replay_options, replay_usage,
                             PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);
 
+       /*
+        * TODO: For now, we reject any unknown or invalid option,
+        * including revision related ones, like --not,
+        * --first-parent, etc that would be allowed and eaten by
+        * setup_revisions() below. In the future we should definitely
+        * accept those that make sense and add related tests and doc
+        * though.
+        */
+       for (i = 0; i < argc; i++)
+               if (argv[i][0] == '-') {
+                       error(_("invalid option: %s"), argv[i]);
+                       usage_with_options(replay_usage, replay_options);
+               }
+
        if (!onto_name) {
                error(_("option --onto is mandatory"));
                usage_with_options(replay_usage, replay_options);

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 172

Quoted 9 lines
builtin/replay.c +6 -0
@@ -150,6 +164,17 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
                goto cleanup;
        }
 
+       /*
+        * TODO: For now, we reject any pathspec. (They are allowed
+        * and eaten by setup_revisions() above.) In the future we
+        * should definitely accept them and add related tests and doc
+        * though.
+        */

I like the previous TODO, but I think this one can just be left out. While it might be possible to do something sensible with pathspecs at least for linear history, it's not clear to me how it could generally work with non-linear history. And since replay has handling non-linear history as a primary (eventual) goal, the "definitely" here seems incorrect to me.

[...]

Rest looks good.

#52 lore raw

PATCH v2 13/15 replay: add --advance or 'cherry-pick' mode

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 Documentation/git-replay.txt |  33 ++++++-
 builtin/replay.c             | 185 +++++++++++++++++++++++++++++++++--
 t/t3650-replay-basics.sh     |  26 +++++
 3 files changed, 230 insertions(+), 14 deletions(-)
Documentation/git-replay.txt +28 -5
index 394d7b0050..439b2f92e7 100644
@@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree
 SYNOPSIS
 --------
 [verse]
-'git replay' --onto <newbase> <revision-range>...
+'git replay' (--onto <newbase> | --advance <branch>) <revision-range>...
 
 DESCRIPTION
 -----------
@@ -29,9 +29,17 @@ OPTIONS
 	Starting point at which to create the new commits.  May be any
 	valid commit, and not just an existing branch name.
 +
-The update-ref commands in the output will update the branch(es)
-in the revision range to point at the new commits (in other
-words, this mimics a rebase operation).
+When `--onto` is specified, the update-ref command(s) in the output will
+update the branch(es) in the revision range to point at the new
+commits (in other words, this mimics a rebase operation).
+
+--advance <branch>::
+	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).
 
 <revision-range>::
 	Range of commits to replay; see "Specifying Ranges" in
@@ -47,7 +55,10 @@ input to `git update-ref --stdin`.  It is basically of the form:
 	update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
 	update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
 
-where the number of refs updated depend on the arguments passed.
+where the number of refs updated depend on the arguments passed.  When
+using `--advance`, the number of refs updated is always one, but for
+`--onto`, it can be one or more (rebasing multiple branches
+simultaneously is supported).
 
 EXIT STATUS
 -----------
@@ -67,6 +78,18 @@ $ git replay --onto target origin/main..mybranch
 update refs/heads/mybranch ${NEW_mybranch_HASH} ${OLD_mybranch_HASH}
 ------------
 
+To cherry-pick the commits from mybranch onto target:
+
+------------
+$ git replay --advance target origin/main..mybranch
+update refs/heads/target ${NEW_target_HASH} ${OLD_target_HASH}
+------------
+
+Note that the first two examples replay the exact same commits and on
+top of the exact same new base, they only differ in that the first
+provides instructions to make mybranch point at the new commits and
+the second provides instructions to make target point at them.
+
 When calling `git replay`, one does not need to specify a range of
 commits to replay using the syntax `A..B`; any range expression will
 do:
builtin/replay.c +176 -9

256 lines not on this page · raw message

t/t3650-replay-basics.sh +26 -0
index de6e40950e..bca405c431 100755
@@ -96,4 +96,30 @@ test_expect_success 'using replay on bare repo with disallowed pathspec' '
 	test_must_fail git -C bare replay --onto main topic1..topic2 -- A.t
 '
 
+test_expect_success 'using replay to perform basic cherry-pick' '
+	# The differences between this test and previous ones are:
+	#   --advance vs --onto
+	# 2nd field of result is refs/heads/main vs. refs/heads/topic2
+	# 4th field of result is hash for main instead of hash for topic2
+
+	git replay --advance main topic1..topic2 >result &&
+
+	test_line_count = 1 result &&
+
+	git log --format=%s $(cut -f 3 -d " " result) >actual &&
+	test_write_lines E D M L B A >expect &&
+	test_cmp expect actual &&
+
+	printf "update refs/heads/main " >expect &&
+	printf "%s " $(cut -f 3 -d " " result) >>expect &&
+	git rev-parse main >>expect &&
+
+	test_cmp expect result
+'
+
+test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
+	git -C bare replay --advance main topic1..topic2 >result-bare &&
+	test_cmp expect result-bare
+'
+
 test_done
Signature · 1 line
2.40.1.491.gdff9a222ea
#53 lore raw

PATCH v2 14/15 replay: add --contained to rebase contained branches

In reply to Christian Couder

From: Elijah Newren <[email protected]>

Let's add a --contained option that can be used along with --onto to rebase all the branches contained in the <revision-range> argument.

---
 Documentation/git-replay.txt | 16 +++++++++++++++-
 builtin/replay.c             | 12 ++++++++++--
 t/t3650-replay-basics.sh     | 29 +++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)
Documentation/git-replay.txt +15 -1
index 439b2f92e7..3e06ab2f5e 100644
@@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree
 SYNOPSIS
 --------
 [verse]
-'git replay' (--onto <newbase> | --advance <branch>) <revision-range>...
+'git replay' [--contained] (--onto <newbase> | --advance <branch>) <revision-range>...
 
 DESCRIPTION
 -----------
@@ -90,6 +90,20 @@ 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}
+------------
+
+In contrast, trying to do this with rebase would require 3 separate
+rebases, eacho of which involves a different <ONTO> and <UPSTREAM> and
+forces you to first check out each branch in turn.
+
 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:
builtin/replay.c +10 -2
index c146f38f58..4d24eb95d8 100644
@@ -256,6 +256,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;
@@ -266,7 +267,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	int ret = 0, i;
 
 	const char * const replay_usage[] = {
-		N_("git replay (--onto <newbase> | --advance <branch>) <revision-range>..."),
+		N_("git replay [--contained] (--onto <newbase> | --advance <branch>) <revision-range>..."),
 		NULL
 	};
 	struct option replay_options[] = {
@@ -276,6 +277,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()
 	};
 
@@ -301,6 +304,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);
@@ -363,7 +370,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),
t/t3650-replay-basics.sh +29 -0
index bca405c431..3fb4167e69 100755
@@ -122,4 +122,33 @@ test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
 	test_cmp expect result-bare
 '
 
+test_expect_success 'using replay to also rebase a contained branch' '
+	git replay --contained --onto main main..topic3 >result &&
+
+	test_line_count = 2 result &&
+	cut -f 3 -d " " result >new-branch-tips &&
+
+	git log --format=%s $(head -n 1 new-branch-tips) >actual &&
+	test_write_lines F C M L B A >expect &&
+	test_cmp expect actual &&
+
+	git log --format=%s $(tail -n 1 new-branch-tips) >actual &&
+	test_write_lines H G F C M L B A >expect &&
+	test_cmp expect actual &&
+
+	printf "update refs/heads/topic1 " >expect &&
+	printf "%s " $(head -n 1 new-branch-tips) >>expect &&
+	git rev-parse topic1 >>expect &&
+	printf "update refs/heads/topic3 " >>expect &&
+	printf "%s " $(tail -n 1 new-branch-tips) >>expect &&
+	git rev-parse topic3 >>expect &&
+
+	test_cmp expect result
+'
+
+test_expect_success 'using replay on bare repo to also rebase a contained branch' '
+	git -C bare replay --contained --onto main main..topic3 >result-bare &&
+	test_cmp expect result-bare
+'
+
 test_done
Signature · 1 line
2.40.1.491.gdff9a222ea
#54 lore raw

Re: [PATCH v2 14/15] replay: add --contained to rebase contained branches

Quoted 21 lines · Christian Couder

From: Elijah Newren <[email protected]>

Let's add a --contained option that can be used along with --onto to rebase all the branches contained in the <revision-range> argument.

---
 Documentation/git-replay.txt | 16 +++++++++++++++-
 builtin/replay.c             | 12 ++++++++++--
 t/t3650-replay-basics.sh     | 29 +++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)
Documentation/git-replay.txt +0 -0
index 439b2f92e7..3e06ab2f5e 100644

Documentation/git-replay.txt git-replay - Replay commits on a different base, without touching working tree · line 12

Quoted 5 lines
Documentation/git-replay.txt +1 -1
@@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree
 SYNOPSIS
 --------
 [verse]
-'git replay' (--onto <newbase> | --advance <branch>) <revision-range>...
+'git replay' [--contained] (--onto <newbase> | --advance <branch>) <revision-range>...

Should this be

'git replay' ([--contained] --onto <newbase> | --advance <branch>)
<revision-range>...

?

Quoted 9 lines
Documentation/git-replay.txt +2 -0
 DESCRIPTION
 -----------
@@ -90,6 +90,20 @@ 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?

Documentation/git-replay.txt top of the exact same new base, they only differ in that the first · line 104

Quoted 10 lines
Documentation/git-replay.txt +10 -0
+
+------------
+$ 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}
+------------
+
+In contrast, trying to do this with rebase would require 3 separate
+rebases, eacho of which involves a different <ONTO> and <UPSTREAM> and

s/eacho/each/

Documentation/git-replay.txt top of the exact same new base, they only differ in that the first · line 105

Quoted 1 line
Documentation/git-replay.txt +1 -0
+forces you to first check out each branch in turn.

This paragraph isn't true anymore with rebase's --update-refs, right?

Quoted 17 lines
Documentation/git-replay.txt +1 -0
+
 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:
builtin/replay.c +1 -0
index c146f38f58..4d24eb95d8 100644
@@ -256,6 +256,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;

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 270

Quoted 5 lines
builtin/replay.c +1 -1
@@ -266,7 +267,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
        int ret = 0, i;
 
        const char * const replay_usage[] = {
-               N_("git replay (--onto <newbase> | --advance <branch>) <revision-range>..."),
+               N_("git replay [--contained] (--onto <newbase> | --advance <branch>) <revision-range>..."),

Possibly need to update this here too.

Quoted 13 lines
builtin/replay.c +2 -0
                NULL
        };
        struct option replay_options[] = {
@@ -276,6 +277,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()
        };
 

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 309

Quoted 6 lines
builtin/replay.c +3 -0
@@ -301,6 +304,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");

But the code does check that these are incompatible. Good.

Quoted 55 lines
builtin/replay.c +3 -1
+
        repo_init_revisions(the_repository, &revs, prefix);
 
        argc = setup_revisions(argc, argv, &revs, NULL);
@@ -363,7 +370,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),
t/t3650-replay-basics.sh +29 -1
index bca405c431..3fb4167e69 100755
@@ -122,4 +122,33 @@ test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
        test_cmp expect result-bare
 '
 
+test_expect_success 'using replay to also rebase a contained branch' '
+       git replay --contained --onto main main..topic3 >result &&
+
+       test_line_count = 2 result &&
+       cut -f 3 -d " " result >new-branch-tips &&
+
+       git log --format=%s $(head -n 1 new-branch-tips) >actual &&
+       test_write_lines F C M L B A >expect &&
+       test_cmp expect actual &&
+
+       git log --format=%s $(tail -n 1 new-branch-tips) >actual &&
+       test_write_lines H G F C M L B A >expect &&
+       test_cmp expect actual &&
+
+       printf "update refs/heads/topic1 " >expect &&
+       printf "%s " $(head -n 1 new-branch-tips) >>expect &&
+       git rev-parse topic1 >>expect &&
+       printf "update refs/heads/topic3 " >>expect &&
+       printf "%s " $(tail -n 1 new-branch-tips) >>expect &&
+       git rev-parse topic3 >>expect &&
+
+       test_cmp expect result
+'
+
+test_expect_success 'using replay on bare repo to also rebase a contained branch' '
+       git -C bare replay --contained --onto main main..topic3 >result-bare &&
+       test_cmp expect result-bare
+'
+
 test_done
--

2.40.1.491.gdff9a222ea

#55 lore raw

PATCH v2 15/15 replay: stop assuming replayed branches do not diverge

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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 reused a replayed commit instead of the original one.

---
 builtin/replay.c         | 44 ++++++++++++++++++++++++++--------
 t/t3650-replay-basics.sh | 52 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 10 deletions(-)
builtin/replay.c +34 -10
index 4d24eb95d8..7699d28f93 100644
@@ -221,20 +221,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);
 
@@ -248,7 +261,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)
@@ -264,6 +277,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	struct merge_options merge_opt;
 	struct merge_result result;
 	struct strset *update_refs = NULL;
+	kh_oid_map_t *replayed_commits;
 	int ret = 0, i;
 
 	const char * const replay_usage[] = {
@@ -347,21 +361,30 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	init_merge_options(&merge_opt, the_repository);
 	memset(&result, 0, sizeof(result));
 	merge_opt.show_rename_progress = 0;
-
-	result.tree = repo_get_commit_tree(the_repository, onto);
 	last_commit = onto;
+	replayed_commits = kh_init_oid_map();
 	while ((commit = get_revision(&revs))) {
 		const struct name_decoration *decoration;
+		khint_t pos;
+		int hr;
 
 		if (!commit->parents)
 			die(_("replaying down to root commit is not supported yet!"));
 		if (commit->parents->next)
 			die(_("replaying merge commits is not supported yet!"));
 
-		last_commit = pick_regular_commit(commit, last_commit, &merge_opt, &result);
+		last_commit = pick_regular_commit(commit, replayed_commits, onto,
+						  &merge_opt, &result);
 		if (!last_commit)
 			break;
 
+		/* Record commit -> last_commit mapping */
+		pos = kh_put_oid_map(replayed_commits, commit->object.oid, &hr);
+		if (hr == 0)
+			BUG("Duplicate rewritten commit: %s\n",
+			    oid_to_hex(&commit->object.oid));
+		kh_value(replayed_commits, pos) = last_commit;
+
 		/* Update any necessary branches */
 		if (advance_name)
 			continue;
@@ -391,13 +414,14 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 
 	/* Cleanup */
 	merge_finalize(&merge_opt, &result);
-	ret = result.clean;
-
-cleanup:
+	kh_destroy_oid_map(replayed_commits);
 	if (update_refs) {
 		strset_clear(update_refs);
 		free(update_refs);
 	}
+	ret = result.clean;
+
+cleanup:
 	release_revisions(&revs);
 
 	/* Return */
t/t3650-replay-basics.sh +52 -0

56 lines not on this page · raw message

Signature · 1 line
2.40.1.491.gdff9a222ea
#56 lore raw

Re: [PATCH v2 15/15] replay: stop assuming replayed branches do not diverge

Quoted 9 lines · Christian Couder

From: Elijah Newren <[email protected]>

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 reused a

s/resued/reuse/

Quoted 5 lines

replayed commit instead of the original one.

#57 lore raw
In reply to Christian Couder
Quoted 11 lines · Christian Couder

# Intro

git replay has initially been developed entirely by Elijah Newren mostly last year (2022) at:

https://github.com/newren/git/commits/replay

I took over a few months ago to polish and upstream it as GitLab is interested in replacing libgit2, and for that purpose needs a command to do server side (so without using a worktree) rebases, cherry-picks and reverts.

It would help to include the following in future updated rounds, as Elijah is shuffling the header files around agressively and these patches do not build when merged into 'seen'. When these two new includes are added, the series would compile both standalone (i.e. applied on top of 'master') and in 'seen' (i.e. with shuffled headers).

Thanks.

 builtin/replay.c | 2 ++
 1 file changed, 2 insertions(+)
builtin/replay.c +2 -0
index 7699d28f93..62dd1f7fff 100644
@@ -15,6 +15,8 @@
 #include "refs.h"
 #include "revision.h"
 #include "strmap.h"
+#include <oidset.h>
+#include <tree.h>
 
 static const char *short_commit_name(struct commit *commit)
 {
#58 lore raw
Quoted 7 lines · Junio C Hamano

It would help to include the following in future updated rounds, as Elijah is shuffling the header files around agressively and these patches do not build when merged into 'seen'. When these two new includes are added, the series would compile both standalone (i.e. applied on top of 'master') and in 'seen' (i.e. with shuffled headers).

I have just added the two new includes in my current version.

Thanks!

#59 lore raw
In reply to Christian Couder
Quoted 1 line · Christian Couder

[...]

Quoted 37 lines

Now the changes between v1 and v2 are:

* The patch series has been rebased on top of current master, so that conflicts with master are resolved. This required replacing calls to functions like get_oid() with repo_get_oid(), as well as changing some #include "*.h" to use different header files. This unfortunately makes the range-diff between v1 and v2 a bit more difficult to read than we would like.

* Patch 1/15 is a new patch. It has been introduced to rework t6429, so that this test script doesn't break when conflict output is removed later in the series. This allowed us to remove the old 9/14 patch ("replay: very coarse worktree updating").

* The old 9/14 patch ("replay: very coarse worktree updating") was removed. This is to make sure that the new command can be used on bare repos. This enables us to focus first on making sure the new command a good plumbing command that works well on bare repos.

* The old 12/14 patch ("replay: introduce guess_new_base()") was removed. This is also to focus first on making sure the new command is a good plumbing command.

* The old 13/14 patch ("replay: add different modes") has been split into 2 patches: patch 13/15 ("replay: add --advance or 'cherry-pick' mode") and patch 14/15 ("replay: add --contained to rebase contained branches").

* Patch 12/15 ("replay: disallow revision specific options and pathspecs") is a new patch that disallow using revision specific options that would be allowed and eaten by setup_revisions(). Even if it would be very nice to have some of these options in the future, not all these options make sense for the new command, and it might require improving the setup_revisions() mechanism (as well as adding tests and doc) to cleanly allow those we want, but that is outside the scope of this first patch series.

Quoted 3 lines

While at it, this patch also disallow pathspecs too.

It would be nice to have them in the future,

Other than these 10 words and the code comment they represent, all the changes made in v2 look good to me...

Quoted 10 lines

but for now it is not necessary and
would require work (at least for tests and doc) that can be done later.

* Patches 11/15 to 15/15 include a number of new tests to check that the command works well on bare repos, and in case of 11/15 to check that exit code in case of conflict is 1.

* Patch 11/15, in which the doc for the git replay command is introduced, now says that the new command is experimental.

..especially this one. Thanks for including this!

Quoted 4 lines

* Note that a segfault that was found by Derrick Stolee in the v1 is fixed by 000c4ceca7 (merge-ort: fix calling merge_finalize() with no intermediate merge, 2023-04-22) merged to master by 3927312601 (Merge branch 'en/ort-finalize-after-0-merges-fix', 2023-05-02).

#60 lore raw

v3 cover Introduce new `git replay` command

In reply to Christian Couder

# Intro

git replay has initially been developed entirely by Elijah Newren mostly last year (2022) at:

https://github.com/newren/git/commits/replay

I took over this year to polish and upstream it as GitLab is interested in replacing libgit2, and for that purpose needs a command to do server side (so without using a worktree) rebases, cherry-picks and reverts.

I reduced the number of commits and features in this first patch series, compared to what Elijah already developed. Especially I stopped short of replaying merge commits and replaying interactively. These and other features might be upstreamed in the future after this patch series has graduated.

The focus in this series is to make it a good plumbing command that can already be used server side and that replaces the "fast-rebase" test-tool command. So things to make it easier to use on the command line, and more advanced features (like replaying merges) are left out.

# Content of this cover letter

The "Quick Overview" and "Reasons for diverging from cherry-pick & rebase" sections just below are describing the purpose of the new command in the big scheme of things. They are taken from Elijah's design notes
(https://github.com/newren/git/blob/replay/replay-design-notes.txt)
and describe what we want this command to become and the reasons for that, not what the command is after only this patch series. Also these design notes were written at least one year ago, so parts of those 2 sections are not true anymore. I have added Phillip Wood's or Felipe Contreras' notes (thanks to them) where that's the case, but some now flawed parts may have missed.

After these two sections, starting with the "Important limitations" section, you will find sections describing what is actually in this patch series.

More interesting material is available in Elijah's design notes like an "Intro via examples"
(https://github.com/newren/git/blob/replay/replay-design-notes.txt#L37-L132),
a discussion about "Preserving topology, replaying merges"
(https://github.com/newren/git/blob/replay/replay-design-notes.txt#L264-L341)
and a "Current status" section describing Elijah's work
(https://github.com/newren/git/blob/replay/replay-design-notes.txt#L344-L392)
before I started working on upstreaming it.

I have not included this material here though, as the documentation added by this patch series for the git replay command already includes an "EXAMPLES" section, and other sections of Elijah's design notes might not be interesting for now. Also this cover letter is already pretty long. But reviewers can refer to the links above if they think it can help.

# Quick Overview (from Elijah's design notes)

git replay, at a basic level, can perhaps be thought of as a "default-to-dry-run rebase" -- meaning no updates to the working tree, or to the index, or to any references. However, it differs from rebase in that it:

* Works for branches that aren't checked out

* Works in a bare repository

* Can replay multiple branches simultaneously (with or without common history in the range being replayed)

* Preserves relative topology by default (merges are replayed too in Elijah's original work, not in this series)

* Focuses on performance

* Has several altered defaults as a result of the above

I sometimes think of git replay as "fast-replay", a patch-based analogue to the snapshot-based fast-export & fast-import tools.

# Reasons for diverging from cherry-pick & rebase (from Elijah's
design notes)

There are multiple reasons to diverge from the defaults in cherry-pick and rebase.

* Server side needs

* Both cherry-pick and rebase, via the sequencer, are heavily tied to updating the working tree, index, some refs, and a lot of control files with every commit replayed, and invoke a mess of hooks[1] that might be hard to avoid for backward compatibility reasons (at least, that's been brought up a few times on the list).

* cherry-pick and rebase both fork various subprocesses unnecessarily, but somewhat intrinsically in part to ensure the same hooks are called that old scripted implementations would have called.

Note: since 356ee4659bb (sequencer: try to commit without forking 'git commit', 2017-11-24) cherry-pick and rebase do not fork subprocesses other than hooks for the cases covered by this patch series (i.e. they do not fork "git commit" for simple picks).

* "Dry run" behavior, where there are no updates to worktree, index, or even refs might be important.

* Should not assume users only want to operate on HEAD (see next section)

* Decapitate HEAD-centric assumptions

* cherry-pick forces commits to be played on top of HEAD; inflexible.

* rebase assumes the range of commits to be replayed is upstream..HEAD by default, though it allows one to replay upstream..otherbranch -- but it still forcibly and needlessly checks out 'otherbranch' before starting to replay things.

Note: since 767a9c417eb (rebase -i: stop checking out the tip of the branch to rebase, 2020-01-24) it's not true that rebase forcibly and needlessly checks out 'otherbranch'.

* Assuming HEAD is involved severely limits replaying multiple (possibly divergent) branches.

Note: since 89fc0b53fdb (rebase: update refs from 'update-ref' commands, 2022-07-19) the sequencer can update multiple branches. The issue with divergent branch is with command line arguments and the todo list generation rather than the capabilities of the sequencer.

* Once you stop assuming HEAD has a certain meaning, there's not much reason to have two separate commands anymore (except for the funny extra not-necessarily-compatible options both have gained over time).

* (Micro issue: Assuming HEAD is involved also makes it harder for new users to learn what rebase means and does; it makes command lines hard to parse. Not sure I want to harp on this too much, as I have a suspicion I might be creating a tool for experts with complicated use cases, but it's a minor quibble.)

* Performance

* jj is slaughtering us on rebase speed[2]. I would like us to become competitive. (I dropped a few comments in the link at [2] about why git is currently so bad.)

* From [3], there was a simple 4-patch series in linux.git that took 53 seconds to rebase. Switching to ort dropped it to 16 seconds. While that sounds great, only 11 *milliseconds* were needed to do the actual merges. That means almost *all* the time (>99%) was overhead! Big offenders:

* --reapply-cherry-picks should be the default

* can_fast_forward() should be ripped out, and perhaps other extraneous revision walks

Note: d42c9ffa0f (rebase: factor out branch_base calculation, 2022-10-17) might already deal with that (according to Felipe Contreras).

* avoid updating working tree, index, refs, reflogs, and control structures except when needed (e.g. hitting a conflict, or operation finished)

* Other performance ideas (mostly for future work, not in this series)

* single-file control structures instead of directory of files (when doing interactive things which is in Elijah's original work, but not in this series)

* avoid forking subprocesses unless explicitly requested (e.g. --exec, --strategy, --run-hooks). For example, definitely do not invoke git commit or git merge.

* Sanitize hooks:

* dispense with all per-commit hooks for sure (pre-commit, post-commit, post-checkout).

* pre-rebase also seems to assume exactly 1 ref is written, and invoking it repeatedly would be stupid. Plus, it's specific to "rebase". So...ignore? (Stolee's --ref-update option for rebase probably broke the pre-rebase assumptions already...)

* post-rewrite hook might make sense, but fast-import got exempted, and I think of replay like a patch-based analogue to the snapshot-based fast-import.

* When not running server side, resolve conflicts in a sparse-cone sparse-index worktree to reduce number of files written to a working tree. (See below as well.)

* [High risk of possible premature optimization] Avoid large numbers of newly created loose objects, when replaying large numbers of commits. Two possibilities: (1) Consider using tmp-objdir and pack objects from the tmp-objdir at end of exercise, (2) Lift code from git-fast-import to immediately stuff new objects into a pack?

* Multiple branches and non-checked out branches

* The ability to operate on non-checked out branches also implies that we should generally be able to replay when in a dirty working tree (exception being when we expect to update HEAD and any of the dirty files is one that needs to be updated by the replay).

* Also, if we are operating locally on a non-checked out branch and hit a conflict, we should have a way to resolve the conflict without messing with the user's work on their current branch. (This is not is this patch series though.)

* Idea: new worktree with sparse cone + sparse index checkout, containing only files in the root directory, and whatever is necessary to get the conflicts

* Companion to above idea: control structures should be written to $GIT_COMMON_DIR/replay-${worktree}, so users can have multiple replay sessions, and so we know which worktrees are associated with which replay operations.

- [1] https://lore.kernel.org/git/[email protected]/
- [2] https://github.com/martinvonz/jj/discussions/49
- [3] https://lore.kernel.org/git/CABPp-BE48=97k_3tnNqXPjSEfA163F8hoE+HY0Zvz1SWB2B8EA@mail.gmail.com/

# Important limitations

* The code exits with code 1 if there are any conflict. No resumability. No nice output. No interactivity. No special exit code depending on the reason.

* When a commit becomes empty as it is replayed, it is still replayed as an empty commit, instead of being dropped.

* No replaying merges, nor root commits. Only regular commits.

* Signed commits are not properly handled. It's not clear what to do to such commits when replaying on the server side.

* Notes associated with replayed commits are not updated nor duplicated. (Thanks to Phillip Wood for noticing.)

# Commit overview

* 1/15 t6429: remove switching aspects of fast-rebase

New preparatory commit to make it easier to later replace the fast-rebase test-tool by git replay without breaking existing tests.

* 2/15 replay: introduce new builtin

This creates a minimal git replay command by moving the code from the fast-rebase test helper from t/helper/ into builtin/ and doing some renames and a few other needed changes. (In v3 some #include ... were changed to deal with upstream changes in this area as suggested by Junio.)

* - 3/15 replay: start using parse_options API
- 4/15 replay: die() instead of failing assert()
- 5/15 replay: introduce pick_regular_commit()
- 6/15 replay: don't simplify history
- 7/15 replay: add an important FIXME comment about gpg signing
- 8/15 replay: remove progress and info output
- 9/15 replay: remove HEAD related sanity check

These slowly change the command to make it behave more like regular commands and to start cleaning up its output.

* 10/15 replay: make it a minimal server side command

After the cleaning up in previous commits, it's now time to radically change the way it works by stopping it to do ref updates, to update the index and worktree, to consider HEAD as special. Instead just make it output commands that should be passed to git update-ref --stdin.

* 11/15 replay: use standard revision ranges

Start addind new interesting features and also documentation and tests, as the interface of the command is cristalizing into its final form.

* 12/15 replay: disallow revision specific options and pathspecs

For now disallow revision specific options and pathspecs that are allowed and eaten by setup_revisions(), as it's not clear if all of these extra features are really needed, and anyway they would require tests and doc. So we leave them for future improvements. (In v3 a typo was fixed in the commit message and a code comment has been improved as suggested by Elijah.)

* - 13/15 replay: add --advance or 'cherry-pick' mode
- 14/15 replay: add --contained to rebase contained branches

Add new option and features to the command. (In v3, in commit 14/15, the synopsys of the command was improved and a sentence about git rebase in its doc was removed as suggested by Elijah.)

* 15/15 replay: stop assuming replayed branches do not diverge

This adds another interesting feature, as well as related documentation and tests. (In v3 a typo in the commit message was fixed as suggested by Elijah.)

# Notes about fast-rebase, tests and documentation

The fast-rebase test-tool helper was developed by Elijah to experiment with a rebasing tool that would be developed from scratch based on his merge-ort work, could be used to test that merge-ort work, and would not have the speed and interface limitations of git rebase or git cherry-pick.

This fast-rebase helper was used before this series in:

t6429-merge-sequence-rename-caching.sh

So when git replay is created from fast-rebase in patch 2/15, the t6429 test script is also converted to use git replay. This ensures that git replay doesn't break too badly during the first 10 patches in this patch series.

Tests and documentation are introduced specifically for git replay only in 11/15 and later patches as it doesn't make much sense to document and test behavior that we know is going to change soon. So it's only when the command is crystalizing towards its final form that we start documenting and testing it.

# Possibly controversial issues

* bare or not bare: this series works towards a plumbing command with the end goal of it being usable and used first on bare repos, contrary to existing commands like git rebase and git cherry-pick. The tests check that the command works on both bare and non-bare repo though.

* exit status: a successful, non-conflicted replay exits with code
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. There are a few tests checking that. It has been suggested in an internal review that conflicts might want to get a more specific error code as an error code of 1 might be quite easy to return by accident. It doesn't seem to me from their docs (which might want to be improved, I didn't look at the code) that other commands like git merge and git rebase exit with a special error code in case of conflict.

* make worktree and index changes optional: commit 10/15 stops updating the index and worktree, but it might be better especially for cli users to make that optional. The issue is that this would make the command more complex while we are developing a number of important features so that the command can be used on bare repos. It seems that this should rather be done in an iterative improvement after the important features have landed.

* when and where to add tests and docs: although t6429 has tests that are changed to use the new command instead of the fast-rebase test-tool command as soon as the former is introduced, there is no specific test script and no doc for the new command until commit 11/15 when standard revision ranges are used. This is done to avoid churn in tests and docs while the final form of the command hasn't crystalized enough. Adding tests and doc at this point makes this commit quite big and possibly more difficult to review than if they were in separate commits though. On the other hand when tests and docs are added in specific commits some reviewers say it would be better to introduce them when the related changes are made.

* --advance and --contained: these two advanced options might not belong to this first series and could perhaps be added in a followup series in separate commits. On the other hand the code for --contained seems involved with the code of --advance and it's nice to see soon that git replay can indeed do cherry-picking and rebase many refs at once, and this way fullfil these parts of its promise.

* replaying diverging branches: 15/15 the last patch in the series, which allow replaying diverging branches, can be seen as a fundamental fix or alternatively as adding an interesting feature. So it's debatable if it should be in its own patch along with its own tests as in this series, or if it should be merged into a previous patch and which one.

* only 2 patches: this patch series can be seen from a high level point of view as 1) introducing the new git replay command, and 2) using git replay to replace, and get rid of, the fast-rebase test-tool command. The fact that not much of the original fast-rebase code and interface is left would agree with that point of view. On the other hand, fast-rebase can also be seen as a first iteration towards git replay. So it can also make sense to see how git replay evolved from it.

# Changes between v2 and v3

Thanks to Elijah and Junio for their suggestions on the previous version! The very few and minor changes compared to v2 are:

* The patch series was rebased onto master at v2.41.0.

* Patch 2/15 contains #include ... changes suggested by Junio to deal with upstream changes in this area that were merged while I was working on v2 and that conflicted with this series.

* Patch 12/15 has a typo fix in its commit message and an improved code comment both suggested by ELijah. The code comment is about rejecting pathspec. I removed the 'TODO' mention in it and worded it like we "might accept" pathspec in the future, instead of saying that "we should definitely accept them".

* In patch 14/15, as suggested by Elijah, the command synopsys now contains:

  ([--contained] --onto <newbase> | --advance <branch>)

instead of:

  [--contained] (--onto <newbase> | --advance <branch>)

Also in the doc about --contained the sentence talking about git rebase has been removed.

* Patch 15/15 has a typo fix in its commit message.

# Changes between v1 and v2

Thanks to all the reviewers on the mailing list or during a Review Club! Especially, thanks to Elijah, Dscho, Phillip Wood, Derrick Stolee, Patrick Steinhardt, Junio, Felipe Contreras, Calvin Wan and all the Review Club participants.

The Review Club notes (see those on 2023-04-18) are available on:

https://docs.google.com/document/d/14L8BAumGTpsXpjDY8VzZ4rRtpAjuGrFSRqn3stCuS_w/

Now the changes between v1 and v2 are:

* The patch series has been rebased on top of current master, so that conflicts with master are resolved. This required replacing calls to functions like get_oid() with repo_get_oid(), as well as changing some #include "*.h" to use different header files. This unfortunately makes the range-diff between v1 and v2 a bit more difficult to read than we would like.

* Patch 1/15 is a new patch. It has been introduced to rework t6429, so that this test script doesn't break when conflict output is removed later in the series. This allowed us to remove the old 9/14 patch ("replay: very coarse worktree updating").

* The old 9/14 patch ("replay: very coarse worktree updating") was removed. This is to make sure that the new command can be used on bare repos. This enables us to focus first on making sure the new command a good plumbing command that works well on bare repos.

* The old 12/14 patch ("replay: introduce guess_new_base()") was removed. This is also to focus first on making sure the new command is a good plumbing command.

* The old 13/14 patch ("replay: add different modes") has been split into 2 patches: patch 13/15 ("replay: add --advance or 'cherry-pick' mode") and patch 14/15 ("replay: add --contained to rebase contained branches").

* Patch 12/15 ("replay: disallow revision specific options and pathspecs") is a new patch that disallow using revision specific options that would be allowed and eaten by setup_revisions(). Even if it would be very nice to have some of these options in the future, not all these options make sense for the new command, and it might require improving the setup_revisions() mechanism (as well as adding tests and doc) to cleanly allow those we want, but that is outside the scope of this first patch series.

While at it, this patch also disallow pathspecs too. It would be nice to have them in the future, but for now it is not necessary and would require work (at least for tests and doc) that can be done later.

* Patches 11/15 to 15/15 include a number of new tests to check that the command works well on bare repos, and in case of 11/15 to check that exit code in case of conflict is 1.

* Patch 11/15, in which the doc for the git replay command is introduced, now says that the new command is experimental.

* Note that a segfault that was found by Derrick Stolee in the v1 is fixed by 000c4ceca7 (merge-ort: fix calling merge_finalize() with no intermediate merge, 2023-04-22) merged to master by 3927312601 (Merge branch 'en/ort-finalize-after-0-merges-fix', 2023-05-02).

# Range-diff between v2 and v3

 1:  e1bef69d8f =  1:  51fa1c7aea t6429: remove switching aspects of fast-rebase
 2:  73396c4fc9 !  2:  19f8cf1b2e replay: introduce new builtin
    @@ t/helper/test-fast-rebase.c => builtin/replay.c
      #include "cache-tree.h"
      #include "commit.h"
      #include "environment.h"
    +@@
    + #include "sequencer.h"
    + #include "setup.h"
    + #include "strvec.h"
    +-#include "tree.h"
    ++#include <oidset.h>
    ++#include <tree.h>
    + 
    + static const char *short_commit_name(struct commit *commit)
    + {
     @@ builtin/replay.c: static struct commit *create_commit(struct tree *tree,
        return (struct commit *)obj;
      }
 3:  1a1b214146 =  3:  295e876db6 replay: start using parse_options API
 4:  f63d6f0c9f =  4:  6ece7d3751 replay: die() instead of failing assert()
 5:  e7de455815 =  5:  9b4bc659fb replay: introduce pick_regular_commit()
 6:  103c18b3eb =  6:  9ab68d50ab replay: don't simplify history
 7:  5be7eec24f =  7:  37e93faafa replay: add an important FIXME comment about gpg signing
 8:  bb5d3a0564 =  8:  03036781ed replay: remove progress and info output
 9:  a75b02ddae =  9:  4ea289952e replay: remove HEAD related sanity check
10:  cff278a0b9 ! 10:  fba98eda07 replay: make it a minimal server side command
    @@ builtin/replay.c
     -#include "sequencer.h"
     -#include "setup.h"
      #include "strvec.h"
    --#include "tree.h"
    - 
    - static const char *short_commit_name(struct commit *commit)
    - {
    + #include <oidset.h>
    + #include <tree.h>
     @@ builtin/replay.c: 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);

11: 926b332d44 ! 11: 03f9f20f6e replay: use standard revision ranges
@@ builtin/replay.c
#include "refs.h"
#include "revision.h"
-#include "strvec.h"
+ #include <oidset.h>
+ #include <tree.h>

- static const char *short_commit_name(struct commit *commit)
- {
@@ builtin/replay.c: int cmd_replay(int argc, const char **argv, const char *prefix)
struct commit *onto;
const char *onto_name = NULL;
12: f7eb2230a7 ! 12: e651250ac7 replay: disallow revision specific options and pathspecs
@@ Commit message
replay: disallow revision specific options and pathspecs

A previous commit changed git replay to make it accept standard
- revision ranges using the setup_revisions() function. While this is good
- thing to make this command more standard and more flexible, it has the
- downside of enabling many revision related options accepted and eaten by
- setup_revisions().
+ revision ranges using the setup_revisions() function. While this is a
+ good thing to make this command more standard and more flexible, it has
+ the downside of enabling many revision related options accepted and eaten
+ by setup_revisions().

Some of these options might make sense, but others, like those generating non-contiguous history, might not. Anyway those we might want
@@ builtin/replay.c: int cmd_replay(int argc, const char **argv, const char *prefix
}

+ /*
-+ * TODO: For now, we reject any pathspec. (They are allowed
-+ * and eaten by setup_revisions() above.) In the future we
-+ * should definitely accept them and add related tests and doc
-+ * though.
++ * Reject any pathspec. (They are allowed and eaten by
++ * setup_revisions() above.) In the future we might accept
++ * them, after adding related tests and doc though.
+ */
+ if (revs.prune_data.nr) {
+ error(_("invalid pathspec: %s"), revs.prune_data.items[0].match);
13: bc301cf93a ! 13: 56e5416dad replay: add --advance or 'cherry-pick' mode
@@ builtin/replay.c
#include "refs.h"
#include "revision.h"
+#include "strmap.h"
+ #include <oidset.h>
+ #include <tree.h>

- static const char *short_commit_name(struct commit *commit)
- {
@@ builtin/replay.c: static struct commit *create_commit(struct tree *tree,
return (struct commit *)obj;
}
14: 3eb582b509 ! 14: 2cc17dfdc7 replay: add --contained to rebase contained branches

    @@ Documentation/git-replay.txt: git-replay - Replay commits on a different base, w
      --------
      [verse]
     -'git replay' (--onto <newbase> | --advance <branch>) <revision-range>...
    -+'git replay' [--contained] (--onto <newbase> | --advance <branch>) <revision-range>...
    ++'git replay' ([--contained] --onto <newbase> | --advance <branch>) <revision-range>...
      
      DESCRIPTION
      -----------
    @@ Documentation/git-replay.txt: top of the exact same new base, they only differ i
     +update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
     +update refs/heads/tipbranch ${NEW_tipbranch_HASH} ${OLD_tipbranch_HASH}
     +------------
    -+
    -+In contrast, trying to do this with rebase would require 3 separate
    -+rebases, eacho of which involves a different <ONTO> and <UPSTREAM> and
    -+forces you to first check out each branch in turn.
     +
      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
    @@ builtin/replay.c: int cmd_replay(int argc, const char **argv, const char *prefix
      
        const char * const replay_usage[] = {
     -          N_("git replay (--onto <newbase> | --advance <branch>) <revision-range>..."),
    -+          N_("git replay [--contained] (--onto <newbase> | --advance <branch>) <revision-range>..."),
    ++          N_("git replay ([--contained] --onto <newbase> | --advance <branch>) <revision-range>..."),
                NULL
        };
        struct option replay_options[] = {

15: bdd8a3b3e1 ! 15: a6d88fc8f0 replay: stop assuming replayed branches do not diverge
@@ Commit message
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 reused a
+ commit in a key value store, so that we can easily find and reuse a
replayed commit instead of the original one.

Christian Couder (1):
replay: disallow revision specific options and pathspecs

Elijah Newren (14):
t6429: remove switching aspects of fast-rebase
replay: introduce new builtin
replay: start using parse_options API
replay: die() instead of failing assert()
replay: introduce pick_regular_commit()
replay: don't simplify history
replay: add an important FIXME comment about gpg signing
replay: remove progress and info output
replay: remove HEAD related sanity check
replay: make it a minimal server side command
replay: use standard revision ranges
replay: add --advance or 'cherry-pick' mode
replay: add --contained to rebase contained branches
replay: stop assuming replayed branches do not diverge

 .gitignore                               |   1 +
 Documentation/git-replay.txt             | 121 +++++++
 Makefile                                 |   2 +-
 builtin.h                                |   1 +
 builtin/replay.c                         | 432 +++++++++++++++++++++++
 command-list.txt                         |   1 +
 git.c                                    |   1 +
 t/helper/test-fast-rebase.c              | 240 -------------
 t/helper/test-tool.c                     |   1 -
 t/helper/test-tool.h                     |   1 -
 t/t3650-replay-basics.sh                 | 206 +++++++++++
 t/t6429-merge-sequence-rename-caching.sh |  45 +--
 12 files changed, 789 insertions(+), 263 deletions(-)
 create mode 100644 Documentation/git-replay.txt
 create mode 100644 builtin/replay.c
 delete mode 100644 t/helper/test-fast-rebase.c
 create mode 100755 t/t3650-replay-basics.sh
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#61 lore raw

PATCH v3 1/15 t6429: remove switching aspects of fast-rebase

From: Elijah Newren <[email protected]>

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.

---
 t/helper/test-fast-rebase.c              | 9 +--------
 t/t6429-merge-sequence-rename-caching.sh | 9 +++++++--
 2 files changed, 8 insertions(+), 10 deletions(-)
t/helper/test-fast-rebase.c +1 -8
index d1d63feaa9..403bdf8e75 100644
@@ -193,7 +193,7 @@ int cmd__fast_rebase(int argc, const char **argv)
 		last_commit = create_commit(result.tree, commit, last_commit);
 	}
 
-	merge_switch_to_result(&merge_opt, head_tree, &result, 1, !result.clean);
+	merge_finalize(&merge_opt, &result);
 
 	if (result.clean < 0)
 		exit(128);
@@ -212,9 +212,6 @@ int cmd__fast_rebase(int argc, const char **argv)
 		}
 		if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0)
 			die(_("unable to update HEAD"));
-
-		prime_cache_tree(the_repository, the_repository->index,
-				 result.tree);
 	} else {
 		fprintf(stderr, "\nAborting: Hit a conflict.\n");
 		strbuf_addf(&reflog_msg, "rebase progress up to %s",
@@ -227,10 +224,6 @@ int cmd__fast_rebase(int argc, const char **argv)
 			die("Failed to update %s", argv[4]);
 		}
 	}
-	if (write_locked_index(&the_index, &lock,
-			       COMMIT_LOCK | SKIP_IF_UNCHANGED))
-		die(_("unable to write %s"), get_index_file());
-
 	ret = (result.clean == 0);
 cleanup:
 	strbuf_release(&reflog_msg);
t/t6429-merge-sequence-rename-caching.sh +7 -2
index d02fa16614..75d3fd2dba 100755
@@ -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 &&
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#62 lore raw

PATCH v3 2/15 replay: introduce new builtin

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 .gitignore                                    |  1 +
 Makefile                                      |  2 +-
 builtin.h                                     |  1 +
 .../test-fast-rebase.c => builtin/replay.c    | 28 ++++++-------------
 command-list.txt                              |  1 +
 git.c                                         |  1 +
 t/helper/test-tool.c                          |  1 -
 t/helper/test-tool.h                          |  1 -
 t/t6429-merge-sequence-rename-caching.sh      | 27 ++++++------------
 9 files changed, 22 insertions(+), 41 deletions(-)
 rename t/helper/test-fast-rebase.c => builtin/replay.c (89%)
.gitignore +1 -0
index e875c59054..b5f025a296 100644
@@ -135,6 +135,7 @@
 /git-remote-ext
 /git-repack
 /git-replace
+/git-replay
 /git-request-pull
 /git-rerere
 /git-reset
Makefile +1 -1
index e440728c24..a6ab78840f 100644
@@ -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
builtin.h +1 -0
index cb0db67681..c3f0b56915 100644
@@ -214,6 +214,7 @@ int cmd_remote(int argc, const char **argv, const char *prefix);
 int cmd_remote_ext(int argc, const char **argv, const char *prefix);
 int cmd_remote_fd(int argc, const char **argv, const char *prefix);
 int cmd_repack(int argc, const char **argv, const char *prefix);
+int cmd_replay(int argc, const char **argv, const char *prefix);
 int cmd_rerere(int argc, const char **argv, const char *prefix);
 int cmd_reset(int argc, const char **argv, const char *prefix);
 int cmd_restore(int argc, const char **argv, const char *prefix);
builtin/replay.c renamed from t/helper/test-fast-rebase.c +8 -20
similarity index 89%
rename from t/helper/test-fast-rebase.c
rename to builtin/replay.c
index 403bdf8e75..252af62d12 100644
@@ -1,18 +1,11 @@
 /*
- * "git fast-rebase" builtin command
- *
- * FAST: Forking Any Subprocesses (is) Taboo
- *
- * This is meant SOLELY as a demo of what is possible.  sequencer.c and
- * rebase.c should be refactored to use the ideas here, rather than attempting
- * to extend this file to replace those (unless Phillip or Dscho say that
- * refactoring is too hard and we need a clean slate, but I'm guessing that
- * refactoring is the better route).
+ * "git replay" builtin command
  */
 
 #define USE_THE_INDEX_VARIABLE
-#include "test-tool.h"
-#include "cache.h"
+#include "git-compat-util.h"
+
+#include "builtin.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "environment.h"
@@ -26,7 +19,8 @@
 #include "sequencer.h"
 #include "setup.h"
 #include "strvec.h"
-#include "tree.h"
+#include <oidset.h>
+#include <tree.h>
 
 static const char *short_commit_name(struct commit *commit)
 {
@@ -93,7 +87,7 @@ static struct commit *create_commit(struct tree *tree,
 	return (struct commit *)obj;
 }
 
-int cmd__fast_rebase(int argc, const char **argv)
+int cmd_replay(int argc, const char **argv, const char *prefix)
 {
 	struct commit *onto;
 	struct commit *last_commit = NULL, *last_picked_commit = NULL;
@@ -109,12 +103,6 @@ int cmd__fast_rebase(int argc, const char **argv)
 	struct strbuf branch_name = STRBUF_INIT;
 	int ret = 0;
 
-	/*
-	 * test-tool stuff doesn't set up the git directory by default; need to
-	 * do that manually.
-	 */
-	setup_git_directory();
-
 	if (argc == 2 && !strcmp(argv[1], "-h")) {
 		printf("Sorry, I am not a psychiatrist; I can not give you the help you need.  Oh, you meant usage...\n");
 		exit(129);
@@ -135,7 +123,7 @@ int cmd__fast_rebase(int argc, const char **argv)
 	if (repo_read_index(the_repository) < 0)
 		BUG("Could not read index");
 
-	repo_init_revisions(the_repository, &revs, NULL);
+	repo_init_revisions(the_repository, &revs, prefix);
 	revs.verbose_header = 1;
 	revs.max_parents = 1;
 	revs.cherry_mark = 1;
command-list.txt +1 -0
index 54b2a50f5f..d74836ab21 100644
@@ -160,6 +160,7 @@ git-reflog                              ancillarymanipulators           complete
 git-remote                              ancillarymanipulators           complete
 git-repack                              ancillarymanipulators           complete
 git-replace                             ancillarymanipulators           complete
+git-replay                              mainporcelain           history
 git-request-pull                        foreignscminterface             complete
 git-rerere                              ancillaryinterrogators
 git-reset                               mainporcelain           history
git.c +1 -0
index 2f42da20f4..cf95c61813 100644
@@ -593,6 +593,7 @@ static struct cmd_struct commands[] = {
 	{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
 	{ "repack", cmd_repack, RUN_SETUP },
 	{ "replace", cmd_replace, RUN_SETUP },
+	{ "replay", cmd_replay, RUN_SETUP },
 	{ "rerere", cmd_rerere, RUN_SETUP },
 	{ "reset", cmd_reset, RUN_SETUP },
 	{ "restore", cmd_restore, RUN_SETUP | NEED_WORK_TREE },
t/helper/test-tool.c +0 -1
index abe8a785eb..9ca1586de7 100644
@@ -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 },
t/helper/test-tool.h +0 -1
index ea2672436c..a03bbfc6b2 100644
@@ -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);
t/t6429-merge-sequence-rename-caching.sh +9 -18
index 75d3fd2dba..7670b72008 100755
@@ -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 &&
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#63 lore raw

PATCH v3 3/15 replay: start using parse_options API

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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 "<oldbase> <branch>" 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.

---
 builtin/replay.c | 44 ++++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)
builtin/replay.c +32 -12
index 252af62d12..7eb05048a5 100644
@@ -14,6 +14,7 @@
 #include "lockfile.h"
 #include "merge-ort.h"
 #include "object-name.h"
+#include "parse-options.h"
 #include "refs.h"
 #include "revision.h"
 #include "sequencer.h"
@@ -90,6 +91,7 @@ static struct commit *create_commit(struct tree *tree,
 int cmd_replay(int argc, const char **argv, const char *prefix)
 {
 	struct commit *onto;
+	const char *onto_name = NULL;
 	struct commit *last_commit = NULL, *last_picked_commit = NULL;
 	struct object_id head;
 	struct lock_file lock = LOCK_INIT;
@@ -103,16 +105,32 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	struct strbuf branch_name = STRBUF_INIT;
 	int ret = 0;
 
-	if (argc == 2 && !strcmp(argv[1], "-h")) {
-		printf("Sorry, I am not a psychiatrist; I can not give you the help you need.  Oh, you meant usage...\n");
-		exit(129);
+	const char * const replay_usage[] = {
+		N_("git replay --onto <newbase> <oldbase> <branch>"),
+		NULL
+	};
+	struct option replay_options[] = {
+		OPT_STRING(0, "onto", &onto_name,
+			   N_("revision"),
+			   N_("replay onto given commit")),
+		OPT_END()
+	};
+
+	argc = parse_options(argc, argv, prefix, replay_options, replay_usage,
+			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);
+
+	if (!onto_name) {
+		error(_("option --onto is mandatory"));
+		usage_with_options(replay_usage, replay_options);
 	}
 
-	if (argc != 5 || strcmp(argv[1], "--onto"))
-		die("usage: read the code, figure out how to use it, then do so");
+	if (argc != 3) {
+		error(_("bad number of arguments"));
+		usage_with_options(replay_usage, replay_options);
+	}
 
-	onto = peel_committish(argv[2]);
-	strbuf_addf(&branch_name, "refs/heads/%s", argv[4]);
+	onto = peel_committish(onto_name);
+	strbuf_addf(&branch_name, "refs/heads/%s", argv[2]);
 
 	/* Sanity check */
 	if (repo_get_oid(the_repository, "HEAD", &head))
@@ -124,6 +142,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		BUG("Could not read index");
 
 	repo_init_revisions(the_repository, &revs, prefix);
+
 	revs.verbose_header = 1;
 	revs.max_parents = 1;
 	revs.cherry_mark = 1;
@@ -132,7 +151,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	revs.right_only = 1;
 	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
 	revs.topo_order = 1;
-	strvec_pushl(&rev_walk_args, "", argv[4], "--not", argv[3], NULL);
+
+	strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL);
 
 	if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) {
 		ret = error(_("unhandled options"));
@@ -195,8 +215,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 			       &last_commit->object.oid,
 			       &last_picked_commit->object.oid,
 			       REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
-			error(_("could not update %s"), argv[4]);
-			die("Failed to update %s", argv[4]);
+			error(_("could not update %s"), argv[2]);
+			die("Failed to update %s", argv[2]);
 		}
 		if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0)
 			die(_("unable to update HEAD"));
@@ -208,8 +228,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 			       &last_commit->object.oid,
 			       &head,
 			       REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
-			error(_("could not update %s"), argv[4]);
-			die("Failed to update %s", argv[4]);
+			error(_("could not update %s"), argv[2]);
+			die("Failed to update %s", argv[2]);
 		}
 	}
 	ret = (result.clean == 0);
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#64 lore raw

PATCH v3 4/15 replay: die() instead of failing assert()

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
builtin/replay.c +6 -1
index 7eb05048a5..2537adbaea 100644
@@ -178,7 +178,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 
 		fprintf(stderr, "Rebasing %s...\r",
 			oid_to_hex(&commit->object.oid));
-		assert(commit->parents && !commit->parents->next);
+
+		if (!commit->parents)
+			die(_("replaying down to root commit is not supported yet!"));
+		if (commit->parents->next)
+			die(_("replaying merge commits is not supported yet!"));
+
 		base = commit->parents->item;
 
 		next_tree = repo_get_commit_tree(the_repository, commit);
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#65 lore raw

PATCH v3 5/15 replay: introduce pick_regular_commit()

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 54 ++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 20 deletions(-)
builtin/replay.c +34 -20
index 2537adbaea..319020f5fd 100644
@@ -88,6 +88,35 @@ static struct commit *create_commit(struct tree *tree,
 	return (struct commit *)obj;
 }
 
+static struct commit *pick_regular_commit(struct commit *pickme,
+					  struct commit *last_commit,
+					  struct merge_options *merge_opt,
+					  struct merge_result *result)
+{
+	struct commit *base;
+	struct tree *pickme_tree, *base_tree;
+
+	base = pickme->parents->item;
+
+	pickme_tree = repo_get_commit_tree(the_repository, pickme);
+	base_tree = repo_get_commit_tree(the_repository, base);
+
+	merge_opt->branch2 = short_commit_name(pickme);
+	merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2);
+
+	merge_incore_nonrecursive(merge_opt,
+				  base_tree,
+				  result->tree,
+				  pickme_tree,
+				  result);
+
+	free((char*)merge_opt->ancestor);
+	merge_opt->ancestor = NULL;
+	if (!result->clean)
+		return NULL;
+	return create_commit(result->tree, pickme, last_commit);
+}
+
 int cmd_replay(int argc, const char **argv, const char *prefix)
 {
 	struct commit *onto;
@@ -99,7 +128,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	struct rev_info revs;
 	struct commit *commit;
 	struct merge_options merge_opt;
-	struct tree *next_tree, *base_tree, *head_tree;
+	struct tree *head_tree;
 	struct merge_result result;
 	struct strbuf reflog_msg = STRBUF_INIT;
 	struct strbuf branch_name = STRBUF_INIT;
@@ -174,7 +203,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	result.tree = head_tree;
 	last_commit = onto;
 	while ((commit = get_revision(&revs))) {
-		struct commit *base;
+		struct commit *pick;
 
 		fprintf(stderr, "Rebasing %s...\r",
 			oid_to_hex(&commit->object.oid));
@@ -184,26 +213,11 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		if (commit->parents->next)
 			die(_("replaying merge commits is not supported yet!"));
 
-		base = commit->parents->item;
-
-		next_tree = repo_get_commit_tree(the_repository, commit);
-		base_tree = repo_get_commit_tree(the_repository, base);
-
-		merge_opt.branch2 = short_commit_name(commit);
-		merge_opt.ancestor = xstrfmt("parent of %s", merge_opt.branch2);
-
-		merge_incore_nonrecursive(&merge_opt,
-					  base_tree,
-					  result.tree,
-					  next_tree,
-					  &result);
-
-		free((char*)merge_opt.ancestor);
-		merge_opt.ancestor = NULL;
-		if (!result.clean)
+		pick = pick_regular_commit(commit, last_commit, &merge_opt, &result);
+		if (!pick)
 			break;
+		last_commit = pick;
 		last_picked_commit = commit;
-		last_commit = create_commit(result.tree, commit, last_commit);
 	}
 
 	merge_finalize(&merge_opt, &result);
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#66 lore raw

PATCH v3 6/15 replay: don't simplify history

In reply to Christian Couder

From: Elijah Newren <[email protected]>

Let's set the rev walking options we need after calling setup_revisions() instead of before. This makes it clearer which options we need.

Also we don't want history simplification, as we want to deal with all the commits in the affected range.

---
 builtin/replay.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
builtin/replay.c +6 -9
index 319020f5fd..d28d468008 100644
@@ -172,15 +172,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 
 	repo_init_revisions(the_repository, &revs, prefix);
 
-	revs.verbose_header = 1;
-	revs.max_parents = 1;
-	revs.cherry_mark = 1;
-	revs.limited = 1;
-	revs.reverse = 1;
-	revs.right_only = 1;
-	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
-	revs.topo_order = 1;
-
 	strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL);
 
 	if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) {
@@ -188,6 +179,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		goto cleanup;
 	}
 
+	/* requirements/overrides for revs */
+	revs.reverse = 1;
+	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
+	revs.topo_order = 1;
+	revs.simplify_history = 0;
+
 	strvec_clear(&rev_walk_args);
 
 	if (prepare_revision_walk(&revs) < 0) {
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#67 lore raw

PATCH v3 7/15 replay: add an important FIXME comment about gpg signing

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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

---
 builtin/replay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/replay.c +1 -1
index d28d468008..52db8e0941 100644
@@ -61,7 +61,7 @@ static struct commit *create_commit(struct tree *tree,
 	struct object *obj;
 	struct commit_list *parents = NULL;
 	char *author;
-	char *sign_commit = NULL;
+	char *sign_commit = NULL; /* FIXME: cli users might want to sign again */
 	struct commit_extra_header *extra;
 	struct strbuf msg = STRBUF_INIT;
 	const char *out_enc = get_commit_output_encoding();
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#68 lore raw

PATCH v3 8/15 replay: remove progress and info output

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
builtin/replay.c +1 -6
index 52db8e0941..2ad0835c06 100644
@@ -194,7 +194,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 
 	init_merge_options(&merge_opt, the_repository);
 	memset(&result, 0, sizeof(result));
-	merge_opt.show_rename_progress = 1;
+	merge_opt.show_rename_progress = 0;
 	merge_opt.branch1 = "HEAD";
 	head_tree = repo_get_commit_tree(the_repository, onto);
 	result.tree = head_tree;
@@ -202,9 +202,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	while ((commit = get_revision(&revs))) {
 		struct commit *pick;
 
-		fprintf(stderr, "Rebasing %s...\r",
-			oid_to_hex(&commit->object.oid));
-
 		if (!commit->parents)
 			die(_("replaying down to root commit is not supported yet!"));
 		if (commit->parents->next)
@@ -223,7 +220,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		exit(128);
 
 	if (result.clean) {
-		fprintf(stderr, "\nDone.\n");
 		strbuf_addf(&reflog_msg, "finish rebase %s onto %s",
 			    oid_to_hex(&last_picked_commit->object.oid),
 			    oid_to_hex(&last_commit->object.oid));
@@ -237,7 +233,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0)
 			die(_("unable to update HEAD"));
 	} else {
-		fprintf(stderr, "\nAborting: Hit a conflict.\n");
 		strbuf_addf(&reflog_msg, "rebase progress up to %s",
 			    oid_to_hex(&last_picked_commit->object.oid));
 		if (update_ref(reflog_msg.buf, "HEAD",
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#69 lore raw

PATCH v3 9/15 replay: remove HEAD related sanity check

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
builtin/replay.c +1 -7
index 2ad0835c06..3b86fe140f 100644
@@ -122,7 +122,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	struct commit *onto;
 	const char *onto_name = NULL;
 	struct commit *last_commit = NULL, *last_picked_commit = NULL;
-	struct object_id head;
 	struct lock_file lock = LOCK_INIT;
 	struct strvec rev_walk_args = STRVEC_INIT;
 	struct rev_info revs;
@@ -161,11 +160,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	onto = peel_committish(onto_name);
 	strbuf_addf(&branch_name, "refs/heads/%s", argv[2]);
 
-	/* Sanity check */
-	if (repo_get_oid(the_repository, "HEAD", &head))
-		die(_("Cannot read HEAD"));
-	assert(oideq(&onto->object.oid, &head));
-
 	repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
 	if (repo_read_index(the_repository) < 0)
 		BUG("Could not read index");
@@ -237,7 +231,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 			    oid_to_hex(&last_picked_commit->object.oid));
 		if (update_ref(reflog_msg.buf, "HEAD",
 			       &last_commit->object.oid,
-			       &head,
+			       &onto->object.oid,
 			       REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
 			error(_("could not update %s"), argv[2]);
 			die("Failed to update %s", argv[2]);
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#70 lore raw

PATCH v3 10/15 replay: make it a minimal server side command

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c                         | 78 ++++++++----------------
 t/t6429-merge-sequence-rename-caching.sh | 39 +++++++-----
 2 files changed, 51 insertions(+), 66 deletions(-)
builtin/replay.c +27 -51
index 3b86fe140f..9385973ffc 100644
@@ -6,10 +6,7 @@
 #include "git-compat-util.h"
 
 #include "builtin.h"
-#include "cache-tree.h"
-#include "commit.h"
 #include "environment.h"
-#include "gettext.h"
 #include "hex.h"
 #include "lockfile.h"
 #include "merge-ort.h"
@@ -17,8 +14,6 @@
 #include "parse-options.h"
 #include "refs.h"
 #include "revision.h"
-#include "sequencer.h"
-#include "setup.h"
 #include "strvec.h"
 #include <oidset.h>
 #include <tree.h>
@@ -101,6 +96,7 @@ static struct commit *pick_regular_commit(struct commit *pickme,
 	pickme_tree = repo_get_commit_tree(the_repository, pickme);
 	base_tree = repo_get_commit_tree(the_repository, base);
 
+	merge_opt->branch1 = short_commit_name(last_commit);
 	merge_opt->branch2 = short_commit_name(pickme);
 	merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2);
 
@@ -121,15 +117,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 {
 	struct commit *onto;
 	const char *onto_name = NULL;
-	struct commit *last_commit = NULL, *last_picked_commit = NULL;
-	struct lock_file lock = LOCK_INIT;
+	struct commit *last_commit = NULL;
 	struct strvec rev_walk_args = STRVEC_INIT;
 	struct rev_info revs;
 	struct commit *commit;
 	struct merge_options merge_opt;
-	struct tree *head_tree;
 	struct merge_result result;
-	struct strbuf reflog_msg = STRBUF_INIT;
 	struct strbuf branch_name = STRBUF_INIT;
 	int ret = 0;
 
@@ -160,10 +153,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	onto = peel_committish(onto_name);
 	strbuf_addf(&branch_name, "refs/heads/%s", argv[2]);
 
-	repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
-	if (repo_read_index(the_repository) < 0)
-		BUG("Could not read index");
-
 	repo_init_revisions(the_repository, &revs, prefix);
 
 	strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL);
@@ -189,58 +178,45 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	init_merge_options(&merge_opt, the_repository);
 	memset(&result, 0, sizeof(result));
 	merge_opt.show_rename_progress = 0;
-	merge_opt.branch1 = "HEAD";
-	head_tree = repo_get_commit_tree(the_repository, onto);
-	result.tree = head_tree;
+	result.tree = repo_get_commit_tree(the_repository, onto);
 	last_commit = onto;
 	while ((commit = get_revision(&revs))) {
-		struct commit *pick;
+		const struct name_decoration *decoration;
 
 		if (!commit->parents)
 			die(_("replaying down to root commit is not supported yet!"));
 		if (commit->parents->next)
 			die(_("replaying merge commits is not supported yet!"));
 
-		pick = pick_regular_commit(commit, last_commit, &merge_opt, &result);
-		if (!pick)
+		last_commit = pick_regular_commit(commit, last_commit, &merge_opt, &result);
+		if (!last_commit)
 			break;
-		last_commit = pick;
-		last_picked_commit = commit;
+
+		decoration = get_name_decoration(&commit->object);
+		if (!decoration)
+			continue;
+
+		while (decoration) {
+			if (decoration->type == DECORATION_REF_LOCAL) {
+				printf("update %s %s %s\n",
+				       decoration->name,
+				       oid_to_hex(&last_commit->object.oid),
+				       oid_to_hex(&commit->object.oid));
+			}
+			decoration = decoration->next;
+		}
 	}
 
+	/* Cleanup */
 	merge_finalize(&merge_opt, &result);
+	ret = result.clean;
 
-	if (result.clean < 0)
-		exit(128);
-
-	if (result.clean) {
-		strbuf_addf(&reflog_msg, "finish rebase %s onto %s",
-			    oid_to_hex(&last_picked_commit->object.oid),
-			    oid_to_hex(&last_commit->object.oid));
-		if (update_ref(reflog_msg.buf, branch_name.buf,
-			       &last_commit->object.oid,
-			       &last_picked_commit->object.oid,
-			       REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
-			error(_("could not update %s"), argv[2]);
-			die("Failed to update %s", argv[2]);
-		}
-		if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0)
-			die(_("unable to update HEAD"));
-	} else {
-		strbuf_addf(&reflog_msg, "rebase progress up to %s",
-			    oid_to_hex(&last_picked_commit->object.oid));
-		if (update_ref(reflog_msg.buf, "HEAD",
-			       &last_commit->object.oid,
-			       &onto->object.oid,
-			       REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
-			error(_("could not update %s"), argv[2]);
-			die("Failed to update %s", argv[2]);
-		}
-	}
-	ret = (result.clean == 0);
 cleanup:
-	strbuf_release(&reflog_msg);
 	strbuf_release(&branch_name);
 	release_revisions(&revs);
-	return ret;
+
+	/* Return */
+	if (ret < 0)
+		exit(128);
+	return ret ? 0 : 1;
 }
t/t6429-merge-sequence-rename-caching.sh +24 -15
index 7670b72008..099aefeffc 100755
@@ -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 <out &&
+		git checkout topic &&
 
 		git ls-files >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >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 <out &&
+		git checkout topic &&
 
 		git ls-files >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 <out &&
+		git checkout topic &&
 
 		git ls-files >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >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 <out &&
+		git checkout topic &&
 
 		grep region_enter.*diffcore_rename trace.output >calls &&
 		test_line_count = 2 calls &&
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#71 lore raw

Re: [PATCH v3 10/15] replay: make it a minimal server side command

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 210

Quoted 5 lines · Christian Couder
builtin/replay.c +3 -0
+			decoration = decoration->next;
+		}
 	}
 
+	/* Cleanup */

Nit: I don't think this comment adds much value. I would argue it's more confusing to have it, because there's a label cleanup: just a few lines down.

Quoted 2 lines
builtin/replay.c +1 -0
 	merge_finalize(&merge_opt, &result);
+	ret = result.clean;
#72 lore raw

Re: [PATCH v3 10/15] replay: make it a minimal server side command

Quoted 7 lines · Toon Claes
Quoted 4 lines · Christian Couder
builtin/replay.c +2 -0
+                     decoration = decoration->next;
+             }
      }
Quoted 5 lines
Quoted 1 line

+ /* Cleanup */

Nit: I don't think this comment adds much value. I would argue it's more confusing to have it, because there's a label cleanup: just a few lines down.

Ok, I have removed that comment in the version 4 I will send soon.

#73 lore raw

PATCH v3 11/15 replay: use standard revision ranges

In reply to Christian Couder

From: Elijah Newren <[email protected]>

Instead of the fixed "<oldbase> <branch>" arguments, the replay command now accepts "<revision-range>..." arguments in a similar way as many other Git commands. This makes its interface more standard and more flexible.

Also as the interface of the command is now mostly finalized, we can add some documentation as well as testcases to make sure the command will continue to work as designed in the future.

---
 Documentation/git-replay.txt             | 88 ++++++++++++++++++++++++
 builtin/replay.c                         | 21 ++----
 t/t3650-replay-basics.sh                 | 83 ++++++++++++++++++++++
 t/t6429-merge-sequence-rename-caching.sh | 18 ++---
 4 files changed, 184 insertions(+), 26 deletions(-)
 create mode 100644 Documentation/git-replay.txt
 create mode 100755 t/t3650-replay-basics.sh
Documentation/git-replay.txt new file +88 -0
new file mode 100644
index 0000000000..394d7b0050
@@ -0,0 +1,88 @@
+git-replay(1)
+=============
+
+NAME
+----
+git-replay - Replay commits on a different base, without touching working tree
+
+
+SYNOPSIS
+--------
+[verse]
+'git replay' --onto <newbase> <revision-range>...
+
+DESCRIPTION
+-----------
+
+Takes a range of commits, and replays them onto a new location.  Does
+not touch the working tree or index, and does not update any
+references.  However, the output of this command is meant to be used
+as input to `git update-ref --stdin`, which would update the relevant
+branches.
+
+THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
+
+OPTIONS
+-------
+
+--onto <newbase>::
+	Starting point at which to create the new commits.  May be any
+	valid commit, and not just an existing branch name.
++
+The update-ref commands in the output will update the branch(es)
+in the revision range to point at the new commits (in other
+words, this mimics a rebase operation).
+
+<revision-range>::
+	Range of commits to replay; see "Specifying Ranges" in
+	linkgit:git-rev-parse.
+
+OUTPUT
+------
+
+When there are no conflicts, the output of this command is usable as
+input to `git update-ref --stdin`.  It is basically of the form:
+
+	update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH}
+	update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
+	update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
+
+where the number of refs updated depend on the arguments passed.
+
+EXIT STATUS
+-----------
+
+For a successful, non-conflicted replay, the exit status is 0.  When
+the replay has conflicts, the exit status is 1.  If the replay is not
+able to complete (or start) due to some kind of error, the exit status
+is something other than 0 or 1.
+
+EXAMPLES
+--------
+
+To simply rebase mybranch onto target:
+
+------------
+$ git replay --onto target origin/main..mybranch
+update refs/heads/mybranch ${NEW_mybranch_HASH} ${OLD_mybranch_HASH}
+------------
+
+When calling `git replay`, one does not need to specify a range of
+commits to replay using the syntax `A..B`; any range expression will
+do:
+
+------------
+$ git replay --onto origin/main ^base branch1 branch2 branch3
+update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH}
+update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
+update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
+------------
+
+This will simultaneously rebase branch1, branch2, and branch3 -- all
+commits they have since base, playing them on top of origin/main.
+These three branches may have commits on top of base that they have in
+common, but that does not need to be the case.
+
+GIT
+---
+Part of the linkgit:git[1] suite
builtin/replay.c +4 -17
index 9385973ffc..c1bd72c0e5 100644
@@ -14,7 +14,6 @@
 #include "parse-options.h"
 #include "refs.h"
 #include "revision.h"
-#include "strvec.h"
 #include <oidset.h>
 #include <tree.h>
 
@@ -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 <newbase> <oldbase> <branch>"),
+		N_("git replay --onto <newbase> <revision-range>..."),
 		NULL
 	};
 	struct option replay_options[] = {
@@ -145,20 +142,13 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		usage_with_options(replay_usage, replay_options);
 	}
 
-	if (argc != 3) {
-		error(_("bad number of arguments"));
-		usage_with_options(replay_usage, replay_options);
-	}
-
 	onto = peel_committish(onto_name);
-	strbuf_addf(&branch_name, "refs/heads/%s", argv[2]);
 
 	repo_init_revisions(the_repository, &revs, prefix);
 
-	strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL);
-
-	if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) {
-		ret = error(_("unhandled options"));
+	argc = setup_revisions(argc, argv, &revs, NULL);
+	if (argc > 1) {
+		ret = error(_("unrecognized argument: %s"), argv[1]);
 		goto cleanup;
 	}
 
@@ -168,8 +158,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	revs.topo_order = 1;
 	revs.simplify_history = 0;
 
-	strvec_clear(&rev_walk_args);
-
 	if (prepare_revision_walk(&revs) < 0) {
 		ret = error(_("error preparing revisions"));
 		goto cleanup;
@@ -212,7 +200,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	ret = result.clean;
 
 cleanup:
-	strbuf_release(&branch_name);
 	release_revisions(&revs);
 
 	/* Return */
t/t3650-replay-basics.sh new file +83 -0

83 lines not on this page · raw message

t/t6429-merge-sequence-rename-caching.sh +9 -9
index 099aefeffc..0f39ed0d08 100755
@@ -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 checkout topic &&
 
@@ -141,7 +141,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -201,7 +201,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -279,7 +279,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -357,7 +357,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 git replay --onto HEAD upstream~1 topic >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 checkout topic &&
 
@@ -523,7 +523,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -626,7 +626,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
@@ -685,7 +685,7 @@ 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 >out &&
+		git replay --onto HEAD upstream~1..topic >out &&
 		git update-ref --stdin <out &&
 		git checkout topic &&
 
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#74 lore raw

Re: [PATCH v3 11/15] replay: use standard revision ranges

Documentation/git-replay.txt line 19

Quoted 6 lines · Christian Couder
Documentation/git-replay.txt new file +6 -0
+DESCRIPTION
+-----------
+
+Takes a range of commits, and replays them onto a new location.  Does
+not touch the working tree or index, and does not update any
+references.  However, the output of this command is meant to be used

Small suggestion here:

Takes a range of commits, and replays them onto a new location. Does neither touch the working tree nor index, and does not update any references.

#75 lore raw

Re: [PATCH v3 11/15] replay: use standard revision ranges

Quoted 12 lines · Toon Claes

Documentation/git-replay.txt line 19

Quoted 6 lines · Christian Couder
Documentation/git-replay.txt new file +6 -0
+DESCRIPTION
+-----------
+
+Takes a range of commits, and replays them onto a new location.  Does
+not touch the working tree or index, and does not update any
+references.  However, the output of this command is meant to be used

Small suggestion here:

Quoted 3 lines

Takes a range of commits, and replays them onto a new location. Does neither touch the working tree nor index, and does not update any references.

I am not a native speaker, so I am not sure what's best here. I find your suggestion a bit less clear though, so until a native speaker agrees with it or maybe finds something even better, I prefer to leave it as-is.

#76 lore raw

Re: [PATCH v3 11/15] replay: use standard revision ranges

Quoted 13 lines · Christian Couder
Quoted 12 lines · Toon Claes

Documentation/git-replay.txt line 19

Quoted 6 lines · Christian Couder
Documentation/git-replay.txt new file +6 -0
+DESCRIPTION
+-----------
+
+Takes a range of commits, and replays them onto a new location.  Does
+not touch the working tree or index, and does not update any
+references.  However, the output of this command is meant to be used

Small suggestion here:

Quoted 8 lines
Quoted 3 lines

Takes a range of commits, and replays them onto a new location. Does neither touch the working tree nor index, and does not update any references.

I am not a native speaker, so I am not sure what's best here. I find your suggestion a bit less clear though, so until a native speaker agrees with it or maybe finds something even better, I prefer to leave it as-is.

I'm also not a native English speaker, but I spent about 2.5 years contributing a whole lot to English Wikipedia, so I'd dare to say I've honed my English skills rather well. Thus, here's my take on this:

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 to be used...

This is written in a concise yet slightly imperative way, which should be suitable for the purpose. I hope you agree.

#77 lore raw

Re: [PATCH v3 11/15] replay: use standard revision ranges

Quoted 28 lines · Dragan Simic
Quoted 13 lines · Christian Couder
Quoted 12 lines · Toon Claes

Documentation/git-replay.txt line 19

Quoted 6 lines · Christian Couder
Documentation/git-replay.txt new file +6 -0
+DESCRIPTION
+-----------
+
+Takes a range of commits, and replays them onto a new location.  Does
+not touch the working tree or index, and does not update any
+references.  However, the output of this command is meant to be used

Small suggestion here:

Quoted 8 lines
Quoted 3 lines

Takes a range of commits, and replays them onto a new location. Does neither touch the working tree nor index, and does not update any references.

I am not a native speaker, so I am not sure what's best here. I find your suggestion a bit less clear though, so until a native speaker agrees with it or maybe finds something even better, I prefer to leave it as-is.

I'm also not a native English speaker, but I spent about 2.5 years contributing a whole lot to English Wikipedia, so I'd dare to say I've honed my English skills rather well. Thus, here's my take on this:

Quoted 6 lines

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 to be used...

This is written in a concise yet slightly imperative way, which should be suitable for the purpose. I hope you agree.

I agree and I like it, so I have changed it to the above in version 5 I just sent.

Thanks!

#78 lore raw

Re: [PATCH v3 11/15] replay: use standard revision ranges

Quoted 33 lines · Christian Couder
Quoted 32 lines · Dragan Simic
Quoted 13 lines · Christian Couder
Quoted 12 lines · Toon Claes

Documentation/git-replay.txt line 19

Quoted 6 lines · Christian Couder
Documentation/git-replay.txt new file +6 -0
+DESCRIPTION
+-----------
+
+Takes a range of commits, and replays them onto a new location.  Does
+not touch the working tree or index, and does not update any
+references.  However, the output of this command is meant to be used

Small suggestion here:

Quoted 8 lines
Quoted 3 lines

Takes a range of commits, and replays them onto a new location. Does neither touch the working tree nor index, and does not update any references.

I am not a native speaker, so I am not sure what's best here. I find your suggestion a bit less clear though, so until a native speaker agrees with it or maybe finds something even better, I prefer to leave it as-is.

I'm also not a native English speaker, but I spent about 2.5 years contributing a whole lot to English Wikipedia, so I'd dare to say I've honed my English skills rather well. Thus, here's my take on this:

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 to be used...

Quoted 5 lines
Quoted 2 lines

This is written in a concise yet slightly imperative way, which should be suitable for the purpose. I hope you agree.

I agree and I like it, so I have changed it to the above in version 5 I just sent.

Great, thanks.

#79 lore raw

PATCH v3 12/15 replay: disallow revision specific options and pathspecs

In reply to Christian Couder

A previous commit changed git replay to make it accept standard revision ranges using the setup_revisions() function. While this is a good thing to make this command more standard and more flexible, it has the downside of enabling many revision related options accepted and eaten by setup_revisions().

Some of these options might make sense, but others, like those generating non-contiguous history, might not. Anyway those we might want to allow should probably be tested and perhaps documented a bit, which could be done in future work.

For now it is just simpler and safer to just disallow all of them, so let's do that.

Other commands, like git fast-export, currently allow all these revision specific options even though some of them might not make sense, as these commands also use setup_revisions() but do not check the options that might be passed to this function.

So a way to fix those commands as well as git replay could be to improve or refactor the setup_revisions() mechanism to let callers allow and disallow options in a relevant way for them. Such improvements are outside the scope of this work though.

Pathspecs, which are also accepted and eaten by setup_revisions(), are likely to result in disconnected history. That could perhaps be useful, but that would need tests and documentation, which can be added in future work. So, while at it, let's disallow them too.

---
 builtin/replay.c         | 26 +++++++++++++++++++++++++-
 t/t3650-replay-basics.sh | 16 ++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)
builtin/replay.c +25 -1
index c1bd72c0e5..cffbf34290 100644
@@ -121,7 +121,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	struct commit *commit;
 	struct merge_options merge_opt;
 	struct merge_result result;
-	int ret = 0;
+	int ret = 0, i;
 
 	const char * const replay_usage[] = {
 		N_("git replay --onto <newbase> <revision-range>..."),
@@ -137,6 +137,20 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, replay_options, replay_usage,
 			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);
 
+	/*
+	 * TODO: For now, we reject any unknown or invalid option,
+	 * including revision related ones, like --not,
+	 * --first-parent, etc that would be allowed and eaten by
+	 * setup_revisions() below. In the future we should definitely
+	 * accept those that make sense and add related tests and doc
+	 * though.
+	 */
+	for (i = 0; i < argc; i++)
+		if (argv[i][0] == '-') {
+			error(_("invalid option: %s"), argv[i]);
+			usage_with_options(replay_usage, replay_options);
+		}
+
 	if (!onto_name) {
 		error(_("option --onto is mandatory"));
 		usage_with_options(replay_usage, replay_options);
@@ -152,6 +166,16 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		goto cleanup;
 	}
 
+	/*
+	 * Reject any pathspec. (They are allowed and eaten by
+	 * setup_revisions() above.) In the future we might accept
+	 * them, after adding related tests and doc though.
+	 */
+	if (revs.prune_data.nr) {
+		error(_("invalid pathspec: %s"), revs.prune_data.items[0].match);
+		usage_with_options(replay_usage, replay_options);
+	}
+
 	/* requirements/overrides for revs */
 	revs.reverse = 1;
 	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
t/t3650-replay-basics.sh +16 -0
index a1da4f9ef9..de6e40950e 100755
@@ -80,4 +80,20 @@ test_expect_success 'using replay on bare repo to rebase with a conflict' '
 	test_expect_code 1 git -C bare replay --onto topic1 B..conflict
 '
 
+test_expect_success 'using replay with (for now) disallowed revision specific option --not' '
+	test_must_fail git replay --onto main topic2 --not topic1
+'
+
+test_expect_success 'using replay on bare repo with (for now) disallowed revision specific option --first-parent' '
+	test_must_fail git -C bare replay --onto main --first-parent topic1..topic2
+'
+
+test_expect_success 'using replay with disallowed pathspec' '
+	test_must_fail git replay --onto main topic1..topic2 A.t
+'
+
+test_expect_success 'using replay on bare repo with disallowed pathspec' '
+	test_must_fail git -C bare replay --onto main topic1..topic2 -- A.t
+'
+
 test_done
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#80 lore raw

Re: [PATCH v3 12/15] replay: disallow revision specific options and pathspecs

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 175

Quoted 7 lines · Christian Couder
builtin/replay.c +7 -0
+	/*
+	 * Reject any pathspec. (They are allowed and eaten by
+	 * setup_revisions() above.) In the future we might accept
+	 * them, after adding related tests and doc though.
+	 */
+	if (revs.prune_data.nr) {
+		error(_("invalid pathspec: %s"), revs.prune_data.items[0].match);

This made me waste a few minutes wondering if and how I misspelt my pathspec elements. If we mean "no pathspec is allowed", we should say so instead.

Quoted 31 lines
builtin/replay.c +3 -0
+		usage_with_options(replay_usage, replay_options);
+	}
+
 	/* requirements/overrides for revs */
 	revs.reverse = 1;
 	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
t/t3650-replay-basics.sh +16 -0
index a1da4f9ef9..de6e40950e 100755
@@ -80,4 +80,20 @@ test_expect_success 'using replay on bare repo to rebase with a conflict' '
 	test_expect_code 1 git -C bare replay --onto topic1 B..conflict
 '
 
+test_expect_success 'using replay with (for now) disallowed revision specific option --not' '
+	test_must_fail git replay --onto main topic2 --not topic1
+'
+
+test_expect_success 'using replay on bare repo with (for now) disallowed revision specific option --first-parent' '
+	test_must_fail git -C bare replay --onto main --first-parent topic1..topic2
+'
+
+test_expect_success 'using replay with disallowed pathspec' '
+	test_must_fail git replay --onto main topic1..topic2 A.t
+'
+
+test_expect_success 'using replay on bare repo with disallowed pathspec' '
+	test_must_fail git -C bare replay --onto main topic1..topic2 -- A.t
+'
+
 test_done
#81 lore raw

Re: [PATCH v3 12/15] replay: disallow revision specific options and pathspecs

Quoted 11 lines · Junio C Hamano

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 175

Quoted 7 lines · Christian Couder
builtin/replay.c +7 -0
+     /*
+      * Reject any pathspec. (They are allowed and eaten by
+      * setup_revisions() above.) In the future we might accept
+      * them, after adding related tests and doc though.
+      */
+     if (revs.prune_data.nr) {
+             error(_("invalid pathspec: %s"), revs.prune_data.items[0].match);
Quoted 3 lines

This made me waste a few minutes wondering if and how I misspelt my pathspec elements. If we mean "no pathspec is allowed", we should say so instead.

Yeah, right. I have changed this to:

            error(_("no pathspec is allowed: '%s'"),

revs.prune_data.items[0].match);

Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+             usage_with_options(replay_usage, replay_options);
+     }
#82 lore raw

PATCH v3 13/15 replay: add --advance or 'cherry-pick' mode

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 Documentation/git-replay.txt |  33 ++++++-
 builtin/replay.c             | 185 +++++++++++++++++++++++++++++++++--
 t/t3650-replay-basics.sh     |  26 +++++
 3 files changed, 230 insertions(+), 14 deletions(-)
Documentation/git-replay.txt +28 -5
index 394d7b0050..439b2f92e7 100644
@@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree
 SYNOPSIS
 --------
 [verse]
-'git replay' --onto <newbase> <revision-range>...
+'git replay' (--onto <newbase> | --advance <branch>) <revision-range>...
 
 DESCRIPTION
 -----------
@@ -29,9 +29,17 @@ OPTIONS
 	Starting point at which to create the new commits.  May be any
 	valid commit, and not just an existing branch name.
 +
-The update-ref commands in the output will update the branch(es)
-in the revision range to point at the new commits (in other
-words, this mimics a rebase operation).
+When `--onto` is specified, the update-ref command(s) in the output will
+update the branch(es) in the revision range to point at the new
+commits (in other words, this mimics a rebase operation).
+
+--advance <branch>::
+	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).
 
 <revision-range>::
 	Range of commits to replay; see "Specifying Ranges" in
@@ -47,7 +55,10 @@ input to `git update-ref --stdin`.  It is basically of the form:
 	update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
 	update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
 
-where the number of refs updated depend on the arguments passed.
+where the number of refs updated depend on the arguments passed.  When
+using `--advance`, the number of refs updated is always one, but for
+`--onto`, it can be one or more (rebasing multiple branches
+simultaneously is supported).
 
 EXIT STATUS
 -----------
@@ -67,6 +78,18 @@ $ git replay --onto target origin/main..mybranch
 update refs/heads/mybranch ${NEW_mybranch_HASH} ${OLD_mybranch_HASH}
 ------------
 
+To cherry-pick the commits from mybranch onto target:
+
+------------
+$ git replay --advance target origin/main..mybranch
+update refs/heads/target ${NEW_target_HASH} ${OLD_target_HASH}
+------------
+
+Note that the first two examples replay the exact same commits and on
+top of the exact same new base, they only differ in that the first
+provides instructions to make mybranch point at the new commits and
+the second provides instructions to make target point at them.
+
 When calling `git replay`, one does not need to specify a range of
 commits to replay using the syntax `A..B`; any range expression will
 do:
builtin/replay.c +176 -9

256 lines not on this page · raw message

t/t3650-replay-basics.sh +26 -0
index de6e40950e..bca405c431 100755
@@ -96,4 +96,30 @@ test_expect_success 'using replay on bare repo with disallowed pathspec' '
 	test_must_fail git -C bare replay --onto main topic1..topic2 -- A.t
 '
 
+test_expect_success 'using replay to perform basic cherry-pick' '
+	# The differences between this test and previous ones are:
+	#   --advance vs --onto
+	# 2nd field of result is refs/heads/main vs. refs/heads/topic2
+	# 4th field of result is hash for main instead of hash for topic2
+
+	git replay --advance main topic1..topic2 >result &&
+
+	test_line_count = 1 result &&
+
+	git log --format=%s $(cut -f 3 -d " " result) >actual &&
+	test_write_lines E D M L B A >expect &&
+	test_cmp expect actual &&
+
+	printf "update refs/heads/main " >expect &&
+	printf "%s " $(cut -f 3 -d " " result) >>expect &&
+	git rev-parse main >>expect &&
+
+	test_cmp expect result
+'
+
+test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
+	git -C bare replay --advance main topic1..topic2 >result-bare &&
+	test_cmp expect result-bare
+'
+
 test_done
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#83 lore raw

Re: [PATCH v3 13/15] replay: add --advance or 'cherry-pick' mode

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 108

Quoted 4 lines · Christian Couder
builtin/replay.c +4 -0
+	/*
+	 * When the user specifies e.g.
+	 *   git replay origin/main..mybranch
+	 *   git replay ^origin/next mybranch1 mybranch2

When I'm trying these, I'm getting the error:
error: option --onto or --advance is mandatory

In what situation can I omit both --onto and --advance?

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 152

Quoted 4 lines
builtin/replay.c +4 -0
+static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
+				  const char *onto_name,
+				  const char **advance_name,
+				  struct commit **onto,

Would it make sense to call this target?

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 161

Quoted 9 lines
builtin/replay.c +9 -0
+				  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"));

Do we actually need to disallow this? I mean from git-replay's point of view, there's no technical limitation why can cannot support both modes at once. The update-ref commands in the output will update both target and source branches, but it's not up to us whether that's desired.

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 162

Quoted 1 line
builtin/replay.c +1 -0
+	else if (onto_name) {

No need to 'else' here IMHO.

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 166

Quoted 4 lines
builtin/replay.c +4 -0
+		*onto = peel_committish(onto_name);
+		if (rinfo.positive_refexprs <
+		    strset_get_size(&rinfo.positive_refs))
+			die(_("all positive revisions given must be references"));

I tested this locally with the following command:

$ git replay --onto main OID..OID

This command didn't give any errors, neither did it return any update-ref lines. I would have expected to hit this die().

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 179

Quoted 13 lines
builtin/replay.c +13 -0
+	} else if (*advance_name) {
+		struct object_id oid;
+		char *fullname = NULL;
+
+		*onto = peel_committish(*advance_name);
+		if (repo_dwim_ref(the_repository, *advance_name, strlen(*advance_name),
+			     &oid, &fullname, 0) == 1) {
+			*advance_name = fullname;
+		} else {
+			die(_("argument to --advance must be a reference"));
+		}
+		if (rinfo.positive_refexprs > 1)
+			die(_("cannot advance target with multiple source branches because ordering would be ill-defined"));

The sources aren't always branches, so I suggest something like:

+ die(_("cannot advance target with multiple sources because ordering would be ill-defined"));

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 334

Quoted 5 lines
builtin/replay.c +5 -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!");

When I was testing locally I tried the following:

$ git replay --onto main feature

I was expecting this command to find the common ancestor automatically, but instead I got this error. I'm fine if for now the command does not determine the common ancestor yet, but I think we should provide a better error for this scenario.

t/t3650-replay-basics.sh test_expect_success 'using replay on bare repo with disallowed pathspec' ' · line 125

Quoted 6 lines
t/t3650-replay-basics.sh +5 -0
+test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
+	git -C bare replay --advance main topic1..topic2 >result-bare &&
+	test_cmp expect result-bare
+'
+
 test_done

Shall we add a test case when providing both --onto and --advance? And one that omits both?

#84 lore raw

Re: [PATCH v3 13/15] replay: add --advance or 'cherry-pick' mode

Quoted 9 lines · Toon Claes

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 108

Quoted 4 lines · Christian Couder
builtin/replay.c +4 -0
+     /*
+      * When the user specifies e.g.
+      *   git replay origin/main..mybranch
+      *   git replay ^origin/next mybranch1 mybranch2
Quoted 4 lines

When I'm trying these, I'm getting the error:
error: option --onto or --advance is mandatory

In what situation can I omit both --onto and --advance?

It was possible with version 1 of this series as one of the patches allowed the command to guess the base:

https://lore.kernel.org/git/[email protected]/

so --onto wasn't needed to specify it.

Comments on that patch said that it might be better to focus on a plumbing command first and for that the patch wasn't needed, so I removed it in version 2.

Quoted 6 lines

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 152

Quoted 4 lines
builtin/replay.c +4 -0
+static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
+                               const char *onto_name,
+                               const char **advance_name,
+                               struct commit **onto,

Would it make sense to call this target?

This is more the new base we are rebasing target branches onto. So if we want to change the name, --base or --newbase would make more sense. git rebase already has --onto though, so, if we want to be consistent with it, we should keep --onto for this.

Quoted 6 lines
Quoted 6 lines
builtin/replay.c +6 -0
+                               struct strset **update_refs)
+{
+     struct ref_info rinfo;
+
+     get_ref_information(cmd_info, &rinfo);
+     if (!rinfo.positive_refexprs)
Quoted 8 lines

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 161

Quoted 3 lines
builtin/replay.c +3 -0
+             die(_("need some commits to replay"));
+     if (onto_name && *advance_name)
+             die(_("--onto and --advance are incompatible"));

Do we actually need to disallow this? I mean from git-replay's point of view, there's no technical limitation why can cannot support both modes at once. The update-ref commands in the output will update both target and source branches, but it's not up to us whether that's desired.

I am not sure what you call "target" and "source" branches. Anyway here is in simple terms the way the command works:

1) it takes either --onto <newbase> or --advance <branch> and
then one or more <revision-range>,
2) it replays all the commits in the <revision-range> onto either
<newbase> or <branch>,
3) in case of --advance, it outputs a single command for `git
update-ref --stdin` to advance <branch> to the last commit that was just replayed,
4) in case of --onto, it outputs a number of commands for `git
update-ref --stdin` to update the branches in <revision-range> to where the tip commits of these branches have been replayed.

So --advance is like a cherry-pick, and --onto is like a rebase.

It would be possible to do both a rebase onto a branch and a cherry-pick of the rebased commits onto that branch, but this is not very common and you can achieve the same result by just rebasing and then using git reset or git update-ref to make the branch point to the result of the rebase. So I don't see the point of complicating the command at this point.

Quoted 9 lines
Quoted 1 line

+ else if (onto_name) {

No need to 'else' here IMHO.

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 166

Quoted 4 lines
builtin/replay.c +4 -0
+             *onto = peel_committish(onto_name);
+             if (rinfo.positive_refexprs <
+                 strset_get_size(&rinfo.positive_refs))
+                     die(_("all positive revisions given must be references"));
Quoted 6 lines

I tested this locally with the following command:

$ git replay --onto main OID..OID

This command didn't give any errors, neither did it return any update-ref lines. I would have expected to hit this die().

Yeah, this might be unexpected.

I tested it too and 'rinfo.positive_refexprs' is 1 while 'strset_get_size(&rinfo.positive_refs)' is 0 with such a command.

The result does not look wrong though. Above that code there is:

    if (!rinfo.positive_refexprs)
        die(_("need some commits to replay"));

so it looks like there is at least a check that the revision range passed to the command contains positive commits.

It might be possible that users prefer a command that outputs nothing when there is nothing to replay instead of erroring out.

Quoted 14 lines

builtin/replay.c static struct commit *create_commit(struct tree *tree, · line 179

Quoted 13 lines
builtin/replay.c +13 -0
+     } else if (*advance_name) {
+             struct object_id oid;
+             char *fullname = NULL;
+
+             *onto = peel_committish(*advance_name);
+             if (repo_dwim_ref(the_repository, *advance_name, strlen(*advance_name),
+                          &oid, &fullname, 0) == 1) {
+                     *advance_name = fullname;
+             } else {
+                     die(_("argument to --advance must be a reference"));
+             }
+             if (rinfo.positive_refexprs > 1)
+                     die(_("cannot advance target with multiple source branches because ordering would be ill-defined"));
Quoted 3 lines

The sources aren't always branches, so I suggest something like:

+ die(_("cannot advance target with multiple sources because ordering would be ill-defined"));

Yeah, that looks reasonable. I have made this change in version 4 I will send very soon.

Quoted 6 lines

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 334

Quoted 5 lines
builtin/replay.c +5 -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!");
Quoted 8 lines

When I was testing locally I tried the following:

$ git replay --onto main feature

I was expecting this command to find the common ancestor automatically, but instead I got this error. I'm fine if for now the command does not determine the common ancestor yet, but I think we should provide a better error for this scenario.

I agree that it isn't very user friendly. We could indeed try to find if there is a common ancestor, and, if that's the case, suggest another way to call the command. This is a plumbing command in its early stage though for now. So I guess it's Ok to postpone working on nicer error messages.

Quoted 9 lines

t/t3650-replay-basics.sh test_expect_success 'using replay on bare repo with disallowed pathspec' ' · line 125

Quoted 6 lines
t/t3650-replay-basics.sh +5 -0
+test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
+     git -C bare replay --advance main topic1..topic2 >result-bare &&
+     test_cmp expect result-bare
+'
+
 test_done

Shall we add a test case when providing both --onto and --advance? And one that omits both?

Ok, I have made this change in version 4.

#85 lore raw

Re: [PATCH v3 13/15] replay: add --advance or 'cherry-pick' mode

In reply to Christian Couder
Quoted 3 lines · Christian Couder

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.

If I say

	$ git replay --(advance|onto) xyzzy frotz..nitfol yomin

where the topology of the cherry-picked range look like this

                      x---x---Y yomin
                     /
            E---F---x----x----N nitfol
           /  frotz
          /
         X xyzzy     

after transplanting the commits, we would get something like

                      x---x---Y yomin
                     /
            E---F---x----x----N nitfol
           /  frotz
          /
         X---x----x----N'
              \
               x---x---Y'

Now, if this was done with --onto, nitfol and yomin would point at N' and Y', but with --advance, where would xyzzy go?

Yes, my point is that without --advance, there always is a reasonable set of branch tips that will be moved, but with "--advance", you cannot guarantee that you have any reasonable answer to that question.

The answer could be "when there is no single 'tip of the new history', the command with '--advance' errors out", but whatever behaviour we choose, it should be documented.

Quoted 8 lines
Documentation/git-replay.txt +1 -3
@@ -29,9 +29,17 @@ OPTIONS
 	Starting point at which to create the new commits.  May be any
 	valid commit, and not just an existing branch name.
 +
-The update-ref commands in the output will update the branch(es)
-in the revision range to point at the new commits (in other
-words, this mimics a rebase operation).
+When `--onto` is specified, the update-ref command(s) in the output will

Documentation/git-replay.txt OPTIONS · line 42

Quoted 10 lines
Documentation/git-replay.txt +10 -0
+update the branch(es) in the revision range to point at the new
+commits (in other words, this mimics a rebase operation).
+
+--advance <branch>::
+	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).

This part is not giving much useful information to determine the answer (which might be fine, as long as the answer can easily be found in some other parts of this document, but I would have expected everything necessary would be found here or one item before this one about --onto).

Documentation/git-replay.txt input to `git update-ref --stdin`. It is basically of the form: · line 61

Quoted 9 lines
Documentation/git-replay.txt +4 -1
@@ -47,7 +55,10 @@ input to `git update-ref --stdin`.  It is basically of the form:
 	update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
 	update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
 
-where the number of refs updated depend on the arguments passed.
+where the number of refs updated depend on the arguments passed.  When
+using `--advance`, the number of refs updated is always one, but for
+`--onto`, it can be one or more (rebasing multiple branches
+simultaneously is supported).

"dependS on the arguments passed" is not incorrect per-se, in the sense that if you "replay --onto X E..N" (in the above picture), I think you'll move F and N (two), while "F..N" will only move N (one). But the important thing to convey is how many branches had their tips in the replayed range, no? "depends on the shape of the history being replayed" would be a more correct thing to say for the "--onto" mode. For "--advance", presumably you would require to have a single positive endpoint [*], so "depends on the arguments" is still not wrong per-se, because "when --advance is part of the arguments, the number becomes one".

Side note: even then, I suspect that

git replay --advance X E..F N

should be allowed, simply because there is only one sensible interpretation. You'll end up with a single strand of pearls F--x--x--N transplanted on top of X, and the range happens to contain F and N but it is obvious the end result should advance xyzzy to N because F fast-forwards to N.

I'd say "where the number of ..." and everything after these sample "update" lines should be removed, and instead we should add a few words to the main description of the options, e.g. for "--onto"

Documentation/git-replay.txt OPTIONS · line 34

Quoted 3 lines
Documentation/git-replay.txt +3 -0
+When `--onto` is specified, the update-ref command(s) in the output will
+update the branch(es) in the revision range to point at the new
+commits (in other words, this mimics a rebase operation).

we could update the above to something like

... will update the branches in the revision range to point at the new commits, similar to the way how "rebase --update-refs" updates multiple branches in the affected range.

#86 lore raw

Re: [PATCH v3 13/15] replay: add --advance or 'cherry-pick' mode

Quoted 34 lines · Junio C Hamano
Quoted 3 lines · Christian Couder

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.

If I say

        $ git replay --(advance|onto) xyzzy frotz..nitfol yomin

where the topology of the cherry-picked range look like this

                      x---x---Y yomin
                     /
            E---F---x----x----N nitfol
           /  frotz
          /
         X xyzzy

after transplanting the commits, we would get something like

                      x---x---Y yomin
                     /
            E---F---x----x----N nitfol
           /  frotz
          /
         X---x----x----N'
              \
               x---x---Y'

Now, if this was done with --onto, nitfol and yomin would point at N' and Y', but with --advance, where would xyzzy go?

Quoted 8 lines

Yes, my point is that without --advance, there always is a reasonable set of branch tips that will be moved, but with "--advance", you cannot guarantee that you have any reasonable answer to that question.

The answer could be "when there is no single 'tip of the new history', the command with '--advance' errors out", but whatever behaviour we choose, it should be documented.

Ok, I have improved the commit message by adding the following:

"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."

I have also updated the doc for <revision-range> like this:

"<revision-range>::
Range of commits to replay. More than one <revision-range> can be passed, but in --advance <branch> mode, they should have a single tip, so that it's clear where <branch> should point to. See "Specifying Ranges" in linkgit:git-rev-parse."

Quoted 5 lines
Quoted 5 lines

+--advance <branch>::

Documentation/git-replay.txt +4 -0
+     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
Quoted 8 lines

Documentation/git-replay.txt OPTIONS · line 42

Quoted 2 lines
Documentation/git-replay.txt +2 -0
+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).

This part is not giving much useful information to determine the answer (which might be fine, as long as the answer can easily be found in some other parts of this document, but I would have expected everything necessary would be found here or one item before this one about --onto).

The doc about <revision-range> is just after the above, so I think the above change in the <revision-range> doc is Ok and enough here.

Quoted 4 lines
Quoted 4 lines
Documentation/git-replay.txt +0 -0
@@ -47,7 +55,10 @@ input to `git update-ref --stdin`.  It is basically of the form:
      update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
      update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
 
Quoted 16 lines

Documentation/git-replay.txt input to `git update-ref --stdin`. It is basically of the form: · line 61

Quoted 5 lines
Documentation/git-replay.txt +4 -1
-where the number of refs updated depend on the arguments passed.
+where the number of refs updated depend on the arguments passed.  When
+using `--advance`, the number of refs updated is always one, but for
+`--onto`, it can be one or more (rebasing multiple branches
+simultaneously is supported).

"dependS on the arguments passed" is not incorrect per-se, in the sense that if you "replay --onto X E..N" (in the above picture), I think you'll move F and N (two), while "F..N" will only move N (one). But the important thing to convey is how many branches had their tips in the replayed range, no? "depends on the shape of the history being replayed" would be a more correct thing to say for the "--onto" mode. For "--advance", presumably you would require to have a single positive endpoint [*], so "depends on the arguments" is still not wrong per-se, because "when --advance is part of the arguments, the number becomes one".

Yeah, I agree.

Quoted 4 lines

Side note: even then, I suspect that

git replay --advance X E..F N

Quoted 8 lines

should be allowed, simply because there is only one sensible interpretation. You'll end up with a single strand of pearls F--x--x--N transplanted on top of X, and the range happens to contain F and N but it is obvious the end result should advance xyzzy to N because F fast-forwards to N.

I'd say "where the number of ..." and everything after these sample "update" lines should be removed,

I am not sure it's a good thing to remove that, as I think repeating how things work in the context of an example output can help people understand. I have updated these sentences to the following:

"where the number of refs updated depends on the arguments passed and 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)."

Quoted 9 lines

and instead we should add a few
words to the main description of the options, e.g. for "--onto"

Documentation/git-replay.txt OPTIONS · line 34

Quoted 3 lines
Documentation/git-replay.txt +3 -0
+When `--onto` is specified, the update-ref command(s) in the output will
+update the branch(es) in the revision range to point at the new
+commits (in other words, this mimics a rebase operation).

we could update the above to something like

Quoted 3 lines

... will update the branches in the revision range to point at the new commits, similar to the way how "rebase --update-refs" updates multiple branches in the affected range.

Yeah, I agree. In the version 4 I will send soon, have updated the above to:

"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."

#87 lore raw

PATCH v3 14/15 replay: add --contained to rebase contained branches

In reply to Christian Couder

From: Elijah Newren <[email protected]>

Let's add a --contained option that can be used along with --onto to rebase all the branches contained in the <revision-range> argument.

---
 Documentation/git-replay.txt | 12 +++++++++++-
 builtin/replay.c             | 12 ++++++++++--
 t/t3650-replay-basics.sh     | 29 +++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 3 deletions(-)
Documentation/git-replay.txt +11 -1
index 439b2f92e7..6fcaa44ef2 100644
@@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree
 SYNOPSIS
 --------
 [verse]
-'git replay' (--onto <newbase> | --advance <branch>) <revision-range>...
+'git replay' ([--contained] --onto <newbase> | --advance <branch>) <revision-range>...
 
 DESCRIPTION
 -----------
@@ -90,6 +90,16 @@ top of the exact same new base, they only differ in that the first
 provides instructions to make mybranch point at the new commits and
 the second provides instructions to make target point at them.
 
+What if you have a stack of branches, one depending upon another, and
+you'd really like to rebase the whole set?
+
+------------
+$ git replay --contained --onto origin/main origin/main..tipbranch
+update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH}
+update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
+update refs/heads/tipbranch ${NEW_tipbranch_HASH} ${OLD_tipbranch_HASH}
+------------
+
 When calling `git replay`, one does not need to specify a range of
 commits to replay using the syntax `A..B`; any range expression will
 do:
builtin/replay.c +10 -2
index 4b64d15159..9b182eaa90 100644
@@ -258,6 +258,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	const char *advance_name = NULL;
 	struct commit *onto = NULL;
 	const char *onto_name = NULL;
+	int contained = 0;
 
 	struct rev_info revs;
 	struct commit *last_commit = NULL;
@@ -268,7 +269,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	int ret = 0, i;
 
 	const char * const replay_usage[] = {
-		N_("git replay (--onto <newbase> | --advance <branch>) <revision-range>..."),
+		N_("git replay ([--contained] --onto <newbase> | --advance <branch>) <revision-range>..."),
 		NULL
 	};
 	struct option replay_options[] = {
@@ -278,6 +279,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "onto", &onto_name,
 			   N_("revision"),
 			   N_("replay onto given commit")),
+		OPT_BOOL(0, "contained", &contained,
+			 N_("advance all branches contained in revision-range")),
 		OPT_END()
 	};
 
@@ -303,6 +306,10 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		usage_with_options(replay_usage, replay_options);
 	}
 
+	if (advance_name && contained)
+		die(_("options '%s' and '%s' cannot be used together"),
+		    "--advance", "--contained");
+
 	repo_init_revisions(the_repository, &revs, prefix);
 
 	argc = setup_revisions(argc, argv, &revs, NULL);
@@ -364,7 +371,8 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 			continue;
 		while (decoration) {
 			if (decoration->type == DECORATION_REF_LOCAL &&
-			    strset_contains(update_refs, decoration->name)) {
+			    (contained || strset_contains(update_refs,
+							  decoration->name))) {
 				printf("update %s %s %s\n",
 				       decoration->name,
 				       oid_to_hex(&last_commit->object.oid),
t/t3650-replay-basics.sh +29 -0
index bca405c431..3fb4167e69 100755
@@ -122,4 +122,33 @@ test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
 	test_cmp expect result-bare
 '
 
+test_expect_success 'using replay to also rebase a contained branch' '
+	git replay --contained --onto main main..topic3 >result &&
+
+	test_line_count = 2 result &&
+	cut -f 3 -d " " result >new-branch-tips &&
+
+	git log --format=%s $(head -n 1 new-branch-tips) >actual &&
+	test_write_lines F C M L B A >expect &&
+	test_cmp expect actual &&
+
+	git log --format=%s $(tail -n 1 new-branch-tips) >actual &&
+	test_write_lines H G F C M L B A >expect &&
+	test_cmp expect actual &&
+
+	printf "update refs/heads/topic1 " >expect &&
+	printf "%s " $(head -n 1 new-branch-tips) >>expect &&
+	git rev-parse topic1 >>expect &&
+	printf "update refs/heads/topic3 " >>expect &&
+	printf "%s " $(tail -n 1 new-branch-tips) >>expect &&
+	git rev-parse topic3 >>expect &&
+
+	test_cmp expect result
+'
+
+test_expect_success 'using replay on bare repo to also rebase a contained branch' '
+	git -C bare replay --contained --onto main main..topic3 >result-bare &&
+	test_cmp expect result-bare
+'
+
 test_done
Signature · 1 line
2.41.0.15.ga6d88fc8f0
#88 lore raw

Re: [PATCH v3 14/15] replay: add --contained to rebase contained branches

Quoted 11 lines · Christian Couder
Documentation/git-replay.txt +1 -1
index 439b2f92e7..6fcaa44ef2 100644
@@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree
 SYNOPSIS
 --------
 [verse]
-'git replay' (--onto <newbase> | --advance <branch>) <revision-range>...
+'git replay' ([--contained] --onto <newbase> | --advance <branch>)

<revision-range>...

I'm not sure we need this, or at least not right now. I've been testing with a repo having:

* a13d9c4 (another-feature) yet another commit
* c7afc2e (HEAD -> feature) third commit
* e95cecc second commit
* f141e77 first commit

| * 7bb62ac (main) later commit
| * 506cb0a another commit
|/

* e7acac6 initial commit

I tried both commands:

$ git replay --onto main main..feature main..another-feature
$ git replay --onto main --contained main..another-feature

and they both give the same result (especially with the commit following up this one). What is the upside of having this --contained option?

Maybe it's better to defer this patch to a separate series.

And another question, in git-rebase(1) a similar option is called --update-refs. Would you consider reusing that name here is a good idea for consistency?

builtin/replay.c int cmd_replay(int argc, const char **argv, const char *prefix) · line 311

Quoted 11 lines
builtin/replay.c +3 -0
index 4b64d15159..9b182eaa90 100644
@@ -303,6 +306,10 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		usage_with_options(replay_usage, replay_options);
 	}
 
+	if (advance_name && contained)
+		die(_("options '%s' and '%s' cannot be used together"),
+		    "--advance", "--contained");

Is there a technical issue why we don't support this? I don't really see why we couldn't.

--
Toon

#89 lore raw

Re: [PATCH v3 14/15] replay: add --contained to rebase contained branches

Quoted 28 lines · Toon Claes
Quoted 11 lines · Christian Couder
Documentation/git-replay.txt +1 -1
index 439b2f92e7..6fcaa44ef2 100644
@@ -9,7 +9,7 @@ git-replay - Replay commits on a different base, without touching working tree
 SYNOPSIS
 --------
 [verse]
-'git replay' (--onto <newbase> | --advance <branch>) <revision-range>...
+'git replay' ([--contained] --onto <newbase> | --advance <branch>)

<revision-range>...

I'm not sure we need this, or at least not right now. I've been testing with a repo having:

* a13d9c4 (another-feature) yet another commit
* c7afc2e (HEAD -> feature) third commit
* e95cecc second commit
* f141e77 first commit

| * 7bb62ac (main) later commit
| * 506cb0a another commit
|/

* e7acac6 initial commit

Quoted 7 lines

I tried both commands:

$ git replay --onto main main..feature main..another-feature
$ git replay --onto main --contained main..another-feature

and they both give the same result (especially with the commit following up this one). What is the upside of having this --contained option?

This is expected. The thing is that:

$ git replay --onto main main..another-feature

will only output something to update 'another-feature'

while:

$ git replay --onto main --contained main..another-feature

will output something to update 'another-feature' and also something to update 'feature'.

So when you use --contained you don't need to first find the other branches like 'feature' that point to commits between 'main' and 'another-feature', as --contained will find them for you.

Quoted 1 line

Maybe it's better to defer this patch to a separate series.

I am not sure why you are proposing this. It's true that there are other means to achieve the same thing as --contained, but that doesn't mean that it cannot be useful already. If there were things that needed to be more polished in this feature, then maybe leaving it for a separate series later might allow this series to graduate while --contained is polished, but I don't think we are in this case.

Quoted 3 lines

And another question, in git-rebase(1) a similar option is called --update-refs. Would you consider reusing that name here is a good idea for consistency?

git replay outputs commands that can be passed to git update-ref --stdin, but for now it doesn't run that command itself. So no refs are actually updated. If we ever add an option for git replay to also update the refs, it would have a name probably quite similar to --update-refs so it would be unfortunate if --update-refs is already used for something else.

--contained also tells about the fact that the branches affected by the option are "contained" in the revision range that is passed, which is nice.

In short I think it's just unfortunate that git rebase already uses --update-refs for the "contained" branches, as it would be likely to confuse people if we would use it here for that.

#90 lore raw

PATCH v3 15/15 replay: stop assuming replayed branches do not diverge

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c         | 44 ++++++++++++++++++++++++++--------
 t/t3650-replay-basics.sh | 52 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 10 deletions(-)
builtin/replay.c +34 -10
index 9b182eaa90..a06649fa6e 100644
@@ -223,20 +223,33 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
 	strset_clear(&rinfo.positive_refs);
 }
 
+static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
+				    struct commit *commit,
+				    struct commit *fallback)
+{
+	khint_t pos = kh_get_oid_map(replayed_commits, commit->object.oid);
+	if (pos == kh_end(replayed_commits))
+		return fallback;
+	return kh_value(replayed_commits, pos);
+}
+
 static struct commit *pick_regular_commit(struct commit *pickme,
-					  struct commit *last_commit,
+					  kh_oid_map_t *replayed_commits,
+					  struct commit *onto,
 					  struct merge_options *merge_opt,
 					  struct merge_result *result)
 {
-	struct commit *base;
+	struct commit *base, *replayed_base;
 	struct tree *pickme_tree, *base_tree;
 
 	base = pickme->parents->item;
+	replayed_base = mapped_commit(replayed_commits, base, onto);
 
+	result->tree = repo_get_commit_tree(the_repository, replayed_base);
 	pickme_tree = repo_get_commit_tree(the_repository, pickme);
 	base_tree = repo_get_commit_tree(the_repository, base);
 
-	merge_opt->branch1 = short_commit_name(last_commit);
+	merge_opt->branch1 = short_commit_name(replayed_base);
 	merge_opt->branch2 = short_commit_name(pickme);
 	merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2);
 
@@ -250,7 +263,7 @@ static struct commit *pick_regular_commit(struct commit *pickme,
 	merge_opt->ancestor = NULL;
 	if (!result->clean)
 		return NULL;
-	return create_commit(result->tree, pickme, last_commit);
+	return create_commit(result->tree, pickme, replayed_base);
 }
 
 int cmd_replay(int argc, const char **argv, const char *prefix)
@@ -266,6 +279,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	struct merge_options merge_opt;
 	struct merge_result result;
 	struct strset *update_refs = NULL;
+	kh_oid_map_t *replayed_commits;
 	int ret = 0, i;
 
 	const char * const replay_usage[] = {
@@ -348,21 +362,30 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 	init_merge_options(&merge_opt, the_repository);
 	memset(&result, 0, sizeof(result));
 	merge_opt.show_rename_progress = 0;
-
-	result.tree = repo_get_commit_tree(the_repository, onto);
 	last_commit = onto;
+	replayed_commits = kh_init_oid_map();
 	while ((commit = get_revision(&revs))) {
 		const struct name_decoration *decoration;
+		khint_t pos;
+		int hr;
 
 		if (!commit->parents)
 			die(_("replaying down to root commit is not supported yet!"));
 		if (commit->parents->next)
 			die(_("replaying merge commits is not supported yet!"));
 
-		last_commit = pick_regular_commit(commit, last_commit, &merge_opt, &result);
+		last_commit = pick_regular_commit(commit, replayed_commits, onto,
+						  &merge_opt, &result);
 		if (!last_commit)
 			break;
 
+		/* Record commit -> last_commit mapping */
+		pos = kh_put_oid_map(replayed_commits, commit->object.oid, &hr);
+		if (hr == 0)
+			BUG("Duplicate rewritten commit: %s\n",
+			    oid_to_hex(&commit->object.oid));
+		kh_value(replayed_commits, pos) = last_commit;
+
 		/* Update any necessary branches */
 		if (advance_name)
 			continue;
@@ -392,13 +415,14 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 
 	/* Cleanup */
 	merge_finalize(&merge_opt, &result);
-	ret = result.clean;
-
-cleanup:
+	kh_destroy_oid_map(replayed_commits);
 	if (update_refs) {
 		strset_clear(update_refs);
 		free(update_refs);
 	}
+	ret = result.clean;
+
+cleanup:
 	release_revisions(&revs);
 
 	/* Return */
t/t3650-replay-basics.sh +52 -0

56 lines not on this page · raw message

Signature · 1 line
2.41.0.15.ga6d88fc8f0
#91 lore raw
In reply to Christian Couder
Quoted 6 lines · Christian Couder

# Changes between v2 and v3

Thanks to Elijah and Junio for their suggestions on the previous version! The very few and minor changes compared to v2 are:

* The patch series was rebased onto master at v2.41.0.

It is good to say this than not to say it, but without "in order to ..." it does not help very much. I was hoping "by rebasing, we can avoid unnecessary conflicts with what happened in the upstream in the meantime, namely, modify-remove conflict of X is now gone" or something like that.

#92 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Christian Couder

# Changes between v2 and v3

Thanks to Elijah and Junio for their suggestions on the previous version! The very few and minor changes compared to v2 are:

Quoted 7 lines
Quoted 1 line

* The patch series was rebased onto master at v2.41.0.

It is good to say this than not to say it, but without "in order to ..." it does not help very much. I was hoping "by rebasing, we can avoid unnecessary conflicts with what happened in the upstream in the meantime, namely, modify-remove conflict of X is now gone" or something like that.

The reason was because v2 had conflicts with a patch series from Elijah that changed "#include ...". You asked me to squash a small patch that fixed it, and I did squash it into v3, but I thought it was safer to also rebase.

#93 lore raw

v4 cover Introduce new `git replay` command

In reply to Christian Couder

# Intro

git replay has initially been developed entirely by Elijah Newren mostly last year (2022) at:

https://github.com/newren/git/commits/replay

I took over this year to polish and upstream it as GitLab is interested in replacing libgit2, and for that purpose needs a command to do server side (so without using a worktree) rebases, cherry-picks and reverts.

I reduced the number of commits and features in this first patch series, compared to what Elijah already developed. Especially I stopped short of replaying merge commits and replaying interactively. These and other features might be upstreamed in the future after this patch series has graduated.

The focus in this series is to make it a good plumbing command that can already be used server side and that replaces the "fast-rebase" test-tool command. So things to make it easier to use on the command line, and more advanced features (like replaying merges) are left out.

It looks like GitHub has actually already been using version 3 of this patch series in production with good results. See:

https://github.blog/2023-07-27-scaling-merge-ort-across-github/
https://lore.kernel.org/git/[email protected]/

# Content of this cover letter

The "Quick Overview" and "Reasons for diverging from cherry-pick & rebase" sections just below are describing the purpose of the new command in the big scheme of things. They are taken from Elijah's design notes
(https://github.com/newren/git/blob/replay/replay-design-notes.txt)
and describe what we want this command to become and the reasons for that, not what the command is after only this patch series. Also these design notes were written at least one year ago, so parts of those 2 sections are not true anymore. I have added Phillip Wood's or Felipe Contreras' notes (thanks to them) where that's the case, but some now flawed parts may have missed.

After these two sections, starting with the "Important limitations" section, you will find sections describing what is actually in this patch series.

More interesting material is available in Elijah's design notes like an "Intro via examples"
(https://github.com/newren/git/blob/replay/replay-design-notes.txt#L37-L132),
a discussion about "Preserving topology, replaying merges"
(https://github.com/newren/git/blob/replay/replay-design-notes.txt#L264-L341)
and a "Current status" section describing Elijah's work
(https://github.com/newren/git/blob/replay/replay-design-notes.txt#L344-L392)
before I started working on upstreaming it.

I have not included this material here though, as the documentation added by this patch series for the git replay command already includes an "EXAMPLES" section, and other sections of Elijah's design notes might not be interesting for now. Also this cover letter is already pretty long. But reviewers can refer to the links above if they think it can help.

# Quick Overview (from Elijah's design notes)

git replay, at a basic level, can perhaps be thought of as a "default-to-dry-run rebase" -- meaning no updates to the working tree, or to the index, or to any references. However, it differs from rebase in that it:

* Works for branches that aren't checked out

* Works in a bare repository

* Can replay multiple branches simultaneously (with or without common history in the range being replayed)

* Preserves relative topology by default (merges are replayed too in Elijah's original work, not in this series)

* Focuses on performance

* Has several altered defaults as a result of the above

I sometimes think of git replay as "fast-replay", a patch-based analogue to the snapshot-based fast-export & fast-import tools.

# Reasons for diverging from cherry-pick & rebase (from Elijah's
design notes)

There are multiple reasons to diverge from the defaults in cherry-pick and rebase.

* Server side needs

* Both cherry-pick and rebase, via the sequencer, are heavily tied to updating the working tree, index, some refs, and a lot of control files with every commit replayed, and invoke a mess of hooks[1] that might be hard to avoid for backward compatibility reasons (at least, that's been brought up a few times on the list).

* cherry-pick and rebase both fork various subprocesses unnecessarily, but somewhat intrinsically in part to ensure the same hooks are called that old scripted implementations would have called.

Note: since 356ee4659bb (sequencer: try to commit without forking 'git commit', 2017-11-24) cherry-pick and rebase do not fork subprocesses other than hooks for the cases covered by this patch series (i.e. they do not fork "git commit" for simple picks).

* "Dry run" behavior, where there are no updates to worktree, index, or even refs might be important.

* Should not assume users only want to operate on HEAD (see next section)

* Decapitate HEAD-centric assumptions

* cherry-pick forces commits to be played on top of HEAD; inflexible.

* rebase assumes the range of commits to be replayed is upstream..HEAD by default, though it allows one to replay upstream..otherbranch -- but it still forcibly and needlessly checks out 'otherbranch' before starting to replay things.

Note: since 767a9c417eb (rebase -i: stop checking out the tip of the branch to rebase, 2020-01-24) it's not true that rebase forcibly and needlessly checks out 'otherbranch'.

* Assuming HEAD is involved severely limits replaying multiple (possibly divergent) branches.

Note: since 89fc0b53fdb (rebase: update refs from 'update-ref' commands, 2022-07-19) the sequencer can update multiple branches. The issue with divergent branch is with command line arguments and the todo list generation rather than the capabilities of the sequencer.

* Once you stop assuming HEAD has a certain meaning, there's not much reason to have two separate commands anymore (except for the funny extra not-necessarily-compatible options both have gained over time).

* (Micro issue: Assuming HEAD is involved also makes it harder for new users to learn what rebase means and does; it makes command lines hard to parse. Not sure I want to harp on this too much, as I have a suspicion I might be creating a tool for experts with complicated use cases, but it's a minor quibble.)

* Performance

* jj is slaughtering us on rebase speed[2]. I would like us to become competitive. (I dropped a few comments in the link at [2] about why git is currently so bad.)

* From [3], there was a simple 4-patch series in linux.git that took 53 seconds to rebase. Switching to ort dropped it to 16 seconds. While that sounds great, only 11 *milliseconds* were needed to do the actual merges. That means almost *all* the time (>99%) was overhead! Big offenders:

* --reapply-cherry-picks should be the default

* can_fast_forward() should be ripped out, and perhaps other extraneous revision walks

Note: d42c9ffa0f (rebase: factor out branch_base calculation, 2022-10-17) might already deal with that (according to Felipe Contreras).

* avoid updating working tree, index, refs, reflogs, and control structures except when needed (e.g. hitting a conflict, or operation finished)

* Other performance ideas (mostly for future work, not in this series)

* single-file control structures instead of directory of files (when doing interactive things which is in Elijah's original work, but not in this series)

* avoid forking subprocesses unless explicitly requested (e.g. --exec, --strategy, --run-hooks). For example, definitely do not invoke git commit or git merge.

* Sanitize hooks:

* dispense with all per-commit hooks for sure (pre-commit, post-commit, post-checkout).

* pre-rebase also seems to assume exactly 1 ref is written, and invoking it repeatedly would be stupid. Plus, it's specific to "rebase". So...ignore? (Stolee's --ref-update option for rebase probably broke the pre-rebase assumptions already...)

* post-rewrite hook might make sense, but fast-import got exempted, and I think of replay like a patch-based analogue to the snapshot-based fast-import.

* When not running server side, resolve conflicts in a sparse-cone sparse-index worktree to reduce number of files written to a working tree. (See below as well.)

* [High risk of possible premature optimization] Avoid large numbers of newly created loose objects, when replaying large numbers of commits. Two possibilities: (1) Consider using tmp-objdir and pack objects from the tmp-objdir at end of exercise, (2) Lift code from git-fast-import to immediately stuff new objects into a pack?

* Multiple branches and non-checked out branches

* The ability to operate on non-checked out branches also implies that we should generally be able to replay when in a dirty working tree (exception being when we expect to update HEAD and any of the dirty files is one that needs to be updated by the replay).

* Also, if we are operating locally on a non-checked out branch and hit a conflict, we should have a way to resolve the conflict without messing with the user's work on their current branch. (This is not is this patch series though.)

* Idea: new worktree with sparse cone + sparse index checkout, containing only files in the root directory, and whatever is necessary to get the conflicts

* Companion to above idea: control structures should be written to $GIT_COMMON_DIR/replay-${worktree}, so users can have multiple replay sessions, and so we know which worktrees are associated with which replay operations.

- [1] https://lore.kernel.org/git/[email protected]/
- [2] https://github.com/martinvonz/jj/discussions/49
- [3] https://lore.kernel.org/git/CABPp-BE48=97k_3tnNqXPjSEfA163F8hoE+HY0Zvz1SWB2B8EA@mail.gmail.com/

# Important limitations

* The code exits with code 1 if there are any conflict. No resumability. No nice output. No interactivity. No special exit code depending on the reason.

* When a commit becomes empty as it is replayed, it is still replayed as an empty commit, instead of being dropped.

* No replaying merges, nor root commits. Only regular commits.

* Signed commits are not properly handled. It's not clear what to do to such commits when replaying on the server side.

* Notes associated with replayed commits are not updated nor duplicated. (Thanks to Phillip Wood for noticing.)

# Commit overview

* 1/15 t6429: remove switching aspects of fast-rebase

New preparatory commit to make it easier to later replace the fast-rebase test-tool by git replay without breaking existing tests.

* 2/15 replay: introduce new builtin

This creates a minimal git replay command by moving the code from the fast-rebase test helper from t/helper/ into builtin/ and doing some renames and a few other needed changes. (In v3 some #include ... were changed to deal with upstream changes in this area as suggested by Junio.)

* - 3/15 replay: start using parse_options API
- 4/15 replay: die() instead of failing assert()
- 5/15 replay: introduce pick_regular_commit()
- 6/15 replay: don't simplify history
- 7/15 replay: add an important FIXME comment about gpg signing
- 8/15 replay: remove progress and info output
- 9/15 replay: remove HEAD related sanity check

These slowly change the command to make it behave more like regular commands and to start cleaning up its output.

* 10/15 replay: make it a minimal server side command

After the cleaning up in previous commits, it's now time to radically change the way it works by stopping it to do ref updates, to update the index and worktree, to consider HEAD as special. Instead just make it output commands that should be passed to git update-ref --stdin.

* 11/15 replay: use standard revision ranges

Start addind new interesting features and also documentation and tests, as the interface of the command is cristalizing into its final form.

* 12/15 replay: disallow revision specific options and pathspecs

For now disallow revision specific options and pathspecs that are allowed and eaten by setup_revisions(), as it's not clear if all of these extra features are really needed, and anyway they would require tests and doc. So we leave them for future improvements. (In v3 a typo was fixed in the commit message and a code comment has been improved as suggested by Elijah.)

* - 13/15 replay: add --advance or 'cherry-pick' mode
- 14/15 replay: add --contained to rebase contained branches

Add new option and features to the command. (In v3, in commit 14/15, the synopsys of the command was improved and a sentence about git rebase in its doc was removed as suggested by Elijah.)

* 15/15 replay: stop assuming replayed branches do not diverge

This adds another interesting feature, as well as related documentation and tests. (In v3 a typo in the commit message was fixed as suggested by Elijah.)

# Notes about fast-rebase, tests and documentation

The fast-rebase test-tool helper was developed by Elijah to experiment with a rebasing tool that would be developed from scratch based on his merge-ort work, could be used to test that merge-ort work, and would not have the speed and interface limitations of git rebase or git cherry-pick.

This fast-rebase helper was used before this series in:

t6429-merge-sequence-rename-caching.sh

So when git replay is created from fast-rebase in patch 2/15, the t6429 test script is also converted to use git replay. This ensures that git replay doesn't break too badly during the first 10 patches in this patch series.

Tests and documentation are introduced specifically for git replay only in 11/15 and later patches as it doesn't make much sense to document and test behavior that we know is going to change soon. So it's only when the command is crystalizing towards its final form that we start documenting and testing it.

# Possibly controversial issues

* bare or not bare: this series works towards a plumbing command with the end goal of it being usable and used first on bare repos, contrary to existing commands like git rebase and git cherry-pick. The tests check that the command works on both bare and non-bare repo though.

* exit status: a successful, non-conflicted replay exits with code
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. There are a few tests checking that. It has been suggested in an internal review that conflicts might want to get a more specific error code as an error code of 1 might be quite easy to return by accident. It doesn't seem to me from their docs (which might want to be improved, I didn't look at the code) that other commands like git merge and git rebase exit with a special error code in case of conflict.

* make worktree and index changes optional: commit 10/15 stops updating the index and worktree, but it might be better especially for cli users to make that optional. The issue is that this would make the command more complex while we are developing a number of important features so that the command can be used on bare repos. It seems that this should rather be done in an iterative improvement after the important features have landed.

* when and where to add tests and docs: although t6429 has tests that are changed to use the new command instead of the fast-rebase test-tool command as soon as the former is introduced, there is no specific test script and no doc for the new command until commit 11/15 when standard revision ranges are used. This is done to avoid churn in tests and docs while the final form of the command hasn't crystalized enough. Adding tests and doc at this point makes this commit quite big and possibly more difficult to review than if they were in separate commits though. On the other hand when tests and docs are added in specific commits some reviewers say it would be better to introduce them when the related changes are made.

* --advance and --contained: these two advanced options might not belong to this first series and could perhaps be added in a followup series in separate commits. On the other hand the code for --contained seems involved with the code of --advance and it's nice to see soon that git replay can indeed do cherry-picking and rebase many refs at once, and this way fullfil these parts of its promise.

* replaying diverging branches: 15/15 the last patch in the series, which allow replaying diverging branches, can be seen as a fundamental fix or alternatively as adding an interesting feature. So it's debatable if it should be in its own patch along with its own tests as in this series, or if it should be merged into a previous patch and which one.

* only 2 patches: this patch series can be seen from a high level point of view as 1) introducing the new git replay command, and 2) using git replay to replace, and get rid of, the fast-rebase test-tool command. The fact that not much of the original fast-rebase code and interface is left would agree with that point of view. On the other hand, fast-rebase can also be seen as a first iteration towards git replay. So it can also make sense to see how git replay evolved from it.

# Changes between v3 and v4

Thanks to Toon, Junio and Dscho for their suggestions on the previous version! The very few and minor changes compared to v3 are:

* The patch series was rebased onto master at d814540bb7 (The fifth batch, 2023-09-01). This is to fix a few header related conflicts as can be seen in the range-diff.

* In patch 10/15 (replay: make it a minimal server side command) a /* Cleanup */ code comment has been removed as suggested by Toon.

* In patch 11/15 (replay: use standard revision ranges) the git-replay documentation related to --onto has been improved to better explain which branches will be updated by the update-ref command(s) in the output as suggested by Junio.

* In patch 12/15 (replay: disallow revision specific options and pathspecs) an error message has been improved as suggested by Junio.

* In patch 13/15 (replay: add --advance or 'cherry-pick' mode) the commit message and the git-replay documentation have been improved to better explain that --advance only works when the revision range passed has a single tip as suggested by Junio.

* Also in patch 13/15 (replay: add --advance or 'cherry-pick' mode) an error message has been improved, and a few tests have been added to check that git replay fails when it's passed both --advance and --onto and when it's passed none of these options, as suggested by Toon.

# Range-diff between v3 and v4

 1:  51fa1c7aea =  1:  1eaca9b788 t6429: remove switching aspects of fast-rebase
 2:  19f8cf1b2e !  2:  5ac4beb1ae replay: introduce new builtin
    @@ t/helper/test-fast-rebase.c => builtin/replay.c
      
      #define USE_THE_INDEX_VARIABLE
     -#include "test-tool.h"
    --#include "cache.h"
     +#include "git-compat-util.h"
     +
     +#include "builtin.h"
 3:  295e876db6 !  3:  299381aa9b replay: start using parse_options API
    @@ builtin/replay.c
      #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"
 4:  6ece7d3751 =  4:  3b825c9be0 replay: die() instead of failing assert()
 5:  9b4bc659fb =  5:  b1e890745d replay: introduce pick_regular_commit()
 6:  9ab68d50ab =  6:  ec51351889 replay: don't simplify history
 7:  37e93faafa =  7:  cd4ed07d2d replay: add an important FIXME comment about gpg signing
 8:  03036781ed =  8:  e45a55917c replay: remove progress and info output
 9:  4ea289952e =  9:  0587a76cbb replay: remove HEAD related sanity check
10:  fba98eda07 ! 10:  d10368e87a replay: make it a minimal server side command
    @@ builtin/replay.c
     -#include "commit.h"
      #include "environment.h"
     -#include "gettext.h"
    +-#include "hash.h"
      #include "hex.h"
      #include "lockfile.h"
      #include "merge-ort.h"
    @@ builtin/replay.c: int cmd_replay(int argc, const char **argv, const char *prefix
     +          }
        }
      
    -+  /* Cleanup */
        merge_finalize(&merge_opt, &result);
     +  ret = result.clean;

11: 03f9f20f6e ! 11: 4e09572c43 replay: use standard revision ranges
@@ Documentation/git-replay.txt (new)
+ Starting point at which to create the new commits. May be any
+ valid commit, and not just an existing branch name.
++
-+The update-ref commands in the output will update the branch(es)
-+in the revision range to point at the new commits (in other
-+words, this mimics a rebase operation).
++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.
+
+<revision-range>::
+ Range of commits to replay; see "Specifying Ranges" in
@@ Documentation/git-replay.txt (new)
+ update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
+ update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}
+
-+where the number of refs updated depend on the arguments passed. ++where the number of refs updated depends on the arguments passed and ++the shape of the history being replayed.
+
+EXIT STATUS
+-----------
12: e651250ac7 ! 12: 64b803f1cf replay: disallow revision specific options and pathspecs
@@ builtin/replay.c: int cmd_replay(int argc, const char **argv, const char *prefix
+ * them, after adding related tests and doc though.
+ */
+ if (revs.prune_data.nr) {
-+ error(_("invalid pathspec: %s"), revs.prune_data.items[0].match);
++ error(_("no pathspec is allowed: '%s'"), revs.prune_data.items[0].match);
+ usage_with_options(replay_usage, replay_options);
+ }
+
13: 56e5416dad ! 13: 04f27d81ab replay: add --advance or 'cherry-pick' mode
@@ Commit message
'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.
+

@@ Documentation/git-replay.txt: OPTIONS
Starting point at which to create the new commits. May be any valid commit, and not just an existing branch name.
+
--The update-ref commands in the output will update the branch(es) --in the revision range to point at the new commits (in other --words, this mimics a rebase operation).
+-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 (in other words, this mimics a rebase operation). ++commits, similar to the way how git rebase --update-refs updates ++multiple branches in the affected range.
+
+--advance <branch>::
+ Starting point at which to create the new commits; must be a
@@ Documentation/git-replay.txt: OPTIONS
+the new commits (in other words, this mimics a cherry-pick operation).

<revision-range>::
- Range of commits to replay; see "Specifying Ranges" in
+- Range of commits to replay; see "Specifying Ranges" in
+- linkgit:git-rev-parse.
++ Range of commits to replay. More than one <revision-range> can
++ be passed, but in --advance <branch> mode, they should have
++ a single tip, so that it's clear where <branch> should point
++ to. See "Specifying Ranges" in linkgit:git-rev-parse.
+
+ OUTPUT
+ ------
@@ Documentation/git-replay.txt: input to git update-ref --stdin. It is basically of the form:
- update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH}
update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH}

--where the number of refs updated depend on the arguments passed. -+where the number of refs updated depend on the arguments passed. When -+using --advance, the number of refs updated is always one, but for -+--onto, it can be one or more (rebasing multiple branches -+simultaneously is supported).
+ 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
-----------
@@ builtin/replay.c: static struct commit *create_commit(struct tree *tree,
+ die(_("argument to --advance must be a reference"));
+ }
+ if (rinfo.positive_refexprs > 1)
-+ die(_("cannot advance target with multiple source branches because ordering would be ill-defined"));
++ die(_("cannot advance target with multiple sources because ordering would be ill-defined"));
+ } else {
+ int positive_refs_complete = (
+ rinfo.positive_refexprs ==
@@ builtin/replay.c: int cmd_replay(int argc, const char **argv, const char *prefix
+ oid_to_hex(&onto->object.oid));
+ }
+
- /* Cleanup */
merge_finalize(&merge_opt, &result);
ret = result.clean;

@@ t/t3650-replay-basics.sh: test_expect_success 'using replay on bare repo with di
+ 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
14: 2cc17dfdc7 ! 14: 9ed0919ad5 replay: add --contained to rebase contained branches
@@ builtin/replay.c: int cmd_replay(int argc, const char **argv, const char *prefix
oid_to_hex(&last_commit->object.oid),

## t/t3650-replay-basics.sh ##
-@@ t/t3650-replay-basics.sh: test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
- test_cmp expect result-bare
+@@ t/t3650-replay-basics.sh: 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' '
15: a6d88fc8f0 ! 15: cf8c984877 replay: stop assuming replayed branches do not diverge
@@ builtin/replay.c: int cmd_replay(int argc, const char **argv, const char *prefix
if (advance_name)
continue;
@@ builtin/replay.c: int cmd_replay(int argc, const char **argv, const char *prefix)
+ }

- /* Cleanup */
merge_finalize(&merge_opt, &result);
- ret = result.clean;
-

Christian Couder (1):
replay: disallow revision specific options and pathspecs

Elijah Newren (14):
t6429: remove switching aspects of fast-rebase
replay: introduce new builtin
replay: start using parse_options API
replay: die() instead of failing assert()
replay: introduce pick_regular_commit()
replay: don't simplify history
replay: add an important FIXME comment about gpg signing
replay: remove progress and info output
replay: remove HEAD related sanity check
replay: make it a minimal server side command
replay: use standard revision ranges
replay: add --advance or 'cherry-pick' mode
replay: add --contained to rebase contained branches
replay: stop assuming replayed branches do not diverge

 .gitignore                               |   1 +
 Documentation/git-replay.txt             | 124 +++++++
 Makefile                                 |   2 +-
 builtin.h                                |   1 +
 builtin/replay.c                         | 431 +++++++++++++++++++++++
 command-list.txt                         |   1 +
 git.c                                    |   1 +
 t/helper/test-fast-rebase.c              | 241 -------------
 t/helper/test-tool.c                     |   1 -
 t/helper/test-tool.h                     |   1 -
 t/t3650-replay-basics.sh                 | 214 +++++++++++
 t/t6429-merge-sequence-rename-caching.sh |  45 +--
 12 files changed, 799 insertions(+), 264 deletions(-)
 create mode 100644 Documentation/git-replay.txt
 create mode 100644 builtin/replay.c
 delete mode 100644 t/helper/test-fast-rebase.c
 create mode 100755 t/t3650-replay-basics.sh
Signature · 1 line
2.42.0.126.gcf8c984877
#94 lore raw

PATCH v4 1/15 t6429: remove switching aspects of fast-rebase

From: Elijah Newren <[email protected]>

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.

---
 t/helper/test-fast-rebase.c              | 9 +--------
 t/t6429-merge-sequence-rename-caching.sh | 9 +++++++--
 2 files changed, 8 insertions(+), 10 deletions(-)
t/helper/test-fast-rebase.c +1 -8
index cac20a72b3..2bfab66b1b 100644
@@ -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);
t/t6429-merge-sequence-rename-caching.sh +7 -2
index d02fa16614..75d3fd2dba 100755
@@ -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 &&
Signature · 1 line
2.42.0.126.gcf8c984877
#95 lore raw

PATCH v4 2/15 replay: introduce new builtin

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 .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%)
.gitignore +1 -0
index 5e56e471b3..612c0f6a0f 100644
@@ -135,6 +135,7 @@
 /git-remote-ext
 /git-repack
 /git-replace
+/git-replay
 /git-request-pull
 /git-rerere
 /git-reset
Makefile +1 -1
index 5776309365..05a504dc28 100644
@@ -799,7 +799,6 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
 TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
 TEST_BUILTINS_OBJS += test-env-helper.o
 TEST_BUILTINS_OBJS += test-example-decorate.o
-TEST_BUILTINS_OBJS += test-fast-rebase.o
 TEST_BUILTINS_OBJS += test-fsmonitor-client.o
 TEST_BUILTINS_OBJS += test-genrandom.o
 TEST_BUILTINS_OBJS += test-genzeros.o
@@ -1287,6 +1286,7 @@ BUILTIN_OBJS += builtin/remote-fd.o
 BUILTIN_OBJS += builtin/remote.o
 BUILTIN_OBJS += builtin/repack.o
 BUILTIN_OBJS += builtin/replace.o
+BUILTIN_OBJS += builtin/replay.o
 BUILTIN_OBJS += builtin/rerere.o
 BUILTIN_OBJS += builtin/reset.o
 BUILTIN_OBJS += builtin/rev-list.o
builtin.h +1 -0
index d560baa661..28280636da 100644
@@ -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);
builtin/replay.c renamed from t/helper/test-fast-rebase.c +8 -19
similarity index 89%
rename from t/helper/test-fast-rebase.c
rename to builtin/replay.c
index 2bfab66b1b..e102749ab6 100644
@@ -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 <oidset.h>
+#include <tree.h>
 
 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;
command-list.txt +1 -0
index 54b2a50f5f..d74836ab21 100644
@@ -160,6 +160,7 @@ git-reflog                              ancillarymanipulators           complete
 git-remote                              ancillarymanipulators           complete
 git-repack                              ancillarymanipulators           complete
 git-replace                             ancillarymanipulators           complete
+git-replay                              mainporcelain           history
 git-request-pull                        foreignscminterface             complete
 git-rerere                              ancillaryinterrogators
 git-reset                               mainporcelain           history
git.c +1 -0
index c67e44dd82..7068a184b0 100644
@@ -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 },
t/helper/test-tool.c +0 -1
index abe8a785eb..9ca1586de7 100644
@@ -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 },
t/helper/test-tool.h +0 -1
index ea2672436c..a03bbfc6b2 100644
@@ -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);
t/t6429-merge-sequence-rename-caching.sh +9 -18
index 75d3fd2dba..7670b72008 100755
@@ -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 &&
Signature · 1 line
2.42.0.126.gcf8c984877
#96 lore raw

Re: [PATCH v4 02/15] replay: introduce new builtin

Hi Christian & Elijah,

command-list.txt git-reflog ancillarymanipulators complete · line 163

Quoted 9 lines · Christian Couder
command-list.txt +1 -0
index 54b2a50f5f..d74836ab21 100644
@@ -160,6 +160,7 @@ git-reflog                              ancillarymanipulators           complete
 git-remote                              ancillarymanipulators           complete
 git-repack                              ancillarymanipulators           complete
 git-replace                             ancillarymanipulators           complete
+git-replay                              mainporcelain           history

I recall this having come up before, but in light of the still active discussion revolving around command-line parameter validation, I would strongly advise removing git replay from the main page and instead go for plumbingmanipulators.

Ciao,
Johannes

#97 lore raw

Re: [PATCH v4 02/15] replay: introduce new builtin

Hi Dscho,

Quoted 5 lines · Johannes Schindelin

Hi Christian & Elijah,

On Thu, 7 Sep 2023, Christian Couder wrote:

Quoted 14 lines

command-list.txt git-reflog ancillarymanipulators complete · line 163

Quoted 9 lines
command-list.txt +1 -0
index 54b2a50f5f..d74836ab21 100644
@@ -160,6 +160,7 @@ git-reflog                              ancillarymanipulators           complete
 git-remote                              ancillarymanipulators           complete
 git-repack                              ancillarymanipulators           complete
 git-replace                             ancillarymanipulators           complete
+git-replay                              mainporcelain           history

I recall this having come up before, but in light of the still active discussion revolving around command-line parameter validation, I would strongly advise removing git replay from the main page and instead go for plumbingmanipulators.

Ok, I have done that in the version 5 I just sent.

#98 lore raw

PATCH v4 3/15 replay: start using parse_options API

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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 "<oldbase> <branch>" 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.

---
 builtin/replay.c | 45 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 13 deletions(-)
builtin/replay.c +32 -13
index e102749ab6..d6dec7c866 100644
@@ -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 <newbase> <oldbase> <branch>"),
+		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);
Signature · 1 line
2.42.0.126.gcf8c984877
#99 lore raw

PATCH v4 4/15 replay: die() instead of failing assert()

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
builtin/replay.c +6 -1
index d6dec7c866..f3fdbe48c9 100644
@@ -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);
Signature · 1 line
2.42.0.126.gcf8c984877
#100 lore raw

PATCH v4 5/15 replay: introduce pick_regular_commit()

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 54 ++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 20 deletions(-)
builtin/replay.c +34 -20
index f3fdbe48c9..c66888679b 100644
@@ -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);
Signature · 1 line
2.42.0.126.gcf8c984877
#101 lore raw

PATCH v4 6/15 replay: don't simplify history

In reply to Christian Couder

From: Elijah Newren <[email protected]>

Let's set the rev walking options we need after calling setup_revisions() instead of before. This makes it clearer which options we need.

Also we don't want history simplification, as we want to deal with all the commits in the affected range.

---
 builtin/replay.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
builtin/replay.c +6 -9
index c66888679b..4b1e501595 100644
@@ -173,15 +173,6 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 
 	repo_init_revisions(the_repository, &revs, prefix);
 
-	revs.verbose_header = 1;
-	revs.max_parents = 1;
-	revs.cherry_mark = 1;
-	revs.limited = 1;
-	revs.reverse = 1;
-	revs.right_only = 1;
-	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
-	revs.topo_order = 1;
-
 	strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL);
 
 	if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) {
@@ -189,6 +180,12 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
 		goto cleanup;
 	}
 
+	/* requirements/overrides for revs */
+	revs.reverse = 1;
+	revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
+	revs.topo_order = 1;
+	revs.simplify_history = 0;
+
 	strvec_clear(&rev_walk_args);
 
 	if (prepare_revision_walk(&revs) < 0) {
Signature · 1 line
2.42.0.126.gcf8c984877
#102 lore raw

Re: [PATCH v4 06/15] replay: don't simplify history

Hi Christian & Elijah,

Quoted 5 lines · Christian Couder

From: Elijah Newren <[email protected]>

Let's set the rev walking options we need after calling setup_revisions() instead of before. This makes it clearer which options we need.

In light of the currently open issue about command-line validation, this change does more than this paragraph lets on: It hardcodes certain settings, overriding (silently) any rev-list options the user might have passed.

Is there any chance that we can avoid this change?

Quoted 2 lines

Also we don't want history simplification, as we want to deal with all the commits in the affected range.

This, however, is a good change. It deserves to live in its own commit, with its own commit message, in particular because it is not obvious from the attribute names which ones we're talking about (I guess it's limited and simplify_history, not just the latter.

Ciao,
Johannes

#103 lore raw

Re: [PATCH v4 06/15] replay: don't simplify history

Hi Dscho,

Quoted 11 lines · Johannes Schindelin

Hi Christian & Elijah,

Quoted 5 lines · Christian Couder

From: Elijah Newren <[email protected]>

Let's set the rev walking options we need after calling setup_revisions() instead of before. This makes it clearer which options we need.

Quoted 6 lines

In light of the currently open issue about command-line validation, this change does more than this paragraph lets on: It hardcodes certain settings, overriding (silently) any rev-list options the user might have passed.

Is there any chance that we can avoid this change?

In the version 5 I just sent, I have changed the commit message and the code.

The commit messages says:

"
replay: change rev walking options

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.
"

So about "revs.reverse" the code is now:

  revs.reverse = !revs.reverse;

which seems to be what you suggested elsewhere.

Apart from that I think it's fair to enforce some values for a few options. This way we can make the command work the way we want by default, get consistent behavior and avoid users shooting themselves in the foot for now. If more flexibility is needed and useful in the future, then we might allow it in future patches with proper justification, tests and docs. There is still a lot of flexibility left especially as the patch that disallowed some rev walking options and pathspecs has been removed as you suggested.

Quoted 7 lines
Quoted 2 lines

Also we don't want history simplification, as we want to deal with all the commits in the affected range.

This, however, is a good change. It deserves to live in its own commit, with its own commit message, in particular because it is not obvious from the attribute names which ones we're talking about (I guess it's limited and simplify_history, not just the latter.

We only enforce "revs.sort_order", "revs.topo_order" and yeah "revs.simplify_history".

Also I don't think it makes much sense to separate these changes in different commits/patches. I am Ok to improve the commit message if you think it's worth it, but the patch series is designed to make it easy to review the changes from the "fast-rebase" test-tool to a good "replay" plumbing command, and I don't think separating those related changes would improve things much.

#104 lore raw

PATCH v4 7/15 replay: add an important FIXME comment about gpg signing

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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

---
 builtin/replay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/replay.c +1 -1
index 4b1e501595..47d695df93 100644
@@ -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();
Signature · 1 line
2.42.0.126.gcf8c984877
#105 lore raw

PATCH v4 8/15 replay: remove progress and info output

In reply to Christian Couder

From: Elijah Newren <[email protected]>

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.

---
 builtin/replay.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
builtin/replay.c +1 -6
index 47d695df93..b5c854c686 100644
@@ -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",
Signature · 1 line
2.42.0.126.gcf8c984877