Re: [PATCH 00/83] libify apply and use lib in am

2016-04-24 Thread Christian Couder
On Sun, Apr 24, 2016 at 6:27 PM, Christian Couder wrote: > On Sun, Apr 24, 2016 at 5:23 PM, Ramsay Jones > wrote: >> >> >> On 24/04/16 14:33, Christian Couder wrote: >>> This is a patch series about libifying `git apply` functionality, and >>> using t

Re: [PATCH 00/83] libify apply and use lib in am

2016-04-24 Thread Christian Couder
On Sun, Apr 24, 2016 at 5:23 PM, Ramsay Jones wrote: > > > On 24/04/16 14:33, Christian Couder wrote: >> This is a patch series about libifying `git apply` functionality, and >> using this libified functionality in `git am`, so that no 'git apply' >> process

Re: [PATCH 00/83] libify apply and use lib in am

2016-04-24 Thread Ramsay Jones
On 24/04/16 14:33, Christian Couder wrote: > This is a patch series about libifying `git apply` functionality, and > using this libified functionality in `git am`, so that no 'git apply' > process is spawn anymore. This makes `git am` significantly faster, so > `git rebase

[PATCH 26/83] builtin/apply: move 'apply' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
apply_state { const char *prefix; int prefix_length; + int apply; int allow_overlap; int apply_in_reverse; int apply_with_reject; @@ -71,7 +72,7 @@ static int newfd = -1; static int state_p_value = 1; static int p_value_known; -static int apply = 1

[PATCH 15/83] builtin/apply: move 'allow_overlap' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
char *prefix; int prefix_length; + int allow_overlap; int apply_in_reverse; int apply_with_reject; int apply_verbosely; @@ -58,7 +59,6 @@ static int diffstat; static int numstat; static int summary; static int apply = 1; -static int allow_overlap; static int

[PATCH 16/83] builtin/apply: move 'cached' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
modified, but doesn't apply the patch @@ -48,13 +51,11 @@ struct apply_state { * --stat does just a diffstat, and doesn't actually apply * --numstat does numeric diffstat, and doesn't actually apply * --index-info shows the old and new index info for paths if available

[PATCH 04/83] builtin/apply: avoid local variable shadowing 'len' parameter

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 7115dc2..78849e4 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -2194,17 +2194,17 @@ static void update_pre

[PATCH 14/83] builtin/apply: move 'update_index' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
se == 1) { if (write_out_one_reject(state, l)) errs = 1; @@ -4458,8 +4466,8 @@ static int apply_patch(struct apply_state *state, if (whitespace_error && (ws_error_action == die_on_ws_error)) apply = 0; - upda

[PATCH 05/83] builtin/apply: extract line_by_line_fuzzy_match() from match_fragment()

2016-04-24 Thread Christian Couder
The match_fragment() function is very big and contains a big special case algorithm that does line by line fuzzy matching. So let's extract this algorithm in a separate line_by_line_fuzzy_match() function. Signed-off-by: Christian Couder --- builtin/apply.c | 129

[PATCH 79/83] apply: make some parsing functions static again

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- apply.c | 6 +++--- apply.h | 5 - 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/apply.c b/apply.c index 99b7a2d..86e0d20 100644 --- a/apply.c +++ b/apply.c @@ -27,7 +27,7 @@ static void git_apply_config(void) git_config(git_default

[PATCH 81/83] apply: roll back index in case of error

2016-04-24 Thread Christian Couder
state->whitespace_error), state->whitespace_error); + } if (state->applied_after_fixing_ws && state->apply) warning("%d line%s applied after"

[PATCH 30/83] builtin/apply: move 'has_include' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index c8b9bf0..0717cd2 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -70,6 +70,7 @@ struct apply_state { const char *patc

[PATCH 07/83] builtin/apply: introduce 'struct apply_state' to start libifying

2016-04-24 Thread Christian Couder
Currently commands that want to use the apply functionality have to launch a "git apply" process which can be bad for performance. Let's start libifying the apply functionality and to do that we first need to get rid of the global variables in "builtin/apply.c". This

[PATCH 22/83] builtin/apply: move 'unsafe_paths' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
unidiff_zero; int update_index; + + int unsafe_paths; }; /* @@ -67,7 +69,6 @@ static int newfd = -1; static int state_p_value = 1; static int p_value_known; static int apply = 1; -static int unsafe_paths; static const char *fake_ancestor; static int line_termination = '\n'

[PATCH 18/83] builtin/apply: move 'numstat' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
does just a diffstat, and doesn't actually apply */ int diffstat; + /* --numstat does numeric diffstat, and doesn't actually apply */ + int numstat; + /* * --check turns on checking that the working tree matches the *files that are bein

[PATCH 11/83] builtin/apply: move 'apply_in_reverse' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
@@ struct apply_state { const char *prefix; int prefix_length; + int apply_in_reverse; + /* * --check turns on checking that the working tree matches the *files that are being modified, but doesn't apply the patch @@ -53,7 +55,6 @@ stati

[PATCH 83/83] builtin/am: use apply api in run_apply()

2016-04-24 Thread Christian Couder
This replaces run_apply() implementation with a new one that uses the apply api that has been previously prepared in apply.c and apply.h. This shoud improve performance a lot in certain cases. As the previous implementation was creating a new `git apply` process to apply each patch, it could be

[PATCH 20/83] builtin/apply: move 'threeway' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
summary; + int threeway; + /* * --check turns on checking that the working tree matches the *files that are being modified, but doesn't apply the patch @@ -64,7 +66,6 @@ static int state_p_value = 1; static int p_value_known; static int apply = 1; s

[PATCH 09/83] builtin/apply: move 'check' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
{ const char *prefix; int prefix_length; + /* +* --check turns on checking that the working tree matches the +*files that are being modified, but doesn't apply the patch +*/ + int check; int unidiff_zero; }; /* - * --check turns on che

[PATCH 56/83] apply: move 'struct apply_state' to apply.h

2016-04-24 Thread Christian Couder
+struct apply_state { + const char *prefix; + int prefix_length; + + /* +* Since lockfile.c keeps a linked list of all created +* lock_file structures, it isn't safe to free(lock_file). +*/ + struct lock_file *lock_file; + + int apply; + int a

[PATCH 75/83] builtin/apply: make create_one_file() return -1 on error

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 36 +--- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 32c38f0..5bd5154 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4184,32 +4184,36 @@ static

[PATCH 63/83] builtin/apply: make apply_all_patches() return -1 on error

2016-04-24 Thread Christian Couder
ce_error), - state->whitespace_error); + return error(Q_("%d line adds whitespace errors.", + "%d lines add whitespace errors.", + state->whit

[PATCH 48/83] builtin/apply: rename 'prefix_' parameter to 'prefix'

2016-04-24 Thread Christian Couder
ate->prefix = prefix; state->prefix_length = state->prefix ? strlen(state->prefix) : 0; state->apply = 1; state->line_termination = '\n'; @@ -4789,7 +4789,7 @@ static int apply_all_patches(struct apply_state *state, return !!errs; } -int

[PATCH 29/83] builtin/apply: move 'limit_by_name' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
struct option builtin_apply_options[] = { - { OPTION_CALLBACK, 0, "exclude", NULL, N_("path"), + { OPTION_CALLBACK, 0, "exclude", &state, N_("path"), N_("don't apply changes matching the given path"),

[PATCH 27/83] builtin/apply: move 'read_stdin' global into cmd_apply()

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/apply.c b/builtin/apply.c index 699cabf..be237d1 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -96,7 +96,6 @@ static enum ws_ignore { static const char *patch

[PATCH 74/83] builtin/apply: make try_create_file() return -1 on error

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 38 ++ 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 49ef4c9..32c38f0 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4136,6 +4136,12 @@ static

[PATCH 40/83] builtin/apply: move 'ws_ignore_action' into 'struct apply_state'

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 37 - 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 7d91454..fa07b33 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -28,6 +28,12 @@ enum ws_er

[PATCH 42/83] builtin/apply: move 'linenr' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
nenr); + die(_("unable to find filename in patch at line %d"), state->linenr); } static int gitdiff_hdrend(struct apply_state *state, @@ -986,17 +986,17 @@ static void gitdiff_verify_name(struct apply_state *state, char *another;

[PATCH 35/83] builtin/apply: move 'whitespace_option' into 'struct apply_state'

2016-04-24 Thread Christian Couder
;, &state, N_("path"), N_("don't apply changes matching the given path"), @@ -4703,7 +4702,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix_) N_("paths are separated with NUL character"), 

[PATCH 55/83] builtin/apply: make parse_single_patch() return -1 on error

2016-04-24 Thread Christian Couder
patch); + if (patchsize < 0) + return -1; + if (!patchsize) { static const char git_binary[] = "GIT binary patch\n"; int hd = hdrsize + offset; diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binar

[PATCH 66/83] builtin/apply: change die_on_unsafe_path() to check_unsafe_path()

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 11 ++- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 268356b..8b7a8e0 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -3699,7 +3699,7 @@ static int path_is_beyond_symlink(s

[PATCH 34/83] builtin/apply: move 'whitespace_error' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
action == die_on_ws_error)) + if (state->whitespace_error && (ws_error_action == die_on_ws_error)) state->apply = 0; state->update_index = state->check_index && state->apply; @@ -4797,11 +4798,11 @@ int cmd_apply(int argc, const ch

[PATCH 41/83] builtin/apply: move 'max_change' and 'max_len' into 'struct apply_state'

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 49 + 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index fa07b33..bb58174 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -78,6 +78,14 @

[PATCH 31/83] builtin/apply: move 'p_value' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
d gitdiff_verify_name(const char *line, int isnull, char **name, int s if (isnull) die(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"), *name, linenr); - another = find_name(line, NULL

[PATCH 73/83] builtin/apply: make write_out_results() return -1 on error

2016-04-24 Thread Christian Couder
write_out_one_reject(struct apply_state *state, struct patch *patch) return -1; } +/* + * Returns: + * -1 if an error happened + * 0 if the patch applied cleanly + * 1 if the patch did not apply cleanly + */ static int write_out_results(struct apply_state *state, struct patch *list

[PATCH 57/83] builtin/apply: libify parse_whitespace_option()

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 23 --- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 1c1ac7d..8d96f70 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -27,34 +27,34 @@ static const char * con

[PATCH 71/83] builtin/apply: make create_file() return -1 on error

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 25 + 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index e021fad..ebac9ee 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4253,7 +4253,7 @@ static int add_conf

[PATCH 65/83] builtin/apply: make gitdiff_verify_name() return -1 on error

2016-04-24 Thread Christian Couder
L, state->p_value, TERM_TAB); - return; + return 0; } if (*name) { int len = strlen(*name); char *another; if (isnull) - die(_("git apply: bad git-diff - expected /dev/null, g

[PATCH 38/83] builtin/apply: move 'applied_after_fixing_ws' into 'struct apply_state'

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 259f256..52602af 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -79,6 +79,7 @@ struct apply_state { const char

[PATCH 45/83] builtin/apply: move 'state' init into init_apply_state()

2016-04-24 Thread Christian Couder
len(state->prefix) : 0; + state->apply = 1; + state->line_termination = '\n'; + state->p_value = 1; + state->p_context = UINT_MAX; + state->squelch_whitespace_errors = 5; + state->ws_error_action = warn_on_ws_error; +

[PATCH 54/83] builtin/apply: make parse_chunk() return a negative integer on error

2016-04-24 Thread Christian Couder
@@ -2185,8 +2185,9 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si * empty to us here. */ if ((state->apply || state->check) && - (!patch->is_binary && !metadata_cha

[PATCH 44/83] builtin/apply: move 'symlink_changes' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 50 -- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index b4c2bd8..8508607 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -34,6 +34,20

[PATCH 43/83] builtin/apply: move 'fn_table' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 45 +++-- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index f387340..b4c2bd8 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -93,6 +93,12 @@ st

[PATCH 69/83] builtin/apply: make add_conflicted_stages_file() return -1 on error

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 16 ++-- 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 89118c1..5a5be49 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4210,7 +4210,7 @@ static void create_one_file(s

[PATCH 51/83] builtin/apply: make apply_patch() return -1 instead of die()ing

2016-04-24 Thread Christian Couder
To libify `git apply` functionality we have to signal errors to the caller instead of die()ing. As a first step in this direction, let's make apply_patch() return -1 in case of errors instead of dying. For now its only caller apply_all_patches() will exit(1) when apply_patch() return -1.

[PATCH 76/83] builtin/apply: rename option parsing functions

2016-04-24 Thread Christian Couder
As these functions are going to be part of the libified apply api, let's give them a name that is more specific to the apply api. Signed-off-by: Christian Couder --- builtin/apply.c | 40 1 file changed, 20 insertions(+), 20 deletions(-) diff --

[PATCH 52/83] builtin/apply: read_patch_file() return -1 instead of die()ing

2016-04-24 Thread Christian Couder
*output, const char *fmt, struct patch *patch) #define SLOP (16) -static void read_patch_file(struct strbuf *sb, int fd) +static int read_patch_file(struct strbuf *sb, int fd) { if (strbuf_read(sb, fd, 0) < 0) - die_errno("git apply: failed to read"); +

[PATCH 50/83] builtin/apply: get rid of the 'newfd' global

2016-04-24 Thread Christian Couder
y.c index d26419a..84ff2da 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -141,8 +141,6 @@ struct apply_state { enum ws_ignore ws_ignore_action; }; -static int newfd = -1; - static const char * const apply_usage[] = { N_("git apply [] [...]"), NULL @@ -4572

[PATCH 70/83] builtin/apply: make add_index_file() return -1 on error

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 48 +++- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 5a5be49..e021fad 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4085,11 +4085,

[PATCH 64/83] builtin/apply: make parse_traditional_patch() return -1 on error

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 73247c7..6b8ba2a 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -755,10 +755,10 @@ static int has_epoch_timestamp(

[PATCH 68/83] builtin/apply: make remove_file() return -1 on error

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 17 +++-- 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 69bb94c..89118c1 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4071,17 +4071,18 @@ static void patch_stats(st

[PATCH 53/83] builtin/apply: make find_header() return -1 instead of die()ing

2016-04-24 Thread Christian Couder
e_chunk(struct apply_state *state, char *buffer, unsigned long si int hdrsize, patchsize; int offset = find_header(state, buffer, size, &hdrsize, patch); + if (offset == -1) + exit(1); + if (offset < 0) return offset; diff --git

[PATCH 58/83] builtin/apply: libify parse_ignorewhitespace_option()

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 8d96f70..2f89922 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -57,20 +57,20 @@ static int parse_whitespace_option

[PATCH 47/83] builtin/apply: move applying patches into apply_all_patches()

2016-04-24 Thread Christian Couder
+ } + if (state->ws_error_action == die_on_ws_error) + die(Q_("%d line adds whitespace errors.", + "%d lines add whitespace errors.", + state->whitespace_error), +

[PATCH 49/83] builtin/apply: move 'lock_file' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
char *prefix; int prefix_length; + /* +* Since lockfile.c keeps a linked list of all created +* lock_file structures, it isn't safe to free(lock_file). +*/ + struct lock_file *lock_file; + int apply; int allow_overlap; int apply

[PATCH 72/83] builtin/apply: make write_out_one_result() return -1 on error

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 38 -- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index ebac9ee..dae89e2 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4271,36 +4271,29 @@ stat

[PATCH 61/83] builtin/apply: libify check_apply_state()

2016-04-24 Thread Christian Couder
ply && (state->diffstat || state->numstat || state->summary || state->check || state->fake_ancestor)) state->apply = 0; if (state->check_index && is_not_gitdir) - die(_("--index outside a repository")); + return error(_(

[PATCH 59/83] builtin/apply: move init_apply_state() to apply.c

2016-04-24 Thread Christian Couder
change")) { + state->ws_ignore_action = ignore_ws_change; + return 0; + } + return error(_("unrecognized whitespace ignore option '%s'"), option); +} + +void init_apply_state(struct apply_state *state, const char *prefix) +{ + memset(

[PATCH 77/83] apply: rename and move opt constants to apply.h

2016-04-24 Thread Christian Couder
(1<<1) - /* * Try to apply a patch. * @@ -4473,8 +4470,8 @@ static int apply_patch(struct apply_state *state, int nr; patch = xcalloc(1, sizeof(*patch)); - patch->inaccurate_eof = !!(options & INACCURATE_EOF);

[PATCH 67/83] builtin/apply: make build_fake_ancestor() return -1 on error

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 28 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 8b7a8e0..69bb94c 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -3891,7 +3891,7 @@ static int preim

[PATCH 60/83] apply: libify init_apply_state()

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- apply.c | 7 --- apply.h | 2 +- builtin/apply.c | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apply.c b/apply.c index 9c5f258..11bec48 100644 --- a/apply.c +++ b/apply.c @@ -56,7 +56,7 @@ int parse_ignorewhitespace

[PATCH 62/83] builtin/apply: move check_apply_state() to apply.c

2016-04-24 Thread Christian Couder
tate->threeway) { + if (is_not_gitdir) + return error(_("--3way outside a repository")); + state->check_index = 1; + } + if (state->apply_with_reject) + state->apply = state->apply_verbosely = 1; + if (!force_ap

[PATCH 46/83] builtin/apply: move 'state' check into check_apply_state()

2016-04-24 Thread Christian Couder
used together."); + if (state->threeway) { + if (is_not_gitdir) + die(_("--3way outside a repository")); + state->check_index = 1; + } + if (state->apply_with_reject) + state->apply = state->apply_v

[PATCH 33/83] builtin/apply: move 'root' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
) { - *name = find_name(line, NULL, state->p_value, TERM_TAB); + *name = find_name(state, line, NULL, state->p_value, TERM_TAB); return; } @@ -967,7 +981,7 @@ static void gitdiff_verify_name(struct apply_state *state,

[PATCH 36/83] builtin/apply: remove whitespace_option arg from set_default_whitespace_mode()

2016-04-24 Thread Christian Couder
e(struct apply_state *state) { - if (!whitespace_option && !apply_default_whitespace) + if (!state->whitespace_option && !apply_default_whitespace) ws_error_action = (state->apply ? warn_on_ws_error : nowarn_ws_error); } @@ -4790,11 +4789,11 @@

[PATCH 32/83] builtin/apply: move 'p_value_known' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
line_termination; int p_value; + int p_value_known; unsigned int p_context; const char *patch_input_file; @@ -76,8 +77,6 @@ struct apply_state { static int newfd = -1; -static int p_value_known; - static const char * const apply_usage[] = { N_("git

[PATCH 08/83] builtin/apply: move 'unidiff_zero' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
try_threeway(struct image *image, struct patch *patch, img = strbuf_detach(&buf, &len); prepare_image(&tmp_image, img, len, 1); /* Apply the patch to get the post image */ - if (apply_fragments(&tmp_image, patch) < 0) { + if (apply_fragments(state,

[PATCH 10/83] builtin/apply: move 'check_index' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
+30,10 @@ struct apply_state { *files that are being modified, but doesn't apply the patch */ int check; + + /* --index updates the cache as well. */ + int check_index; + int unidiff_zero; }; @@ -37,14 +41,12 @@ struct apply_state { * -

[PATCH 25/83] builtin/apply: move 'p_context' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
unsafe_paths; int line_termination; + + unsigned int p_context; }; static int newfd = -1; @@ -70,7 +72,6 @@ static int newfd = -1; static int state_p_value = 1; static int p_value_known; static int apply = 1; -static unsigned int p_context = UINT_MAX; static const char * const

[PATCH 24/83] builtin/apply: move 'fake_ancestor' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
By the way remove a comment about '--index-info' that was renamed '--build-fake-ancestor' in commit 26b28007689d27a921ea90e5a29fc8eb74b0d297 (apply: get rid of --index-info in favor of --build-fake-ancestor, Sep 17 2007). Signed-off-by: Christian Couder ---

[PATCH 28/83] builtin/apply: move 'patch_input_file' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 28 ++-- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index be237d1..ab311c1 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -66,6 +66,8 @@ struct apply_state {

[PATCH 37/83] builtin/apply: move 'squelch_whitespace_errors' into 'struct apply_state'

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 22 +++--- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 401e111..259f256 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -78,6 +78,7 @@ struct apply_state {

[PATCH 23/83] builtin/apply: move 'line_termination' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
update_index; int unsafe_paths; + + int line_termination; }; /* @@ -70,7 +72,6 @@ static int state_p_value = 1; static int p_value_known; static int apply = 1; static const char *fake_ancestor; -static int line_termination = '\n'; static unsigned int p_context

[PATCH 02/83] builtin/apply: avoid parameter shadowing 'p_value' global

2016-04-24 Thread Christian Couder
; + *name = find_name(line, NULL, state_p_value, TERM_TAB); return; } @@ -938,7 +938,7 @@ static void gitdiff_verify_name(const char *line, int isnull, char **name, int s if (isnull) die(_("git apply: bad git-diff -

[PATCH 39/83] builtin/apply: move 'ws_error_action' into 'struct apply_state'

2016-04-24 Thread Christian Couder
_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 : no

[PATCH 13/83] builtin/apply: move 'apply_verbosely' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
{ int apply_in_reverse; int apply_with_reject; + int apply_verbosely; /* * --check turns on checking that the working tree matches the @@ -56,7 +57,6 @@ static int diffstat; static int numstat; static int summary; static int apply = 1; -static int

[PATCH 06/83] builtin/apply: move 'options' variable into cmd_apply()

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/apply.c b/builtin/apply.c index 02239d9..8fd8dbc 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -79,7 +79,6 @@ static enum ws_ignore { static const char *patch_i

[PATCH 21/83] builtin/apply: move 'no-add' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
; + int no_add; + /* * --check turns on checking that the working tree matches the *files that are being modified, but doesn't apply the patch @@ -65,7 +67,6 @@ static int newfd = -1; static int state_p_value = 1; static int p_value_known; static int

[PATCH 00/83] libify apply and use lib in am

2016-04-24 Thread Christian Couder
This is a patch series about libifying `git apply` functionality, and using this libified functionality in `git am`, so that no 'git apply' process is spawn anymore. This makes `git am` significantly faster, so `git rebase`, when it uses the am backend, is also significantly faster.

[PATCH 17/83] builtin/apply: move 'diffstat' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
{ /* --cached updates only the cache without ever touching the working tree. */ int cached; + /* --stat does just a diffstat, and doesn't actually apply */ + int diffstat; + /* * --check turns on checking that the working tree matches the *files tha

[PATCH 19/83] builtin/apply: move 'summary' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
does numeric diffstat, and doesn't actually apply */ int numstat; + int summary; + /* * --check turns on checking that the working tree matches the *files that are being modified, but doesn't apply the patch @@ -60,7 +62,6 @@ static int

[PATCH 01/83] builtin/apply: make gitdiff_verify_name() return void

2016-04-24 Thread Christian Couder
n = strlen(*name); char *another; if (isnull) die(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"), - orig_name, linenr); + *name, linenr); another = find_name(lin

[PATCH 12/83] builtin/apply: move 'apply_with_reject' global into 'struct apply_state'

2016-04-24 Thread Christian Couder
prefix_length; int apply_in_reverse; + int apply_with_reject; /* * --check turns on checking that the working tree matches the @@ -55,7 +56,6 @@ static int diffstat; static int numstat; static int summary; static int apply = 1; -static int apply_with_reject

[PATCH 03/83] builtin/apply: avoid parameter shadowing 'linenr' global

2016-04-24 Thread Christian Couder
Signed-off-by: Christian Couder --- builtin/apply.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index e133b38..7115dc2 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -1516,7 +1516,7 @@ static int find_header(const char *line, un

[PATCH] gitweb: apply fallback encoding before highlight

2016-04-20 Thread Shin Kojima
Some multi-byte character encodings (such as Shift_JIS and GBK) have characters whose final bytes is an ASCII '\' (0x5c), and they will be displayed as funny-characters even if $fallback_encoding is correct. This is because `highlight` command always expects UTF-8 encoded strings from STDIN.

Re: [PATCH v3] builtin/apply: handle parse_binary() failure

2016-04-01 Thread Christian Couder
by "your follow-up patch" you meant the other one that had also been forgotten and that I also replied to, that is: [PATCH] builtin/apply: free patch when parse_chunk() fails I had first sent both of them at around the same time. Thanks, Christian. -- To unsubscribe from this list: s

Re: [PATCH] builtin/apply: free patch when parse_chunk() fails

2016-04-01 Thread Junio C Hamano
Christian Couder writes: > When parse_chunk() fails it can return -1, for example > when find_header() doesn't find a patch header. > > In this case it's better in apply_patch() to free the > "struct patch" that we just allocated instead of > leaking it. > > Signed-off-by: Christian Couder > ---

Re: [PATCH v3] builtin/apply: handle parse_binary() failure

2016-04-01 Thread Junio C Hamano
Christian Couder writes: > On Fri, Mar 18, 2016 at 1:30 PM, Christian Couder > wrote: >> In parse_binary() there is: >> >> forward = parse_binary_hunk(&buffer, &size, &status, &used); >> if (!forward && !status) >> /* there has to be one hunk (forward hunk) */ >>

Re: [PATCH] builtin/apply: free patch when parse_chunk() fails

2016-03-31 Thread Christian Couder
On Fri, Apr 1, 2016 at 12:56 AM, Junio C Hamano wrote: > Christian Couder writes: > >> On Wed, Mar 16, 2016 at 3:35 PM, Christian Couder >> wrote: >>> When parse_chunk() fails it can return -1, for example >>> when find_header() doesn't find a patch header. >>> >>> In this case it's better in ap

Re: [PATCH] builtin/apply: free patch when parse_chunk() fails

2016-03-31 Thread Junio C Hamano
Christian Couder writes: > On Wed, Mar 16, 2016 at 3:35 PM, Christian Couder > wrote: >> When parse_chunk() fails it can return -1, for example >> when find_header() doesn't find a patch header. >> >> In this case it's better in apply_patch() to free the >> "struct patch" that we just allocated

Re: [PATCH] builtin/apply: free patch when parse_chunk() fails

2016-03-31 Thread Christian Couder
On Wed, Mar 16, 2016 at 3:35 PM, Christian Couder wrote: > When parse_chunk() fails it can return -1, for example > when find_header() doesn't find a patch header. > > In this case it's better in apply_patch() to free the > "struct patch" that we just allocated instead of > leaking it. Maybe this

Re: [PATCH v3] builtin/apply: handle parse_binary() failure

2016-03-31 Thread Christian Couder
On Fri, Mar 18, 2016 at 1:30 PM, Christian Couder wrote: > In parse_binary() there is: > > forward = parse_binary_hunk(&buffer, &size, &status, &used); > if (!forward && !status) > /* there has to be one hunk (forward hunk) */ > return error(_("unrec

Re: git-apply does not work in a sub-directory of a Git repository

2016-03-30 Thread Junio C Hamano
Duy Nguyen writes: > But your suggestion is good and I can't think of any better. We could > introduce pathspec as ftiler after "--", but it does not look elegant, > and it overlaps with --include/--exclude. I was imagining that we would allow the magic pathspec syntax used in --include/--exclud

Re: git-apply does not work in a sub-directory of a Git repository

2016-03-30 Thread Duy Nguyen
ne explicit "--include" given, we skip this "return 0". > > That way, we do not have to commit to turning --include/--exclude to > pathspec (which I agree is a huge change in behaviour that may not > be a good idea) and we do not have to add "--full-tree"

Re: git-apply does not work in a sub-directory of a Git repository

2016-03-29 Thread Duy Nguyen
redates the pathspec machinery that was >>>> made reusable in places like this). We should be able to >>>> >>>> $ cd d/e/e/p/d/i/r >>>> $ git apply --include=:/ ../../../../../../../patch >>>> >>>> to lift this li

Issue: `git apply` doesn't respect `--work-tree`

2016-03-26 Thread Ciprian Dorin Craciun
[I've quickly looked at the mailing list archive and didn't see this issue reported. However I might be wrong.] The issue is simple: `git apply` does not respect the `--work-tree` argument when called outside the repository. The version of Git I used is OpenSUSE's official

Re: git-apply does not work in a sub-directory of a Git repository

2016-03-24 Thread Junio C Hamano
t; given, we skip this "return 0". > > That way, we do not have to commit to turning --include/--exclude to > pathspec (which I agree is a huge change in behaviour that may not > be a good idea) and we do not have to add "--full-tree" that is only > understood by "

Re: git-apply does not work in a sub-directory of a Git repository

2016-03-24 Thread Junio C Hamano
like this). We should be able to >>> >>> $ cd d/e/e/p/d/i/r >>> $ git apply --include=:/ ../../../../../../../patch >>> >>> to lift this limitation. IOW, we can think of the use_patch() to >>> include only the paths in the subdirect

Re: git-apply does not work in a sub-directory of a Git repository

2016-03-24 Thread Junio C Hamano
Duy Nguyen writes: >> The include/exclude mechanism does use wildmatch() but does not use >> the pathspec mechanism (it predates the pathspec machinery that was >> made reusable in places like this). We should be able to >> >> $ cd d/e/e/p/d/i/

[PATCH 4/4] apply: report patch skipping in verbose mode

2016-03-24 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/apply.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/apply.c b/builtin/apply.c index 01e1d5e..9cbb186 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4384,6 +4384,8 @@ static int apply_patch(int fd, const char *filename, int

<    6   7   8   9   10   11   12   13   14   15   >