git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5 00/44] Make git-am a builtin

From
Paul Tan <pyokagan@gmail.com>
Date
Jul 8, 2015, 08:19 UTC
Message-ID
<20150708081902.GA8606@yoshi.chippynet.com>
In-Reply-To
<xmqqa8v7yts9.fsf@gitster.dls.corp.google.com>
On Wed, Jul 08, 2015 at 12:48:06AM -0700, Junio C Hamano wrote:
Show 14 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> $ git am -s ./+dt
> ...
> error: patch failed: builtin/update-ref.c:421
> error: builtin/update-ref.c: patch does not apply
> Patch failed at 0007 update-ref and tag: add --create-reflog arg
> The copy of the patch that failed is found in:.git/rebase-apply/patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".
> $ git am -3
> git: builtin/am.c:1332: parse_mail: Assertion `!state->author_name'
> failed.
> Aborted (core dumped)

Ah, it's because parse_mail() does not expect to be called while the authorship and commit msg fields have been filled up. This is a wrong assumption, of course.

So the fix would be to remove the assert()s, as follows:
diff --git a/builtin/am.c b/builtin/am.c
index c548129..ab560ab 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1327,16 +1327,20 @@ static int parse_mail(struct am_state *state, const char *mail)
 	if (state->append_signoff)
 		append_signoff(&msg, 0, 0);
 
-	assert(!state->author_name);
+	if (state->author_name)
+		free(state->author_name);
 	state->author_name = strbuf_detach(&author_name, NULL);
 
-	assert(!state->author_email);
+	if (state->author_email)
+		free(state->author_email);
 	state->author_email = strbuf_detach(&author_email, NULL);
 
-	assert(!state->author_date);
+	if (state->author_date)
+		free(state->author_date);
 	state->author_date = strbuf_detach(&author_date, NULL);
 
-	assert(!state->msg);
+	if (state->msg)
+		free(state->msg);
 	state->msg = strbuf_detach(&msg, &state->msg_len);
 
 finish:
@@ -1392,7 +1396,9 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
 		die(_("invalid ident line: %s"), sb.buf);
 	}
 
-	assert(!state->author_name);
+	if (state->author_name)
+		free(state->author_name);
+
 	if (ident_split.name_begin) {
 		strbuf_add(&sb, ident_split.name_begin,
 			ident_split.name_end - ident_split.name_begin);
@@ -1400,7 +1406,9 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
 	} else
 		state->author_name = xstrdup("");
 
-	assert(!state->author_email);
+	if (state->author_email)
+		free(state->author_email);
+
 	if (ident_split.mail_begin) {
 		strbuf_add(&sb, ident_split.mail_begin,
 			ident_split.mail_end - ident_split.mail_begin);
@@ -1410,13 +1418,17 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
 
 	author_date = show_ident_date(&ident_split, DATE_NORMAL);
 	strbuf_addstr(&sb, author_date);
-	assert(!state->author_date);
+
+	if (state->author_date)
+		free(state->author_date);
 	state->author_date = strbuf_detach(&sb, NULL);
 
-	assert(!state->msg);
 	msg = strstr(buffer, "\n\n");
 	if (!msg)
 		die(_("unable to parse commit %s"), sha1_to_hex(commit->object.sha1));
+
+	if (state->msg)
+		free(state->msg);
 	state->msg = xstrdup(msg + 2);
 	state->msg_len = strlen(state->msg);
 }
Previous: Junio C HamanoNext: Junio C Hamano
Message 58 of 63 in “Make git-am a builtin”
  1. 00/44 Make git-am a builtinPaul Tan, Jul 7, 2015
  2. 01/44 wrapper: implement xopen()Paul Tan, Jul 7, 2015
  3. 02/44 wrapper: implement xfopen()Paul Tan, Jul 7, 2015
  4. 03/44 builtin-am: implement skeletal builtin amPaul Tan, Jul 7, 2015
  5. 04/44 builtin-am: implement patch queue mechanismPaul Tan, Jul 7, 2015
  6. 05/44 builtin-am: split out mbox/maildir patches with git-mailsplitPaul Tan, Jul 7, 2015
  7. 06/44 builtin-am: auto-detect mbox patchesPaul Tan, Jul 7, 2015
  8. 07/44 builtin-am: extract patch and commit info with git-mailinfoPaul Tan, Jul 7, 2015
  9. 08/44 builtin-am: apply patch with git-applyPaul Tan, Jul 7, 2015
  10. 09/44 builtin-am: implement committing applied patchPaul Tan, Jul 7, 2015
  11. 10/44 builtin-am: refuse to apply patches if index is dirtyPaul Tan, Jul 7, 2015
  12. 11/44 builtin-am: implement --resolved/--continuePaul Tan, Jul 7, 2015
  13. 12/44 builtin-am: implement --skipPaul Tan, Jul 7, 2015
  14. Stefan BellerJul 13, 2015
  15. Paul TanJul 14, 2015
  16. Stefan BellerJul 14, 2015
  17. Paul TanJul 18, 2015
  18. 13/44 builtin-am: implement --abortPaul Tan, Jul 7, 2015
  19. 14/44 builtin-am: reject patches when there's a session in progressPaul Tan, Jul 7, 2015
  20. 15/44 builtin-am: implement -q/--quietPaul Tan, Jul 7, 2015
  21. 16/44 builtin-am: exit with user friendly message on failurePaul Tan, Jul 7, 2015
  22. 17/44 builtin-am: implement -s/--signoffPaul Tan, Jul 7, 2015
  23. 18/44 cache-tree: introduce write_index_as_tree()Paul Tan, Jul 7, 2015
  24. Junio C HamanoJul 7, 2015
  25. 19/44 builtin-am: implement --3way, am.threeWayPaul Tan, Jul 7, 2015
  26. Junio C HamanoJul 7, 2015
  27. Paul TanJul 14, 2015
  28. 20/44 builtin-am: implement --rebasing modePaul Tan, Jul 7, 2015
  29. 21/44 builtin-am: bypass git-mailinfo when --rebasingPaul Tan, Jul 7, 2015
  30. 22/44 builtin-am: handle stray state directoryPaul Tan, Jul 7, 2015
  31. 23/44 builtin-am: implement -u/--utf8Paul Tan, Jul 7, 2015
  32. 24/44 builtin-am: implement -k/--keep, --keep-non-patchPaul Tan, Jul 7, 2015
  33. 25/44 builtin-am: implement --[no-]message-id, am.messageidPaul Tan, Jul 7, 2015
  34. 26/44 builtin-am: support --keep-cr, am.keepcrPaul Tan, Jul 7, 2015
  35. 27/44 builtin-am: implement --[no-]scissorsPaul Tan, Jul 7, 2015
  36. 28/44 builtin-am: pass git-apply's options to git-applyPaul Tan, Jul 7, 2015
  37. 29/44 builtin-am: implement --ignore-datePaul Tan, Jul 7, 2015
  38. 30/44 builtin-am: implement --committer-date-is-author-datePaul Tan, Jul 7, 2015
  39. 31/44 builtin-am: implement -S/--gpg-sign, commit.gpgsignPaul Tan, Jul 7, 2015
  40. 32/44 builtin-am: invoke post-rewrite hookPaul Tan, Jul 7, 2015
  41. 33/44 builtin-am: support automatic notes copyingPaul Tan, Jul 7, 2015
  42. 34/44 builtin-am: invoke applypatch-msg hookPaul Tan, Jul 7, 2015
  43. 35/44 builtin-am: invoke pre-applypatch hookPaul Tan, Jul 7, 2015
  44. 36/44 builtin-am: invoke post-applypatch hookPaul Tan, Jul 7, 2015
  45. 37/44 builtin-am: rerere supportPaul Tan, Jul 7, 2015
  46. 38/44 builtin-am: support and auto-detect StGit patchesPaul Tan, Jul 7, 2015
  47. 39/44 builtin-am: support and auto-detect StGit series filesPaul Tan, Jul 7, 2015
  48. 40/44 builtin-am: support and auto-detect mercurial patchesPaul Tan, Jul 7, 2015
  49. 41/44 builtin-am: implement -i/--interactivePaul Tan, Jul 7, 2015
  50. 42/44 builtin-am: implement legacy -b/--binary optionPaul Tan, Jul 7, 2015
  51. 43/44 builtin-am: check for valid committer identPaul Tan, Jul 7, 2015
  52. 44/44 builtin-am: remove redirection to git-am.shPaul Tan, Jul 7, 2015
  53. Junio C HamanoJul 7, 2015
  54. Paul TanJul 7, 2015
  55. Junio C HamanoJul 8, 2015
  56. Paul TanJul 8, 2015
  57. Junio C HamanoJul 8, 2015
  58. Paul TanJul 8, 2015
  59. Junio C HamanoJul 9, 2015
  60. Paul TanJul 12, 2015
  61. Junio C HamanoJul 12, 2015
  62. Junio C HamanoJul 13, 2015
  63. Paul TanJul 14, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.