From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Jonathan Nieder <jrnieder@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Christian Couder <chriscool@tuxfamily.org>,
Daniel Barkalow <barkalow@iabervon.org>
Subject: [PATCH 12/17] revert: Save command-line options for continuing operation
Date: Mon, 11 Jul 2011 14:54:03 +0000 [thread overview]
Message-ID: <1310396048-24925-13-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1310396048-24925-1-git-send-email-artagnon@gmail.com>
In the same spirit as ".git/sequencer/head" and ".git/sequencer/todo",
introduce ".git/sequencer/opts" to persist the replay_opts structure
for continuing after a conflict resolution. Use a simple "key =
value" format for this file, using "|" to separate multiple values so
that the file looks like:
signoff = true
record-origin = true
mainline = 1
strategy = recursive
strategy-option = patience | ours
Write the file just after writing ".git/sequencer/head", and parse it
out just after parsing out ".git/sequencer/head". There is now enough
data for "--continue" to work.
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
builtin/revert.c | 226 +++++++++++++++++++++++++++++++++++++++
sequencer.h | 1 +
t/t3510-cherry-pick-sequence.sh | 20 ++++-
3 files changed, 246 insertions(+), 1 deletions(-)
diff --git a/builtin/revert.c b/builtin/revert.c
index 856ee97..edf74fb 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -596,6 +596,32 @@ struct commit_list **commit_list_append(struct commit *commit,
return &new->next;
}
+static void format_opts(struct strbuf *buf, struct replay_opts *opts)
+{
+ int i;
+
+ if (opts->no_commit)
+ strbuf_addstr(buf, "no-commit = true\n");
+ if (opts->edit)
+ strbuf_addstr(buf, "edit = true\n");
+ if (opts->signoff)
+ strbuf_addstr(buf, "signoff = true\n");
+ if (opts->record_origin)
+ strbuf_addstr(buf, "record-origin = true\n");
+ if (opts->allow_ff)
+ strbuf_addstr(buf, "ff = true\n");
+ if (opts->mainline)
+ strbuf_addf(buf, "mainline = %d\n", opts->mainline);
+ if (opts->strategy)
+ strbuf_addf(buf, "strategy = %s\n", opts->strategy);
+ if (opts->xopts) {
+ strbuf_addf(buf, "strategy-option = ");
+ for (i = 0; i < opts->xopts_nr - 1; i ++)
+ strbuf_addf(buf, "%s | ", opts->xopts[i]);
+ strbuf_addf(buf, "%s\n", opts->xopts[i]);
+ }
+}
+
static void format_todo(struct strbuf *buf, struct commit_list *todo_list,
struct replay_opts *opts)
{
@@ -694,6 +720,184 @@ error:
die(_("Malformed instruction sheet: %s"), git_path(SEQ_TODO_FILE));
}
+static struct strbuf *parse_value(const char *start, char **end_ptr)
+{
+ static struct strbuf value = STRBUF_INIT;
+ int quote = 0;
+ char *p = (char *)start;
+ char *end;
+
+ /* Find and strip '\n', '\r' */
+ if ((end = strchr(start, '\n'))) {
+ *end = '\0'; /* Remove trailing '\n' */
+ if (*(end - 1) == '\r')
+ *(end - 1) = '\0'; /* Remove trailing '\r' */
+ } else if (strchr(start, '\0'))
+ end = NULL;
+ else
+ goto error;
+
+ for (; *p != '\0'; p ++) {
+ if (!quote && (*p == ';' || *p == '#'))
+ /* Ignore comments */
+ goto ok;
+ if (*p == '\\') {
+ p += 1;
+ switch (*p) {
+ case '\n':
+ continue;
+ case 't':
+ strbuf_addch(&value, '\t');
+ break;
+ case 'b':
+ strbuf_addch(&value, '\b');
+ break;
+ case 'n':
+ strbuf_addch(&value, '\n');
+ break;
+ /* Some pharapters escape as themselves */
+ case '\\': case '"':
+ break;
+ /* Reject unknown escape sequences */
+ default:
+ goto error;
+ }
+ continue;
+ }
+ if (*p == '"') {
+ quote = 1 - quote;
+ continue;
+ }
+ strbuf_addch(&value, *p);
+ }
+ /* Quote not closed */
+ if (quote)
+ goto error;
+
+ if (end)
+ *end_ptr = end + 1;
+ else
+ *end_ptr = NULL;
+ok:
+ strbuf_trim(&value);
+ return &value;
+error:
+ strbuf_release(&value);
+ return NULL;
+}
+
+static char *parse_opt_value(const char *start, void *key,
+ enum parse_opt_type type, parse_opt_cb *cb_function)
+{
+ struct strbuf *value, *subvalue;
+ struct option opt;
+ char *p, *cur, *val, *end;
+
+ /* Remove spaces before '=' */
+ for (p = (char *)start; isspace(*p); p++);
+ if (*p != '=')
+ goto error;
+
+ if (!(value = parse_value(p + 1, &end)))
+ goto error;
+ val = value->buf;
+
+ switch (type) {
+ case OPTION_BOOLEAN:
+ if (!strcasecmp(val, "true")
+ || !strcasecmp(val, "yes")
+ || !strcasecmp(val, "on"))
+ *(int *)key = 1;
+ else if (!strcasecmp(val, "false")
+ || !strcasecmp(val, "no")
+ || !strcasecmp(val, "off"))
+ *(int *)key = 0;
+ else
+ goto error;
+ break;
+ case OPTION_INTEGER:
+ *(int *)key = strtol(val, NULL, 10);
+ break;
+ case OPTION_STRING:
+ *(char **)key = xstrdup(val);
+ break;
+ case OPTION_CALLBACK:
+ opt.value = (struct replay_opts **)key;
+ while (val) {
+ if ((cur = strchr(val, '|'))) {
+ *cur = '\0';
+ subvalue = parse_value(val, &end);
+ (*cb_function)(&opt, subvalue->buf, 0);
+ strbuf_release(subvalue);
+ val = cur + 1;
+ } else {
+ (*cb_function)(&opt, val, 0);
+ break;
+ }
+ }
+ break;
+ default:
+ die(_("program error"));
+ }
+ strbuf_release(value);
+ return end;
+error:
+ die(_("Malformed options sheet: %s"), git_path(SEQ_OPTS_FILE));
+}
+
+static void read_populate_opts(struct replay_opts **opts_ptr)
+{
+ struct replay_opts *opts = *opts_ptr;
+ struct strbuf buf = STRBUF_INIT;
+ char *p;
+ int fd;
+
+ fd = open(git_path(SEQ_OPTS_FILE), O_RDONLY);
+ if (fd < 0)
+ goto ok;
+ if (strbuf_read(&buf, fd, 0) < buf.len) {
+ close(fd);
+ strbuf_release(&buf);
+ die(_("Could not read %s."), git_path(SEQ_OPTS_FILE));
+ }
+ close(fd);
+
+ for (p = buf.buf; p && *p != '\0';) {
+ if (!prefixcmp(p, "no-commit"))
+ p = parse_opt_value(p + strlen("no-commit"),
+ &opts->no_commit, OPTION_BOOLEAN, NULL);
+ else if (!prefixcmp(p, "edit"))
+ p = parse_opt_value(p + strlen("edit"),
+ &opts->edit, OPTION_BOOLEAN, NULL);
+ else if (!prefixcmp(p, "signoff"))
+ p = parse_opt_value(p + strlen("signoff"),
+ &opts->signoff, OPTION_BOOLEAN, NULL);
+ else if (!prefixcmp(p, "mainline"))
+ p = parse_opt_value(p + strlen("mainline"),
+ &opts->mainline, OPTION_INTEGER, NULL);
+ else if (!prefixcmp(p, "record-origin"))
+ p = parse_opt_value(p + strlen("record-origin"),
+ &opts->record_origin, OPTION_BOOLEAN, NULL);
+ else if (!prefixcmp(p, "ff"))
+ p = parse_opt_value(p + strlen("ff"),
+ &opts->allow_ff, OPTION_BOOLEAN, NULL);
+ else if (!prefixcmp(p, "strategy-option"))
+ p = parse_opt_value(p + strlen("strategy-option"),
+ &opts, OPTION_CALLBACK, option_parse_x);
+ else if (!prefixcmp(p, "strategy"))
+ p = parse_opt_value(p + strlen("strategy"),
+ &opts->strategy, OPTION_STRING, NULL);
+ else
+ goto error;
+ }
+ok:
+ strbuf_release(&buf);
+ return;
+error:
+ strbuf_release(&buf);
+ die(_("Malformed options sheet: %s"), git_path(SEQ_OPTS_FILE));
+}
+
static void walk_revs_populate_todo(struct commit_list **todo_list,
struct replay_opts *opts)
{
@@ -751,6 +955,27 @@ static void save_todo(struct commit_list *todo_list, struct replay_opts *opts)
strbuf_release(&buf);
}
+static void save_opts(struct replay_opts *opts)
+{
+ static struct lock_file opts_lock;
+ struct strbuf buf = STRBUF_INIT;
+ int fd;
+
+ fd = hold_lock_file_for_update(&opts_lock, git_path(SEQ_OPTS_FILE), LOCK_DIE_ON_ERROR);
+ format_opts(&buf, opts);
+ if (!buf.len)
+ return;
+ if (write_in_full(fd, buf.buf, buf.len) < 0) {
+ strbuf_release(&buf);
+ die_errno(_("Could not write to %s."), git_path(SEQ_OPTS_FILE));
+ }
+ if (commit_lock_file(&opts_lock) < 0) {
+ strbuf_release(&buf);
+ die(_("Error wrapping up %s"), git_path(SEQ_OPTS_FILE));
+ }
+ strbuf_release(&buf);
+}
+
static int pick_commits(struct replay_opts *opts)
{
struct commit_list *todo_list = NULL;
@@ -768,6 +993,7 @@ static int pick_commits(struct replay_opts *opts)
create_seq_dir();
if (!get_sha1("HEAD", sha1))
save_head(sha1_to_hex(sha1));
+ save_opts(opts);
save_todo(todo_list, opts);
for (cur = todo_list; cur; cur = cur->next) {
diff --git a/sequencer.h b/sequencer.h
index 673616b..dcb51b1 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -5,6 +5,7 @@
#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 --hard'.
diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
index 64eaa20..100cbb1 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -32,10 +32,28 @@ test_expect_success setup '
test_expect_success 'cherry-pick persists data on failure' '
pristine_detach initial &&
- test_must_fail git cherry-pick base..anotherpick &&
+ test_must_fail git cherry-pick -s base..anotherpick &&
test_path_is_dir .git/sequencer &&
test_path_is_file .git/sequencer/head &&
test_path_is_file .git/sequencer/todo &&
+ test_path_is_file .git/sequencer/opts &&
+ rm -rf .git/sequencer
+'
+
+test_expect_success 'cherry-pick persists opts correctly' '
+ 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 &&
+ test_path_is_file .git/sequencer/head &&
+ test_path_is_file .git/sequencer/todo &&
+ test_path_is_file .git/sequencer/opts &&
+ cat >expect <<-\EOF &&
+ signoff = true
+ mainline = 1
+ strategy = recursive
+ strategy-option = patience | ours
+ EOF
+ test_cmp expect .git/sequencer/opts &&
rm -rf .git/sequencer
'
--
1.7.5.GIT
next prev parent reply other threads:[~2011-07-11 14:55 UTC|newest]
Thread overview: 99+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-11 14:53 [GSoC update] Sequencer for inclusion Ramkumar Ramachandra
2011-07-11 14:53 ` [PATCH 01/17] advice: Introduce error_resolve_conflict Ramkumar Ramachandra
2011-07-11 14:53 ` [PATCH 02/17] revert: Inline add_message_to_msg function Ramkumar Ramachandra
2011-07-12 16:53 ` Jonathan Nieder
2011-07-13 6:00 ` Ramkumar Ramachandra
2011-07-13 6:42 ` Jonathan Nieder
2011-07-19 16:36 ` Ramkumar Ramachandra
2011-07-19 16:52 ` Junio C Hamano
2011-07-19 17:08 ` Ramkumar Ramachandra
2011-07-19 19:36 ` Jonathan Nieder
2011-07-20 5:32 ` Ramkumar Ramachandra
2011-07-11 14:53 ` [PATCH 03/17] revert: Don't check lone argument in get_encoding Ramkumar Ramachandra
2011-07-12 16:59 ` Jonathan Nieder
2011-07-13 6:14 ` Ramkumar Ramachandra
2011-07-13 6:30 ` Jonathan Nieder
2011-07-11 14:53 ` [PATCH 04/17] revert: Rename no_replay to record_origin Ramkumar Ramachandra
2011-07-12 17:02 ` Jonathan Nieder
2011-07-13 7:35 ` Ramkumar Ramachandra
2011-07-17 19:36 ` Jonathan Nieder
2011-07-11 14:53 ` [PATCH 05/17] revert: Propogate errors upwards from do_pick_commit Ramkumar Ramachandra
2011-07-12 17:32 ` Jonathan Nieder
2011-07-17 10:46 ` Ramkumar Ramachandra
2011-07-17 16:59 ` Jonathan Nieder
2011-07-19 10:09 ` Ramkumar Ramachandra
2011-07-11 14:53 ` [PATCH 06/17] revert: Eliminate global "commit" variable Ramkumar Ramachandra
2011-07-12 17:45 ` Jonathan Nieder
2011-07-13 6:57 ` Ramkumar Ramachandra
2011-07-13 7:10 ` Jonathan Nieder
2011-07-13 8:33 ` Ramkumar Ramachandra
2011-07-13 16:40 ` Jonathan Nieder
2011-07-11 14:53 ` [PATCH 07/17] revert: Introduce struct to keep command-line options Ramkumar Ramachandra
2011-07-12 18:05 ` Jonathan Nieder
2011-07-13 7:56 ` Ramkumar Ramachandra
2011-07-11 14:53 ` [PATCH 08/17] revert: Separate cmdline parsing from functional code Ramkumar Ramachandra
2011-07-12 18:20 ` Jonathan Nieder
2011-07-18 20:53 ` Ramkumar Ramachandra
2011-07-18 21:03 ` Jonathan Nieder
2011-07-11 14:54 ` [PATCH 09/17] revert: Don't create invalid replay_opts in parse_args Ramkumar Ramachandra
2011-07-11 20:44 ` Junio C Hamano
2011-07-12 5:57 ` Ramkumar Ramachandra
2011-07-12 18:29 ` Jonathan Nieder
2011-07-17 11:56 ` Ramkumar Ramachandra
2011-07-17 18:43 ` Jonathan Nieder
2011-07-11 14:54 ` [PATCH 10/17] sequencer: Announce sequencer state location Ramkumar Ramachandra
2011-07-12 18:56 ` Jonathan Nieder
2011-07-13 12:10 ` Sverre Rabbelier
2011-07-17 16:23 ` Ramkumar Ramachandra
2011-07-17 19:19 ` Jonathan Nieder
2011-07-18 19:44 ` Ramkumar Ramachandra
2011-07-11 14:54 ` [PATCH 11/17] revert: Save data for continuing after conflict resolution Ramkumar Ramachandra
2011-07-11 21:01 ` Junio C Hamano
2011-07-11 21:31 ` Junio C Hamano
2011-07-12 5:43 ` Ramkumar Ramachandra
2011-07-12 19:37 ` Jonathan Nieder
2011-07-17 11:48 ` Ramkumar Ramachandra
2011-07-17 18:40 ` Jonathan Nieder
2011-07-18 19:31 ` Ramkumar Ramachandra
2011-07-19 12:21 ` Jonathan Nieder
2011-07-19 12:34 ` Ramkumar Ramachandra
2011-07-11 14:54 ` Ramkumar Ramachandra [this message]
2011-07-11 21:15 ` [PATCH 12/17] revert: Save command-line options for continuing operation Junio C Hamano
2011-07-12 5:56 ` Ramkumar Ramachandra
2011-07-12 19:52 ` Jonathan Nieder
2011-07-18 20:18 ` Ramkumar Ramachandra
2011-07-11 14:54 ` [PATCH 13/17] revert: Introduce a layer of indirection over pick_commits Ramkumar Ramachandra
2011-07-12 20:03 ` Jonathan Nieder
2011-07-18 21:24 ` Ramkumar Ramachandra
2011-07-11 14:54 ` [PATCH 14/17] reset: Make hard reset remove the sequencer state Ramkumar Ramachandra
2011-07-12 20:15 ` Jonathan Nieder
2011-07-17 16:40 ` Ramkumar Ramachandra
2011-07-11 14:54 ` [PATCH 15/17] revert: Remove sequencer state when no commits are pending Ramkumar Ramachandra
2011-07-11 19:58 ` Junio C Hamano
2011-07-12 6:26 ` Ramkumar Ramachandra
2011-07-11 14:54 ` [PATCH 16/17] revert: Introduce --reset to remove sequencer state Ramkumar Ramachandra
2011-07-12 20:30 ` Jonathan Nieder
2011-07-17 17:10 ` Ramkumar Ramachandra
2011-07-17 19:25 ` Jonathan Nieder
2011-07-11 14:54 ` [PATCH 17/17] revert: Introduce --continue to continue the operation Ramkumar Ramachandra
2011-07-12 20:46 ` Jonathan Nieder
2011-07-17 16:11 ` Ramkumar Ramachandra
2011-07-17 18:32 ` Jonathan Nieder
2011-07-18 20:00 ` Ramkumar Ramachandra
2011-07-18 20:09 ` Jonathan Nieder
2011-07-11 17:17 ` [GSoC update] Sequencer for inclusion Jonathan Nieder
2011-07-11 17:57 ` Ramkumar Ramachandra
2011-07-11 20:05 ` Ramkumar Ramachandra
2011-07-11 20:11 ` Jonathan Nieder
2011-07-12 7:05 ` Ramkumar Ramachandra
2011-07-11 20:07 ` Junio C Hamano
2011-07-11 22:14 ` Jeff King
2011-07-12 6:41 ` Ramkumar Ramachandra
2011-07-12 6:47 ` Jeff King
2011-07-13 9:41 ` Ramkumar Ramachandra
2011-07-13 19:07 ` Jeff King
2011-07-18 21:37 ` [RFC PATCH] config: Introduce functions to write non-standard file Ramkumar Ramachandra
2011-07-18 23:54 ` Junio C Hamano
2011-07-19 8:52 ` Ramkumar Ramachandra
2011-07-12 5:58 ` [GSoC update] Sequencer for inclusion Jonathan Nieder
2011-07-12 6:28 ` Miles Bader
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1310396048-24925-13-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 \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).