Thread (37 messages) flat view 37 messages, 5 authors, 2016-06-15
STALE3744d

Revision v1 of 4 in this series.

Revisions (4)
  1. rfc [diff vs current]
  2. v1 current
  3. v3 [diff vs current]
  4. v4 [diff vs current]

[PATCH 4/8] revert: Separate cmdline argument handling from the functional code

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:51:13
Subsystem: the rest · Maintainer: Linus Torvalds

Reading the Git configuration, setting environment variables, parsing
command-line arguments, and populating the options structure should be
done in cmd_cherry_pick/ cmd_revert.  The job pick_commits of
simplified into setting up the revision walker and calling
do_pick_commit in a loop- later in the series, it will handle
failures, and serve as the starting point for continuation.

Based-on-patch-by: Christian Couder [off-list ref]
Signed-off-by: Ramkumar Ramachandra <redacted>
---
 This patch is fairly straightforward.

 builtin/revert.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/builtin/revert.c b/builtin/revert.c
index 8550927..288c898 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -603,19 +603,12 @@ static int read_and_refresh_cache(struct replay_opts *opts)
 	return 0;
 }
 
-static int revert_or_cherry_pick(int argc, const char **argv,
-				struct replay_opts *opts)
+static int pick_commits(struct replay_opts *opts)
 {
 	struct rev_info revs;
 	struct commit *commit;
-	const char *me;
 	int res;
 
-	git_config(git_default_config, NULL);
-	me = (opts->action == REVERT ? "revert" : "cherry-pick");
-	setenv(GIT_REFLOG_ACTION, me, 0);
-	parse_args(argc, argv, opts);
-
 	if (opts->allow_ff) {
 		if (opts->signoff)
 			die(_("cherry-pick --ff cannot be used with --signoff"));
@@ -642,18 +635,27 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
 {
 	struct replay_opts opts;
 
+	git_config(git_default_config, NULL);
 	memset(&opts, 0, sizeof(struct replay_opts));
 	if (isatty(0))
 		opts.edit = 1;
+
 	opts.action = REVERT;
-	return revert_or_cherry_pick(argc, argv, &opts);
+	setenv(GIT_REFLOG_ACTION, "revert", 0);
+	parse_args(argc, argv, &opts);
+
+	return pick_commits(&opts);
 }
 
 int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
 {
 	struct replay_opts opts;
 
+	git_config(git_default_config, NULL);
 	memset(&opts, 0, sizeof(struct replay_opts));
 	opts.action = CHERRY_PICK;
-	return revert_or_cherry_pick(argc, argv, &opts);
+	setenv(GIT_REFLOG_ACTION, "cherry-pick", 0);
+	parse_args(argc, argv, &opts);
+
+	return pick_commits(&opts);
 }
-- 
1.7.5.GIT
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help