During the discussion on the recent "git am" regression, I noticed that the command reimplemented in C spawns one "mailsplit" and then spawns "mailinfo" followed by "apply --index" to commit the changes described in each message. As there are platforms where spawning subprocess via run_command() interface is heavy-weight, something that is conceptually very simple like "mailinfo" is better called directly inside the process---something that is lightweight and frequently used is where the overhead of run_command() would be felt most. I think this round is ready for 'next'. Relative to the previous round, the changes are: * Editorial fixes on log messages. * The previous round leaked some fields in struct mailinfo upon completion (of course, inherited from the original that let the system clean them up upon process termination). clear_mailinfo() has been enhanced to clear them. * The step to remove the global "line" variable has been split into multiple steps. * The step to move metainfo_charset to the struct has been split into two. And here are the patches. mailinfo: remove a no-op call convert_to_utf8(it, "") mailinfo: fold decode_header_bq() into decode_header() mailinfo: fix an off-by-one error in the boundary stack mailinfo: explicitly close file handle to the patch output mailinfo: move handle_boundary() lower mailinfo: get rid of function-local static states Mostly unchanged other than editorial fixes on their log messages. mailinfo: do not let handle_body() touch global "line" directly mailinfo: do not let handle_boundary() touch global "line" directly mailinfo: do not let find_boundary() touch global "line" directly mailinfo: move global "line" into mailinfo() function After Stefan's review comments, I wanted to be really sure that this conversion was correct. Blindingly replacing the reference to the global with a pointer passed from the callern is not sufficient to ensure that the change is a no-op; the patches needed to show that the pointer passed from the caller is always the global "line". For that, the patch [v2 7/31] needed to be split further into 3 patches to convert three functions, each of which always is called with the pointer that points at the global "line", in separate steps. mailinfo: introduce "struct mailinfo" to hold globals The previous round was lazy and did not introduce clear_mailinfo() until later, leaking the two strbuf moved into the struct. The original was leaking the global anyway, so it is not a big deal, but this round adds corresponding clean-up as the patches move global variables to the struct, which should make it harder to miss forgotten clean-up. mailinfo: move keep_subject & keep_non_patch_bracket to struct mailinfo mailinfo: move global "FILE *fin, *fout" to struct mailinfo mailinfo: move filter/header stage to struct mailinfo mailinfo: move patch_lines to struct mailinfo mailinfo: move add_message_id and message_id to struct mailinfo mailinfo: move use_scissors and use_inbody_headers to struct mailinfo mailinfo: move metainfo_charset to struct mailinfo Mostly unchanged, except for the clean-up in clear_mailinfo(). mailinfo: move check for metainfo_charset to convert_to_utf8() Eric's review noticed that the previous round conflated this step in the previous step. Separated the change to its own commit. mailinfo: move transfer_encoding to struct mailinfo mailinfo: move charset to struct mailinfo mailinfo: move cmitmsg and patchfile to struct mailinfo mailinfo: move [ps]_hdr_data to struct mailinfo mailinfo: move content/content_top to struct mailinfo Mostly unchanged, except for the clean-up in clear_mailinfo(). mailinfo: handle_commit_msg() shouldn't be called after finding patchbreak mailinfo: keep the parsed log message in a strbuf These two were placed earlier in the series in the previous round, but are not about moving globals to struct. This round finishes moving the globals to struct mailinfo before doing these two steps. mailinfo: move read_one_header_line() closer to its callers mailinfo: move check_header() after the helpers it uses mailinfo: move cleanup_space() before its users mailinfo: move definition of MAX_HDR_PARSED closer to its use Mostly unchanged. These are pure shuffling of functions and variables to lose forward declarations and to allow easier reading by grouping related things together. mailinfo: libify Mostly pure code movement that is unchanged since v2. mailinfo: handle charset conversion errors in the caller mailinfo: remove calls to exit() and die() deep in the callchain am: make direct call to mailinfo Makefile | 1 + builtin/am.c | 42 +- builtin/mailinfo.c | 1137 ++------------------------------------ builtin/mailinfo.c => mailinfo.c | 799 +++++++++++++-------------- mailinfo.h | 41 ++ 5 files changed, 505 insertions(+), 1515 deletions(-) rewrite builtin/mailinfo.c (95%) copy builtin/mailinfo.c => mailinfo.c (67%) create mode 100644 mailinfo.h -- 2.6.2-383-g144b2e6 -- 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