Skip to content

Commit 7af4659

Browse files
chriscoolgitster
authored andcommitted
revert: refactor code into a do_pick_commit() function
This is needed because we are going to make it possible to cherry-pick many commits instead of just one in the following commits. And we will be able to do that by just calling do_pick_commit() once for each commit to cherry-pick. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2fb0e14 commit 7af4659

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

builtin/revert.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void do_recursive_merge(struct commit *base, struct commit *next,
365365
fprintf(stderr, "Finished one %s.\n", me);
366366
}
367367

368-
static int revert_or_cherry_pick(int argc, const char **argv)
368+
static int do_pick_commit(void)
369369
{
370370
unsigned char head[20];
371371
struct commit *base, *next, *parent;
@@ -374,24 +374,6 @@ static int revert_or_cherry_pick(int argc, const char **argv)
374374
char *defmsg = NULL;
375375
struct strbuf msgbuf = STRBUF_INIT;
376376

377-
git_config(git_default_config, NULL);
378-
me = action == REVERT ? "revert" : "cherry-pick";
379-
setenv(GIT_REFLOG_ACTION, me, 0);
380-
parse_args(argc, argv);
381-
382-
if (allow_ff) {
383-
if (signoff)
384-
die("cherry-pick --ff cannot be used with --signoff");
385-
if (no_commit)
386-
die("cherry-pick --ff cannot be used with --no-commit");
387-
if (no_replay)
388-
die("cherry-pick --ff cannot be used with -x");
389-
if (edit)
390-
die("cherry-pick --ff cannot be used with --edit");
391-
}
392-
393-
if (read_cache() < 0)
394-
die("git %s: failed to read the index", me);
395377
if (no_commit) {
396378
/*
397379
* We do not intend to commit immediately. We just want to
@@ -545,6 +527,30 @@ static int revert_or_cherry_pick(int argc, const char **argv)
545527
return 0;
546528
}
547529

530+
static int revert_or_cherry_pick(int argc, const char **argv)
531+
{
532+
git_config(git_default_config, NULL);
533+
me = action == REVERT ? "revert" : "cherry-pick";
534+
setenv(GIT_REFLOG_ACTION, me, 0);
535+
parse_args(argc, argv);
536+
537+
if (allow_ff) {
538+
if (signoff)
539+
die("cherry-pick --ff cannot be used with --signoff");
540+
if (no_commit)
541+
die("cherry-pick --ff cannot be used with --no-commit");
542+
if (no_replay)
543+
die("cherry-pick --ff cannot be used with -x");
544+
if (edit)
545+
die("cherry-pick --ff cannot be used with --edit");
546+
}
547+
548+
if (read_cache() < 0)
549+
die("git %s: failed to read the index", me);
550+
551+
return do_pick_commit();
552+
}
553+
548554
int cmd_revert(int argc, const char **argv, const char *prefix)
549555
{
550556
if (isatty(0))

0 commit comments

Comments
 (0)