[PATCH 8/8] revert: Implement --abort processing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To abort, perform a "rerere clear" and "reset --hard" to the ref
specified by the "head" file introduced earlier in the series.

Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx>
---
 This code is dependent on the rerere_clear public API (which I've
 posted in another thread).  Have the essential parts of the "reset
 --hard" been copied over correctly?  Should reset get a public API as
 well?

 builtin/revert.c |   56 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/builtin/revert.c b/builtin/revert.c
index ccfc295..50c36e9 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -799,6 +799,54 @@ static int pick_commits(struct replay_opts *opts)
 	return persist_todo_done(res, revs.commits, done_list, opts);
 }
 
+static int process_args(int argc, const char **argv, struct replay_opts *opts)
+{
+	const char *me;
+	int fd;
+
+	parse_args(argc, argv, opts);
+	me = (opts->action == REVERT ? "revert" : "cherry-pick");
+	if (opts->abort_oper) {
+		char head[DEFAULT_ABBREV];
+		unsigned char sha1[20];
+		rerere_clear(0);
+
+		if (!file_exists(HEAD_FILE))
+			goto error;
+		if ((fd = open(HEAD_FILE, O_RDONLY, 0666)) < 0) {
+			int err = errno;
+			error(_("Could not open '%s' for reading: %s"),
+				HEAD_FILE, strerror(err));
+			return -err;
+		}
+		if (xread(fd, head, DEFAULT_ABBREV) < DEFAULT_ABBREV) {
+			int err = errno;
+			close(fd);
+			error(_("Corrupt '%s': %s"), HEAD_FILE, strerror(err));
+			return -err;
+		}
+		close(fd);
+
+		if (get_sha1(head, sha1))
+			return error(_("Failed to resolve '%s' as a valid ref."), head);
+		update_ref(NULL, "HEAD", sha1, NULL, 0, MSG_ON_ERR);
+	}
+	else if (opts->skip_oper) {
+		if (!file_exists(TODO_FILE))
+			goto error;
+		return 0;
+	}
+	else if (opts->continue_oper) {
+		if (!file_exists(TODO_FILE))
+			goto error;
+		return 0;
+	}
+
+	return pick_commits(opts);
+error:
+	return error(_("No %s in progress"), me);
+}
+
 int cmd_revert(int argc, const char **argv, const char *prefix)
 {
 	struct replay_opts opts;
@@ -810,9 +858,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
 
 	opts.action = REVERT;
 	setenv(GIT_REFLOG_ACTION, "revert", 0);
-	parse_args(argc, argv, &opts);
-
-	return pick_commits(&opts);
+	return process_args(argc, argv, &opts);
 }
 
 int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
@@ -823,7 +869,5 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
 	memset(&opts, 0, sizeof(struct replay_opts));
 	opts.action = CHERRY_PICK;
 	setenv(GIT_REFLOG_ACTION, "cherry-pick", 0);
-	parse_args(argc, argv, &opts);
-
-	return pick_commits(&opts);
+	return process_args(argc, argv, &opts);
 }
-- 
1.7.5.GIT

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]