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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Jun 2, 2010 at 07:58 UTC
7af46595b2667214e98da55ed2f82ce1ac2b404a
1 file changed
+25
-19
builtin/revert.c
+25
-19
@@ -365,7 +365,7 @@ static void do_recursive_merge(struct commit *base, struct commit *next,
365
fprintf(stderr, "Finished one %s.\n", me);
366
}
367
368
-static int revert_or_cherry_pick(int argc, const char **argv)
368
+static int do_pick_commit(void)
369
{
370
unsigned char head[20];
371
struct commit *base, *next, *parent;
@@ -374,24 +374,6 @@ static int revert_or_cherry_pick(int argc, const char **argv)
374
char *defmsg = NULL;
375
struct strbuf msgbuf = STRBUF_INIT;
376
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);
377
if (no_commit) {
378
/*
379
* 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)
527
return 0;
528
}
529
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
+
554
int cmd_revert(int argc, const char **argv, const char *prefix)
555
{
556
if (isatty(0))