Skip to content

Commit f920b02

Browse files
newrenchriscool
authored andcommitted
replay: introduce new builtin
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. Let's add a stub documentation and a stub test script though. Subsequent commits will flesh out the capabilities of the new command and make it a more standard regular builtin. Helped-by: Johannes Schindelin <[email protected]> Co-authored-by: Christian Couder <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b9d0991 commit f920b02

File tree

11 files changed

+122
-41
lines changed

11 files changed

+122
-41
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
/git-remote-ext
136136
/git-repack
137137
/git-replace
138+
/git-replay
138139
/git-request-pull
139140
/git-rerere
140141
/git-reset

Documentation/git-replay.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
git-replay(1)
2+
=============
3+
4+
NAME
5+
----
6+
git-replay - EXPERIMENTAL: Replay commits on a new base, works with bare repos too
7+
8+
9+
SYNOPSIS
10+
--------
11+
[verse]
12+
(EXPERIMENTAL!) 'git replay' --onto <newbase> <oldbase> <branch>
13+
14+
DESCRIPTION
15+
-----------
16+
17+
Takes a range of commits, specified by <oldbase> and <branch>, and
18+
replays them onto a new location (see `--onto` option below).
19+
20+
THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
21+
22+
OPTIONS
23+
-------
24+
25+
--onto <newbase>::
26+
Starting point at which to create the new commits. May be any
27+
valid commit, and not just an existing branch name.
28+
29+
EXIT STATUS
30+
-----------
31+
32+
For a successful, non-conflicted replay, the exit status is 0. When
33+
the replay has conflicts, the exit status is 1. If the replay is not
34+
able to complete (or start) due to some kind of error, the exit status
35+
is something other than 0 or 1.
36+
37+
GIT
38+
---
39+
Part of the linkgit:git[1] suite

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,6 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
799799
TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
800800
TEST_BUILTINS_OBJS += test-env-helper.o
801801
TEST_BUILTINS_OBJS += test-example-decorate.o
802-
TEST_BUILTINS_OBJS += test-fast-rebase.o
803802
TEST_BUILTINS_OBJS += test-find-pack.o
804803
TEST_BUILTINS_OBJS += test-fsmonitor-client.o
805804
TEST_BUILTINS_OBJS += test-genrandom.o
@@ -1290,6 +1289,7 @@ BUILTIN_OBJS += builtin/remote-fd.o
12901289
BUILTIN_OBJS += builtin/remote.o
12911290
BUILTIN_OBJS += builtin/repack.o
12921291
BUILTIN_OBJS += builtin/replace.o
1292+
BUILTIN_OBJS += builtin/replay.o
12931293
BUILTIN_OBJS += builtin/rerere.o
12941294
BUILTIN_OBJS += builtin/reset.o
12951295
BUILTIN_OBJS += builtin/rev-list.o

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ int cmd_remote(int argc, const char **argv, const char *prefix);
211211
int cmd_remote_ext(int argc, const char **argv, const char *prefix);
212212
int cmd_remote_fd(int argc, const char **argv, const char *prefix);
213213
int cmd_repack(int argc, const char **argv, const char *prefix);
214+
int cmd_replay(int argc, const char **argv, const char *prefix);
214215
int cmd_rerere(int argc, const char **argv, const char *prefix);
215216
int cmd_reset(int argc, const char **argv, const char *prefix);
216217
int cmd_restore(int argc, const char **argv, const char *prefix);

t/helper/test-fast-rebase.c renamed to builtin/replay.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
/*
2-
* "git fast-rebase" builtin command
3-
*
4-
* FAST: Forking Any Subprocesses (is) Taboo
5-
*
6-
* This is meant SOLELY as a demo of what is possible. sequencer.c and
7-
* rebase.c should be refactored to use the ideas here, rather than attempting
8-
* to extend this file to replace those (unless Phillip or Dscho say that
9-
* refactoring is too hard and we need a clean slate, but I'm guessing that
10-
* refactoring is the better route).
2+
* "git replay" builtin command
113
*/
124

135
#define USE_THE_INDEX_VARIABLE
14-
#include "test-tool.h"
6+
#include "git-compat-util.h"
7+
8+
#include "builtin.h"
159
#include "cache-tree.h"
1610
#include "commit.h"
1711
#include "environment.h"
@@ -27,7 +21,8 @@
2721
#include "sequencer.h"
2822
#include "setup.h"
2923
#include "strvec.h"
30-
#include "tree.h"
24+
#include <oidset.h>
25+
#include <tree.h>
3126

3227
static const char *short_commit_name(struct commit *commit)
3328
{
@@ -94,7 +89,7 @@ static struct commit *create_commit(struct tree *tree,
9489
return (struct commit *)obj;
9590
}
9691

97-
int cmd__fast_rebase(int argc, const char **argv)
92+
int cmd_replay(int argc, const char **argv, const char *prefix)
9893
{
9994
struct commit *onto;
10095
struct commit *last_commit = NULL, *last_picked_commit = NULL;
@@ -110,14 +105,8 @@ int cmd__fast_rebase(int argc, const char **argv)
110105
struct strbuf branch_name = STRBUF_INIT;
111106
int ret = 0;
112107

113-
/*
114-
* test-tool stuff doesn't set up the git directory by default; need to
115-
* do that manually.
116-
*/
117-
setup_git_directory();
118-
119108
if (argc == 2 && !strcmp(argv[1], "-h")) {
120-
printf("Sorry, I am not a psychiatrist; I can not give you the help you need. Oh, you meant usage...\n");
109+
printf("usage: (EXPERIMENTAL!) git replay --onto <newbase> <oldbase> <branch>\n");
121110
exit(129);
122111
}
123112

@@ -136,7 +125,7 @@ int cmd__fast_rebase(int argc, const char **argv)
136125
if (repo_read_index(the_repository) < 0)
137126
BUG("Could not read index");
138127

139-
repo_init_revisions(the_repository, &revs, NULL);
128+
repo_init_revisions(the_repository, &revs, prefix);
140129
revs.verbose_header = 1;
141130
revs.max_parents = 1;
142131
revs.cherry_mark = 1;

command-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ git-reflog ancillarymanipulators complete
160160
git-remote ancillarymanipulators complete
161161
git-repack ancillarymanipulators complete
162162
git-replace ancillarymanipulators complete
163+
git-replay plumbingmanipulators
163164
git-request-pull foreignscminterface complete
164165
git-rerere ancillaryinterrogators
165166
git-reset mainporcelain history

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ static struct cmd_struct commands[] = {
594594
{ "remote-fd", cmd_remote_fd, NO_PARSEOPT },
595595
{ "repack", cmd_repack, RUN_SETUP },
596596
{ "replace", cmd_replace, RUN_SETUP },
597+
{ "replay", cmd_replay, RUN_SETUP },
597598
{ "rerere", cmd_rerere, RUN_SETUP },
598599
{ "reset", cmd_reset, RUN_SETUP },
599600
{ "restore", cmd_restore, RUN_SETUP | NEED_WORK_TREE },

t/helper/test-tool.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ static struct test_cmd cmds[] = {
3030
{ "dump-untracked-cache", cmd__dump_untracked_cache },
3131
{ "env-helper", cmd__env_helper },
3232
{ "example-decorate", cmd__example_decorate },
33-
{ "fast-rebase", cmd__fast_rebase },
3433
{ "find-pack", cmd__find_pack },
3534
{ "fsmonitor-client", cmd__fsmonitor_client },
3635
{ "genrandom", cmd__genrandom },

t/helper/test-tool.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ int cmd__dump_untracked_cache(int argc, const char **argv);
2424
int cmd__dump_reftable(int argc, const char **argv);
2525
int cmd__env_helper(int argc, const char **argv);
2626
int cmd__example_decorate(int argc, const char **argv);
27-
int cmd__fast_rebase(int argc, const char **argv);
2827
int cmd__find_pack(int argc, const char **argv);
2928
int cmd__fsmonitor_client(int argc, const char **argv);
3029
int cmd__genrandom(int argc, const char **argv);

t/t3650-replay-basics.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
3+
test_description='basic git replay tests'
4+
5+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7+
8+
. ./test-lib.sh
9+
10+
GIT_AUTHOR_NAME=author@name
11+
GIT_AUTHOR_EMAIL=bogus@email@address
12+
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
13+
14+
test_expect_success 'setup' '
15+
test_commit A &&
16+
test_commit B &&
17+
18+
git switch -c topic1 &&
19+
test_commit C &&
20+
git switch -c topic2 &&
21+
test_commit D &&
22+
test_commit E &&
23+
git switch topic1 &&
24+
test_commit F &&
25+
git switch -c topic3 &&
26+
test_commit G &&
27+
test_commit H &&
28+
git switch -c topic4 main &&
29+
test_commit I &&
30+
test_commit J &&
31+
32+
git switch -c next main &&
33+
test_commit K &&
34+
git merge -m "Merge topic1" topic1 &&
35+
git merge -m "Merge topic2" topic2 &&
36+
git merge -m "Merge topic3" topic3 &&
37+
>evil &&
38+
git add evil &&
39+
git commit --amend &&
40+
git merge -m "Merge topic4" topic4 &&
41+
42+
git switch main &&
43+
test_commit L &&
44+
test_commit M &&
45+
46+
git switch -c conflict B &&
47+
test_commit C.conflict C.t conflict
48+
'
49+
50+
test_expect_success 'using replay to rebase two branches, one on top of other' '
51+
git switch main &&
52+
53+
git replay --onto main topic1 topic2 >result &&
54+
55+
git log --format=%s $(cut -f 3 -d " " result) >actual &&
56+
test_write_lines E D M L B A >expect &&
57+
test_cmp expect actual
58+
'
59+
60+
test_done

0 commit comments

Comments
 (0)