From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Karsten Blees" <karsten.blees@gmail.com>,
"Nguyen Thai Ngoc Duy" <pclouds@gmail.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Stefan Beller" <sbeller@google.com>,
"Matthieu Moy" <Matthieu.Moy@grenoble-inp.fr>,
"Christian Couder" <chriscool@tuxfamily.org>
Subject: [PATCH 39/83] builtin/apply: move 'ws_error_action' into 'struct apply_state'
Date: Sun, 24 Apr 2016 15:33:39 +0200 [thread overview]
Message-ID: <1461504863-15946-40-git-send-email-chriscool@tuxfamily.org> (raw)
In-Reply-To: <1461504863-15946-1-git-send-email-chriscool@tuxfamily.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin/apply.c | 62 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 34 insertions(+), 28 deletions(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index 52602af..7d91454 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -21,6 +21,13 @@
#include "ll-merge.h"
#include "rerere.h"
+enum ws_error_action {
+ nowarn_ws_error,
+ warn_on_ws_error,
+ die_on_ws_error,
+ correct_ws_error
+};
+
struct apply_state {
const char *prefix;
int prefix_length;
@@ -80,6 +87,8 @@ struct apply_state {
int whitespace_error;
int squelch_whitespace_errors;
int applied_after_fixing_ws;
+
+ enum ws_error_action ws_error_action;
};
static int newfd = -1;
@@ -89,12 +98,6 @@ static const char * const apply_usage[] = {
NULL
};
-static enum ws_error_action {
- nowarn_ws_error,
- warn_on_ws_error,
- die_on_ws_error,
- correct_ws_error
-} ws_error_action = warn_on_ws_error;
static enum ws_ignore {
ignore_ws_none,
@@ -105,28 +108,28 @@ static enum ws_ignore {
static void parse_whitespace_option(struct apply_state *state, const char *option)
{
if (!option) {
- ws_error_action = warn_on_ws_error;
+ state->ws_error_action = warn_on_ws_error;
return;
}
if (!strcmp(option, "warn")) {
- ws_error_action = warn_on_ws_error;
+ state->ws_error_action = warn_on_ws_error;
return;
}
if (!strcmp(option, "nowarn")) {
- ws_error_action = nowarn_ws_error;
+ state->ws_error_action = nowarn_ws_error;
return;
}
if (!strcmp(option, "error")) {
- ws_error_action = die_on_ws_error;
+ state->ws_error_action = die_on_ws_error;
return;
}
if (!strcmp(option, "error-all")) {
- ws_error_action = die_on_ws_error;
+ state->ws_error_action = die_on_ws_error;
state->squelch_whitespace_errors = 0;
return;
}
if (!strcmp(option, "strip") || !strcmp(option, "fix")) {
- ws_error_action = correct_ws_error;
+ state->ws_error_action = correct_ws_error;
return;
}
die(_("unrecognized whitespace option '%s'"), option);
@@ -150,7 +153,7 @@ static void parse_ignorewhitespace_option(const char *option)
static void set_default_whitespace_mode(struct apply_state *state)
{
if (!state->whitespace_option && !apply_default_whitespace)
- ws_error_action = (state->apply ? warn_on_ws_error : nowarn_ws_error);
+ state->ws_error_action = (state->apply ? warn_on_ws_error : nowarn_ws_error);
}
/*
@@ -1685,12 +1688,12 @@ static int parse_fragment(struct apply_state *state,
leading++;
trailing++;
if (!state->apply_in_reverse &&
- ws_error_action == correct_ws_error)
+ state->ws_error_action == correct_ws_error)
check_whitespace(state, line, len, patch->ws_rule);
break;
case '-':
if (state->apply_in_reverse &&
- ws_error_action != nowarn_ws_error)
+ state->ws_error_action != nowarn_ws_error)
check_whitespace(state, line, len, patch->ws_rule);
deleted++;
oldlines--;
@@ -1698,7 +1701,7 @@ static int parse_fragment(struct apply_state *state,
break;
case '+':
if (!state->apply_in_reverse &&
- ws_error_action != nowarn_ws_error)
+ state->ws_error_action != nowarn_ws_error)
check_whitespace(state, line, len, patch->ws_rule);
added++;
newlines--;
@@ -2411,7 +2414,8 @@ static int line_by_line_fuzzy_match(struct image *img,
return 1;
}
-static int match_fragment(struct image *img,
+static int match_fragment(struct apply_state *state,
+ struct image *img,
struct image *preimage,
struct image *postimage,
unsigned long try,
@@ -2432,7 +2436,7 @@ static int match_fragment(struct image *img,
preimage_limit = preimage->nr;
if (match_end && (preimage->nr + try_lno != img->nr))
return 0;
- } else if (ws_error_action == correct_ws_error &&
+ } else if (state->ws_error_action == correct_ws_error &&
(ws_rule & WS_BLANK_AT_EOF)) {
/*
* This hunk extends beyond the end of img, and we are
@@ -2505,7 +2509,7 @@ static int match_fragment(struct image *img,
return line_by_line_fuzzy_match(img, preimage, postimage,
try, try_lno, preimage_limit);
- if (ws_error_action != correct_ws_error)
+ if (state->ws_error_action != correct_ws_error)
return 0;
/*
@@ -2617,7 +2621,8 @@ static int match_fragment(struct image *img,
return 0;
}
-static int find_pos(struct image *img,
+static int find_pos(struct apply_state *state,
+ struct image *img,
struct image *preimage,
struct image *postimage,
int line,
@@ -2661,7 +2666,7 @@ static int find_pos(struct image *img,
try_lno = line;
for (i = 0; ; i++) {
- if (match_fragment(img, preimage, postimage,
+ if (match_fragment(state, img, preimage, postimage,
try, try_lno, ws_rule,
match_beginning, match_end))
return try_lno;
@@ -2874,7 +2879,7 @@ static int apply_one_fragment(struct apply_state *state,
start = newlines.len;
if (first != '+' ||
!state->whitespace_error ||
- ws_error_action != correct_ws_error) {
+ state->ws_error_action != correct_ws_error) {
strbuf_add(&newlines, patch + 1, plen);
}
else {
@@ -2952,7 +2957,7 @@ static int apply_one_fragment(struct apply_state *state,
for (;;) {
- applied_pos = find_pos(img, &preimage, &postimage, pos,
+ applied_pos = find_pos(state, img, &preimage, &postimage, pos,
ws_rule, match_beginning, match_end);
if (applied_pos >= 0)
@@ -2988,10 +2993,10 @@ static int apply_one_fragment(struct apply_state *state,
if (new_blank_lines_at_end &&
preimage.nr + applied_pos >= img->nr &&
(ws_rule & WS_BLANK_AT_EOF) &&
- ws_error_action != nowarn_ws_error) {
+ state->ws_error_action != nowarn_ws_error) {
record_ws_error(state, WS_BLANK_AT_EOF, "+", 1,
found_new_blank_lines_at_end);
- if (ws_error_action == correct_ws_error) {
+ if (state->ws_error_action == correct_ws_error) {
while (new_blank_lines_at_end--)
remove_last_line(&postimage);
}
@@ -3002,7 +3007,7 @@ static int apply_one_fragment(struct apply_state *state,
* apply_patch->check_patch_list->check_patch->
* apply_data->apply_fragments->apply_one_fragment
*/
- if (ws_error_action == die_on_ws_error)
+ if (state->ws_error_action == die_on_ws_error)
state->apply = 0;
}
@@ -4546,7 +4551,7 @@ static int apply_patch(struct apply_state *state,
if (!list && !skipped_patch)
die(_("unrecognized input"));
- if (state->whitespace_error && (ws_error_action == die_on_ws_error))
+ if (state->whitespace_error && (state->ws_error_action == die_on_ws_error))
state->apply = 0;
state->update_index = state->check_index && state->apply;
@@ -4738,6 +4743,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
state.p_value = 1;
state.p_context = UINT_MAX;
state.squelch_whitespace_errors = 5;
+ state.ws_error_action = warn_on_ws_error;
strbuf_init(&state.root, 0);
git_apply_config();
@@ -4806,7 +4812,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
squelched),
squelched);
}
- if (ws_error_action == die_on_ws_error)
+ if (state.ws_error_action == die_on_ws_error)
die(Q_("%d line adds whitespace errors.",
"%d lines add whitespace errors.",
state.whitespace_error),
--
2.8.1.300.g5fed0c0
next prev parent reply other threads:[~2016-04-24 13:36 UTC|newest]
Thread overview: 156+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-24 13:33 [PATCH 00/83] libify apply and use lib in am Christian Couder
2016-04-24 13:33 ` [PATCH 01/83] builtin/apply: make gitdiff_verify_name() return void Christian Couder
2016-04-24 13:33 ` [PATCH 02/83] builtin/apply: avoid parameter shadowing 'p_value' global Christian Couder
2016-04-24 13:33 ` [PATCH 03/83] builtin/apply: avoid parameter shadowing 'linenr' global Christian Couder
2016-04-27 16:27 ` Junio C Hamano
2016-04-27 17:07 ` Christian Couder
2016-04-24 13:33 ` [PATCH 04/83] builtin/apply: avoid local variable shadowing 'len' parameter Christian Couder
2016-04-24 13:33 ` [PATCH 05/83] builtin/apply: extract line_by_line_fuzzy_match() from match_fragment() Christian Couder
2016-04-25 18:50 ` Stefan Beller
2016-04-26 16:15 ` Christian Couder
2016-04-26 20:20 ` Junio C Hamano
2016-04-27 13:31 ` Christian Couder
2016-04-24 13:33 ` [PATCH 06/83] builtin/apply: move 'options' variable into cmd_apply() Christian Couder
2016-04-24 13:33 ` [PATCH 07/83] builtin/apply: introduce 'struct apply_state' to start libifying Christian Couder
2016-04-24 13:33 ` [PATCH 08/83] builtin/apply: move 'unidiff_zero' global into 'struct apply_state' Christian Couder
2016-04-24 13:33 ` [PATCH 09/83] builtin/apply: move 'check' " Christian Couder
2016-04-25 18:57 ` Stefan Beller
2016-04-26 16:26 ` Christian Couder
2016-04-26 16:31 ` Stefan Beller
2016-04-24 13:33 ` [PATCH 10/83] builtin/apply: move 'check_index' " Christian Couder
2016-04-26 20:25 ` Junio C Hamano
2016-04-24 13:33 ` [PATCH 11/83] builtin/apply: move 'apply_in_reverse' " Christian Couder
2016-04-24 13:33 ` [PATCH 12/83] builtin/apply: move 'apply_with_reject' " Christian Couder
2016-04-24 13:33 ` [PATCH 13/83] builtin/apply: move 'apply_verbosely' " Christian Couder
2016-04-24 13:33 ` [PATCH 14/83] builtin/apply: move 'update_index' " Christian Couder
2016-04-24 13:33 ` [PATCH 15/83] builtin/apply: move 'allow_overlap' " Christian Couder
2016-04-24 13:33 ` [PATCH 16/83] builtin/apply: move 'cached' " Christian Couder
2016-04-24 13:33 ` [PATCH 17/83] builtin/apply: move 'diffstat' " Christian Couder
2016-04-24 13:33 ` [PATCH 18/83] builtin/apply: move 'numstat' " Christian Couder
2016-04-25 21:40 ` Stefan Beller
2016-04-26 16:35 ` Christian Couder
2016-04-24 13:33 ` [PATCH 19/83] builtin/apply: move 'summary' " Christian Couder
2016-04-24 13:33 ` [PATCH 20/83] builtin/apply: move 'threeway' " Christian Couder
2016-04-24 13:33 ` [PATCH 21/83] builtin/apply: move 'no-add' " Christian Couder
2016-04-24 13:33 ` [PATCH 22/83] builtin/apply: move 'unsafe_paths' " Christian Couder
2016-04-26 20:27 ` Junio C Hamano
2016-04-27 12:14 ` Christian Couder
2016-04-27 15:26 ` Junio C Hamano
2016-04-24 13:33 ` [PATCH 23/83] builtin/apply: move 'line_termination' " Christian Couder
2016-04-24 13:33 ` [PATCH 24/83] builtin/apply: move 'fake_ancestor' " Christian Couder
2016-04-24 13:33 ` [PATCH 25/83] builtin/apply: move 'p_context' " Christian Couder
2016-04-24 13:33 ` [PATCH 26/83] builtin/apply: move 'apply' " Christian Couder
2016-04-24 13:33 ` [PATCH 27/83] builtin/apply: move 'read_stdin' global into cmd_apply() Christian Couder
2016-04-26 20:28 ` Junio C Hamano
2016-04-27 13:13 ` Christian Couder
2016-04-24 13:33 ` [PATCH 28/83] builtin/apply: move 'patch_input_file' global into 'struct apply_state' Christian Couder
2016-04-24 13:33 ` [PATCH 29/83] builtin/apply: move 'limit_by_name' " Christian Couder
2016-04-24 13:33 ` [PATCH 30/83] builtin/apply: move 'has_include' " Christian Couder
2016-04-24 13:33 ` [PATCH 31/83] builtin/apply: move 'p_value' " Christian Couder
2016-04-24 13:33 ` [PATCH 32/83] builtin/apply: move 'p_value_known' " Christian Couder
2016-04-24 13:33 ` [PATCH 33/83] builtin/apply: move 'root' " Christian Couder
2016-04-25 21:50 ` Stefan Beller
2016-04-25 21:54 ` Stefan Beller
2016-04-26 20:13 ` Christian Couder
2016-04-24 13:33 ` [PATCH 34/83] builtin/apply: move 'whitespace_error' " Christian Couder
2016-04-24 13:33 ` [PATCH 35/83] builtin/apply: move 'whitespace_option' " Christian Couder
2016-04-24 13:33 ` [PATCH 36/83] builtin/apply: remove whitespace_option arg from set_default_whitespace_mode() Christian Couder
2016-04-24 13:33 ` [PATCH 37/83] builtin/apply: move 'squelch_whitespace_errors' into 'struct apply_state' Christian Couder
2016-04-24 13:33 ` [PATCH 38/83] builtin/apply: move 'applied_after_fixing_ws' " Christian Couder
2016-04-24 13:33 ` Christian Couder [this message]
2016-04-26 20:36 ` [PATCH 39/83] builtin/apply: move 'ws_error_action' " Junio C Hamano
2016-04-26 20:40 ` Junio C Hamano
2016-04-27 13:23 ` Christian Couder
2016-04-24 13:33 ` [PATCH 40/83] builtin/apply: move 'ws_ignore_action' " Christian Couder
2016-04-24 13:33 ` [PATCH 41/83] builtin/apply: move 'max_change' and 'max_len' " Christian Couder
2016-04-24 13:33 ` [PATCH 42/83] builtin/apply: move 'linenr' global " Christian Couder
2016-04-24 13:33 ` [PATCH 43/83] builtin/apply: move 'fn_table' " Christian Couder
2016-04-24 13:33 ` [PATCH 44/83] builtin/apply: move 'symlink_changes' " Christian Couder
2016-04-24 13:33 ` [PATCH 45/83] builtin/apply: move 'state' init into init_apply_state() Christian Couder
2016-04-25 7:32 ` Eric Sunshine
2016-04-27 12:00 ` Christian Couder
2016-04-24 13:33 ` [PATCH 46/83] builtin/apply: move 'state' check into check_apply_state() Christian Couder
2016-04-24 13:33 ` [PATCH 47/83] builtin/apply: move applying patches into apply_all_patches() Christian Couder
2016-04-25 22:00 ` Stefan Beller
2016-04-27 15:51 ` Christian Couder
2016-04-24 13:33 ` [PATCH 48/83] builtin/apply: rename 'prefix_' parameter to 'prefix' Christian Couder
2016-04-24 13:33 ` [PATCH 49/83] builtin/apply: move 'lock_file' global into 'struct apply_state' Christian Couder
2016-04-25 7:50 ` Eric Sunshine
2016-04-25 17:55 ` Junio C Hamano
2016-04-28 16:30 ` Christian Couder
2016-04-28 20:17 ` Junio C Hamano
2016-04-30 19:39 ` Christian Couder
2016-04-24 13:33 ` [PATCH 50/83] builtin/apply: get rid of the 'newfd' global Christian Couder
2016-04-24 13:33 ` [PATCH 51/83] builtin/apply: make apply_patch() return -1 instead of die()ing Christian Couder
2016-04-26 1:20 ` Eric Sunshine
2016-04-30 19:41 ` Christian Couder
2016-04-24 13:33 ` [PATCH 52/83] builtin/apply: read_patch_file() " Christian Couder
2016-04-24 13:33 ` [PATCH 53/83] builtin/apply: make find_header() " Christian Couder
2016-04-25 13:18 ` Duy Nguyen
2016-04-27 18:10 ` Eric Sunshine
2016-05-01 16:53 ` Christian Couder
2016-04-27 18:08 ` Eric Sunshine
2016-05-01 16:45 ` Christian Couder
2016-04-24 13:33 ` [PATCH 54/83] builtin/apply: make parse_chunk() return a negative integer on error Christian Couder
2016-05-01 19:04 ` Eric Sunshine
2016-05-01 19:51 ` Christian Couder
2016-04-24 13:33 ` [PATCH 55/83] builtin/apply: make parse_single_patch() return -1 " Christian Couder
2016-05-01 19:32 ` Eric Sunshine
2016-04-24 13:33 ` [PATCH 56/83] apply: move 'struct apply_state' to apply.h Christian Couder
2016-04-24 13:33 ` [PATCH 57/83] builtin/apply: libify parse_whitespace_option() Christian Couder
2016-04-24 13:33 ` [PATCH 58/83] builtin/apply: libify parse_ignorewhitespace_option() Christian Couder
2016-04-24 13:33 ` [PATCH 59/83] builtin/apply: move init_apply_state() to apply.c Christian Couder
2016-05-01 19:37 ` Eric Sunshine
2016-05-01 20:19 ` Christian Couder
2016-04-24 13:34 ` [PATCH 60/83] apply: libify init_apply_state() Christian Couder
2016-04-24 13:34 ` [PATCH 61/83] builtin/apply: libify check_apply_state() Christian Couder
2016-04-25 13:26 ` Duy Nguyen
2016-05-01 16:58 ` Christian Couder
2016-04-24 13:34 ` [PATCH 62/83] builtin/apply: move check_apply_state() to apply.c Christian Couder
2016-04-24 13:34 ` [PATCH 63/83] builtin/apply: make apply_all_patches() return -1 on error Christian Couder
2016-04-25 13:30 ` Duy Nguyen
2016-05-01 18:32 ` Christian Couder
2016-05-01 21:03 ` Eric Sunshine
2016-05-02 7:09 ` Johannes Schindelin
2016-05-03 13:01 ` Christian Couder
2016-04-24 13:34 ` [PATCH 64/83] builtin/apply: make parse_traditional_patch() " Christian Couder
2016-04-24 13:34 ` [PATCH 65/83] builtin/apply: make gitdiff_verify_name() " Christian Couder
2016-04-25 13:36 ` Duy Nguyen
2016-05-01 19:31 ` Christian Couder
2016-04-24 13:34 ` [PATCH 66/83] builtin/apply: change die_on_unsafe_path() to check_unsafe_path() Christian Couder
2016-04-24 13:34 ` [PATCH 67/83] builtin/apply: make build_fake_ancestor() return -1 on error Christian Couder
2016-05-02 7:32 ` Eric Sunshine
2016-05-03 13:52 ` Christian Couder
2016-04-24 13:34 ` [PATCH 68/83] builtin/apply: make remove_file() " Christian Couder
2016-04-24 13:34 ` [PATCH 69/83] builtin/apply: make add_conflicted_stages_file() " Christian Couder
2016-05-02 7:36 ` Eric Sunshine
2016-05-03 14:33 ` Christian Couder
2016-04-24 13:34 ` [PATCH 70/83] builtin/apply: make add_index_file() " Christian Couder
2016-04-24 13:34 ` [PATCH 71/83] builtin/apply: make create_file() " Christian Couder
2016-04-24 13:34 ` [PATCH 72/83] builtin/apply: make write_out_one_result() " Christian Couder
2016-04-24 13:34 ` [PATCH 73/83] builtin/apply: make write_out_results() " Christian Couder
2016-05-02 17:42 ` Eric Sunshine
2016-05-03 14:55 ` Christian Couder
2016-04-24 13:34 ` [PATCH 74/83] builtin/apply: make try_create_file() " Christian Couder
2016-05-02 18:01 ` Eric Sunshine
2016-05-03 16:24 ` Christian Couder
2016-04-24 13:34 ` [PATCH 75/83] builtin/apply: make create_one_file() " Christian Couder
2016-04-24 13:34 ` [PATCH 76/83] builtin/apply: rename option parsing functions Christian Couder
2016-04-24 13:34 ` [PATCH 77/83] apply: rename and move opt constants to apply.h Christian Couder
2016-04-24 15:23 ` [PATCH 00/83] libify apply and use lib in am Ramsay Jones
2016-04-24 16:27 ` Christian Couder
2016-04-24 16:56 ` Christian Couder
2016-04-24 17:42 ` Ramsay Jones
2016-04-25 0:14 ` Duy Nguyen
2016-04-25 9:15 ` Christian Couder
2016-04-25 15:09 ` Johannes Schindelin
2016-04-25 9:02 ` Duy Nguyen
2016-04-25 9:57 ` Christian Couder
2016-04-25 10:11 ` Duy Nguyen
[not found] ` <1461504863-15946-79-git-send-email-chriscool@tuxfamily.org>
2016-04-25 13:46 ` [PATCH 78/83] Move libified code from builtin/apply.c to apply.{c,h} Duy Nguyen
2016-05-04 10:39 ` Christian Couder
2016-05-04 11:32 ` Duy Nguyen
2016-05-05 8:50 ` Christian Couder
2016-05-06 20:18 ` Christian Couder
2016-05-06 21:07 ` Junio C Hamano
2016-05-08 20:11 ` Christian Couder
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461504863-15946-40-git-send-email-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=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).