git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Nguyen Thai Ngoc Duy" <pclouds@gmail.com>,
	"Stefan Beller" <sbeller@google.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Ramsay Jones" <ramsay@ramsayjones.plus.com>,
	"Jeff King" <peff@peff.net>,
	"Karsten Blees" <karsten.blees@gmail.com>,
	"Matthieu Moy" <Matthieu.Moy@grenoble-inp.fr>,
	"Christian Couder" <chriscool@tuxfamily.org>
Subject: [PATCH v2 47/94] builtin/apply: move applying patches into apply_all_patches()
Date: Wed, 11 May 2016 15:16:58 +0200	[thread overview]
Message-ID: <20160511131745.2914-48-chriscool@tuxfamily.org> (raw)
In-Reply-To: <20160511131745.2914-1-chriscool@tuxfamily.org>

To libify the apply functionality we should provide a function to
apply many patches. Let's move the code to do that into a new
apply_all_patches() function.

Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/apply.c | 128 ++++++++++++++++++++++++++++++--------------------------
 1 file changed, 69 insertions(+), 59 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index e5f76d8..67c64a5 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -4709,13 +4709,79 @@ static void check_apply_state(struct apply_state *state, int force_apply)
 		state->unsafe_paths = 0;
 }
 
-int cmd_apply(int argc, const char **argv, const char *prefix_)
+static int apply_all_patches(struct apply_state *state,
+			     int argc,
+			     const char **argv,
+			     int options)
 {
 	int i;
 	int errs = 0;
+	int read_stdin = 1;
+
+	for (i = 0; i < argc; i++) {
+		const char *arg = argv[i];
+		int fd;
+
+		if (!strcmp(arg, "-")) {
+			errs |= apply_patch(state, 0, "<stdin>", options);
+			read_stdin = 0;
+			continue;
+		} else if (0 < state->prefix_length)
+			arg = prefix_filename(state->prefix,
+					      state->prefix_length,
+					      arg);
+
+		fd = open(arg, O_RDONLY);
+		if (fd < 0)
+			die_errno(_("can't open patch '%s'"), arg);
+		read_stdin = 0;
+		set_default_whitespace_mode(state);
+		errs |= apply_patch(state, fd, arg, options);
+		close(fd);
+	}
+	set_default_whitespace_mode(state);
+	if (read_stdin)
+		errs |= apply_patch(state, 0, "<stdin>", options);
+
+	if (state->whitespace_error) {
+		if (state->squelch_whitespace_errors &&
+		    state->squelch_whitespace_errors < state->whitespace_error) {
+			int squelched =
+				state->whitespace_error - state->squelch_whitespace_errors;
+			warning(Q_("squelched %d whitespace error",
+				   "squelched %d whitespace errors",
+				   squelched),
+				squelched);
+		}
+		if (state->ws_error_action == die_on_ws_error)
+			die(Q_("%d line adds whitespace errors.",
+			       "%d lines add whitespace errors.",
+			       state->whitespace_error),
+			    state->whitespace_error);
+		if (state->applied_after_fixing_ws && state->apply)
+			warning("%d line%s applied after"
+				" fixing whitespace errors.",
+				state->applied_after_fixing_ws,
+				state->applied_after_fixing_ws == 1 ? "" : "s");
+		else if (state->whitespace_error)
+			warning(Q_("%d line adds whitespace errors.",
+				   "%d lines add whitespace errors.",
+				   state->whitespace_error),
+				state->whitespace_error);
+	}
+
+	if (state->update_index) {
+		if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
+			die(_("Unable to write new index file"));
+	}
+
+	return !!errs;
+}
+
+int cmd_apply(int argc, const char **argv, const char *prefix_)
+{
 	int force_apply = 0;
 	int options = 0;
-	int read_stdin = 1;
 	struct apply_state state;
 
 	struct option builtin_apply_options[] = {
@@ -4794,61 +4860,5 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
 
 	check_apply_state(&state, force_apply);
 
-	for (i = 0; i < argc; i++) {
-		const char *arg = argv[i];
-		int fd;
-
-		if (!strcmp(arg, "-")) {
-			errs |= apply_patch(&state, 0, "<stdin>", options);
-			read_stdin = 0;
-			continue;
-		} else if (0 < state.prefix_length)
-			arg = prefix_filename(state.prefix,
-					      state.prefix_length,
-					      arg);
-
-		fd = open(arg, O_RDONLY);
-		if (fd < 0)
-			die_errno(_("can't open patch '%s'"), arg);
-		read_stdin = 0;
-		set_default_whitespace_mode(&state);
-		errs |= apply_patch(&state, fd, arg, options);
-		close(fd);
-	}
-	set_default_whitespace_mode(&state);
-	if (read_stdin)
-		errs |= apply_patch(&state, 0, "<stdin>", options);
-	if (state.whitespace_error) {
-		if (state.squelch_whitespace_errors &&
-		    state.squelch_whitespace_errors < state.whitespace_error) {
-			int squelched =
-				state.whitespace_error - state.squelch_whitespace_errors;
-			warning(Q_("squelched %d whitespace error",
-				   "squelched %d whitespace errors",
-				   squelched),
-				squelched);
-		}
-		if (state.ws_error_action == die_on_ws_error)
-			die(Q_("%d line adds whitespace errors.",
-			       "%d lines add whitespace errors.",
-			       state.whitespace_error),
-			    state.whitespace_error);
-		if (state.applied_after_fixing_ws && state.apply)
-			warning("%d line%s applied after"
-				" fixing whitespace errors.",
-				state.applied_after_fixing_ws,
-				state.applied_after_fixing_ws == 1 ? "" : "s");
-		else if (state.whitespace_error)
-			warning(Q_("%d line adds whitespace errors.",
-				   "%d lines add whitespace errors.",
-				   state.whitespace_error),
-				state.whitespace_error);
-	}
-
-	if (state.update_index) {
-		if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
-			die(_("Unable to write new index file"));
-	}
-
-	return !!errs;
+	return apply_all_patches(&state, argc, argv, options);
 }
-- 
2.8.2.490.g3dabe57

  parent reply	other threads:[~2016-05-11 13:20 UTC|newest]

Thread overview: 148+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-11 13:16 [PATCH v2 00/94] libify apply and use lib in am Christian Couder
2016-05-11 13:16 ` [PATCH v2 01/94] builtin/apply: make gitdiff_verify_name() return void Christian Couder
2016-05-12 19:06   ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 02/94] builtin/apply: avoid parameter shadowing 'p_value' global Christian Couder
2016-05-12 19:09   ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 03/94] builtin/apply: avoid parameter shadowing 'linenr' global Christian Couder
2016-05-12 19:11   ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 04/94] builtin/apply: avoid local variable shadowing 'len' parameter Christian Couder
2016-05-11 13:16 ` [PATCH v2 05/94] builtin/apply: extract line_by_line_fuzzy_match() from match_fragment() Christian Couder
2016-05-12 19:20   ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 06/94] builtin/apply: move 'options' variable into cmd_apply() Christian Couder
2016-05-11 13:16 ` [PATCH v2 07/94] builtin/apply: move 'read_stdin' global " Christian Couder
2016-05-11 13:16 ` [PATCH v2 08/94] builtin/apply: introduce 'struct apply_state' to start libifying Christian Couder
2016-05-11 13:16 ` [PATCH v2 09/94] builtin/apply: move 'state' init into init_apply_state() Christian Couder
2016-05-12 19:25   ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 10/94] builtin/apply: move 'unidiff_zero' global into 'struct apply_state' Christian Couder
2016-05-12 19:28   ` Junio C Hamano
2016-05-12 20:18     ` Christian Couder
2016-05-11 13:16 ` [PATCH v2 11/94] builtin/apply: move 'check' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 12/94] builtin/apply: move 'check_index' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 13/94] builtin/apply: move 'apply_in_reverse' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 14/94] builtin/apply: move 'apply_with_reject' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 15/94] builtin/apply: move 'apply_verbosely' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 16/94] builtin/apply: move 'update_index' " Christian Couder
2016-05-12 19:31   ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 17/94] builtin/apply: move 'allow_overlap' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 18/94] builtin/apply: move 'cached' " Christian Couder
2016-05-12 19:33   ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 19/94] builtin/apply: move 'diffstat' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 20/94] builtin/apply: move 'numstat' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 21/94] builtin/apply: move 'summary' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 22/94] builtin/apply: move 'threeway' " Christian Couder
2016-05-12 19:41   ` Junio C Hamano
2016-05-12 20:26     ` Christian Couder
2016-05-12 21:21       ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 23/94] builtin/apply: move 'no_add' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 24/94] builtin/apply: move 'unsafe_paths' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 25/94] builtin/apply: move 'line_termination' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 26/94] builtin/apply: move 'fake_ancestor' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 27/94] builtin/apply: move 'p_context' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 28/94] builtin/apply: move 'apply' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 29/94] builtin/apply: move 'patch_input_file' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 30/94] builtin/apply: move 'limit_by_name' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 31/94] builtin/apply: move 'has_include' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 32/94] builtin/apply: move 'p_value' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 33/94] builtin/apply: move 'p_value_known' " Christian Couder
2016-05-12 19:43   ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 34/94] builtin/apply: move 'root' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 35/94] builtin/apply: move 'whitespace_error' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 36/94] builtin/apply: move 'whitespace_option' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 37/94] builtin/apply: remove whitespace_option arg from set_default_whitespace_mode() Christian Couder
2016-05-11 13:16 ` [PATCH v2 38/94] builtin/apply: move 'squelch_whitespace_errors' into 'struct apply_state' Christian Couder
2016-05-11 13:16 ` [PATCH v2 39/94] builtin/apply: move 'applied_after_fixing_ws' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 40/94] builtin/apply: move 'ws_error_action' " Christian Couder
2016-05-12 19:48   ` Junio C Hamano
2016-05-11 13:16 ` [PATCH v2 41/94] builtin/apply: move 'ws_ignore_action' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 42/94] builtin/apply: move 'max_change' and 'max_len' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 43/94] builtin/apply: move 'state_linenr' global " Christian Couder
2016-05-11 13:16 ` [PATCH v2 44/94] builtin/apply: move 'fn_table' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 45/94] builtin/apply: move 'symlink_changes' " Christian Couder
2016-05-11 13:16 ` [PATCH v2 46/94] builtin/apply: move 'state' check into check_apply_state() Christian Couder
2016-05-11 13:16 ` Christian Couder [this message]
2016-05-11 13:16 ` [PATCH v2 48/94] builtin/apply: rename 'prefix_' parameter to 'prefix' Christian Couder
2016-05-12 19:56   ` Junio C Hamano
2016-05-12 20:43     ` Junio C Hamano
2016-05-13 19:45       ` Christian Couder
2016-05-14 18:27         ` Junio C Hamano
2016-05-24  8:24           ` Christian Couder
2016-05-13 19:42     ` Christian Couder
2016-05-24  8:15       ` Christian Couder
2016-05-11 13:17 ` [PATCH v2 49/94] builtin/apply: move 'lock_file' global into 'struct apply_state' Christian Couder
2016-05-11 13:17 ` [PATCH v2 50/94] builtin/apply: move 'newfd' " Christian Couder
2016-05-11 13:17 ` [PATCH v2 51/94] builtin/apply: make apply_patch() return -1 instead of die()ing Christian Couder
2016-05-11 13:17 ` [PATCH v2 52/94] builtin/apply: read_patch_file() " Christian Couder
2016-05-16  1:56   ` Eric Sunshine
2016-05-16 17:19     ` Christian Couder
2016-05-11 13:17 ` [PATCH v2 53/94] builtin/apply: make find_header() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 54/94] builtin/apply: make parse_chunk() return a negative integer on error Christian Couder
2016-05-16  3:04   ` Eric Sunshine
2016-05-16 18:19     ` Christian Couder
2016-06-08 15:14     ` Christian Couder
2016-05-11 13:17 ` [PATCH v2 55/94] builtin/apply: make parse_single_patch() return -1 " Christian Couder
2016-05-11 13:17 ` [PATCH v2 56/94] apply: move 'struct apply_state' to apply.h Christian Couder
2016-05-16  3:10   ` Eric Sunshine
2016-05-16 16:03     ` Junio C Hamano
2016-06-08 15:25       ` Christian Couder
2016-05-11 13:17 ` [PATCH v2 57/94] builtin/apply: make parse_whitespace_option() return -1 instead of die()ing Christian Couder
2016-05-11 13:17 ` [PATCH v2 58/94] builtin/apply: make parse_ignorewhitespace_option() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 59/94] builtin/apply: move init_apply_state() to apply.c Christian Couder
2016-05-16  3:16   ` Eric Sunshine
2016-05-11 13:17 ` [PATCH v2 60/94] apply: make init_apply_state() return -1 instead of exit()ing Christian Couder
2016-05-16  3:37   ` Eric Sunshine
2016-05-11 13:17 ` [PATCH v2 61/94] builtin/apply: make check_apply_state() return -1 instead of die()ing Christian Couder
2016-05-11 13:17 ` [PATCH v2 62/94] builtin/apply: move check_apply_state() to apply.c Christian Couder
2016-05-11 13:17 ` [PATCH v2 63/94] builtin/apply: make apply_all_patches() return -1 on error Christian Couder
2016-05-16  3:44   ` Eric Sunshine
2016-06-08 16:37     ` Christian Couder
2016-06-08 17:44       ` Eric Sunshine
2016-06-09 22:01         ` Christian Couder
2016-05-11 13:17 ` [PATCH v2 64/94] builtin/apply: make parse_traditional_patch() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 65/94] builtin/apply: make gitdiff_*() return 1 at end of header Christian Couder
2016-05-11 13:17 ` [PATCH v2 66/94] builtin/apply: make gitdiff_*() return -1 on error Christian Couder
2016-05-11 13:17 ` [PATCH v2 67/94] builtin/apply: change die_on_unsafe_path() to check_unsafe_path() Christian Couder
2016-05-11 13:17 ` [PATCH v2 68/94] builtin/apply: make build_fake_ancestor() return -1 on error Christian Couder
2016-05-11 13:17 ` [PATCH v2 69/94] builtin/apply: make remove_file() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 70/94] builtin/apply: make add_conflicted_stages_file() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 71/94] builtin/apply: make add_index_file() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 72/94] builtin/apply: make create_file() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 73/94] builtin/apply: make write_out_one_result() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 74/94] builtin/apply: make write_out_results() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 75/94] builtin/apply: make try_create_file() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 76/94] builtin/apply: make create_one_file() " Christian Couder
2016-05-11 13:17 ` [PATCH v2 77/94] builtin/apply: rename option parsing functions Christian Couder
2016-05-11 13:17 ` [PATCH v2 78/94] apply: rename and move opt constants to apply.h Christian Couder
2016-05-11 13:17 ` [PATCH v2 80/94] apply: make some parsing functions static again Christian Couder
2016-05-11 13:17 ` [PATCH v2 81/94] run-command: make dup_devnull() non static Christian Couder
2016-05-11 13:17 ` [PATCH v2 82/94] apply: roll back index lock file in case of error Christian Couder
2016-05-11 13:17 ` [PATCH v2 83/94] environment: add set_index_file() Christian Couder
2016-05-11 13:17 ` [PATCH v2 84/94] builtin/am: use apply api in run_apply() Christian Couder
2016-05-11 13:17 ` [PATCH v2 85/94] write_or_die: use warning() instead of fprintf(stderr, ...) Christian Couder
2016-05-11 13:17 ` [PATCH v2 86/94] apply: add 'be_silent' variable to 'struct apply_state' Christian Couder
2016-05-11 13:17 ` [PATCH v2 87/94] apply: make 'be_silent' incomatible with 'apply_verbosely' Christian Couder
2016-05-11 13:17 ` [PATCH v2 88/94] apply: don't print on stdout when be_silent is set Christian Couder
2016-05-11 13:17 ` [PATCH v2 89/94] usage: add set_warn_routine() Christian Couder
2016-05-11 13:17 ` [PATCH v2 90/94] usage: add get_error_routine() and get_warn_routine() Christian Couder
2016-05-11 13:17 ` [PATCH v2 91/94] apply: change error_routine when be_silent is set Christian Couder
2016-05-11 13:17 ` [PATCH v2 92/94] am: use be_silent in 'struct apply_state' to shut up applying patches Christian Couder
2016-05-11 13:17 ` [PATCH v2 93/94] run-command: make dup_devnull() static again Christian Couder
2016-05-11 13:17 ` [PATCH v2 94/94] builtin/apply: add a cli option for be_silent Christian Couder
2016-05-12 17:06 ` [PATCH v2 00/94] libify apply and use lib in am Johannes Sixt
2016-05-12 18:02   ` Christian Couder
2016-06-09 21:10     ` Johannes Sixt
2016-06-10  6:40       ` Christian Couder
2016-06-10  7:01       ` Johannes Schindelin
2016-06-10  8:59         ` Christian Couder
2016-06-10 11:11           ` Johannes Schindelin
2016-06-10 17:04             ` Johannes Sixt
2016-06-10 20:31               ` Christian Couder
2016-06-11  7:02               ` Johannes Schindelin
2016-05-12 19:04   ` Junio C Hamano
2016-05-12 20:05     ` Christian Couder
2016-05-13  6:32 ` Johannes Schindelin
2016-05-13 18:49   ` Christian Couder
2016-05-14  6:26     ` Johannes Schindelin
2016-05-14  9:19       ` Christian Couder
2016-05-14 18:31         ` Junio C Hamano
2016-05-14 19:37           ` Christian Couder
2016-05-15 18:30             ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160511131745.2914-48-chriscool@tuxfamily.org \
    --to=christian.couder@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=avarab@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karsten.blees@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=sbeller@google.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).