git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Paul Tan <pyokagan@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org,
	Johannes Schindelin <johannes.schindelin@gmx.de>,
	Stefan Beller <sbeller@google.com>
Subject: Re: [PATCH v5 00/44] Make git-am a builtin
Date: Tue, 14 Jul 2015 18:08:03 +0800	[thread overview]
Message-ID: <20150714100803.GA23901@yoshi.chippynet.com> (raw)
In-Reply-To: <xmqqh9p7y9iu.fsf@gitster.dls.corp.google.com>

On Mon, Jul 13, 2015 at 03:31:37PM -0700, Junio C Hamano wrote:
> A fix is to edit the patch to replace that "flags);" line with full
> "return delete_ref()" line and save it.  Then running
> 
>   $ git am
> 
> (no argument) is supposed to read from the corrected patch file and
> continue the application.
> 
> This no longer works with the version with this series, it seems.

Ah, this is actually the same bug as the previous one, and it actually
all stems from the fact that I completely overlooked the code path
change introduced by 271440e (git-am: make it easier after fixing up an
unapplicable patch., 2005-10-25). When "git am" is run again while
paused, the mail message should not be re-parsed at all.

So, I'm thinking of something like the following as a separate patch in
this series to re-implement the feature:

diff a/builtin/am.c b/builtin/am.c
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1714,6 +1692,21 @@ static void do_commit(const struct am_state *state)
 }
 
 /**
+ * Validates the am_state for resuming -- the "msg" and authorship fields must
+ * be filled up.
+ */
+static void validate_resume_state(const struct am_state *state)
+{
+	if (!state->msg)
+		die(_("cannot resume: %s does not exist."),
+			am_path(state, "final-commit"));
+
+	if (!state->author_name || !state->author_email || !state->author_date)
+		die(_("cannot resume: %s does not exist."),
+			am_path(state, "author-script"));
+}
+
+/**
  * Interactively prompt the user on whether the current patch should be
  * applied.
  *
@@ -1774,8 +1767,12 @@ static int do_interactive(struct am_state *state)
 
 /**
  * Applies all queued mail.
+ *
+ * If `resume` is true, we are "resuming". The "msg" and authorship fields, as
+ * well as the state directory's "patch" file is used as-is for applying the
+ * patch and committing it.
  */
-static void am_run(struct am_state *state)
+static void am_run(struct am_state *state, int resume)
 {
 	const char *argv_gc_auto[] = {"gc", "--auto", NULL};
 	struct strbuf sb = STRBUF_INIT;
@@ -1793,21 +1790,28 @@ static void am_run(struct am_state *state)
 
 	while (state->cur <= state->last) {
 		const char *mail = am_path(state, msgnum(state));
-		int apply_status, skip;
+		int apply_status;
 
 		if (!file_exists(mail))
 			goto next;
 
-		if (state->rebasing)
-			skip = parse_mail_rebase(state, mail);
-		else
-			skip = parse_mail(state, mail);
+		if (resume) {
+			validate_resume_state(state);
+			resume = 0;
+		} else {
+			int skip;
+
+			if (state->rebasing)
+				skip = parse_mail_rebase(state, mail);
+			else
+				skip = parse_mail(state, mail);
 
-		if (skip)
-			goto next; /* mail should be skipped */
+			if (skip)
+				goto next; /* mail should be skipped */
 
-		write_author_script(state);
-		write_commit_msg(state);
+			write_author_script(state);
+			write_commit_msg(state);
+		}
 
 		if (state->interactive && do_interactive(state))
 			goto next;
@@ -1880,13 +1884,7 @@ next:
  */
 static void am_resolve(struct am_state *state)
 {
-	if (!state->msg)
-		die(_("cannot resume: %s does not exist."),
-			am_path(state, "final-commit"));
-
-	if (!state->author_name || !state->author_email || !state->author_date)
-		die(_("cannot resume: %s does not exist."),
-			am_path(state, "author-script"));
+	validate_resume_state(state);
 
 	say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
 
@@ -1915,7 +1913,7 @@ static void am_resolve(struct am_state *state)
 
 next:
 	am_next(state);
-	am_run(state);
+	am_run(state, 0);
 }
 
 /**
@@ -2040,7 +2038,7 @@ static void am_skip(struct am_state *state)
 		die(_("failed to clean index"));
 
 	am_next(state);
-	am_run(state);
+	am_run(state, 0);
 }
 
 /**
@@ -2136,6 +2134,7 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
 
 enum resume_mode {
 	RESUME_FALSE = 0,
+	RESUME_APPLY,
 	RESUME_RESOLVED,
 	RESUME_SKIP,
 	RESUME_ABORT
@@ -2271,6 +2270,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
 			die(_("previous rebase directory %s still exists but mbox given."),
 				state.dir);
 
+		if (resume == RESUME_FALSE)
+			resume = RESUME_APPLY;
+
 		am_load(&state);
 	} else {
 		struct argv_array paths = ARGV_ARRAY_INIT;
@@ -2310,7 +2312,10 @@ int cmd_am(int argc, const char **argv, const char *prefix)
 
 	switch (resume) {
 	case RESUME_FALSE:
-		am_run(&state);
+		am_run(&state, 0);
+		break;
+	case RESUME_APPLY:
+		am_run(&state, 1);
 		break;
 	case RESUME_RESOLVED:
 		am_resolve(&state);

At this point I've accumulated a lot of changes on my end so I'll do a
re-roll.

Thanks,
Paul

      reply	other threads:[~2015-07-14 10:08 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-07 14:20 [PATCH v5 00/44] Make git-am a builtin Paul Tan
2015-07-07 14:20 ` [PATCH v5 01/44] wrapper: implement xopen() Paul Tan
2015-07-07 14:20 ` [PATCH v5 02/44] wrapper: implement xfopen() Paul Tan
2015-07-07 14:20 ` [PATCH v5 03/44] builtin-am: implement skeletal builtin am Paul Tan
2015-07-07 14:20 ` [PATCH v5 04/44] builtin-am: implement patch queue mechanism Paul Tan
2015-07-07 14:20 ` [PATCH v5 05/44] builtin-am: split out mbox/maildir patches with git-mailsplit Paul Tan
2015-07-07 14:20 ` [PATCH v5 06/44] builtin-am: auto-detect mbox patches Paul Tan
2015-07-07 14:20 ` [PATCH v5 07/44] builtin-am: extract patch and commit info with git-mailinfo Paul Tan
2015-07-07 14:20 ` [PATCH v5 08/44] builtin-am: apply patch with git-apply Paul Tan
2015-07-07 14:20 ` [PATCH v5 09/44] builtin-am: implement committing applied patch Paul Tan
2015-07-07 14:20 ` [PATCH v5 10/44] builtin-am: refuse to apply patches if index is dirty Paul Tan
2015-07-07 14:20 ` [PATCH v5 11/44] builtin-am: implement --resolved/--continue Paul Tan
2015-07-07 14:20 ` [PATCH v5 12/44] builtin-am: implement --skip Paul Tan
2015-07-13 19:05   ` Stefan Beller
2015-07-14  9:34     ` Paul Tan
2015-07-14 16:54       ` Stefan Beller
2015-07-18 15:22         ` Paul Tan
2015-07-07 14:20 ` [PATCH v5 13/44] builtin-am: implement --abort Paul Tan
2015-07-07 14:20 ` [PATCH v5 14/44] builtin-am: reject patches when there's a session in progress Paul Tan
2015-07-07 14:20 ` [PATCH v5 15/44] builtin-am: implement -q/--quiet Paul Tan
2015-07-07 14:20 ` [PATCH v5 16/44] builtin-am: exit with user friendly message on failure Paul Tan
2015-07-07 14:20 ` [PATCH v5 17/44] builtin-am: implement -s/--signoff Paul Tan
2015-07-07 14:20 ` [PATCH v5 18/44] cache-tree: introduce write_index_as_tree() Paul Tan
2015-07-07 20:10   ` Junio C Hamano
2015-07-07 14:20 ` [PATCH v5 19/44] builtin-am: implement --3way, am.threeWay Paul Tan
2015-07-07 20:14   ` Junio C Hamano
2015-07-14  9:32     ` Paul Tan
2015-07-07 14:20 ` [PATCH v5 20/44] builtin-am: implement --rebasing mode Paul Tan
2015-07-07 14:20 ` [PATCH v5 21/44] builtin-am: bypass git-mailinfo when --rebasing Paul Tan
2015-07-07 14:20 ` [PATCH v5 22/44] builtin-am: handle stray state directory Paul Tan
2015-07-07 14:20 ` [PATCH v5 23/44] builtin-am: implement -u/--utf8 Paul Tan
2015-07-07 14:20 ` [PATCH v5 24/44] builtin-am: implement -k/--keep, --keep-non-patch Paul Tan
2015-07-07 14:20 ` [PATCH v5 25/44] builtin-am: implement --[no-]message-id, am.messageid Paul Tan
2015-07-07 14:20 ` [PATCH v5 26/44] builtin-am: support --keep-cr, am.keepcr Paul Tan
2015-07-07 14:20 ` [PATCH v5 27/44] builtin-am: implement --[no-]scissors Paul Tan
2015-07-07 14:20 ` [PATCH v5 28/44] builtin-am: pass git-apply's options to git-apply Paul Tan
2015-07-07 14:20 ` [PATCH v5 29/44] builtin-am: implement --ignore-date Paul Tan
2015-07-07 14:20 ` [PATCH v5 30/44] builtin-am: implement --committer-date-is-author-date Paul Tan
2015-07-07 14:20 ` [PATCH v5 31/44] builtin-am: implement -S/--gpg-sign, commit.gpgsign Paul Tan
2015-07-07 14:20 ` [PATCH v5 32/44] builtin-am: invoke post-rewrite hook Paul Tan
2015-07-07 14:20 ` [PATCH v5 33/44] builtin-am: support automatic notes copying Paul Tan
2015-07-07 14:20 ` [PATCH v5 34/44] builtin-am: invoke applypatch-msg hook Paul Tan
2015-07-07 14:20 ` [PATCH v5 35/44] builtin-am: invoke pre-applypatch hook Paul Tan
2015-07-07 14:20 ` [PATCH v5 36/44] builtin-am: invoke post-applypatch hook Paul Tan
2015-07-07 14:20 ` [PATCH v5 37/44] builtin-am: rerere support Paul Tan
2015-07-07 14:20 ` [PATCH v5 38/44] builtin-am: support and auto-detect StGit patches Paul Tan
2015-07-07 14:20 ` [PATCH v5 39/44] builtin-am: support and auto-detect StGit series files Paul Tan
2015-07-07 14:20 ` [PATCH v5 40/44] builtin-am: support and auto-detect mercurial patches Paul Tan
2015-07-07 14:20 ` [PATCH v5 41/44] builtin-am: implement -i/--interactive Paul Tan
2015-07-07 14:21 ` [PATCH v5 42/44] builtin-am: implement legacy -b/--binary option Paul Tan
2015-07-07 14:21 ` [PATCH v5 43/44] builtin-am: check for valid committer ident Paul Tan
2015-07-07 14:21 ` [PATCH v5 44/44] builtin-am: remove redirection to git-am.sh Paul Tan
2015-07-07 18:52 ` [PATCH v5 00/44] Make git-am a builtin Junio C Hamano
2015-07-07 19:25   ` Paul Tan
2015-07-08  7:31 ` Junio C Hamano
2015-07-08  7:44   ` Paul Tan
2015-07-08  7:48   ` Junio C Hamano
2015-07-08  8:19     ` Paul Tan
2015-07-09  6:00       ` Junio C Hamano
2015-07-12 12:29         ` Paul Tan
2015-07-12 17:32           ` Junio C Hamano
2015-07-13 22:31 ` Junio C Hamano
2015-07-14 10:08   ` Paul Tan [this message]

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=20150714100803.GA23901@yoshi.chippynet.com \
    --to=pyokagan@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=sbeller@google.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).