39
static int edit, no_replay, no_commit, mainline, signoff, allow_ff;
40
static enum { REVERT, CHERRY_PICK } action;
41
static struct commit *commit;
42
-static const char *commit_name;
42
+static int commit_argc;
43
+static const char **commit_argv;
44
static int allow_rerere_auto;
45
46
static const char *me;
54
{
55
const char * const * usage_str =
56
action == REVERT ? revert_usage : cherry_pick_usage;
56
- unsigned char sha1[20];
57
int noop;
58
struct option options[] = {
59
OPT_BOOLEAN('n', "no-commit", &no_commit, "don't automatically commit"),
78
die("program error");
79
}
80
81
- if (parse_options(argc, argv, NULL, options, usage_str, 0) != 1)
81
+ commit_argc = parse_options(argc, argv, NULL, options, usage_str, 0);
82
+ if (commit_argc < 1)
83
usage_with_options(usage_str, options);
84
84
- commit_name = argv[0];
85
- if (get_sha1(commit_name, sha1))
86
- die ("Cannot find '%s'", commit_name);
87
- commit = lookup_commit_reference(sha1);
88
- if (!commit)
89
- exit(1);
85
+ commit_argv = argv;
86
}
87
88
struct commit_message {
523
return 0;
524
}
525
526
+static void prepare_revs(struct rev_info *revs)
527
+{
528
+ int argc = 0;
529
+ int i;
530
+ const char **argv = xmalloc((commit_argc + 4) * sizeof(*argv));
531
+
532
+ argv[argc++] = NULL;
533
+ argv[argc++] = "--no-walk";
534
+ if (action != REVERT)
535
+ argv[argc++] = "--reverse";
536
+ for (i = 0; i < commit_argc; i++)
537
+ argv[argc++] = commit_argv[i];
538
+ argv[argc++] = NULL;
539
+
540
+ init_revisions(revs, NULL);
541
+ setup_revisions(argc - 1, argv, revs, NULL);
542
+ if (prepare_revision_walk(revs))
543
+ die("revision walk setup failed");
544
+
545
+ if (!revs->commits)
546
+ die("empty commit set passed");
547
+
548
+ free(argv);
549
+}
550
+
551
static int revert_or_cherry_pick(int argc, const char **argv)
552
{
553
+ struct rev_info revs;
554
+
555
git_config(git_default_config, NULL);
556
me = action == REVERT ? "revert" : "cherry-pick";
557
setenv(GIT_REFLOG_ACTION, me, 0);
571
if (read_cache() < 0)
572
die("git %s: failed to read the index", me);
573
551
- return do_pick_commit();
574
+ prepare_revs(&revs);
575
+
576
+ while ((commit = get_revision(&revs))) {
577
+ int res = do_pick_commit();
578
+ if (res)
579
+ return res;
580
+ }
581
+
582
+ return 0;
583
}
584
585
int cmd_revert(int argc, const char **argv, const char *prefix)