revert: prepare to move replay_action to header

REVERT and CHERRY_PICK and are unsuitable names for an enumerator in a public interface, because they are generic enough to be likely to clash with identifiers with other meanings. Rename to REPLAY_REVERT and REPLAY_PICK as preparation for exposing them. Helped-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Jan 11, 2012 at 23:45 UTC 644a36908d6b52cb8c0c4d1ac69fd0b451e38f13
1 file changed +22 -18
builtin/revert.c
+22 -18
@@ -39,7 +39,11 @@ static const char * const cherry_pick_usage[] = {
39 NULL
40 };
41
42 -enum replay_action { REVERT, CHERRY_PICK };
42 +enum replay_action {
43 + REPLAY_REVERT,
44 + REPLAY_PICK
45 +};
46 +
47 enum replay_subcommand {
48 REPLAY_NONE,
49 REPLAY_REMOVE_STATE,
@@ -74,14 +78,14 @@ struct replay_opts {
78
79 static const char *action_name(const struct replay_opts *opts)
80 {
77 - return opts->action == REVERT ? "revert" : "cherry-pick";
81 + return opts->action == REPLAY_REVERT ? "revert" : "cherry-pick";
82 }
83
84 static char *get_encoding(const char *message);
85
86 static const char * const *revert_or_cherry_pick_usage(struct replay_opts *opts)
87 {
84 - return opts->action == REVERT ? revert_usage : cherry_pick_usage;
88 + return opts->action == REPLAY_REVERT ? revert_usage : cherry_pick_usage;
89 }
90
91 static int option_parse_x(const struct option *opt,
@@ -160,7 +164,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
164 OPT_END(),
165 };
166
163 - if (opts->action == CHERRY_PICK) {
167 + if (opts->action == REPLAY_PICK) {
168 struct option cp_extra[] = {
169 OPT_BOOLEAN('x', NULL, &opts->record_origin, "append commit name"),
170 OPT_BOOLEAN(0, "ff", &opts->allow_ff, "allow fast-forward"),
@@ -374,7 +378,7 @@ static int error_dirty_index(struct replay_opts *opts)
378 return error_resolve_conflict(action_name(opts));
379
380 /* Different translation strings for cherry-pick and revert */
377 - if (opts->action == CHERRY_PICK)
381 + if (opts->action == REPLAY_PICK)
382 error(_("Your local changes would be overwritten by cherry-pick."));
383 else
384 error(_("Your local changes would be overwritten by revert."));
@@ -553,7 +557,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
557
558 defmsg = git_pathdup("MERGE_MSG");
559
556 - if (opts->action == REVERT) {
560 + if (opts->action == REPLAY_REVERT) {
561 base = commit;
562 base_label = msg.label;
563 next = parent;
@@ -594,7 +598,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
598 }
599 }
600
597 - if (!opts->strategy || !strcmp(opts->strategy, "recursive") || opts->action == REVERT) {
601 + if (!opts->strategy || !strcmp(opts->strategy, "recursive") || opts->action == REPLAY_REVERT) {
602 res = do_recursive_merge(base, next, base_label, next_label,
603 head, &msgbuf, opts);
604 write_message(&msgbuf, defmsg);
@@ -618,13 +622,13 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
622 * However, if the merge did not even start, then we don't want to
623 * write it at all.
624 */
621 - if (opts->action == CHERRY_PICK && !opts->no_commit && (res == 0 || res == 1))
625 + if (opts->action == REPLAY_PICK && !opts->no_commit && (res == 0 || res == 1))
626 write_cherry_pick_head(commit, "CHERRY_PICK_HEAD");
623 - if (opts->action == REVERT && ((opts->no_commit && res == 0) || res == 1))
627 + if (opts->action == REPLAY_REVERT && ((opts->no_commit && res == 0) || res == 1))
628 write_cherry_pick_head(commit, "REVERT_HEAD");
629
630 if (res) {
627 - error(opts->action == REVERT
631 + error(opts->action == REPLAY_REVERT
632 ? _("could not revert %s... %s")
633 : _("could not apply %s... %s"),
634 find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),
@@ -644,7 +648,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
648
649 static void prepare_revs(struct replay_opts *opts)
650 {
647 - if (opts->action != REVERT)
651 + if (opts->action != REPLAY_REVERT)
652 opts->revs->reverse ^= 1;
653
654 if (prepare_revision_walk(opts->revs))
@@ -701,7 +705,7 @@ static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
705 {
706 struct commit_list *cur = NULL;
707 const char *sha1_abbrev = NULL;
704 - const char *action_str = opts->action == REVERT ? "revert" : "pick";
708 + const char *action_str = opts->action == REPLAY_REVERT ? "revert" : "pick";
709 const char *subject;
710 int subject_len;
711
@@ -722,10 +726,10 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
726 int saved, status, padding;
727
728 if (!prefixcmp(bol, "pick")) {
725 - action = CHERRY_PICK;
729 + action = REPLAY_PICK;
730 bol += strlen("pick");
731 } else if (!prefixcmp(bol, "revert")) {
728 - action = REVERT;
732 + action = REPLAY_REVERT;
733 bol += strlen("revert");
734 } else
735 return NULL;
@@ -748,7 +752,7 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
752 */
753 if (action != opts->action) {
754 const char *action_str;
751 - action_str = action == REVERT ? "revert" : "cherry-pick";
755 + action_str = action == REPLAY_REVERT ? "revert" : "cherry-pick";
756 error(_("Cannot %s during a %s"), action_str, action_name(opts));
757 return NULL;
758 }
@@ -1124,7 +1128,7 @@ static int pick_revisions(struct replay_opts *opts)
1128 if (create_seq_dir() < 0)
1129 return -1;
1130 if (get_sha1("HEAD", sha1)) {
1127 - if (opts->action == REVERT)
1131 + if (opts->action == REPLAY_REVERT)
1132 return error(_("Can't revert as initial commit"));
1133 return error(_("Can't cherry-pick into empty head"));
1134 }
@@ -1141,7 +1145,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
1145 memset(&opts, 0, sizeof(opts));
1146 if (isatty(0))
1147 opts.edit = 1;
1144 - opts.action = REVERT;
1148 + opts.action = REPLAY_REVERT;
1149 git_config(git_default_config, NULL);
1150 parse_args(argc, argv, &opts);
1151 res = pick_revisions(&opts);
@@ -1156,7 +1160,7 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
1160 int res;
1161
1162 memset(&opts, 0, sizeof(opts));
1159 - opts.action = CHERRY_PICK;
1163 + opts.action = REPLAY_PICK;
1164 git_config(git_default_config, NULL);
1165 parse_args(argc, argv, &opts);
1166 res = pick_revisions(&opts);