Skip to content

Commit 8964147

Browse files
artagnongitster
authored andcommitted
revert: Separate cmdline parsing from functional code
Currently, revert_or_cherry_pick sets up a default git config, parses command-line arguments, before preparing to pick commits. This makes for a bad API as the central worry of callers is to assert whether or not a conflict occured while cherry picking. The current API is like: if (revert_or_cherry_pick(argc, argv, opts) < 0) print "Something failed, we're not sure what" Simplify and rename revert_or_cherry_pick to pick_commits so that it only has the responsibility of setting up the revision walker and picking commits in a loop. Transfer the remaining work to its callers. Now, the API is simplified as: if (parse_args(argc, argv, opts) < 0) print "Can't parse arguments" if (pick_commits(opts) < 0) print "Error encountered in picking machinery" Later in the series, pick_commits will also serve as the starting point for continuing a cherry-pick or revert. Inspired-by: Christian Couder <[email protected]> Helped-by: Jonathan Nieder <[email protected]> Signed-off-by: Ramkumar Ramachandra <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80e1f79 commit 8964147

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

builtin/revert.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -563,16 +563,12 @@ static void read_and_refresh_cache(struct replay_opts *opts)
563563
rollback_lock_file(&index_lock);
564564
}
565565

566-
static int revert_or_cherry_pick(int argc, const char **argv,
567-
struct replay_opts *opts)
566+
static int pick_commits(struct replay_opts *opts)
568567
{
569568
struct rev_info revs;
570569
struct commit *commit;
571570

572-
git_config(git_default_config, NULL);
573571
setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
574-
parse_args(argc, argv, opts);
575-
576572
if (opts->allow_ff) {
577573
if (opts->signoff)
578574
die(_("cherry-pick --ff cannot be used with --signoff"));
@@ -605,7 +601,9 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
605601
if (isatty(0))
606602
opts.edit = 1;
607603
opts.action = REVERT;
608-
return revert_or_cherry_pick(argc, argv, &opts);
604+
git_config(git_default_config, NULL);
605+
parse_args(argc, argv, &opts);
606+
return pick_commits(&opts);
609607
}
610608

611609
int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
@@ -614,5 +612,7 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
614612

615613
memset(&opts, 0, sizeof(opts));
616614
opts.action = CHERRY_PICK;
617-
return revert_or_cherry_pick(argc, argv, &opts);
615+
git_config(git_default_config, NULL);
616+
parse_args(argc, argv, &opts);
617+
return pick_commits(&opts);
618618
}

0 commit comments

Comments
 (0)