From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git List <git@vger.kernel.org>,
Jonathan Nieder <jrnieder@gmail.com>,
Christian Couder <chriscool@tuxfamily.org>,
Daniel Barkalow <barkalow@iabervon.org>,
Jeff King <peff@peff.net>
Subject: [PATCH 13/18] revert: Introduce --reset to remove sequencer state
Date: Mon, 1 Aug 2011 23:37:00 +0530 [thread overview]
Message-ID: <1312222025-28453-14-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1312222025-28453-1-git-send-email-artagnon@gmail.com>
To explicitly remove the sequencer state for a fresh cherry-pick or
revert invocation, introduce a new subcommand called "--reset" to
remove the sequencer state.
Take the opportunity to publicly expose the sequencer paths, and a
generic function called "remove_sequencer_state" that various git
programs can use to remove the sequencer state in a uniform manner;
"git reset" uses it later in this series. Introducing this public API
is also in line with our long-term goal of eventually factoring out
functions from revert.c into a generic commit sequencer.
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Documentation/git-cherry-pick.txt | 5 +++
Documentation/git-revert.txt | 5 +++
Documentation/sequencer.txt | 4 ++
Makefile | 2 +
builtin/revert.c | 62 +++++++++++++++++++++++++-----------
sequencer.c | 19 +++++++++++
sequencer.h | 20 ++++++++++++
t/t3510-cherry-pick-sequence.sh | 15 ++++++++-
8 files changed, 111 insertions(+), 21 deletions(-)
create mode 100644 Documentation/sequencer.txt
create mode 100644 sequencer.c
create mode 100644 sequencer.h
diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index 6c9c2cb..12a85ba 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -9,6 +9,7 @@ SYNOPSIS
--------
[verse]
'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...
+'git cherry-pick' --reset
DESCRIPTION
-----------
@@ -110,6 +111,10 @@ effect to your index in a row.
Pass the merge strategy-specific option through to the
merge strategy. See linkgit:git-merge[1] for details.
+SEQUENCER SUBCOMMANDS
+---------------------
+include::sequencer.txt[]
+
EXAMPLES
--------
git cherry-pick master::
diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
index 3d0a7d1..31c85b4 100644
--- a/Documentation/git-revert.txt
+++ b/Documentation/git-revert.txt
@@ -9,6 +9,7 @@ SYNOPSIS
--------
[verse]
'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>...
+'git revert' --reset
DESCRIPTION
-----------
@@ -91,6 +92,10 @@ effect to your index in a row.
Pass the merge strategy-specific option through to the
merge strategy. See linkgit:git-merge[1] for details.
+SEQUENCER SUBCOMMANDS
+---------------------
+include::sequencer.txt[]
+
EXAMPLES
--------
git revert HEAD~3::
diff --git a/Documentation/sequencer.txt b/Documentation/sequencer.txt
new file mode 100644
index 0000000..16ce88c
--- /dev/null
+++ b/Documentation/sequencer.txt
@@ -0,0 +1,4 @@
+--reset::
+ Forget about the current operation in progress. Can be used
+ to clear the sequencer state after a failed cherry-pick or
+ revert.
diff --git a/Makefile b/Makefile
index 4ed7996..afd7673 100644
--- a/Makefile
+++ b/Makefile
@@ -554,6 +554,7 @@ LIB_H += rerere.h
LIB_H += resolve-undo.h
LIB_H += revision.h
LIB_H += run-command.h
+LIB_H += sequencer.h
LIB_H += sha1-array.h
LIB_H += sha1-lookup.h
LIB_H += sideband.h
@@ -658,6 +659,7 @@ LIB_OBJS += revision.o
LIB_OBJS += run-command.o
LIB_OBJS += server-info.o
LIB_OBJS += setup.o
+LIB_OBJS += sequencer.o
LIB_OBJS += sha1-array.o
LIB_OBJS += sha1-lookup.o
LIB_OBJS += sha1_file.o
diff --git a/builtin/revert.c b/builtin/revert.c
index cc130e0..2ddd7e7 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -14,6 +14,7 @@
#include "merge-recursive.h"
#include "refs.h"
#include "dir.h"
+#include "sequencer.h"
/*
* This implements the builtins revert and cherry-pick.
@@ -28,18 +29,22 @@
static const char * const revert_usage[] = {
"git revert [options] <commit-ish>",
+ "git revert <subcommand>",
NULL
};
static const char * const cherry_pick_usage[] = {
"git cherry-pick [options] <commit-ish>",
+ "git cherry-pick <subcommand>",
NULL
};
enum replay_action { REVERT, CHERRY_PICK };
+enum replay_subcommand { REPLAY_NONE, REPLAY_RESET };
struct replay_opts {
enum replay_action action;
+ enum replay_subcommand subcommand;
/* Boolean options */
int edit;
@@ -61,11 +66,6 @@ struct replay_opts {
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
-#define SEQ_DIR "sequencer"
-#define SEQ_HEAD_FILE "sequencer/head"
-#define SEQ_TODO_FILE "sequencer/todo"
-#define SEQ_OPTS_FILE "sequencer/opts"
-
static const char *action_name(const struct replay_opts *opts)
{
return opts->action == REVERT ? "revert" : "cherry-pick";
@@ -115,7 +115,9 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
const char * const * usage_str = revert_or_cherry_pick_usage(opts);
const char *me = action_name(opts);
int noop;
+ int reset = 0;
struct option options[] = {
+ OPT_BOOLEAN(0, "reset", &reset, "forget the current operation"),
OPT_BOOLEAN('n', "no-commit", &opts->no_commit, "don't automatically commit"),
OPT_BOOLEAN('e', "edit", &opts->edit, "edit the commit message"),
{ OPTION_BOOLEAN, 'r', NULL, &noop, NULL, "no-op (backward compatibility)",
@@ -144,7 +146,27 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
opts->commit_argc = parse_options(argc, argv, NULL, options, usage_str,
PARSE_OPT_KEEP_ARGV0 |
PARSE_OPT_KEEP_UNKNOWN);
- if (opts->commit_argc < 2)
+
+ /* Set the subcommand */
+ if (reset)
+ opts->subcommand = REPLAY_RESET;
+ else
+ opts->subcommand = REPLAY_NONE;
+
+ /* Check for incompatible command line arguments */
+ if (opts->subcommand == REPLAY_RESET) {
+ verify_opt_compatible(me, "--reset",
+ "--no-commit", opts->no_commit,
+ "--signoff", opts->signoff,
+ "--mainline", opts->mainline,
+ "--strategy", opts->strategy ? 1 : 0,
+ "--strategy-option", opts->xopts ? 1 : 0,
+ "-x", opts->record_origin,
+ "--ff", opts->allow_ff,
+ NULL);
+ }
+
+ else if (opts->commit_argc < 2)
usage_with_options(usage_str, options);
if (opts->allow_ff)
@@ -731,7 +753,6 @@ static void save_opts(struct replay_opts *opts)
static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
{
- struct strbuf buf = STRBUF_INIT;
struct commit_list *cur;
int res;
@@ -752,9 +773,7 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
* Sequence of picks finished successfully; cleanup by
* removing the .git/sequencer directory
*/
- strbuf_addf(&buf, "%s", git_path(SEQ_DIR));
- remove_dir_recursively(&buf, 0);
- strbuf_release(&buf);
+ remove_sequencer_state(1);
return 0;
}
@@ -770,16 +789,21 @@ static int pick_revisions(struct replay_opts *opts)
* cherry-pick should be handled differently from an existing
* one that is being continued
*/
- walk_revs_populate_todo(&todo_list, opts);
- create_seq_dir();
- if (get_sha1("HEAD", sha1)) {
- if (opts->action == REVERT)
- die(_("Can't revert as initial commit"));
- die(_("Can't cherry-pick into empty head"));
+ if (opts->subcommand == REPLAY_RESET) {
+ remove_sequencer_state(1);
+ return 0;
+ } else {
+ /* Start a new cherry-pick/ revert sequence */
+ walk_revs_populate_todo(&todo_list, opts);
+ create_seq_dir();
+ if (get_sha1("HEAD", sha1)) {
+ if (opts->action == REVERT)
+ die(_("Can't revert as initial commit"));
+ die(_("Can't cherry-pick into empty head"));
+ }
+ save_head(sha1_to_hex(sha1));
+ save_opts(opts);
}
- save_head(sha1_to_hex(sha1));
- save_opts(opts);
-
return pick_commits(todo_list, opts);
}
diff --git a/sequencer.c b/sequencer.c
new file mode 100644
index 0000000..bc2c046
--- /dev/null
+++ b/sequencer.c
@@ -0,0 +1,19 @@
+#include "cache.h"
+#include "sequencer.h"
+#include "strbuf.h"
+#include "dir.h"
+
+void remove_sequencer_state(int aggressive)
+{
+ struct strbuf seq_dir = STRBUF_INIT;
+ struct strbuf seq_old_dir = STRBUF_INIT;
+
+ strbuf_addf(&seq_dir, "%s", git_path(SEQ_DIR));
+ strbuf_addf(&seq_old_dir, "%s", git_path(SEQ_OLD_DIR));
+ remove_dir_recursively(&seq_old_dir, 0);
+ rename(git_path(SEQ_DIR), git_path(SEQ_OLD_DIR));
+ if (aggressive)
+ remove_dir_recursively(&seq_old_dir, 0);
+ strbuf_release(&seq_dir);
+ strbuf_release(&seq_old_dir);
+}
diff --git a/sequencer.h b/sequencer.h
new file mode 100644
index 0000000..905d295
--- /dev/null
+++ b/sequencer.h
@@ -0,0 +1,20 @@
+#ifndef SEQUENCER_H
+#define SEQUENCER_H
+
+#define SEQ_DIR "sequencer"
+#define SEQ_OLD_DIR "sequencer-old"
+#define SEQ_HEAD_FILE "sequencer/head"
+#define SEQ_TODO_FILE "sequencer/todo"
+#define SEQ_OPTS_FILE "sequencer/opts"
+
+/*
+ * Removes SEQ_OLD_DIR and renames SEQ_DIR to SEQ_OLD_DIR, ignoring
+ * any errors. Intended to be used by 'git reset'.
+ *
+ * With the aggressive flag, it additionally removes SEQ_OLD_DIR,
+ * ignoring any errors. Inteded to be used by the sequencer's
+ * '--reset' subcommand.
+ */
+void remove_sequencer_state(int aggressive);
+
+#endif
diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
index 6038419..a3427a5 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -13,7 +13,7 @@ test_description='Test cherry-pick continuation features
. ./test-lib.sh
pristine_detach () {
- rm -rf .git/sequencer &&
+ git cherry-pick --reset &&
git checkout -f "$1^0" &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x
@@ -41,7 +41,6 @@ test_expect_success 'cherry-pick persists data on failure' '
'
test_expect_success 'cherry-pick persists opts correctly' '
- rm -rf .git/sequencer &&
pristine_detach initial &&
test_must_fail git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours base..anotherpick &&
test_path_is_dir .git/sequencer &&
@@ -71,4 +70,16 @@ test_expect_success 'cherry-pick cleans up sequencer state upon success' '
test_path_is_missing .git/sequencer
'
+test_expect_success '--reset does not complain when no cherry-pick is in progress' '
+ pristine_detach initial &&
+ git cherry-pick --reset
+'
+
+test_expect_success '--reset cleans up sequencer state' '
+ pristine_detach initial &&
+ test_must_fail git cherry-pick base..picked &&
+ git cherry-pick --reset &&
+ test_path_is_missing .git/sequencer
+'
+
test_done
--
1.7.4.rc1.7.g2cf08.dirty
next prev parent reply other threads:[~2011-08-01 18:12 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-01 18:06 [PATCH v5 00/18] Sequencer for inclusion Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 01/18] advice: Introduce error_resolve_conflict Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 02/18] config: Introduce functions to write non-standard file Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 03/18] revert: Simplify and inline add_message_to_msg Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 04/18] revert: Don't check lone argument in get_encoding Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 05/18] revert: Rename no_replay to record_origin Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 06/18] revert: Eliminate global "commit" variable Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 07/18] revert: Introduce struct to keep command-line options Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 08/18] revert: Separate cmdline parsing from functional code Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 09/18] revert: Don't create invalid replay_opts in parse_args Ramkumar Ramachandra
2011-08-02 6:28 ` Christian Couder
2011-08-02 6:41 ` Christian Couder
2011-08-04 9:34 ` Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 10/18] revert: Save data for continuing after conflict resolution Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 11/18] revert: Save command-line options for continuing operation Ramkumar Ramachandra
2011-08-04 4:05 ` Christian Couder
2011-08-04 9:25 ` Ramkumar Ramachandra
2011-08-01 18:06 ` [PATCH 12/18] revert: Make pick_commits functionally act on a commit list Ramkumar Ramachandra
2011-08-01 18:07 ` Ramkumar Ramachandra [this message]
2011-08-01 18:07 ` [PATCH 14/18] reset: Make reset remove the sequencer state Ramkumar Ramachandra
2011-08-01 18:07 ` [PATCH 15/18] revert: Remove sequencer state when no commits are pending Ramkumar Ramachandra
2011-08-01 18:07 ` [PATCH 16/18] revert: Don't implicitly stomp pending sequencer operation Ramkumar Ramachandra
2011-08-01 18:07 ` [PATCH 17/18] revert: Introduce --continue to continue the operation Ramkumar Ramachandra
2011-08-01 18:31 ` Ramkumar Ramachandra
2011-08-02 2:36 ` Christian Couder
2011-08-02 2:47 ` Christian Couder
2011-08-02 2:51 ` Christian Couder
2011-08-02 4:41 ` Ramkumar Ramachandra
2011-08-04 10:02 ` Ramkumar Ramachandra
2011-08-02 6:24 ` Christian Couder
2011-08-04 4:57 ` Christian Couder
2011-08-04 9:22 ` Ramkumar Ramachandra
2011-08-01 18:07 ` [PATCH 18/18] revert: Propagate errors upwards from do_pick_commit Ramkumar Ramachandra
-- strict thread matches above, loose matches on Subject: below --
2011-08-04 10:38 [PATCH 00/18] Sequencer for inclusion v6 Ramkumar Ramachandra
2011-08-04 10:39 ` [PATCH 13/18] revert: Introduce --reset to remove sequencer state Ramkumar Ramachandra
2011-07-28 16:52 [PATCH 00/18] Sequencer for inclusion v4 Ramkumar Ramachandra
2011-07-28 16:52 ` [PATCH 13/18] revert: Introduce --reset to remove sequencer state Ramkumar Ramachandra
2011-07-31 14:01 ` Christian Couder
2011-08-01 17:52 ` Ramkumar Ramachandra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1312222025-28453-14-git-send-email-artagnon@gmail.com \
--to=artagnon@gmail.com \
--cc=barkalow@iabervon.org \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).