{"thread":{"id":"43946","subject":"[PATCH v13 00/14] libify apply and use lib in am, part 3","startedAt":"2016-08-27T18:46:07Z","lastAt":"2016-09-04T20:18:02Z","messageCount":38,"participants":["Christian Couder","Junio C Hamano","Stefan Beller","Ramsay Jones"],"isPatch":true,"patchVersion":13,"patchTotal":14},"messages":[{"id":"300338","messageId":"20160827184547.4365-1-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":null,"subject":"[PATCH v13 00/14] libify apply and use lib in am, part 3","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:33Z","receivedAt":"2016-08-27T18:46:07Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Goal\n~~~~\n\nThis is a patch series about libifying `git apply` functionality, and\nusing this libified functionality in `git am`, so that no 'git apply'\nprocess is spawn anymore. This makes `git am` significantly faster, so\n`git rebase`, when it uses the am backend, is also significantly\nfaster.\n\nPrevious discussions and patches series\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis has initially been discussed in the following thread:\n\n  http://thread.gmane.org/gmane.comp.version-control.git/287236/\n\nThen the following patch series were sent:\n\nRFC: http://thread.gmane.org/gmane.comp.version-control.git/288489/\nv1: http://thread.gmane.org/gmane.comp.version-control.git/292324/\nv2: http://thread.gmane.org/gmane.comp.version-control.git/294248/\nv3: http://thread.gmane.org/gmane.comp.version-control.git/295429/\nv4: http://thread.gmane.org/gmane.comp.version-control.git/296350/\nv5: http://thread.gmane.org/gmane.comp.version-control.git/296490/\nv6: http://thread.gmane.org/gmane.comp.version-control.git/297024/\nv7: http://thread.gmane.org/gmane.comp.version-control.git/297193/\nv8: https://public-inbox.org/git/20160627182429.31550-1-chriscool%40tuxfamily.org/\nv9: https://public-inbox.org/git/20160730172509.22939-1-chriscool%40tuxfamily.org/\nv10: https://public-inbox.org/git/20160808210337.5038-1-chriscool%40tuxfamily.org/\nv11: https://public-inbox.org/git/20160811085229.19017-1-chriscool%40tuxfamily.org/\nv12: https://public-inbox.org/git/20160811184501.384-1-chriscool@tuxfamily.org/\n\nHighlevel view of the patches in the series\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis is \"part 3\" of the full patch series. I am resending only the\nlast 14 patches of the full series as \"part 3\", because I don't want\nto resend the first 27 patches of v10 nearly as is.\n\n(So \"part 2\" is made of patch 01/40 from v11 and patches from 02/40 to\n27/40 from v10. And \"part 1\" has been in \"master\" for some time now.)\n\n  - Patch 01/14 to 04/14 were v1, v2, v6, v7, v8, v9, v10, v11 and v12.\n\nThey haven't changed since v12.\n\nThey finish libifying the apply functionality that was in\nbuiltin/apply.c and move it into apply.{c,h}, but the libified\nfunctionality is not yet used in `git am`.\n\n  - Patch 05/14 was in v6, v7, v8, v9, v10 and v12 and hasn't changed.\n\nIt replaces some calls to error() with calls to error_errno().\n\n  - Patches 06/14 to 10/14 were in v2, v6, v7, v8, v9 and v10.\n\nThey haven't changed since v10.\n\nThey implement a way to make the libified apply code silent by\nchanging the bool `apply_verbosely` into a tristate enum called\n`apply_verbosity`, that can be one of `verbosity_verbose`,\n`verbosity_normal` or `verbosity_silent`.\n\nThis is because \"git am\", since it was a shell script, has been\nsilencing the apply functionality by redirecting file descriptors to\n/dev/null, but this is not acceptable in C.\n\n  - Patch 11/14 was in v9, v10 and v12, and hasn't changed.\n\nIt refactors `git apply` option parsing to make it possible for `git\nam` to easily pass some command line options to the libified applied\ncode.\n\n  - Patch 12/14 is new.\n\nIt is a refactoring to prepare for some new changes in patch 13/14.\n\n  - Patch 13/14 was in v12.\n\nIt replaces patch 33/40 in v10 (environment: add set_index_file())\nthat was a hack to make it possible for `git am` to use the libified\napply functionality on a different index file.\n\nFor this purpose in this patch we add a \"const char *index_file\" into\n\"struct apply_state\", and when \"index_file\" is set, we use\nhold_lock_file_for_update(), passing it \"state->index_file\", instead\nof using hold_locked_index(), as it is not possible to pass an index\nfilename in hold_locked_index().\n\nThis patch was changed in this version to also use\n\"read_cache_from(state->index_file)\" instead of \"read_cache()\" when\nstate->index_file is set.\n\n  - Patch 14/14 was in v1, v2, v6, v7, v8, v9, v10 and v12, and hasn't\n    changed since v12.\n\nThis patch makes `git am` use the libified functionality.\n\nGeneral comments\n~~~~~~~~~~~~~~~~\n\nNow this patch series is shorter than previously. Hopefully also the\nearly part of this series until 05/14 or 11/14 will be ready soon to\nbe moved to next and master, and I may only need to resend the last 3\npatches if anything.\n\nI will send a diff between this version and v12 as a reply to this\nemail.\n\nThe benefits are not just related to not creating new processes. When\n`git am` launched a `git apply` process, this new process had to read\nthe index from disk. Then after the `git apply`process had terminated,\n`git am` dropped its index and read the index from disk to get the\nindex that had been modified by the `git apply`process. This was\ninefficient and also prevented the split-index mechanism to provide\nmany performance benefits.\n\nBy the way, current work is ongoing to make it possible to use\nsplit-index more easily by adding a config variable, see:\n\nhttps://public-inbox.org/git/20160711172254.13439-1-chriscool%40tuxfamily.org/\n\nUsing an earlier version of this series as rebase material, Duy\nexplained split-index benefits along with this patch series like this:\n\n > Without the series, the picture is not so surprising. We run git-apply\n > 80+ times, each consists of this sequence\n >\n > read index\n > write index (cache tree updates only)\n > read index again\n > optionally initialize name hash (when new entries are added, I guess)\n > read packed-refs\n > write index\n >\n > With this series, we run a single git-apply which does\n >\n > read index (and sharedindex too if in split-index mode)\n > initialize name hash\n > write index 80+ times\n\n(See: http://thread.gmane.org/gmane.comp.version-control.git/292324/focus=292460)\n\nLinks\n~~~~~\n\nThis patch series is available here:\n\nhttps://github.com/chriscool/git/commits/libify-apply-use-in-am\n\nThe previous versions are available there:\n\nv1: https://github.com/chriscool/git/commits/libify-apply-use-in-am25 \nv2: https://github.com/chriscool/git/commits/libify-apply-use-in-am54\nv6: https://github.com/chriscool/git/commits/libify-apply-use-in-am65\nv7: https://github.com/chriscool/git/commits/libify-apply-use-in-am75\nv8: https://github.com/chriscool/git/commits/libify-apply-use-in-am97\nv9: https://github.com/chriscool/git/commits/libify-apply-use-in-am106\nv10: https://github.com/chriscool/git/commits/libify-apply-use-in-am114\nv11: https://github.com/chriscool/git/commits/libify-apply-use-in-am116\nv12: https://github.com/chriscool/git/commits/libify-apply-use-in-am118\n\nPerformance numbers\n~~~~~~~~~~~~~~~~~~~\n\nNumbers are only available for tests that have been performed on Linux\nusing a very early version of this series, though Johannes Sixt\nreported great improvements on Windows. It could be interesting to get\ndetailed numbers on other platforms like Windows and OSX.\n\n  - Around mid April Ævar did a huge many-hundred commit rebase on the\n    kernel with untracked cache.\n\ncommand: git rebase --onto 1993b17 52bef0c 29dde7c\n\nVanilla \"next\" without split index:                1m54.953s\nVanilla \"next\" with split index:                   1m22.476s\nThis series on top of \"next\" without split index:  1m12.034s\nThis series on top of \"next\" with split index:     0m15.678s\n\nÆvar used his Debian laptop with SSD.\n\n  - Around mid April I tested rebasing 13 commits in Booking.com's\n    monorepo on a Red Hat 6.5 server with split-index and\n    GIT_TRACE_PERFORMANCE=1.\n\nWith Git v2.8.0, the rebase took 6.375888383 s, with the git am\ncommand launched by the rebase command taking 3.705677431 s.\n\nWith this series on top of next, the rebase took 3.044529494 s, with\nthe git am command launched by the rebase command taking 0.583521168\ns.\n\nChristian Couder (14):\n  builtin/apply: rename option parsing functions\n  apply: rename and move opt constants to apply.h\n  Move libified code from builtin/apply.c to apply.{c,h}\n  apply: make some parsing functions static again\n  apply: use error_errno() where possible\n  apply: make it possible to silently apply\n  apply: don't print on stdout in verbosity_silent mode\n  usage: add set_warn_routine()\n  usage: add get_error_routine() and get_warn_routine()\n  apply: change error_routine when silent\n  apply: refactor `git apply` option parsing\n  apply: pass apply state to build_fake_ancestor()\n  apply: learn to use a different index file\n  builtin/am: use apply API in run_apply()\n\n apply.c           | 4871 ++++++++++++++++++++++++++++++++++++++++++++++++++++-\n apply.h           |   34 +-\n builtin/am.c      |   65 +-\n builtin/apply.c   | 4814 +---------------------------------------------------\n git-compat-util.h |    3 +\n usage.c           |   15 +\n 6 files changed, 4961 insertions(+), 4841 deletions(-)\n\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300339","messageId":"20160827184547.4365-5-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 04/14] apply: make some parsing functions static again","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:37Z","receivedAt":"2016-08-27T18:46:11Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Some parsing functions that were used in both \"apply.c\" and\n\"builtin/apply.c\" are now only used in the former, so they\ncan be made static to \"apply.c\".\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n apply.c | 6 +++---\n apply.h | 5 -----\n 2 files changed, 3 insertions(+), 8 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 7b96130..c0cb3f5 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -27,7 +27,7 @@ static void git_apply_config(void)\n \tgit_config(git_default_config, NULL);\n }\n \n-int parse_whitespace_option(struct apply_state *state, const char *option)\n+static int parse_whitespace_option(struct apply_state *state, const char *option)\n {\n \tif (!option) {\n \t\tstate->ws_error_action = warn_on_ws_error;\n@@ -57,8 +57,8 @@ int parse_whitespace_option(struct apply_state *state, const char *option)\n \treturn error(_(\"unrecognized whitespace option '%s'\"), option);\n }\n \n-int parse_ignorewhitespace_option(struct apply_state *state,\n-\t\t\t\t  const char *option)\n+static int parse_ignorewhitespace_option(struct apply_state *state,\n+\t\t\t\t\t\t const char *option)\n {\n \tif (!option || !strcmp(option, \"no\") ||\n \t    !strcmp(option, \"false\") || !strcmp(option, \"never\") ||\ndiff --git a/apply.h b/apply.h\nindex 5ec022c..df44b51 100644\n--- a/apply.h\n+++ b/apply.h\n@@ -97,11 +97,6 @@ struct apply_state {\n \tint applied_after_fixing_ws;\n };\n \n-extern int parse_whitespace_option(struct apply_state *state,\n-\t\t\t\t   const char *option);\n-extern int parse_ignorewhitespace_option(struct apply_state *state,\n-\t\t\t\t\t const char *option);\n-\n extern int apply_option_parse_exclude(const struct option *opt,\n \t\t\t\t      const char *arg, int unset);\n extern int apply_option_parse_include(const struct option *opt,\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300340","messageId":"20160827184547.4365-3-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 02/14] apply: rename and move opt constants to apply.h","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:35Z","receivedAt":"2016-08-27T18:46:12Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"The constants for the \"inaccurate-eof\" and the \"recount\" options will\nbe used in both \"apply.c\" and \"builtin/apply.c\", so they need to go\ninto \"apply.h\", and therefore they need a name that is more specific\nto the API they belong to.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n apply.h         |  3 +++\n builtin/apply.c | 11 ++++-------\n 2 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/apply.h b/apply.h\nindex 53f09b5..ca1dcee 100644\n--- a/apply.h\n+++ b/apply.h\n@@ -108,4 +108,7 @@ extern int init_apply_state(struct apply_state *state,\n extern void clear_apply_state(struct apply_state *state);\n extern int check_apply_state(struct apply_state *state, int force_apply);\n \n+#define APPLY_OPT_INACCURATE_EOF\t(1<<0)\n+#define APPLY_OPT_RECOUNT\t\t(1<<1)\n+\n #endif\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 429fe44..9c396bb 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -4463,9 +4463,6 @@ static int write_out_results(struct apply_state *state, struct patch *list)\n \n static struct lock_file lock_file;\n \n-#define INACCURATE_EOF\t(1<<0)\n-#define RECOUNT\t\t(1<<1)\n-\n /*\n  * Try to apply a patch.\n  *\n@@ -4495,8 +4492,8 @@ static int apply_patch(struct apply_state *state,\n \t\tint nr;\n \n \t\tpatch = xcalloc(1, sizeof(*patch));\n-\t\tpatch->inaccurate_eof = !!(options & INACCURATE_EOF);\n-\t\tpatch->recount =  !!(options & RECOUNT);\n+\t\tpatch->inaccurate_eof = !!(options & APPLY_OPT_INACCURATE_EOF);\n+\t\tpatch->recount =  !!(options & APPLY_OPT_RECOUNT);\n \t\tnr = parse_chunk(state, buf.buf + offset, buf.len - offset, patch);\n \t\tif (nr < 0) {\n \t\t\tfree_patch(patch);\n@@ -4811,10 +4808,10 @@ int cmd_apply(int argc, const char **argv, const char *prefix)\n \t\tOPT__VERBOSE(&state.apply_verbosely, N_(\"be verbose\")),\n \t\tOPT_BIT(0, \"inaccurate-eof\", &options,\n \t\t\tN_(\"tolerate incorrectly detected missing new-line at the end of file\"),\n-\t\t\tINACCURATE_EOF),\n+\t\t\tAPPLY_OPT_INACCURATE_EOF),\n \t\tOPT_BIT(0, \"recount\", &options,\n \t\t\tN_(\"do not trust the line counts in the hunk headers\"),\n-\t\t\tRECOUNT),\n+\t\t\tAPPLY_OPT_RECOUNT),\n \t\t{ OPTION_CALLBACK, 0, \"directory\", &state, N_(\"root\"),\n \t\t\tN_(\"prepend <root> to all filenames\"),\n \t\t\t0, apply_option_parse_directory },\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300341","messageId":"20160827184547.4365-2-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 01/14] builtin/apply: rename option parsing functions","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:34Z","receivedAt":"2016-08-27T18:46:15Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"As these functions are going to be part of the libified\napply API, let's give them a name that is more specific\nto the apply API.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin/apply.c | 40 ++++++++++++++++++++--------------------\n 1 file changed, 20 insertions(+), 20 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex ad403f8..429fe44 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -4588,16 +4588,16 @@ static int apply_patch(struct apply_state *state,\n \treturn res;\n }\n \n-static int option_parse_exclude(const struct option *opt,\n-\t\t\t\tconst char *arg, int unset)\n+static int apply_option_parse_exclude(const struct option *opt,\n+\t\t\t\t      const char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tadd_name_limit(state, arg, 1);\n \treturn 0;\n }\n \n-static int option_parse_include(const struct option *opt,\n-\t\t\t\tconst char *arg, int unset)\n+static int apply_option_parse_include(const struct option *opt,\n+\t\t\t\t      const char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tadd_name_limit(state, arg, 0);\n@@ -4605,9 +4605,9 @@ static int option_parse_include(const struct option *opt,\n \treturn 0;\n }\n \n-static int option_parse_p(const struct option *opt,\n-\t\t\t  const char *arg,\n-\t\t\t  int unset)\n+static int apply_option_parse_p(const struct option *opt,\n+\t\t\t\tconst char *arg,\n+\t\t\t\tint unset)\n {\n \tstruct apply_state *state = opt->value;\n \tstate->p_value = atoi(arg);\n@@ -4615,8 +4615,8 @@ static int option_parse_p(const struct option *opt,\n \treturn 0;\n }\n \n-static int option_parse_space_change(const struct option *opt,\n-\t\t\t\t     const char *arg, int unset)\n+static int apply_option_parse_space_change(const struct option *opt,\n+\t\t\t\t\t   const char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tif (unset)\n@@ -4626,8 +4626,8 @@ static int option_parse_space_change(const struct option *opt,\n \treturn 0;\n }\n \n-static int option_parse_whitespace(const struct option *opt,\n-\t\t\t\t   const char *arg, int unset)\n+static int apply_option_parse_whitespace(const struct option *opt,\n+\t\t\t\t\t const char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tstate->whitespace_option = arg;\n@@ -4636,8 +4636,8 @@ static int option_parse_whitespace(const struct option *opt,\n \treturn 0;\n }\n \n-static int option_parse_directory(const struct option *opt,\n-\t\t\t\t  const char *arg, int unset)\n+static int apply_option_parse_directory(const struct option *opt,\n+\t\t\t\t\tconst char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tstrbuf_reset(&state->root);\n@@ -4755,13 +4755,13 @@ int cmd_apply(int argc, const char **argv, const char *prefix)\n \tstruct option builtin_apply_options[] = {\n \t\t{ OPTION_CALLBACK, 0, \"exclude\", &state, N_(\"path\"),\n \t\t\tN_(\"don't apply changes matching the given path\"),\n-\t\t\t0, option_parse_exclude },\n+\t\t\t0, apply_option_parse_exclude },\n \t\t{ OPTION_CALLBACK, 0, \"include\", &state, N_(\"path\"),\n \t\t\tN_(\"apply changes matching the given path\"),\n-\t\t\t0, option_parse_include },\n+\t\t\t0, apply_option_parse_include },\n \t\t{ OPTION_CALLBACK, 'p', NULL, &state, N_(\"num\"),\n \t\t\tN_(\"remove <num> leading slashes from traditional diff paths\"),\n-\t\t\t0, option_parse_p },\n+\t\t\t0, apply_option_parse_p },\n \t\tOPT_BOOL(0, \"no-add\", &state.no_add,\n \t\t\tN_(\"ignore additions made by the patch\")),\n \t\tOPT_BOOL(0, \"stat\", &state.diffstat,\n@@ -4793,13 +4793,13 @@ int cmd_apply(int argc, const char **argv, const char *prefix)\n \t\t\t\tN_(\"ensure at least <n> lines of context match\")),\n \t\t{ OPTION_CALLBACK, 0, \"whitespace\", &state, N_(\"action\"),\n \t\t\tN_(\"detect new or modified lines that have whitespace errors\"),\n-\t\t\t0, option_parse_whitespace },\n+\t\t\t0, apply_option_parse_whitespace },\n \t\t{ OPTION_CALLBACK, 0, \"ignore-space-change\", &state, NULL,\n \t\t\tN_(\"ignore changes in whitespace when finding context\"),\n-\t\t\tPARSE_OPT_NOARG, option_parse_space_change },\n+\t\t\tPARSE_OPT_NOARG, apply_option_parse_space_change },\n \t\t{ OPTION_CALLBACK, 0, \"ignore-whitespace\", &state, NULL,\n \t\t\tN_(\"ignore changes in whitespace when finding context\"),\n-\t\t\tPARSE_OPT_NOARG, option_parse_space_change },\n+\t\t\tPARSE_OPT_NOARG, apply_option_parse_space_change },\n \t\tOPT_BOOL('R', \"reverse\", &state.apply_in_reverse,\n \t\t\tN_(\"apply the patch in reverse\")),\n \t\tOPT_BOOL(0, \"unidiff-zero\", &state.unidiff_zero,\n@@ -4817,7 +4817,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)\n \t\t\tRECOUNT),\n \t\t{ OPTION_CALLBACK, 0, \"directory\", &state, N_(\"root\"),\n \t\t\tN_(\"prepend <root> to all filenames\"),\n-\t\t\t0, option_parse_directory },\n+\t\t\t0, apply_option_parse_directory },\n \t\tOPT_END()\n \t};\n \n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300342","messageId":"20160827184547.4365-6-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 05/14] apply: use error_errno() where possible","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:38Z","receivedAt":"2016-08-27T18:46:19Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"To avoid possible mistakes and to uniformly show the errno\nrelated messages, let's use error_errno() where possible.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n apply.c | 18 +++++++++---------\n 1 file changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex c0cb3f5..41a33d3 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -3497,7 +3497,7 @@ static int load_current(struct apply_state *state,\n \tce = active_cache[pos];\n \tif (lstat(name, &st)) {\n \t\tif (errno != ENOENT)\n-\t\t\treturn error(_(\"%s: %s\"), name, strerror(errno));\n+\t\t\treturn error_errno(\"%s\", name);\n \t\tif (checkout_target(&the_index, ce, &st))\n \t\t\treturn -1;\n \t}\n@@ -3647,7 +3647,7 @@ static int check_preimage(struct apply_state *state,\n \t} else if (!state->cached) {\n \t\tstat_ret = lstat(old_name, st);\n \t\tif (stat_ret && errno != ENOENT)\n-\t\t\treturn error(_(\"%s: %s\"), old_name, strerror(errno));\n+\t\t\treturn error_errno(\"%s\", old_name);\n \t}\n \n \tif (state->check_index && !previous) {\n@@ -3669,7 +3669,7 @@ static int check_preimage(struct apply_state *state,\n \t} else if (stat_ret < 0) {\n \t\tif (patch->is_new < 0)\n \t\t\tgoto is_new;\n-\t\treturn error(_(\"%s: %s\"), old_name, strerror(errno));\n+\t\treturn error_errno(\"%s\", old_name);\n \t}\n \n \tif (!state->cached && !previous)\n@@ -3728,7 +3728,7 @@ static int check_to_create(struct apply_state *state,\n \n \t\treturn EXISTS_IN_WORKTREE;\n \t} else if ((errno != ENOENT) && (errno != ENOTDIR)) {\n-\t\treturn error(\"%s: %s\", new_name, strerror(errno));\n+\t\treturn error_errno(\"%s\", new_name);\n \t}\n \treturn 0;\n }\n@@ -4247,9 +4247,9 @@ static int add_index_file(struct apply_state *state,\n \t\tif (!state->cached) {\n \t\t\tif (lstat(path, &st) < 0) {\n \t\t\t\tfree(ce);\n-\t\t\t\treturn error(_(\"unable to stat newly \"\n-\t\t\t\t\t       \"created file '%s': %s\"),\n-\t\t\t\t\t     path, strerror(errno));\n+\t\t\t\treturn error_errno(_(\"unable to stat newly \"\n+\t\t\t\t\t\t     \"created file '%s'\"),\n+\t\t\t\t\t\t   path);\n \t\t\t}\n \t\t\tfill_stat_cache_info(ce, &st);\n \t\t}\n@@ -4306,7 +4306,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,\n \tstrbuf_release(&nbuf);\n \n \tif (close(fd) < 0 && !res)\n-\t\treturn error(_(\"closing file '%s': %s\"), path, strerror(errno));\n+\t\treturn error_errno(_(\"closing file '%s'\"), path);\n \n \treturn res ? -1 : 0;\n }\n@@ -4503,7 +4503,7 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)\n \n \trej = fopen(namebuf, \"w\");\n \tif (!rej)\n-\t\treturn error(_(\"cannot open %s: %s\"), namebuf, strerror(errno));\n+\t\treturn error_errno(_(\"cannot open %s\"), namebuf);\n \n \t/* Normal git tools never deal with .rej, so do not pretend\n \t * this is a git patch by saying --git or giving extended\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300343","messageId":"20160827184547.4365-8-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 07/14] apply: don't print on stdout in verbosity_silent mode","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:40Z","receivedAt":"2016-08-27T18:46:22Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"When apply_verbosity is set to verbosity_silent nothing should be\nprinted on both stderr and stdout.\n\nTo avoid printing on stdout, we can just skip calling the following\nfunctions:\n\n\t- stat_patch_list(),\n\t- numstat_patch_list(),\n\t- summary_patch_list().\n\nIt is safe to do that because the above functions have no side\neffects other than printing:\n\n- stat_patch_list() only computes some local values and then call\nshow_stats() and print_stat_summary(), those two functions only\ncompute local values and call printing functions,\n- numstat_patch_list() also only computes local values and calls\nprinting functions,\n- summary_patch_list() calls show_file_mode_name(), printf(),\nshow_rename_copy(), show_mode_change() that are only printing.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n apply.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex df85cbc..ddbb0a2 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4702,13 +4702,13 @@ static int apply_patch(struct apply_state *state,\n \t\tgoto end;\n \t}\n \n-\tif (state->diffstat)\n+\tif (state->diffstat && state->apply_verbosity > verbosity_silent)\n \t\tstat_patch_list(state, list);\n \n-\tif (state->numstat)\n+\tif (state->numstat && state->apply_verbosity > verbosity_silent)\n \t\tnumstat_patch_list(state, list);\n \n-\tif (state->summary)\n+\tif (state->summary && state->apply_verbosity > verbosity_silent)\n \t\tsummary_patch_list(list);\n \n end:\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300344","messageId":"20160827184547.4365-7-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 06/14] apply: make it possible to silently apply","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:39Z","receivedAt":"2016-08-27T18:46:26Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This changes 'int apply_verbosely' into 'enum apply_verbosity', and\nchanges the possible values of the variable from a bool to\na tristate.\n\nThe previous 'false' state is changed into 'verbosity_normal'.\nThe previous 'true' state is changed into 'verbosity_verbose'.\n\nThe new added state is 'verbosity_silent'. It should prevent\nanything to be printed on both stderr and stdout.\n\nThis is needed because `git am` wants to first call apply\nfunctionality silently, if it can then fall back on 3-way merge\nin case of error.\n\nPrinting on stdout, and calls to warning() or error() are not\ntaken care of in this patch, as that will be done in following\npatches.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n apply.c         | 62 +++++++++++++++++++++++++++++++++++++--------------------\n apply.h         |  8 +++++++-\n builtin/apply.c |  2 +-\n 3 files changed, 48 insertions(+), 24 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 41a33d3..df85cbc 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -125,8 +125,11 @@ int check_apply_state(struct apply_state *state, int force_apply)\n \t\t\treturn error(_(\"--3way outside a repository\"));\n \t\tstate->check_index = 1;\n \t}\n-\tif (state->apply_with_reject)\n-\t\tstate->apply = state->apply_verbosely = 1;\n+\tif (state->apply_with_reject) {\n+\t\tstate->apply = 1;\n+\t\tif (state->apply_verbosity == verbosity_normal)\n+\t\t\tstate->apply_verbosity = verbosity_verbose;\n+\t}\n \tif (!force_apply && (state->diffstat || state->numstat || state->summary || state->check || state->fake_ancestor))\n \t\tstate->apply = 0;\n \tif (state->check_index && is_not_gitdir)\n@@ -1620,8 +1623,9 @@ static void record_ws_error(struct apply_state *state,\n \t\treturn;\n \n \terr = whitespace_error_string(result);\n-\tfprintf(stderr, \"%s:%d: %s.\\n%.*s\\n\",\n-\t\tstate->patch_input_file, linenr, err, len, line);\n+\tif (state->apply_verbosity > verbosity_silent)\n+\t\tfprintf(stderr, \"%s:%d: %s.\\n%.*s\\n\",\n+\t\t\tstate->patch_input_file, linenr, err, len, line);\n \tfree(err);\n }\n \n@@ -1816,7 +1820,7 @@ static int parse_single_patch(struct apply_state *state,\n \t\treturn error(_(\"new file %s depends on old contents\"), patch->new_name);\n \tif (0 < patch->is_delete && newlines)\n \t\treturn error(_(\"deleted file %s still has contents\"), patch->old_name);\n-\tif (!patch->is_delete && !newlines && context)\n+\tif (!patch->is_delete && !newlines && context && state->apply_verbosity > verbosity_silent)\n \t\tfprintf_ln(stderr,\n \t\t\t   _(\"** warning: \"\n \t\t\t     \"file %s becomes empty but is not deleted\"),\n@@ -2911,7 +2915,7 @@ static int apply_one_fragment(struct apply_state *state,\n \t\t\t/* Ignore it, we already handled it */\n \t\t\tbreak;\n \t\tdefault:\n-\t\t\tif (state->apply_verbosely)\n+\t\t\tif (state->apply_verbosity > verbosity_normal)\n \t\t\t\terror(_(\"invalid start of line: '%c'\"), first);\n \t\t\tapplied_pos = -1;\n \t\t\tgoto out;\n@@ -3026,7 +3030,7 @@ static int apply_one_fragment(struct apply_state *state,\n \t\t\t\tstate->apply = 0;\n \t\t}\n \n-\t\tif (state->apply_verbosely && applied_pos != pos) {\n+\t\tif (state->apply_verbosity > verbosity_normal && applied_pos != pos) {\n \t\t\tint offset = applied_pos - pos;\n \t\t\tif (state->apply_in_reverse)\n \t\t\t\toffset = 0 - offset;\n@@ -3041,14 +3045,14 @@ static int apply_one_fragment(struct apply_state *state,\n \t\t * Warn if it was necessary to reduce the number\n \t\t * of context lines.\n \t\t */\n-\t\tif ((leading != frag->leading) ||\n-\t\t    (trailing != frag->trailing))\n+\t\tif ((leading != frag->leading ||\n+\t\t     trailing != frag->trailing) && state->apply_verbosity > verbosity_silent)\n \t\t\tfprintf_ln(stderr, _(\"Context reduced to (%ld/%ld)\"\n \t\t\t\t\t     \" to apply fragment at %d\"),\n \t\t\t\t   leading, trailing, applied_pos+1);\n \t\tupdate_image(state, img, applied_pos, &preimage, &postimage);\n \t} else {\n-\t\tif (state->apply_verbosely)\n+\t\tif (state->apply_verbosity > verbosity_normal)\n \t\t\terror(_(\"while searching for:\\n%.*s\"),\n \t\t\t      (int)(old - oldlines), oldlines);\n \t}\n@@ -3539,7 +3543,8 @@ static int try_threeway(struct apply_state *state,\n \t\t read_blob_object(&buf, pre_sha1, patch->old_mode))\n \t\treturn error(\"repository lacks the necessary blob to fall back on 3-way merge.\");\n \n-\tfprintf(stderr, \"Falling back to three-way merge...\\n\");\n+\tif (state->apply_verbosity > verbosity_silent)\n+\t\tfprintf(stderr, \"Falling back to three-way merge...\\n\");\n \n \timg = strbuf_detach(&buf, &len);\n \tprepare_image(&tmp_image, img, len, 1);\n@@ -3569,7 +3574,9 @@ static int try_threeway(struct apply_state *state,\n \tstatus = three_way_merge(image, patch->new_name,\n \t\t\t\t pre_sha1, our_sha1, post_sha1);\n \tif (status < 0) {\n-\t\tfprintf(stderr, \"Failed to fall back on three-way merge...\\n\");\n+\t\tif (state->apply_verbosity > verbosity_silent)\n+\t\t\tfprintf(stderr,\n+\t\t\t\t\"Failed to fall back on three-way merge...\\n\");\n \t\treturn status;\n \t}\n \n@@ -3581,9 +3588,15 @@ static int try_threeway(struct apply_state *state,\n \t\t\thashcpy(patch->threeway_stage[0].hash, pre_sha1);\n \t\thashcpy(patch->threeway_stage[1].hash, our_sha1);\n \t\thashcpy(patch->threeway_stage[2].hash, post_sha1);\n-\t\tfprintf(stderr, \"Applied patch to '%s' with conflicts.\\n\", patch->new_name);\n+\t\tif (state->apply_verbosity > verbosity_silent)\n+\t\t\tfprintf(stderr,\n+\t\t\t\t\"Applied patch to '%s' with conflicts.\\n\",\n+\t\t\t\tpatch->new_name);\n \t} else {\n-\t\tfprintf(stderr, \"Applied patch to '%s' cleanly.\\n\", patch->new_name);\n+\t\tif (state->apply_verbosity > verbosity_silent)\n+\t\t\tfprintf(stderr,\n+\t\t\t\t\"Applied patch to '%s' cleanly.\\n\",\n+\t\t\t\tpatch->new_name);\n \t}\n \treturn 0;\n }\n@@ -3956,7 +3969,7 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)\n \tprepare_fn_table(state, patch);\n \twhile (patch) {\n \t\tint res;\n-\t\tif (state->apply_verbosely)\n+\t\tif (state->apply_verbosity > verbosity_normal)\n \t\t\tsay_patch_name(stderr,\n \t\t\t\t       _(\"Checking patch %s...\"), patch);\n \t\tres = check_patch(state, patch);\n@@ -4472,7 +4485,7 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)\n \t}\n \n \tif (!cnt) {\n-\t\tif (state->apply_verbosely)\n+\t\tif (state->apply_verbosity > verbosity_normal)\n \t\t\tsay_patch_name(stderr,\n \t\t\t\t       _(\"Applied patch %s cleanly.\"), patch);\n \t\treturn 0;\n@@ -4489,7 +4502,8 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)\n \t\t\t    \"Applying patch %%s with %d rejects...\",\n \t\t\t    cnt),\n \t\t    cnt);\n-\tsay_patch_name(stderr, sb.buf, patch);\n+\tif (state->apply_verbosity > verbosity_silent)\n+\t\tsay_patch_name(stderr, sb.buf, patch);\n \tstrbuf_release(&sb);\n \n \tcnt = strlen(patch->new_name);\n@@ -4516,10 +4530,12 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)\n \t     frag;\n \t     cnt++, frag = frag->next) {\n \t\tif (!frag->rejected) {\n-\t\t\tfprintf_ln(stderr, _(\"Hunk #%d applied cleanly.\"), cnt);\n+\t\t\tif (state->apply_verbosity > verbosity_silent)\n+\t\t\t\tfprintf_ln(stderr, _(\"Hunk #%d applied cleanly.\"), cnt);\n \t\t\tcontinue;\n \t\t}\n-\t\tfprintf_ln(stderr, _(\"Rejected hunk #%d.\"), cnt);\n+\t\tif (state->apply_verbosity > verbosity_silent)\n+\t\t\tfprintf_ln(stderr, _(\"Rejected hunk #%d.\"), cnt);\n \t\tfprintf(rej, \"%.*s\", frag->size, frag->patch);\n \t\tif (frag->patch[frag->size-1] != '\\n')\n \t\t\tfputc('\\n', rej);\n@@ -4568,8 +4584,10 @@ static int write_out_results(struct apply_state *state, struct patch *list)\n \t\tstruct string_list_item *item;\n \n \t\tstring_list_sort(&cpath);\n-\t\tfor_each_string_list_item(item, &cpath)\n-\t\t\tfprintf(stderr, \"U %s\\n\", item->string);\n+\t\tif (state->apply_verbosity > verbosity_silent) {\n+\t\t\tfor_each_string_list_item(item, &cpath)\n+\t\t\t\tfprintf(stderr, \"U %s\\n\", item->string);\n+\t\t}\n \t\tstring_list_clear(&cpath, 0);\n \n \t\trerere(0);\n@@ -4626,7 +4644,7 @@ static int apply_patch(struct apply_state *state,\n \t\t\tlistp = &patch->next;\n \t\t}\n \t\telse {\n-\t\t\tif (state->apply_verbosely)\n+\t\t\tif (state->apply_verbosity > verbosity_normal)\n \t\t\t\tsay_patch_name(stderr, _(\"Skipped patch '%s'.\"), patch);\n \t\t\tfree_patch(patch);\n \t\t\tskipped_patch++;\ndiff --git a/apply.h b/apply.h\nindex df44b51..bd4eb6d 100644\n--- a/apply.h\n+++ b/apply.h\n@@ -13,6 +13,12 @@ enum apply_ws_ignore {\n \tignore_ws_change\n };\n \n+enum apply_verbosity {\n+\tverbosity_silent = -1,\n+\tverbosity_normal = 0,\n+\tverbosity_verbose = 1\n+};\n+\n /*\n  * We need to keep track of how symlinks in the preimage are\n  * manipulated by the patches.  A patch to add a/b/c where a/b\n@@ -51,13 +57,13 @@ struct apply_state {\n \tint allow_overlap;\n \tint apply_in_reverse;\n \tint apply_with_reject;\n-\tint apply_verbosely;\n \tint no_add;\n \tint threeway;\n \tint unidiff_zero;\n \tint unsafe_paths;\n \n \t/* Other non boolean parameters */\n+\tenum apply_verbosity apply_verbosity;\n \tconst char *fake_ancestor;\n \tconst char *patch_input_file;\n \tint line_termination;\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 9c66474..7338701 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -74,7 +74,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)\n \t\t\tN_(\"leave the rejected hunks in corresponding *.rej files\")),\n \t\tOPT_BOOL(0, \"allow-overlap\", &state.allow_overlap,\n \t\t\tN_(\"allow overlapping hunks\")),\n-\t\tOPT__VERBOSE(&state.apply_verbosely, N_(\"be verbose\")),\n+\t\tOPT__VERBOSE(&state.apply_verbosity, N_(\"be verbose\")),\n \t\tOPT_BIT(0, \"inaccurate-eof\", &options,\n \t\t\tN_(\"tolerate incorrectly detected missing new-line at the end of file\"),\n \t\t\tAPPLY_OPT_INACCURATE_EOF),\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300345","messageId":"20160827184547.4365-9-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 08/14] usage: add set_warn_routine()","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:41Z","receivedAt":"2016-08-27T18:46:28Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"There are already set_die_routine() and set_error_routine(),\nso let's add set_warn_routine() as this will be needed in a\nfollowing commit.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n git-compat-util.h | 1 +\n usage.c           | 5 +++++\n 2 files changed, 6 insertions(+)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 590bfdd..c7a51f8 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -440,6 +440,7 @@ static inline int const_error(void)\n \n extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));\n extern void set_error_routine(void (*routine)(const char *err, va_list params));\n+extern void set_warn_routine(void (*routine)(const char *warn, va_list params));\n extern void set_die_is_recursing_routine(int (*routine)(void));\n extern void set_error_handle(FILE *);\n \ndiff --git a/usage.c b/usage.c\nindex 1dad03f..67e5526 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -70,6 +70,11 @@ void set_error_routine(void (*routine)(const char *err, va_list params))\n \terror_routine = routine;\n }\n \n+void set_warn_routine(void (*routine)(const char *warn, va_list params))\n+{\n+\twarn_routine = routine;\n+}\n+\n void set_die_is_recursing_routine(int (*routine)(void))\n {\n \tdie_is_recursing = routine;\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300346","messageId":"20160827184547.4365-15-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 14/14] builtin/am: use apply API in run_apply()","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:47Z","receivedAt":"2016-08-27T18:46:31Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This replaces run_apply() implementation with a new one that\nuses the apply API that has been previously prepared in\napply.c and apply.h.\n\nThis shoud improve performance a lot in certain cases.\n\nAs the previous implementation was creating a new `git apply`\nprocess to apply each patch, it could be slow on systems like\nWindows where it is costly to create new processes.\n\nAlso the new `git apply` process had to read the index from\ndisk, and when the process was done the calling process\ndiscarded its own index and read back from disk the new\nindex that had been created by the `git apply` process.\n\nThis could be very inefficient with big repositories that\nhave big index files, especially when the system decided\nthat it was a good idea to run the `git apply` processes on\na different processor core.\n\nAlso eliminating index reads enables further performance\nimprovements by using:\n\n`git update-index --split-index`\n\nFor example here is a benchmark of a multi hundred commit\nrebase on the Linux kernel on a Debian laptop with SSD:\n\ncommand: git rebase --onto 1993b17 52bef0c 29dde7c\n\nVanilla \"next\" without split index:                1m54.953s\nVanilla \"next\" with split index:                   1m22.476s\nThis series on top of \"next\" without split index:  1m12.034s\nThis series on top of \"next\" with split index:     0m15.678s\n\n(using branch \"next\" from mid April 2016.)\n\nBenchmarked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin/am.c | 65 ++++++++++++++++++++++++++++++++++++++++--------------------\n 1 file changed, 43 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 739b34d..0e5d384 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -28,6 +28,7 @@\n #include \"rerere.h\"\n #include \"prompt.h\"\n #include \"mailinfo.h\"\n+#include \"apply.h\"\n \n /**\n  * Returns 1 if the file is empty or does not exist, 0 otherwise.\n@@ -1522,39 +1523,59 @@ static int parse_mail_rebase(struct am_state *state, const char *mail)\n  */\n static int run_apply(const struct am_state *state, const char *index_file)\n {\n-\tstruct child_process cp = CHILD_PROCESS_INIT;\n-\n-\tcp.git_cmd = 1;\n-\n-\tif (index_file)\n-\t\targv_array_pushf(&cp.env_array, \"GIT_INDEX_FILE=%s\", index_file);\n+\tstruct argv_array apply_paths = ARGV_ARRAY_INIT;\n+\tstruct argv_array apply_opts = ARGV_ARRAY_INIT;\n+\tstruct apply_state apply_state;\n+\tint res, opts_left;\n+\tstatic struct lock_file lock_file;\n+\tint force_apply = 0;\n+\tint options = 0;\n+\n+\tif (init_apply_state(&apply_state, NULL, &lock_file))\n+\t\tdie(\"BUG: init_apply_state() failed\");\n+\n+\targv_array_push(&apply_opts, \"apply\");\n+\targv_array_pushv(&apply_opts, state->git_apply_opts.argv);\n+\n+\topts_left = apply_parse_options(apply_opts.argc, apply_opts.argv,\n+\t\t\t\t\t&apply_state, &force_apply, &options,\n+\t\t\t\t\tNULL);\n+\n+\tif (opts_left != 0)\n+\t\tdie(\"unknown option passed thru to git apply\");\n+\n+\tif (index_file) {\n+\t\tapply_state.index_file = index_file;\n+\t\tapply_state.cached = 1;\n+\t} else\n+\t\tapply_state.check_index = 1;\n \n \t/*\n \t * If we are allowed to fall back on 3-way merge, don't give false\n \t * errors during the initial attempt.\n \t */\n-\tif (state->threeway && !index_file) {\n-\t\tcp.no_stdout = 1;\n-\t\tcp.no_stderr = 1;\n-\t}\n+\tif (state->threeway && !index_file)\n+\t\tapply_state.apply_verbosity = verbosity_silent;\n \n-\targv_array_push(&cp.args, \"apply\");\n+\tif (check_apply_state(&apply_state, force_apply))\n+\t\tdie(\"BUG: check_apply_state() failed\");\n \n-\targv_array_pushv(&cp.args, state->git_apply_opts.argv);\n+\targv_array_push(&apply_paths, am_path(state, \"patch\"));\n \n-\tif (index_file)\n-\t\targv_array_push(&cp.args, \"--cached\");\n-\telse\n-\t\targv_array_push(&cp.args, \"--index\");\n+\tres = apply_all_patches(&apply_state, apply_paths.argc, apply_paths.argv, options);\n \n-\targv_array_push(&cp.args, am_path(state, \"patch\"));\n+\targv_array_clear(&apply_paths);\n+\targv_array_clear(&apply_opts);\n+\tclear_apply_state(&apply_state);\n \n-\tif (run_command(&cp))\n-\t\treturn -1;\n+\tif (res)\n+\t\treturn res;\n \n-\t/* Reload index as git-apply will have modified it. */\n-\tdiscard_cache();\n-\tread_cache_from(index_file ? index_file : get_index_file());\n+\tif (index_file) {\n+\t\t/* Reload index as apply_all_patches() will have modified it. */\n+\t\tdiscard_cache();\n+\t\tread_cache_from(index_file);\n+\t}\n \n \treturn 0;\n }\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300347","messageId":"20160827184547.4365-14-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 13/14] apply: learn to use a different index file","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:46Z","receivedAt":"2016-08-27T18:46:34Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Sometimes we want to apply in a different index file.\n\nBefore the apply functionality was libified it was possible to\nuse the GIT_INDEX_FILE environment variable, for this purpose.\n\nBut now, as the apply functionality has been libified, it should\nbe possible to do that in a libified way.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n apply.c | 27 +++++++++++++++++++++------\n apply.h |  1 +\n 2 files changed, 22 insertions(+), 6 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 276e4af..5cd037d 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -3993,12 +3993,21 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)\n \treturn err;\n }\n \n+static int read_apply_cache(struct apply_state *state)\n+{\n+\tif (state->index_file)\n+\t\treturn read_cache_from(state->index_file);\n+\telse\n+\t\treturn read_cache();\n+}\n+\n /* This function tries to read the sha1 from the current index */\n-static int get_current_sha1(const char *path, unsigned char *sha1)\n+static int get_current_sha1(struct apply_state *state, const char *path,\n+\t\t\t    unsigned char *sha1)\n {\n \tint pos;\n \n-\tif (read_cache() < 0)\n+\tif (read_apply_cache(state) < 0)\n \t\treturn -1;\n \tpos = cache_name_pos(path, strlen(path));\n \tif (pos < 0)\n@@ -4071,7 +4080,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)\n \t\t\t; /* ok */\n \t\t} else if (!patch->lines_added && !patch->lines_deleted) {\n \t\t\t/* mode-only change: update the current */\n-\t\t\tif (get_current_sha1(patch->old_name, sha1))\n+\t\t\tif (get_current_sha1(state, patch->old_name, sha1))\n \t\t\t\treturn error(\"mode change for %s, which is not \"\n \t\t\t\t\t     \"in current HEAD\", name);\n \t\t} else\n@@ -4675,10 +4684,16 @@ static int apply_patch(struct apply_state *state,\n \t\tstate->apply = 0;\n \n \tstate->update_index = state->check_index && state->apply;\n-\tif (state->update_index && state->newfd < 0)\n-\t\tstate->newfd = hold_locked_index(state->lock_file, 1);\n+\tif (state->update_index && state->newfd < 0) {\n+\t\tif (state->index_file)\n+\t\t\tstate->newfd = hold_lock_file_for_update(state->lock_file,\n+\t\t\t\t\t\t\t\t state->index_file,\n+\t\t\t\t\t\t\t\t LOCK_DIE_ON_ERROR);\n+\t\telse\n+\t\t\tstate->newfd = hold_locked_index(state->lock_file, 1);\n+\t}\n \n-\tif (state->check_index && read_cache() < 0) {\n+\tif (state->check_index && read_apply_cache(state) < 0) {\n \t\terror(_(\"unable to read index file\"));\n \t\tres = -128;\n \t\tgoto end;\ndiff --git a/apply.h b/apply.h\nindex e2b89e8..1ba4f8d 100644\n--- a/apply.h\n+++ b/apply.h\n@@ -63,6 +63,7 @@ struct apply_state {\n \tint unsafe_paths;\n \n \t/* Other non boolean parameters */\n+\tconst char *index_file;\n \tenum apply_verbosity apply_verbosity;\n \tconst char *fake_ancestor;\n \tconst char *patch_input_file;\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300348","messageId":"20160827184547.4365-12-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 11/14] apply: refactor `git apply` option parsing","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:44Z","receivedAt":"2016-08-27T18:46:37Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Parsing `git apply` options can be useful to other commands that\nwant to call the libified apply functionality, because this way\nthey can easily pass some options from their own command line to\nthe libified apply functionality.\n\nThis will be used by `git am` in a following patch.\n\nTo make this possible, let's refactor the `git apply` option\nparsing code into a new libified apply_parse_options() function.\n\nDoing that makes it possible to remove some functions definitions\nfrom \"apply.h\" and make them static in \"apply.c\".\n\nHelped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n apply.c         | 103 +++++++++++++++++++++++++++++++++++++++++++++++++-------\n apply.h         |  18 +++-------\n builtin/apply.c |  74 ++--------------------------------------\n 3 files changed, 97 insertions(+), 98 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex bf81b70..2ec2a8a 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4730,16 +4730,16 @@ static int apply_patch(struct apply_state *state,\n \treturn res;\n }\n \n-int apply_option_parse_exclude(const struct option *opt,\n-\t\t\t       const char *arg, int unset)\n+static int apply_option_parse_exclude(const struct option *opt,\n+\t\t\t\t      const char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tadd_name_limit(state, arg, 1);\n \treturn 0;\n }\n \n-int apply_option_parse_include(const struct option *opt,\n-\t\t\t       const char *arg, int unset)\n+static int apply_option_parse_include(const struct option *opt,\n+\t\t\t\t      const char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tadd_name_limit(state, arg, 0);\n@@ -4747,9 +4747,9 @@ int apply_option_parse_include(const struct option *opt,\n \treturn 0;\n }\n \n-int apply_option_parse_p(const struct option *opt,\n-\t\t\t const char *arg,\n-\t\t\t int unset)\n+static int apply_option_parse_p(const struct option *opt,\n+\t\t\t\tconst char *arg,\n+\t\t\t\tint unset)\n {\n \tstruct apply_state *state = opt->value;\n \tstate->p_value = atoi(arg);\n@@ -4757,8 +4757,8 @@ int apply_option_parse_p(const struct option *opt,\n \treturn 0;\n }\n \n-int apply_option_parse_space_change(const struct option *opt,\n-\t\t\t\t    const char *arg, int unset)\n+static int apply_option_parse_space_change(const struct option *opt,\n+\t\t\t\t\t   const char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tif (unset)\n@@ -4768,8 +4768,8 @@ int apply_option_parse_space_change(const struct option *opt,\n \treturn 0;\n }\n \n-int apply_option_parse_whitespace(const struct option *opt,\n-\t\t\t\t  const char *arg, int unset)\n+static int apply_option_parse_whitespace(const struct option *opt,\n+\t\t\t\t\t const char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tstate->whitespace_option = arg;\n@@ -4778,8 +4778,8 @@ int apply_option_parse_whitespace(const struct option *opt,\n \treturn 0;\n }\n \n-int apply_option_parse_directory(const struct option *opt,\n-\t\t\t\t const char *arg, int unset)\n+static int apply_option_parse_directory(const struct option *opt,\n+\t\t\t\t\tconst char *arg, int unset)\n {\n \tstruct apply_state *state = opt->value;\n \tstrbuf_reset(&state->root);\n@@ -4893,3 +4893,80 @@ int apply_all_patches(struct apply_state *state,\n \t\treturn res;\n \treturn (res == -1 ? 1 : 128);\n }\n+\n+int apply_parse_options(int argc, const char **argv,\n+\t\t\tstruct apply_state *state,\n+\t\t\tint *force_apply, int *options,\n+\t\t\tconst char * const *apply_usage)\n+{\n+\tstruct option builtin_apply_options[] = {\n+\t\t{ OPTION_CALLBACK, 0, \"exclude\", state, N_(\"path\"),\n+\t\t\tN_(\"don't apply changes matching the given path\"),\n+\t\t\t0, apply_option_parse_exclude },\n+\t\t{ OPTION_CALLBACK, 0, \"include\", state, N_(\"path\"),\n+\t\t\tN_(\"apply changes matching the given path\"),\n+\t\t\t0, apply_option_parse_include },\n+\t\t{ OPTION_CALLBACK, 'p', NULL, state, N_(\"num\"),\n+\t\t\tN_(\"remove <num> leading slashes from traditional diff paths\"),\n+\t\t\t0, apply_option_parse_p },\n+\t\tOPT_BOOL(0, \"no-add\", &state->no_add,\n+\t\t\tN_(\"ignore additions made by the patch\")),\n+\t\tOPT_BOOL(0, \"stat\", &state->diffstat,\n+\t\t\tN_(\"instead of applying the patch, output diffstat for the input\")),\n+\t\tOPT_NOOP_NOARG(0, \"allow-binary-replacement\"),\n+\t\tOPT_NOOP_NOARG(0, \"binary\"),\n+\t\tOPT_BOOL(0, \"numstat\", &state->numstat,\n+\t\t\tN_(\"show number of added and deleted lines in decimal notation\")),\n+\t\tOPT_BOOL(0, \"summary\", &state->summary,\n+\t\t\tN_(\"instead of applying the patch, output a summary for the input\")),\n+\t\tOPT_BOOL(0, \"check\", &state->check,\n+\t\t\tN_(\"instead of applying the patch, see if the patch is applicable\")),\n+\t\tOPT_BOOL(0, \"index\", &state->check_index,\n+\t\t\tN_(\"make sure the patch is applicable to the current index\")),\n+\t\tOPT_BOOL(0, \"cached\", &state->cached,\n+\t\t\tN_(\"apply a patch without touching the working tree\")),\n+\t\tOPT_BOOL(0, \"unsafe-paths\", &state->unsafe_paths,\n+\t\t\tN_(\"accept a patch that touches outside the working area\")),\n+\t\tOPT_BOOL(0, \"apply\", force_apply,\n+\t\t\tN_(\"also apply the patch (use with --stat/--summary/--check)\")),\n+\t\tOPT_BOOL('3', \"3way\", &state->threeway,\n+\t\t\t N_( \"attempt three-way merge if a patch does not apply\")),\n+\t\tOPT_FILENAME(0, \"build-fake-ancestor\", &state->fake_ancestor,\n+\t\t\tN_(\"build a temporary index based on embedded index information\")),\n+\t\t/* Think twice before adding \"--nul\" synonym to this */\n+\t\tOPT_SET_INT('z', NULL, &state->line_termination,\n+\t\t\tN_(\"paths are separated with NUL character\"), '\\0'),\n+\t\tOPT_INTEGER('C', NULL, &state->p_context,\n+\t\t\t\tN_(\"ensure at least <n> lines of context match\")),\n+\t\t{ OPTION_CALLBACK, 0, \"whitespace\", state, N_(\"action\"),\n+\t\t\tN_(\"detect new or modified lines that have whitespace errors\"),\n+\t\t\t0, apply_option_parse_whitespace },\n+\t\t{ OPTION_CALLBACK, 0, \"ignore-space-change\", state, NULL,\n+\t\t\tN_(\"ignore changes in whitespace when finding context\"),\n+\t\t\tPARSE_OPT_NOARG, apply_option_parse_space_change },\n+\t\t{ OPTION_CALLBACK, 0, \"ignore-whitespace\", state, NULL,\n+\t\t\tN_(\"ignore changes in whitespace when finding context\"),\n+\t\t\tPARSE_OPT_NOARG, apply_option_parse_space_change },\n+\t\tOPT_BOOL('R', \"reverse\", &state->apply_in_reverse,\n+\t\t\tN_(\"apply the patch in reverse\")),\n+\t\tOPT_BOOL(0, \"unidiff-zero\", &state->unidiff_zero,\n+\t\t\tN_(\"don't expect at least one line of context\")),\n+\t\tOPT_BOOL(0, \"reject\", &state->apply_with_reject,\n+\t\t\tN_(\"leave the rejected hunks in corresponding *.rej files\")),\n+\t\tOPT_BOOL(0, \"allow-overlap\", &state->allow_overlap,\n+\t\t\tN_(\"allow overlapping hunks\")),\n+\t\tOPT__VERBOSE(&state->apply_verbosity, N_(\"be verbose\")),\n+\t\tOPT_BIT(0, \"inaccurate-eof\", options,\n+\t\t\tN_(\"tolerate incorrectly detected missing new-line at the end of file\"),\n+\t\t\tAPPLY_OPT_INACCURATE_EOF),\n+\t\tOPT_BIT(0, \"recount\", options,\n+\t\t\tN_(\"do not trust the line counts in the hunk headers\"),\n+\t\t\tAPPLY_OPT_RECOUNT),\n+\t\t{ OPTION_CALLBACK, 0, \"directory\", state, N_(\"root\"),\n+\t\t\tN_(\"prepend <root> to all filenames\"),\n+\t\t\t0, apply_option_parse_directory },\n+\t\tOPT_END()\n+\t};\n+\n+\treturn parse_options(argc, argv, state->prefix, builtin_apply_options, apply_usage, 0);\n+}\ndiff --git a/apply.h b/apply.h\nindex 5cde641..e2b89e8 100644\n--- a/apply.h\n+++ b/apply.h\n@@ -111,20 +111,10 @@ struct apply_state {\n \tint applied_after_fixing_ws;\n };\n \n-extern int apply_option_parse_exclude(const struct option *opt,\n-\t\t\t\t      const char *arg, int unset);\n-extern int apply_option_parse_include(const struct option *opt,\n-\t\t\t\t      const char *arg, int unset);\n-extern int apply_option_parse_p(const struct option *opt,\n-\t\t\t\tconst char *arg,\n-\t\t\t\tint unset);\n-extern int apply_option_parse_whitespace(const struct option *opt,\n-\t\t\t\t\t const char *arg, int unset);\n-extern int apply_option_parse_directory(const struct option *opt,\n-\t\t\t\t\tconst char *arg, int unset);\n-extern int apply_option_parse_space_change(const struct option *opt,\n-\t\t\t\t\t   const char *arg, int unset);\n-\n+extern int apply_parse_options(int argc, const char **argv,\n+\t\t\t       struct apply_state *state,\n+\t\t\t       int *force_apply, int *options,\n+\t\t\t       const char * const *apply_usage);\n extern int init_apply_state(struct apply_state *state,\n \t\t\t    const char *prefix,\n \t\t\t    struct lock_file *lock_file);\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 7338701..81b9a61 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -18,80 +18,12 @@ int cmd_apply(int argc, const char **argv, const char *prefix)\n \tint ret;\n \tstruct apply_state state;\n \n-\tstruct option builtin_apply_options[] = {\n-\t\t{ OPTION_CALLBACK, 0, \"exclude\", &state, N_(\"path\"),\n-\t\t\tN_(\"don't apply changes matching the given path\"),\n-\t\t\t0, apply_option_parse_exclude },\n-\t\t{ OPTION_CALLBACK, 0, \"include\", &state, N_(\"path\"),\n-\t\t\tN_(\"apply changes matching the given path\"),\n-\t\t\t0, apply_option_parse_include },\n-\t\t{ OPTION_CALLBACK, 'p', NULL, &state, N_(\"num\"),\n-\t\t\tN_(\"remove <num> leading slashes from traditional diff paths\"),\n-\t\t\t0, apply_option_parse_p },\n-\t\tOPT_BOOL(0, \"no-add\", &state.no_add,\n-\t\t\tN_(\"ignore additions made by the patch\")),\n-\t\tOPT_BOOL(0, \"stat\", &state.diffstat,\n-\t\t\tN_(\"instead of applying the patch, output diffstat for the input\")),\n-\t\tOPT_NOOP_NOARG(0, \"allow-binary-replacement\"),\n-\t\tOPT_NOOP_NOARG(0, \"binary\"),\n-\t\tOPT_BOOL(0, \"numstat\", &state.numstat,\n-\t\t\tN_(\"show number of added and deleted lines in decimal notation\")),\n-\t\tOPT_BOOL(0, \"summary\", &state.summary,\n-\t\t\tN_(\"instead of applying the patch, output a summary for the input\")),\n-\t\tOPT_BOOL(0, \"check\", &state.check,\n-\t\t\tN_(\"instead of applying the patch, see if the patch is applicable\")),\n-\t\tOPT_BOOL(0, \"index\", &state.check_index,\n-\t\t\tN_(\"make sure the patch is applicable to the current index\")),\n-\t\tOPT_BOOL(0, \"cached\", &state.cached,\n-\t\t\tN_(\"apply a patch without touching the working tree\")),\n-\t\tOPT_BOOL(0, \"unsafe-paths\", &state.unsafe_paths,\n-\t\t\tN_(\"accept a patch that touches outside the working area\")),\n-\t\tOPT_BOOL(0, \"apply\", &force_apply,\n-\t\t\tN_(\"also apply the patch (use with --stat/--summary/--check)\")),\n-\t\tOPT_BOOL('3', \"3way\", &state.threeway,\n-\t\t\t N_( \"attempt three-way merge if a patch does not apply\")),\n-\t\tOPT_FILENAME(0, \"build-fake-ancestor\", &state.fake_ancestor,\n-\t\t\tN_(\"build a temporary index based on embedded index information\")),\n-\t\t/* Think twice before adding \"--nul\" synonym to this */\n-\t\tOPT_SET_INT('z', NULL, &state.line_termination,\n-\t\t\tN_(\"paths are separated with NUL character\"), '\\0'),\n-\t\tOPT_INTEGER('C', NULL, &state.p_context,\n-\t\t\t\tN_(\"ensure at least <n> lines of context match\")),\n-\t\t{ OPTION_CALLBACK, 0, \"whitespace\", &state, N_(\"action\"),\n-\t\t\tN_(\"detect new or modified lines that have whitespace errors\"),\n-\t\t\t0, apply_option_parse_whitespace },\n-\t\t{ OPTION_CALLBACK, 0, \"ignore-space-change\", &state, NULL,\n-\t\t\tN_(\"ignore changes in whitespace when finding context\"),\n-\t\t\tPARSE_OPT_NOARG, apply_option_parse_space_change },\n-\t\t{ OPTION_CALLBACK, 0, \"ignore-whitespace\", &state, NULL,\n-\t\t\tN_(\"ignore changes in whitespace when finding context\"),\n-\t\t\tPARSE_OPT_NOARG, apply_option_parse_space_change },\n-\t\tOPT_BOOL('R', \"reverse\", &state.apply_in_reverse,\n-\t\t\tN_(\"apply the patch in reverse\")),\n-\t\tOPT_BOOL(0, \"unidiff-zero\", &state.unidiff_zero,\n-\t\t\tN_(\"don't expect at least one line of context\")),\n-\t\tOPT_BOOL(0, \"reject\", &state.apply_with_reject,\n-\t\t\tN_(\"leave the rejected hunks in corresponding *.rej files\")),\n-\t\tOPT_BOOL(0, \"allow-overlap\", &state.allow_overlap,\n-\t\t\tN_(\"allow overlapping hunks\")),\n-\t\tOPT__VERBOSE(&state.apply_verbosity, N_(\"be verbose\")),\n-\t\tOPT_BIT(0, \"inaccurate-eof\", &options,\n-\t\t\tN_(\"tolerate incorrectly detected missing new-line at the end of file\"),\n-\t\t\tAPPLY_OPT_INACCURATE_EOF),\n-\t\tOPT_BIT(0, \"recount\", &options,\n-\t\t\tN_(\"do not trust the line counts in the hunk headers\"),\n-\t\t\tAPPLY_OPT_RECOUNT),\n-\t\t{ OPTION_CALLBACK, 0, \"directory\", &state, N_(\"root\"),\n-\t\t\tN_(\"prepend <root> to all filenames\"),\n-\t\t\t0, apply_option_parse_directory },\n-\t\tOPT_END()\n-\t};\n-\n \tif (init_apply_state(&state, prefix, &lock_file))\n \t\texit(128);\n \n-\targc = parse_options(argc, argv, state.prefix, builtin_apply_options,\n-\t\t\tapply_usage, 0);\n+\targc = apply_parse_options(argc, argv,\n+\t\t\t\t   &state, &force_apply, &options,\n+\t\t\t\t   apply_usage);\n \n \tif (check_apply_state(&state, force_apply))\n \t\texit(128);\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300349","messageId":"20160827184547.4365-11-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 10/14] apply: change error_routine when silent","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:43Z","receivedAt":"2016-08-27T18:46:42Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"To avoid printing anything when applying with\n`state->apply_verbosity == verbosity_silent`, let's save the\nexisting warn and error routines before applying, and let's\nreplace them with a routine that does nothing.\n\nThen after applying, let's restore the saved routines.\n\nHelped-by: Stefan Beller <sbeller@google.com>\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n apply.c | 21 ++++++++++++++++++++-\n apply.h |  8 ++++++++\n 2 files changed, 28 insertions(+), 1 deletion(-)\n\ndiff --git a/apply.c b/apply.c\nindex ddbb0a2..bf81b70 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -112,6 +112,11 @@ void clear_apply_state(struct apply_state *state)\n \t/* &state->fn_table is cleared at the end of apply_patch() */\n }\n \n+static void mute_routine(const char *bla, va_list params)\n+{\n+\t/* do nothing */\n+}\n+\n int check_apply_state(struct apply_state *state, int force_apply)\n {\n \tint is_not_gitdir = !startup_info->have_repository;\n@@ -144,6 +149,13 @@ int check_apply_state(struct apply_state *state, int force_apply)\n \tif (!state->lock_file)\n \t\treturn error(\"BUG: state->lock_file should not be NULL\");\n \n+\tif (state->apply_verbosity <= verbosity_silent) {\n+\t\tstate->saved_error_routine = get_error_routine();\n+\t\tstate->saved_warn_routine = get_warn_routine();\n+\t\tset_error_routine(mute_routine);\n+\t\tset_warn_routine(mute_routine);\n+\t}\n+\n \treturn 0;\n }\n \n@@ -4864,7 +4876,7 @@ int apply_all_patches(struct apply_state *state,\n \t\tstate->newfd = -1;\n \t}\n \n-\treturn !!errs;\n+\tres = !!errs;\n \n end:\n \tif (state->newfd >= 0) {\n@@ -4872,5 +4884,12 @@ int apply_all_patches(struct apply_state *state,\n \t\tstate->newfd = -1;\n \t}\n \n+\tif (state->apply_verbosity <= verbosity_silent) {\n+\t\tset_error_routine(state->saved_error_routine);\n+\t\tset_warn_routine(state->saved_warn_routine);\n+\t}\n+\n+\tif (res > -1)\n+\t\treturn res;\n \treturn (res == -1 ? 1 : 128);\n }\ndiff --git a/apply.h b/apply.h\nindex bd4eb6d..5cde641 100644\n--- a/apply.h\n+++ b/apply.h\n@@ -94,6 +94,14 @@ struct apply_state {\n \t */\n \tstruct string_list fn_table;\n \n+\t/*\n+\t * This is to save reporting routines before using\n+\t * set_error_routine() or set_warn_routine() to install muting\n+\t * routines when in verbosity_silent mode.\n+\t */\n+\tvoid (*saved_error_routine)(const char *err, va_list params);\n+\tvoid (*saved_warn_routine)(const char *warn, va_list params);\n+\n \t/* These control whitespace errors */\n \tenum apply_ws_error_action ws_error_action;\n \tenum apply_ws_ignore ws_ignore_action;\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300350","messageId":"20160827184547.4365-10-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 09/14] usage: add get_error_routine() and get_warn_routine()","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:42Z","receivedAt":"2016-08-27T18:46:45Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Let's make it possible to get the current error_routine and warn_routine,\nso that we can store them before using set_error_routine() or\nset_warn_routine() to use new ones.\n\nThis way we will be able put back the original routines, when we are done\nwith using new ones.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n git-compat-util.h |  2 ++\n usage.c           | 10 ++++++++++\n 2 files changed, 12 insertions(+)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex c7a51f8..de04df1 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -440,7 +440,9 @@ static inline int const_error(void)\n \n extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));\n extern void set_error_routine(void (*routine)(const char *err, va_list params));\n+extern void (*get_error_routine(void))(const char *err, va_list params);\n extern void set_warn_routine(void (*routine)(const char *warn, va_list params));\n+extern void (*get_warn_routine(void))(const char *warn, va_list params);\n extern void set_die_is_recursing_routine(int (*routine)(void));\n extern void set_error_handle(FILE *);\n \ndiff --git a/usage.c b/usage.c\nindex 67e5526..2fd3045 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -70,11 +70,21 @@ void set_error_routine(void (*routine)(const char *err, va_list params))\n \terror_routine = routine;\n }\n \n+void (*get_error_routine(void))(const char *err, va_list params)\n+{\n+\treturn error_routine;\n+}\n+\n void set_warn_routine(void (*routine)(const char *warn, va_list params))\n {\n \twarn_routine = routine;\n }\n \n+void (*get_warn_routine(void))(const char *warn, va_list params)\n+{\n+\treturn warn_routine;\n+}\n+\n void set_die_is_recursing_routine(int (*routine)(void))\n {\n \tdie_is_recursing = routine;\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300351","messageId":"20160827184547.4365-13-chriscool@tuxfamily.org","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"[PATCH v13 12/14] apply: pass apply state to build_fake_ancestor()","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:45:45Z","receivedAt":"2016-08-27T18:46:46Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"To libify git apply functionality, we will need to read from a\ndifferent index file in get_current_sha1(). This index file will be\nstored in \"struct apply_state\", so let's pass the state to\nbuild_fake_ancestor() which will later pass it to get_current_sha1().\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n apply.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 2ec2a8a..276e4af 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -4042,7 +4042,7 @@ static int preimage_sha1_in_gitlink_patch(struct patch *p, unsigned char sha1[20\n }\n \n /* Build an index that contains the just the files needed for a 3way merge */\n-static int build_fake_ancestor(struct patch *list, const char *filename)\n+static int build_fake_ancestor(struct apply_state *state, struct patch *list)\n {\n \tstruct patch *patch;\n \tstruct index_state result = { NULL };\n@@ -4089,12 +4089,13 @@ static int build_fake_ancestor(struct patch *list, const char *filename)\n \t\t}\n \t}\n \n-\thold_lock_file_for_update(&lock, filename, LOCK_DIE_ON_ERROR);\n+\thold_lock_file_for_update(&lock, state->fake_ancestor, LOCK_DIE_ON_ERROR);\n \tres = write_locked_index(&result, &lock, COMMIT_LOCK);\n \tdiscard_index(&result);\n \n \tif (res)\n-\t\treturn error(\"Could not write temporary index to %s\", filename);\n+\t\treturn error(\"Could not write temporary index to %s\",\n+\t\t\t     state->fake_ancestor);\n \n \treturn 0;\n }\n@@ -4709,7 +4710,7 @@ static int apply_patch(struct apply_state *state,\n \t}\n \n \tif (state->fake_ancestor &&\n-\t    build_fake_ancestor(list, state->fake_ancestor)) {\n+\t    build_fake_ancestor(state, list)) {\n \t\tres = -128;\n \t\tgoto end;\n \t}\n-- \n2.9.2.770.g14ff7d2\n\n"},{"id":"300352","messageId":"CAP8UFD31xnKKigVHFhHT=TKHtDV2bSgVG61aiMnhu3X5HxJvwg@mail.gmail.com","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"Re: [PATCH v13 00/14] libify apply and use lib in am, part 3","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-27T18:49:09Z","receivedAt":"2016-08-27T18:49:14Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Sat, Aug 27, 2016 at 8:45 PM, Christian Couder\n<christian.couder@gmail.com> wrote:\n>\n> I will send a diff between this version and v12 as a reply to this\n> email.\n\nHere is the diff:\n\ndiff --git a/apply.c b/apply.c\nindex 7e561a4..5cd037d 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -3993,12 +3993,21 @@ static int check_patch_list(struct apply_state\n*state, struct patch *patch)\n     return err;\n }\n\n+static int read_apply_cache(struct apply_state *state)\n+{\n+    if (state->index_file)\n+        return read_cache_from(state->index_file);\n+    else\n+        return read_cache();\n+}\n+\n /* This function tries to read the sha1 from the current index */\n-static int get_current_sha1(const char *path, unsigned char *sha1)\n+static int get_current_sha1(struct apply_state *state, const char *path,\n+                unsigned char *sha1)\n {\n     int pos;\n\n-    if (read_cache() < 0)\n+    if (read_apply_cache(state) < 0)\n         return -1;\n     pos = cache_name_pos(path, strlen(path));\n     if (pos < 0)\n@@ -4042,7 +4051,7 @@ static int preimage_sha1_in_gitlink_patch(struct\npatch *p, unsigned char sha1[20\n }\n\n /* Build an index that contains the just the files needed for a 3way merge */\n-static int build_fake_ancestor(struct patch *list, const char *filename)\n+static int build_fake_ancestor(struct apply_state *state, struct patch *list)\n {\n     struct patch *patch;\n     struct index_state result = { NULL };\n@@ -4071,7 +4080,7 @@ static int build_fake_ancestor(struct patch\n*list, const char *filename)\n             ; /* ok */\n         } else if (!patch->lines_added && !patch->lines_deleted) {\n             /* mode-only change: update the current */\n-            if (get_current_sha1(patch->old_name, sha1))\n+            if (get_current_sha1(state, patch->old_name, sha1))\n                 return error(\"mode change for %s, which is not \"\n                          \"in current HEAD\", name);\n         } else\n@@ -4089,12 +4098,13 @@ static int build_fake_ancestor(struct patch\n*list, const char *filename)\n         }\n     }\n\n-    hold_lock_file_for_update(&lock, filename, LOCK_DIE_ON_ERROR);\n+    hold_lock_file_for_update(&lock, state->fake_ancestor, LOCK_DIE_ON_ERROR);\n     res = write_locked_index(&result, &lock, COMMIT_LOCK);\n     discard_index(&result);\n\n     if (res)\n-        return error(\"Could not write temporary index to %s\", filename);\n+        return error(\"Could not write temporary index to %s\",\n+                 state->fake_ancestor);\n\n     return 0;\n }\n@@ -4683,7 +4693,7 @@ static int apply_patch(struct apply_state *state,\n             state->newfd = hold_locked_index(state->lock_file, 1);\n     }\n\n-    if (state->check_index && read_cache() < 0) {\n+    if (state->check_index && read_apply_cache(state) < 0) {\n         error(_(\"unable to read index file\"));\n         res = -128;\n         goto end;\n@@ -4715,7 +4725,7 @@ static int apply_patch(struct apply_state *state,\n     }\n\n     if (state->fake_ancestor &&\n-        build_fake_ancestor(list, state->fake_ancestor)) {\n+        build_fake_ancestor(state, list)) {\n         res = -128;\n         goto end;\n     }\n"},{"id":"300483","messageId":"xmqq7fazbdmk.fsf@gitster.mtv.corp.google.com","threadId":"43946","inReplyTo":"20160827184547.4365-1-chriscool@tuxfamily.org","subject":"Re: [PATCH v13 00/14] libify apply and use lib in am, part 3","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-08-29T19:04:35Z","receivedAt":"2016-08-29T19:05:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n> Highlevel view of the patches in the series\n> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n>\n> This is \"part 3\" of the full patch series. I am resending only the\n> last 14 patches of the full series as \"part 3\", because I don't want\n> to resend the first 27 patches of v10 nearly as is.\n\nJust to make sure, you are sending the first 11 of these 14 exactly\nas-is, right?  I didn't spot anything different other than 12 and 13\nthat replaced the \"alternate index\" step from the previous round.\n\n"},{"id":"300490","messageId":"xmqqtwe39wtg.fsf@gitster.mtv.corp.google.com","threadId":"43946","inReplyTo":"xmqq7fazbdmk.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v13 00/14] libify apply and use lib in am, part 3","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-08-29T19:52:59Z","receivedAt":"2016-08-29T19:53:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Christian Couder <christian.couder@gmail.com> writes:\n>\n>> Highlevel view of the patches in the series\n>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n>>\n>> This is \"part 3\" of the full patch series. I am resending only the\n>> last 14 patches of the full series as \"part 3\", because I don't want\n>> to resend the first 27 patches of v10 nearly as is.\n>\n> Just to make sure, you are sending the first 11 of these 14 exactly\n> as-is, right?  I didn't spot anything different other than 12 and 13\n> that replaced the \"alternate index\" step from the previous round.\n\nIn any case, I didn't spot anything glaringly wrong in the updated\npart of the patches.  I'll wait for a few days and then mark it as\n'Will merge to next' unless we hear comments from others.\n\nThanks.\n"},{"id":"300546","messageId":"CAP8UFD20GY0h8n-7oJp8zhjHPUeKSkcEkNrOMuyGBrtS8JE6Jg@mail.gmail.com","threadId":"43946","inReplyTo":"xmqq7fazbdmk.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v13 00/14] libify apply and use lib in am, part 3","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-08-30T10:19:51Z","receivedAt":"2016-08-30T10:20:09Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Mon, Aug 29, 2016 at 9:04 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Christian Couder <christian.couder@gmail.com> writes:\n>\n>> Highlevel view of the patches in the series\n>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n>>\n>> This is \"part 3\" of the full patch series. I am resending only the\n>> last 14 patches of the full series as \"part 3\", because I don't want\n>> to resend the first 27 patches of v10 nearly as is.\n>\n> Just to make sure, you are sending the first 11 of these 14 exactly\n> as-is, right?  I didn't spot anything different other than 12 and 13\n> that replaced the \"alternate index\" step from the previous round.\n\nYeah, the first 11 of the 14 patches have no change compared to v12.\nI didn't want to create a \"part 4\" as that could be confusing, and\nsending the first 11 patches gives them another chance to be reviewed\nagain.\n"},{"id":"300742","messageId":"CAGZ79kYzOh-trnnc2JH9QX21DX=6nz=q0M99tbpU_Q68tmH0Qw@mail.gmail.com","threadId":"43946","inReplyTo":"20160827184547.4365-3-chriscool@tuxfamily.org","subject":"Re: [PATCH v13 02/14] apply: rename and move opt constants to apply.h","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-08-31T21:46:10Z","receivedAt":"2016-08-31T21:46:16Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n>  extern int check_apply_state(struct apply_state *state, int force_apply);\n>\n\nWith greater scope comes greater responsibility. Nit of the day:\nIn case a reroll is necessary, consider putting a comment here.\n(What are these constants? what do they control? How/where do I use them?)\n\n> +#define APPLY_OPT_INACCURATE_EOF       (1<<0)\n> +#define APPLY_OPT_RECOUNT              (1<<1)\n> +\n"},{"id":"300743","messageId":"CAGZ79kb0gao2KJFi9X3V2ME+1-xnbuSNhjC14Vnn3oP-1ac35A@mail.gmail.com","threadId":"43946","inReplyTo":"20160827184547.4365-4-chriscool@tuxfamily.org","subject":"Re: [PATCH v13 03/14] Move libified code from builtin/apply.c to apply.{c,h}","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-08-31T21:57:53Z","receivedAt":"2016-08-31T21:57:59Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> As most of the apply code in builtin/apply.c has been libified by a number of\n> previous commits, it can now be moved to apply.{c,h}, so that more code can\n> use it.\n>\n> Helped-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  apply.c         | 4731 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  apply.h         |   19 +\n>  builtin/apply.c | 4733 +------------------------------------------------------\n\nI deduce by roughly the same line count in the .c files, it is just\nmoving files over.\n(On my todo list I have an idea how to make reviewing patches like this easier.)\n\n>  3 files changed, 4751 insertions(+), 4732 deletions(-)\n>\n> diff --git a/apply.c b/apply.c\n> index 2eac3e3..7b96130 100644\n> --- a/apply.c\n> +++ b/apply.c\n> @@ -1,5 +1,23 @@\n> +/*\n> + * apply.c\n> + *\n> + * Copyright (C) Linus Torvalds, 2005\n\nWe're very inconsistent with the intellectual property log.\nSometimes we have that at the top of a file, sometimes we don't\nand rather point at the git history to find out who touched the code.\nI'd rather use the history instead of having a bunch of copyright lines.\nSo maybe consider to drop this introductory comment as a\n{preparatory, follow up} cleanup?\n\n(This is also a nit that doesn't require a reroll on its own)\n"},{"id":"300744","messageId":"CAGZ79kYz2kRgDOFvOOAQL5HyjvcZ1+o9fFJMWVtkazVfy3Ev6w@mail.gmail.com","threadId":"43946","inReplyTo":"20160827184547.4365-5-chriscool@tuxfamily.org","subject":"Re: [PATCH v13 04/14] apply: make some parsing functions static again","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-08-31T21:58:30Z","receivedAt":"2016-08-31T21:58:36Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> Some parsing functions that were used in both \"apply.c\" and\n> \"builtin/apply.c\" are now only used in the former, so they\n> can be made static to \"apply.c\".\n>\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  apply.c | 6 +++---\n>  apply.h | 5 -----\n>  2 files changed, 3 insertions(+), 8 deletions(-)\n\nLooks good.\n"},{"id":"300745","messageId":"CAGZ79kYSDs=BjbF5D0CM5krqc9D8u+54fT_geMzJOFXT35zi6Q@mail.gmail.com","threadId":"43946","inReplyTo":"20160827184547.4365-6-chriscool@tuxfamily.org","subject":"Re: [PATCH v13 05/14] apply: use error_errno() where possible","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-08-31T21:59:26Z","receivedAt":"2016-08-31T21:59:33Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> To avoid possible mistakes and to uniformly show the errno\n> related messages, let's use error_errno() where possible.\n>\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n\nLooks good,\nThanks for these cleanups!\nStefan\n"},{"id":"300746","messageId":"CAGZ79kYnp_8iew33KQJK1TB0ROLthHBtvHqf3wVzFkh_JSq5MA@mail.gmail.com","threadId":"43946","inReplyTo":"20160827184547.4365-7-chriscool@tuxfamily.org","subject":"Re: [PATCH v13 06/14] apply: make it possible to silently apply","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-08-31T22:07:54Z","receivedAt":"2016-08-31T22:08:01Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"> Printing on stdout, and calls to warning() or error() are not\n> taken care of in this patch, as that will be done in following\n> patches.\n\n> -               if (state->apply_verbosely)\n> +               if (state->apply_verbosity > verbosity_normal)\n>                         error(_(\"while searching for:\\n%.*s\"),\n>                               (int)(old - oldlines), oldlines);\n\nBut this is an error(..) ?\n\nHave you considered to replace all these print functions (error, warning,\nfprintf, printf, fprintf_ln) with another custom\n\n    int say_when_at_least(verbosity level, const char *fmt,...)\n\n? (I guess that would be more invasive, but the result would be more\nconsistent.)\n"},{"id":"300748","messageId":"xmqq1t14zit7.fsf@gitster.mtv.corp.google.com","threadId":"43946","inReplyTo":"CAP8UFD20GY0h8n-7oJp8zhjHPUeKSkcEkNrOMuyGBrtS8JE6Jg@mail.gmail.com","subject":"Re: [PATCH v13 00/14] libify apply and use lib in am, part 3","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-08-31T22:15:32Z","receivedAt":"2016-08-31T22:15:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n> On Mon, Aug 29, 2016 at 9:04 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Christian Couder <christian.couder@gmail.com> writes:\n>>\n>>> Highlevel view of the patches in the series\n>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n>>>\n>>> This is \"part 3\" of the full patch series. I am resending only the\n>>> last 14 patches of the full series as \"part 3\", because I don't want\n>>> to resend the first 27 patches of v10 nearly as is.\n>>\n>> Just to make sure, you are sending the first 11 of these 14 exactly\n>> as-is, right?  I didn't spot anything different other than 12 and 13\n>> that replaced the \"alternate index\" step from the previous round.\n>\n> Yeah, the first 11 of the 14 patches have no change compared to v12.\n> I didn't want to create a \"part 4\" as that could be confusing, and\n> sending the first 11 patches gives them another chance to be reviewed\n> again.\n\nHmph.\n\nBut most likely, you made sure that those who _could_ review the\nfirst 11 are miniscule minority by omitting the earlier steps before\nthese 14 patches -- unless they are familiar with them, the first 11\npatches are not much use to them.  And those who are familiar have\nalready seen the first 11, too.  That was why I wondered who the\ntarget audience was when seeing only the last 14, among which 11 of\nthem were identical to the previous.\n\n"},{"id":"300749","messageId":"CAGZ79kbdoF-1=ZBZG8y3sEz6LVaNP4Ou+KVk+=M7y9PSzQ1J0Q@mail.gmail.com","threadId":"43946","inReplyTo":"20160827184547.4365-11-chriscool@tuxfamily.org","subject":"Re: [PATCH v13 10/14] apply: change error_routine when silent","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-08-31T22:20:36Z","receivedAt":"2016-08-31T22:20:42Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> To avoid printing anything when applying with\n> `state->apply_verbosity == verbosity_silent`, let's save the\n> existing warn and error routines before applying, and let's\n> replace them with a routine that does nothing.\n>\n> Then after applying, let's restore the saved routines.\n>\n> Helped-by: Stefan Beller <sbeller@google.com>\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  apply.c | 21 ++++++++++++++++++++-\n>  apply.h |  8 ++++++++\n>  2 files changed, 28 insertions(+), 1 deletion(-)\n>\n> diff --git a/apply.c b/apply.c\n> index ddbb0a2..bf81b70 100644\n> --- a/apply.c\n> +++ b/apply.c\n> @@ -112,6 +112,11 @@ void clear_apply_state(struct apply_state *state)\n>         /* &state->fn_table is cleared at the end of apply_patch() */\n>  }\n>\n> +static void mute_routine(const char *bla, va_list params)\n\nInstead of 'bla' you could go with 'format' as the man page for\n[f]printf puts it.\nOr you could leave it empty, i.e.\n\n    static void mute_routine(const char *, va_list)\n    ...\n\nI personally do not mind bla, as I know that the first parameter is\nsupposed to be the format, but let's not add unneeded information.\n(Side question: Is there a culture that doesn't recognize 'bla' as a\nfill word?)\n\n\n\n> +{\n> +       /* do nothing */\n> +}\n> +\n>  int check_apply_state(struct apply_state *state, int force_apply)\n>  {\n>         int is_not_gitdir = !startup_info->have_repository;\n> @@ -144,6 +149,13 @@ int check_apply_state(struct apply_state *state, int force_apply)\n>         if (!state->lock_file)\n>                 return error(\"BUG: state->lock_file should not be NULL\");\n>\n> +       if (state->apply_verbosity <= verbosity_silent) {\n> +               state->saved_error_routine = get_error_routine();\n> +               state->saved_warn_routine = get_warn_routine();\n> +               set_error_routine(mute_routine);\n> +               set_warn_routine(mute_routine);\n> +       }\n> +\n>         return 0;\n>  }\n>\n> @@ -4864,7 +4876,7 @@ int apply_all_patches(struct apply_state *state,\n>                 state->newfd = -1;\n>         }\n>\n> -       return !!errs;\n> +       res = !!errs;\n\nI am trying to understand this and the next chunk (they work together?)\n\n>\n>  end:\n>         if (state->newfd >= 0) {\n> @@ -4872,5 +4884,12 @@ int apply_all_patches(struct apply_state *state,\n>                 state->newfd = -1;\n>         }\n>\n> +       if (state->apply_verbosity <= verbosity_silent) {\n> +               set_error_routine(state->saved_error_routine);\n> +               set_warn_routine(state->saved_warn_routine);\n> +       }\n> +\n> +       if (res > -1)\n> +               return res;\n>         return (res == -1 ? 1 : 128);\n\nSo anything > -1 is returned as is, and == -1 returns 1 and <-1  returns 128 ?\n\nSo I guess a reminder/explanation on why we need to fiddle with return codes\nin the commit message would help. (I do not understand how the\nverbosity influences return codes.)\n"},{"id":"300750","messageId":"CAGZ79kZcK-QxMUa7A0FJbzq=ZQ=prWzJu4K69jaW8E-rwme=oQ@mail.gmail.com","threadId":"43946","inReplyTo":"20160827184547.4365-15-chriscool@tuxfamily.org","subject":"Re: [PATCH v13 14/14] builtin/am: use apply API in run_apply()","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-08-31T22:33:12Z","receivedAt":"2016-08-31T22:33:18Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> +\n> +       if (opts_left != 0)\n> +               die(\"unknown option passed thru to git apply\");\n\nThrough and thru are different spellings of the same word.\nThru is the less preferred form, however, and it might be\nconsidered out of place outside the most informal contexts.\n\n[Source: The Internet]\n\n\"git grep thru\" confirms we only use it in comments or function\nnames, both are not exposed to our dear users.\n\nThe rest looks good.\n"},{"id":"300771","messageId":"CAP8UFD2C_y91+nYBoavq_cPWrUcoJ97jDvs64sBabL6kbpjehw@mail.gmail.com","threadId":"43946","inReplyTo":"CAGZ79kZcK-QxMUa7A0FJbzq=ZQ=prWzJu4K69jaW8E-rwme=oQ@mail.gmail.com","subject":"Re: [PATCH v13 14/14] builtin/am: use apply API in run_apply()","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-09-01T07:41:02Z","receivedAt":"2016-09-01T07:41:11Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Sep 1, 2016 at 12:33 AM, Stefan Beller <sbeller@google.com> wrote:\n> On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n> <christian.couder@gmail.com> wrote:\n>> +\n>> +       if (opts_left != 0)\n>> +               die(\"unknown option passed thru to git apply\");\n>\n> Through and thru are different spellings of the same word.\n> Thru is the less preferred form, however, and it might be\n> considered out of place outside the most informal contexts.\n\nOk I will change to \"through\"...\n\n> [Source: The Internet]\n>\n> \"git grep thru\" confirms we only use it in comments or function\n> names, both are not exposed to our dear users.\n\n...but I find it strange to use different kind of language for our\nusers, who by the way are likely to be developers, than for our own\ndevelopers.\n\n> The rest looks good.\n\nThanks for your review,\nChristian.\n"},{"id":"300772","messageId":"CAP8UFD1pKfCdX84P4iAyZdPdzWQMaNdb0Vaq5UpWy3fXJzFeWg@mail.gmail.com","threadId":"43946","inReplyTo":"CAGZ79kb0gao2KJFi9X3V2ME+1-xnbuSNhjC14Vnn3oP-1ac35A@mail.gmail.com","subject":"Re: [PATCH v13 03/14] Move libified code from builtin/apply.c to apply.{c,h}","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-09-01T07:46:06Z","receivedAt":"2016-09-01T07:46:15Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Wed, Aug 31, 2016 at 11:57 PM, Stefan Beller <sbeller@google.com> wrote:\n> On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n> <christian.couder@gmail.com> wrote:\n>> As most of the apply code in builtin/apply.c has been libified by a number of\n>> previous commits, it can now be moved to apply.{c,h}, so that more code can\n>> use it.\n>>\n>> Helped-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>> Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n>> ---\n>>  apply.c         | 4731 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>>  apply.h         |   19 +\n>>  builtin/apply.c | 4733 +------------------------------------------------------\n>\n> I deduce by roughly the same line count in the .c files, it is just\n> moving files over.\n> (On my todo list I have an idea how to make reviewing patches like this easier.)\n\nYeah, at one point I used some special options to try to get a smaller\ndiff, but it got lost along the way.\n\n>>  3 files changed, 4751 insertions(+), 4732 deletions(-)\n>>\n>> diff --git a/apply.c b/apply.c\n>> index 2eac3e3..7b96130 100644\n>> --- a/apply.c\n>> +++ b/apply.c\n>> @@ -1,5 +1,23 @@\n>> +/*\n>> + * apply.c\n>> + *\n>> + * Copyright (C) Linus Torvalds, 2005\n>\n> We're very inconsistent with the intellectual property log.\n> Sometimes we have that at the top of a file, sometimes we don't\n> and rather point at the git history to find out who touched the code.\n> I'd rather use the history instead of having a bunch of copyright lines.\n> So maybe consider to drop this introductory comment as a\n> {preparatory, follow up} cleanup?\n>\n> (This is also a nit that doesn't require a reroll on its own)\n\nYeah, if people are ok with it I may od it in a follow up patch.\n"},{"id":"300776","messageId":"CAP8UFD3RE6L17nQmvZTkx6wycsdG7EA9eM=tYQD8nrS445zg1w@mail.gmail.com","threadId":"43946","inReplyTo":"CAGZ79kYnp_8iew33KQJK1TB0ROLthHBtvHqf3wVzFkh_JSq5MA@mail.gmail.com","subject":"Re: [PATCH v13 06/14] apply: make it possible to silently apply","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-09-01T08:01:49Z","receivedAt":"2016-09-01T08:01:56Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Sep 1, 2016 at 12:07 AM, Stefan Beller <sbeller@google.com> wrote:\n>> Printing on stdout, and calls to warning() or error() are not\n>> taken care of in this patch, as that will be done in following\n>> patches.\n>\n>> -               if (state->apply_verbosely)\n>> +               if (state->apply_verbosity > verbosity_normal)\n>>                         error(_(\"while searching for:\\n%.*s\"),\n>>                               (int)(old - oldlines), oldlines);\n>\n> But this is an error(..) ?\n\nDo you mean that it was a bug in the original code to print this error\nonly in verbose mode?\n\n> Have you considered to replace all these print functions (error, warning,\n> fprintf, printf, fprintf_ln) with another custom\n>\n>     int say_when_at_least(verbosity level, const char *fmt,...)\n>\n> ? (I guess that would be more invasive, but the result would be more\n> consistent.)\n\nMy opinion is that there is a reason (or there should have been a\nreason) why people decided to use error() instead of warning() for\nexample.\nIf I use say_when_at_least(verbosity level, const char *fmt,...) like\nyou suggest, how do I decide if error() or warning() is used to\nactually print the error message?\nAnother parameter to this function (severity level?) is needed.\n\nAnyway I don't think such a refactoring is needed.\n"},{"id":"300778","messageId":"CAP8UFD3DS_AV_ATH8Z9v0f0y4zFjhjhD0h9LfHwnJ2R0Fm5EqQ@mail.gmail.com","threadId":"43946","inReplyTo":"CAGZ79kYzOh-trnnc2JH9QX21DX=6nz=q0M99tbpU_Q68tmH0Qw@mail.gmail.com","subject":"Re: [PATCH v13 02/14] apply: rename and move opt constants to apply.h","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-09-01T08:03:49Z","receivedAt":"2016-09-01T08:04:04Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Wed, Aug 31, 2016 at 11:46 PM, Stefan Beller <sbeller@google.com> wrote:\n> On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n> <christian.couder@gmail.com> wrote:\n>>  extern int check_apply_state(struct apply_state *state, int force_apply);\n>>\n>\n> With greater scope comes greater responsibility. Nit of the day:\n> In case a reroll is necessary, consider putting a comment here.\n> (What are these constants? what do they control? How/where do I use them?)\n>\n>> +#define APPLY_OPT_INACCURATE_EOF       (1<<0)\n>> +#define APPLY_OPT_RECOUNT              (1<<1)\n\nOk I will reroll with some added comments.\n"},{"id":"300780","messageId":"CAP8UFD2Lwd_1+cWT702deF8=iFmBRKCi9gLSOizPbyLmeKepsw@mail.gmail.com","threadId":"43946","inReplyTo":"CAGZ79kbdoF-1=ZBZG8y3sEz6LVaNP4Ou+KVk+=M7y9PSzQ1J0Q@mail.gmail.com","subject":"Re: [PATCH v13 10/14] apply: change error_routine when silent","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-09-01T08:19:30Z","receivedAt":"2016-09-01T08:19:40Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Sep 1, 2016 at 12:20 AM, Stefan Beller <sbeller@google.com> wrote:\n> On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n> <christian.couder@gmail.com> wrote:\n>> To avoid printing anything when applying with\n>> `state->apply_verbosity == verbosity_silent`, let's save the\n>> existing warn and error routines before applying, and let's\n>> replace them with a routine that does nothing.\n>>\n>> Then after applying, let's restore the saved routines.\n>>\n>> Helped-by: Stefan Beller <sbeller@google.com>\n>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n>> ---\n>>  apply.c | 21 ++++++++++++++++++++-\n>>  apply.h |  8 ++++++++\n>>  2 files changed, 28 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/apply.c b/apply.c\n>> index ddbb0a2..bf81b70 100644\n>> --- a/apply.c\n>> +++ b/apply.c\n>> @@ -112,6 +112,11 @@ void clear_apply_state(struct apply_state *state)\n>>         /* &state->fn_table is cleared at the end of apply_patch() */\n>>  }\n>>\n>> +static void mute_routine(const char *bla, va_list params)\n>\n> Instead of 'bla' you could go with 'format' as the man page for\n> [f]printf puts it.\n> Or you could leave it empty, i.e.\n>\n>     static void mute_routine(const char *, va_list)\n>     ...\n\nOk to do that.\n\n> I personally do not mind bla, as I know that the first parameter is\n> supposed to be the format, but let's not add unneeded information.\n> (Side question: Is there a culture that doesn't recognize 'bla' as a\n> fill word?)\n>\n>> @@ -4864,7 +4876,7 @@ int apply_all_patches(struct apply_state *state,\n>>                 state->newfd = -1;\n>>         }\n>>\n>> -       return !!errs;\n>> +       res = !!errs;\n>\n> I am trying to understand this and the next chunk (they work together?)\n\nYes, they work together.\n\n>>  end:\n>>         if (state->newfd >= 0) {\n>> @@ -4872,5 +4884,12 @@ int apply_all_patches(struct apply_state *state,\n>>                 state->newfd = -1;\n>>         }\n>>\n>> +       if (state->apply_verbosity <= verbosity_silent) {\n>> +               set_error_routine(state->saved_error_routine);\n>> +               set_warn_routine(state->saved_warn_routine);\n>> +       }\n>> +\n>> +       if (res > -1)\n>> +               return res;\n>>         return (res == -1 ? 1 : 128);\n>\n> So anything > -1 is returned as is, and == -1 returns 1 and <-1  returns 128 ?\n>\n> So I guess a reminder/explanation on why we need to fiddle with return codes\n> in the commit message would help. (I do not understand how the\n> verbosity influences return codes.)\n\nIt doesn't influence return codes, but we need to restore error\nroutines just before returning, so we cannot return early anymore.\nI will add something to the commit message.\n"},{"id":"300782","messageId":"CAP8UFD3wA32eXYq3F4=KS-9SkV48Yh45TKgFnn3AmGVfpjwWjA@mail.gmail.com","threadId":"43946","inReplyTo":"xmqq1t14zit7.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v13 00/14] libify apply and use lib in am, part 3","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-09-01T08:28:53Z","receivedAt":"2016-09-01T08:29:01Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Sep 1, 2016 at 12:15 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Christian Couder <christian.couder@gmail.com> writes:\n>\n>> On Mon, Aug 29, 2016 at 9:04 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>>> Christian Couder <christian.couder@gmail.com> writes:\n>>>\n>>>> Highlevel view of the patches in the series\n>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n>>>>\n>>>> This is \"part 3\" of the full patch series. I am resending only the\n>>>> last 14 patches of the full series as \"part 3\", because I don't want\n>>>> to resend the first 27 patches of v10 nearly as is.\n>>>\n>>> Just to make sure, you are sending the first 11 of these 14 exactly\n>>> as-is, right?  I didn't spot anything different other than 12 and 13\n>>> that replaced the \"alternate index\" step from the previous round.\n>>\n>> Yeah, the first 11 of the 14 patches have no change compared to v12.\n>> I didn't want to create a \"part 4\" as that could be confusing, and\n>> sending the first 11 patches gives them another chance to be reviewed\n>> again.\n>\n> Hmph.\n>\n> But most likely, you made sure that those who _could_ review the\n> first 11 are miniscule minority by omitting the earlier steps before\n> these 14 patches -- unless they are familiar with them, the first 11\n> patches are not much use to them.  And those who are familiar have\n> already seen the first 11, too.  That was why I wondered who the\n> target audience was when seeing only the last 14, among which 11 of\n> them were identical to the previous.\n\nFollowing Stefan's review, it looks like I will need to resend at\nleast 02/14, 10/14 and 14/14.\nWhat do you prefer me to resend:\n1) all the last 40 or so patches\n2) the last 14 patches\n3) only the few patches that changed\n?\n"},{"id":"300828","messageId":"xmqqzinrwly4.fsf@gitster.mtv.corp.google.com","threadId":"43946","inReplyTo":"CAP8UFD3wA32eXYq3F4=KS-9SkV48Yh45TKgFnn3AmGVfpjwWjA@mail.gmail.com","subject":"Re: [PATCH v13 00/14] libify apply and use lib in am, part 3","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-09-01T17:48:19Z","receivedAt":"2016-09-01T21:04:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n> Following Stefan's review, it looks like I will need to resend at\n> least 02/14, 10/14 and 14/14.\n> What do you prefer me to resend:\n> 1) all the last 40 or so patches\n> 2) the last 14 patches\n> 3) only the few patches that changed\n\nIf this reroll is to be the candidate to be the final one, I'd\nprefer to see 1 to give an easy access to more sets of eyes, but if\nyou just send them without giving these patches one more read-over\nbefore sending them out, it is not as valuable as it would be.\n\nI think 2 is of the least value.\n\nIf you do 3., pointing people at where the remainder of the series\ncan be found is necessary.\n"},{"id":"300845","messageId":"CAGZ79kZT-t_NZZJcdMEB8E1y_u0=LHGWOxbdEeYMjgFHZYtHHQ@mail.gmail.com","threadId":"43946","inReplyTo":"CAP8UFD3RE6L17nQmvZTkx6wycsdG7EA9eM=tYQD8nrS445zg1w@mail.gmail.com","subject":"Re: [PATCH v13 06/14] apply: make it possible to silently apply","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-09-01T16:57:55Z","receivedAt":"2016-09-01T22:13:04Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Sep 1, 2016 at 1:01 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> On Thu, Sep 1, 2016 at 12:07 AM, Stefan Beller <sbeller@google.com> wrote:\n>>> Printing on stdout, and calls to warning() or error() are not\n>>> taken care of in this patch, as that will be done in following\n>>> patches.\n>>\n>>> -               if (state->apply_verbosely)\n>>> +               if (state->apply_verbosity > verbosity_normal)\n>>>                         error(_(\"while searching for:\\n%.*s\"),\n>>>                               (int)(old - oldlines), oldlines);\n>>\n>> But this is an error(..) ?\n>\n> Do you mean that it was a bug in the original code to print this error\n> only in verbose mode?\n\nOh never mind.\n\nI meant to point out the inconsistency between the commit message, that\nsaid: \"error() are not taken care of in this patch\" and modifying a\ncondition for\nan error call. However we need to fix them as you renamed apply_verbosely\nto apply_verbosity and made it an enum. So I spoke too early.\n\n>\n> Anyway I don't think such a refactoring is needed.\n\ngreat :)\n"},{"id":"300981","messageId":"CAP8UFD38CC-Ah9zVcnU3a4nGH2CzOn74Adx=42pmckjPv=e_Bg@mail.gmail.com","threadId":"43946","inReplyTo":"CAP8UFD2Lwd_1+cWT702deF8=iFmBRKCi9gLSOizPbyLmeKepsw@mail.gmail.com","subject":"Re: [PATCH v13 10/14] apply: change error_routine when silent","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-09-04T10:54:25Z","receivedAt":"2016-09-04T10:55:06Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Sep 1, 2016 at 10:19 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> On Thu, Sep 1, 2016 at 12:20 AM, Stefan Beller <sbeller@google.com> wrote:\n>> On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n>> <christian.couder@gmail.com> wrote:\n>>> To avoid printing anything when applying with\n>>> `state->apply_verbosity == verbosity_silent`, let's save the\n>>> existing warn and error routines before applying, and let's\n>>> replace them with a routine that does nothing.\n>>>\n>>> Then after applying, let's restore the saved routines.\n>>>\n>>> Helped-by: Stefan Beller <sbeller@google.com>\n>>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n>>> ---\n>>>  apply.c | 21 ++++++++++++++++++++-\n>>>  apply.h |  8 ++++++++\n>>>  2 files changed, 28 insertions(+), 1 deletion(-)\n>>>\n>>> diff --git a/apply.c b/apply.c\n>>> index ddbb0a2..bf81b70 100644\n>>> --- a/apply.c\n>>> +++ b/apply.c\n>>> @@ -112,6 +112,11 @@ void clear_apply_state(struct apply_state *state)\n>>>         /* &state->fn_table is cleared at the end of apply_patch() */\n>>>  }\n>>>\n>>> +static void mute_routine(const char *bla, va_list params)\n>>\n>> Instead of 'bla' you could go with 'format' as the man page for\n>> [f]printf puts it.\n>> Or you could leave it empty, i.e.\n>>\n>>     static void mute_routine(const char *, va_list)\n>>     ...\n>\n> Ok to do that.\n\nActually I get the following error when doing that:\n\napply.c: In function ‘mute_routine’:\napply.c:115:1: error: parameter name omitted\n static void mute_routine(const char *, va_list)\n ^\napply.c:115:1: error: parameter name omitted\nmake: *** [apply.o] Error 1\n\nSo I will leave it as is.\n"},{"id":"301029","messageId":"e39d9b83-949b-075c-07f6-60118dc24961@ramsayjones.plus.com","threadId":"43946","inReplyTo":"CAP8UFD38CC-Ah9zVcnU3a4nGH2CzOn74Adx=42pmckjPv=e_Bg@mail.gmail.com","subject":"Re: [PATCH v13 10/14] apply: change error_routine when silent","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2016-09-04T16:31:06Z","receivedAt":"2016-09-04T16:34:15Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 04/09/16 11:54, Christian Couder wrote:\n> On Thu, Sep 1, 2016 at 10:19 AM, Christian Couder\n> <christian.couder@gmail.com> wrote:\n>> On Thu, Sep 1, 2016 at 12:20 AM, Stefan Beller <sbeller@google.com> wrote:\n>>> On Sat, Aug 27, 2016 at 11:45 AM, Christian Couder\n>>> <christian.couder@gmail.com> wrote:\n>>>> To avoid printing anything when applying with\n>>>> `state->apply_verbosity == verbosity_silent`, let's save the\n>>>> existing warn and error routines before applying, and let's\n>>>> replace them with a routine that does nothing.\n>>>>\n>>>> Then after applying, let's restore the saved routines.\n>>>>\n>>>> Helped-by: Stefan Beller <sbeller@google.com>\n>>>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n>>>> ---\n>>>>  apply.c | 21 ++++++++++++++++++++-\n>>>>  apply.h |  8 ++++++++\n>>>>  2 files changed, 28 insertions(+), 1 deletion(-)\n>>>>\n>>>> diff --git a/apply.c b/apply.c\n>>>> index ddbb0a2..bf81b70 100644\n>>>> --- a/apply.c\n>>>> +++ b/apply.c\n>>>> @@ -112,6 +112,11 @@ void clear_apply_state(struct apply_state *state)\n>>>>         /* &state->fn_table is cleared at the end of apply_patch() */\n>>>>  }\n>>>>\n>>>> +static void mute_routine(const char *bla, va_list params)\n>>>\n>>> Instead of 'bla' you could go with 'format' as the man page for\n>>> [f]printf puts it.\n>>> Or you could leave it empty, i.e.\n>>>\n>>>     static void mute_routine(const char *, va_list)\n>>>     ...\n>>\n>> Ok to do that.\n> \n> Actually I get the following error when doing that:\n> \n> apply.c: In function ‘mute_routine’:\n> apply.c:115:1: error: parameter name omitted\n>  static void mute_routine(const char *, va_list)\n>  ^\n> apply.c:115:1: error: parameter name omitted\n> make: *** [apply.o] Error 1\n\nYes, this is not C++. ;-)\n\n> So I will leave it as is.\n\nI think I would prefer to see:\n\n    static void mute_routine(const char *msg, va_list params)\n\ngiven that it would either be an error-msg or a warning-msg.\n\nATB,\nRamsay Jones\n\n"},{"id":"301030","messageId":"CAP8UFD1Dssiw9=ME-084nXWd56X30vt1yEPYgyUnUjPsNcOVOw@mail.gmail.com","threadId":"43946","inReplyTo":"e39d9b83-949b-075c-07f6-60118dc24961@ramsayjones.plus.com","subject":"Re: [PATCH v13 10/14] apply: change error_routine when silent","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-09-04T16:45:53Z","receivedAt":"2016-09-04T16:46:00Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Sun, Sep 4, 2016 at 6:31 PM, Ramsay Jones\n<ramsay@ramsayjones.plus.com> wrote:\n>\n>\n> On 04/09/16 11:54, Christian Couder wrote:\n>> On Thu, Sep 1, 2016 at 10:19 AM, Christian Couder\n>> <christian.couder@gmail.com> wrote:\n>>> On Thu, Sep 1, 2016 at 12:20 AM, Stefan Beller <sbeller@google.com> wrote:\n>>>>>\n>>>>> +static void mute_routine(const char *bla, va_list params)\n>>>>\n>>>> Instead of 'bla' you could go with 'format' as the man page for\n>>>> [f]printf puts it.\n>>>> Or you could leave it empty, i.e.\n>>>>\n>>>>     static void mute_routine(const char *, va_list)\n>>>>     ...\n>>>\n>>> Ok to do that.\n>>\n>> Actually I get the following error when doing that:\n>>\n>> apply.c: In function ‘mute_routine’:\n>> apply.c:115:1: error: parameter name omitted\n>>  static void mute_routine(const char *, va_list)\n>>  ^\n>> apply.c:115:1: error: parameter name omitted\n>> make: *** [apply.o] Error 1\n>\n> Yes, this is not C++. ;-)\n>\n>> So I will leave it as is.\n>\n> I think I would prefer to see:\n>\n>     static void mute_routine(const char *msg, va_list params)\n>\n> given that it would either be an error-msg or a warning-msg.\n\nOk for \"msg\".\n"},{"id":"301033","messageId":"CAP8UFD3+=g+UqwkW7wUG3q3gmShg+6hw6SaGQ0-AfVEVJ6_w7w@mail.gmail.com","threadId":"43946","inReplyTo":"xmqqzinrwly4.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v13 00/14] libify apply and use lib in am, part 3","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-09-04T20:17:55Z","receivedAt":"2016-09-04T20:18:02Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Sep 1, 2016 at 7:48 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Christian Couder <christian.couder@gmail.com> writes:\n>\n>> Following Stefan's review, it looks like I will need to resend at\n>> least 02/14, 10/14 and 14/14.\n>> What do you prefer me to resend:\n>> 1) all the last 40 or so patches\n>> 2) the last 14 patches\n>> 3) only the few patches that changed\n>\n> If this reroll is to be the candidate to be the final one, I'd\n> prefer to see 1 to give an easy access to more sets of eyes, but if\n> you just send them without giving these patches one more read-over\n> before sending them out, it is not as valuable as it would be.\n\nOk, I will send the 41 patches very soon after having given them one\nmore read over and implementing the few changes suggested by Stefan\nand Ramsay and one improvement I spotted.\n\n> I think 2 is of the least value.\n>\n> If you do 3., pointing people at where the remainder of the series\n> can be found is necessary.\n\nThere is always a pointer to the full patch series on GitHub anyway in\nthe cover letter, but I will send everything anyway.\n"}]}