[PATCH v3 00/49] libify apply and use lib in am, part 1

classic Classic list List threaded Threaded
51 messages Options
123
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 20/49] builtin/apply: move 'numstat' global into 'struct apply_state'

Christian Couder-2
To libify the apply functionality the 'numstat' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index d940125..47a45a7 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -33,6 +33,7 @@ struct apply_state {
 
  /* These control cosmetic aspect of the output */
  int diffstat; /* just show a diffstat, and don't actually apply */
+ int numstat; /* just show a numeric diffstat, and don't actually apply */
 
  /* These boolean parameters control how the apply is done */
  int allow_overlap;
@@ -43,14 +44,12 @@ struct apply_state {
 };
 
 /*
- *  --numstat does numeric diffstat, and doesn't actually apply
  *  --index-info shows the old and new index info for paths if available.
  */
 static int newfd = -1;
 
 static int state_p_value = 1;
 static int p_value_known;
-static int numstat;
 static int summary;
 static int apply = 1;
 static int no_add;
@@ -4490,7 +4489,7 @@ static int apply_patch(struct apply_state *state,
  if (state->diffstat)
  stat_patch_list(list);
 
- if (numstat)
+ if (state->numstat)
  numstat_patch_list(list);
 
  if (summary)
@@ -4607,7 +4606,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  N_("instead of applying the patch, output diffstat for the input")),
  OPT_NOOP_NOARG(0, "allow-binary-replacement"),
  OPT_NOOP_NOARG(0, "binary"),
- OPT_BOOL(0, "numstat", &numstat,
+ OPT_BOOL(0, "numstat", &state.numstat,
  N_("show number of added and deleted lines in decimal notation")),
  OPT_BOOL(0, "summary", &summary,
  N_("instead of applying the patch, output a summary for the input")),
@@ -4676,7 +4675,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  }
  if (state.apply_with_reject)
  apply = state.apply_verbosely = 1;
- if (!force_apply && (state.diffstat || numstat || summary || state.check || fake_ancestor))
+ if (!force_apply && (state.diffstat || state.numstat || summary || state.check || fake_ancestor))
  apply = 0;
  if (state.check_index && is_not_gitdir)
  die(_("--index outside a repository"));
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 21/49] builtin/apply: move 'summary' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'summary' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 47a45a7..f174a42 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -34,6 +34,7 @@ struct apply_state {
  /* These control cosmetic aspect of the output */
  int diffstat; /* just show a diffstat, and don't actually apply */
  int numstat; /* just show a numeric diffstat, and don't actually apply */
+ int summary; /* just report creation, deletion, etc, and don't actually apply */
 
  /* These boolean parameters control how the apply is done */
  int allow_overlap;
@@ -50,7 +51,6 @@ static int newfd = -1;
 
 static int state_p_value = 1;
 static int p_value_known;
-static int summary;
 static int apply = 1;
 static int no_add;
 static int threeway;
@@ -4492,7 +4492,7 @@ static int apply_patch(struct apply_state *state,
  if (state->numstat)
  numstat_patch_list(list);
 
- if (summary)
+ if (state->summary)
  summary_patch_list(list);
 
  free_patch_list(list);
@@ -4608,7 +4608,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  OPT_NOOP_NOARG(0, "binary"),
  OPT_BOOL(0, "numstat", &state.numstat,
  N_("show number of added and deleted lines in decimal notation")),
- OPT_BOOL(0, "summary", &summary,
+ OPT_BOOL(0, "summary", &state.summary,
  N_("instead of applying the patch, output a summary for the input")),
  OPT_BOOL(0, "check", &state.check,
  N_("instead of applying the patch, see if the patch is applicable")),
@@ -4675,7 +4675,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  }
  if (state.apply_with_reject)
  apply = state.apply_verbosely = 1;
- if (!force_apply && (state.diffstat || state.numstat || summary || state.check || fake_ancestor))
+ if (!force_apply && (state.diffstat || state.numstat || state.summary || state.check || fake_ancestor))
  apply = 0;
  if (state.check_index && is_not_gitdir)
  die(_("--index outside a repository"));
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 22/49] builtin/apply: move 'threeway' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'threeway' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index f174a42..d00017b 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -41,6 +41,7 @@ struct apply_state {
  int apply_in_reverse;
  int apply_with_reject;
  int apply_verbosely;
+ int threeway;
  int unidiff_zero;
 };
 
@@ -53,7 +54,6 @@ static int state_p_value = 1;
 static int p_value_known;
 static int apply = 1;
 static int no_add;
-static int threeway;
 static int unsafe_paths;
 static const char *fake_ancestor;
 static int line_termination = '\n';
@@ -3491,7 +3491,7 @@ static int apply_data(struct apply_state *state, struct patch *patch,
  if (patch->direct_to_threeway ||
     apply_fragments(state, &image, patch) < 0) {
  /* Note: with --reject, apply_fragments() returns 0 */
- if (!threeway || try_threeway(state, &image, patch, st, ce) < 0)
+ if (!state->threeway || try_threeway(state, &image, patch, st, ce) < 0)
  return -1;
  }
  patch->result = image.buf;
@@ -3786,7 +3786,7 @@ static int check_patch(struct apply_state *state, struct patch *patch)
     ((0 < patch->is_new) || patch->is_rename || patch->is_copy)) {
  int err = check_to_create(state, new_name, ok_if_exists);
 
- if (err && threeway) {
+ if (err && state->threeway) {
  patch->direct_to_threeway = 1;
  } else switch (err) {
  case 0:
@@ -4620,7 +4620,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  N_("accept a patch that touches outside the working area")),
  OPT_BOOL(0, "apply", &force_apply,
  N_("also apply the patch (use with --stat/--summary/--check)")),
- OPT_BOOL('3', "3way", &threeway,
+ OPT_BOOL('3', "3way", &state.threeway,
  N_( "attempt three-way merge if a patch does not apply")),
  OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
  N_("build a temporary index based on embedded index information")),
@@ -4664,11 +4664,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
  apply_usage, 0);
 
- if (state.apply_with_reject && threeway)
+ if (state.apply_with_reject && state.threeway)
  die("--reject and --3way cannot be used together.");
- if (state.cached && threeway)
+ if (state.cached && state.threeway)
  die("--cached and --3way cannot be used together.");
- if (threeway) {
+ if (state.threeway) {
  if (is_not_gitdir)
  die(_("--3way outside a repository"));
  state.check_index = 1;
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 23/49] builtin/apply: move 'no_add' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'no_add' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index d00017b..604e7bf 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -41,6 +41,7 @@ struct apply_state {
  int apply_in_reverse;
  int apply_with_reject;
  int apply_verbosely;
+ int no_add;
  int threeway;
  int unidiff_zero;
 };
@@ -53,7 +54,6 @@ static int newfd = -1;
 static int state_p_value = 1;
 static int p_value_known;
 static int apply = 1;
-static int no_add;
 static int unsafe_paths;
 static const char *fake_ancestor;
 static int line_termination = '\n';
@@ -2782,7 +2782,7 @@ static int apply_one_fragment(struct apply_state *state,
  /* Fall-through for ' ' */
  case '+':
  /* --no-add does not add new lines */
- if (first == '+' && no_add)
+ if (first == '+' && state->no_add)
  break;
 
  start = newlines.len;
@@ -4600,7 +4600,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  { OPTION_CALLBACK, 'p', NULL, NULL, N_("num"),
  N_("remove <num> leading slashes from traditional diff paths"),
  0, option_parse_p },
- OPT_BOOL(0, "no-add", &no_add,
+ OPT_BOOL(0, "no-add", &state.no_add,
  N_("ignore additions made by the patch")),
  OPT_BOOL(0, "stat", &state.diffstat,
  N_("instead of applying the patch, output diffstat for the input")),
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 24/49] builtin/apply: move 'unsafe_paths' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'unsafe_paths' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 604e7bf..4ef83c1 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -44,6 +44,7 @@ struct apply_state {
  int no_add;
  int threeway;
  int unidiff_zero;
+ int unsafe_paths;
 };
 
 /*
@@ -54,7 +55,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';
 static unsigned int p_context = UINT_MAX;
@@ -3827,7 +3827,7 @@ static int check_patch(struct apply_state *state, struct patch *patch)
  }
  }
 
- if (!unsafe_paths)
+ if (!state->unsafe_paths)
  die_on_unsafe_path(patch);
 
  /*
@@ -4616,7 +4616,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  N_("make sure the patch is applicable to the current index")),
  OPT_BOOL(0, "cached", &state.cached,
  N_("apply a patch without touching the working tree")),
- OPT_BOOL(0, "unsafe-paths", &unsafe_paths,
+ OPT_BOOL(0, "unsafe-paths", &state.unsafe_paths,
  N_("accept a patch that touches outside the working area")),
  OPT_BOOL(0, "apply", &force_apply,
  N_("also apply the patch (use with --stat/--summary/--check)")),
@@ -4685,7 +4685,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  state.check_index = 1;
  }
  if (state.check_index)
- unsafe_paths = 0;
+ state.unsafe_paths = 0;
 
  for (i = 0; i < argc; i++) {
  const char *arg = argv[i];
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 25/49] builtin/apply: move 'line_termination' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'line_termination' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 4ef83c1..95cd60a 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -45,6 +45,9 @@ struct apply_state {
  int threeway;
  int unidiff_zero;
  int unsafe_paths;
+
+ /* Other non boolean parameters */
+ int line_termination;
 };
 
 /*
@@ -56,7 +59,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 = UINT_MAX;
 static const char * const apply_usage[] = {
  N_("git apply [<options>] [<patch>...]"),
@@ -3977,7 +3979,8 @@ static void stat_patch_list(struct patch *patch)
  print_stat_summary(stdout, files, adds, dels);
 }
 
-static void numstat_patch_list(struct patch *patch)
+static void numstat_patch_list(struct apply_state *state,
+       struct patch *patch)
 {
  for ( ; patch; patch = patch->next) {
  const char *name;
@@ -3986,7 +3989,7 @@ static void numstat_patch_list(struct patch *patch)
  printf("-\t-\t");
  else
  printf("%d\t%d\t", patch->lines_added, patch->lines_deleted);
- write_name_quoted(name, stdout, line_termination);
+ write_name_quoted(name, stdout, state->line_termination);
  }
 }
 
@@ -4490,7 +4493,7 @@ static int apply_patch(struct apply_state *state,
  stat_patch_list(list);
 
  if (state->numstat)
- numstat_patch_list(list);
+ numstat_patch_list(state, list);
 
  if (state->summary)
  summary_patch_list(list);
@@ -4565,6 +4568,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
  memset(state, 0, sizeof(*state));
  state->prefix = prefix;
  state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
+ state->line_termination = '\n';
 
  git_apply_config();
  if (apply_default_whitespace)
@@ -4625,7 +4629,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
  N_("build a temporary index based on embedded index information")),
  /* Think twice before adding "--nul" synonym to this */
- OPT_SET_INT('z', NULL, &line_termination,
+ OPT_SET_INT('z', NULL, &state.line_termination,
  N_("paths are separated with NUL character"), '\0'),
  OPT_INTEGER('C', NULL, &p_context,
  N_("ensure at least <n> lines of context match")),
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 26/49] builtin/apply: move 'fake_ancestor' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'fake_ancestor' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

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).

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 95cd60a..59b0f1b 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -47,18 +47,15 @@ struct apply_state {
  int unsafe_paths;
 
  /* Other non boolean parameters */
+ const char *fake_ancestor;
  int line_termination;
 };
 
-/*
- *  --index-info shows the old and new index info for paths if available.
- */
 static int newfd = -1;
 
 static int state_p_value = 1;
 static int p_value_known;
 static int apply = 1;
-static const char *fake_ancestor;
 static unsigned int p_context = UINT_MAX;
 static const char * const apply_usage[] = {
  N_("git apply [<options>] [<patch>...]"),
@@ -4486,8 +4483,8 @@ static int apply_patch(struct apply_state *state,
  return 1;
  }
 
- if (fake_ancestor)
- build_fake_ancestor(list, fake_ancestor);
+ if (state->fake_ancestor)
+ build_fake_ancestor(list, state->fake_ancestor);
 
  if (state->diffstat)
  stat_patch_list(list);
@@ -4626,7 +4623,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  N_("also apply the patch (use with --stat/--summary/--check)")),
  OPT_BOOL('3', "3way", &state.threeway,
  N_( "attempt three-way merge if a patch does not apply")),
- OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
+ OPT_FILENAME(0, "build-fake-ancestor", &state.fake_ancestor,
  N_("build a temporary index based on embedded index information")),
  /* Think twice before adding "--nul" synonym to this */
  OPT_SET_INT('z', NULL, &state.line_termination,
@@ -4679,7 +4676,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  }
  if (state.apply_with_reject)
  apply = state.apply_verbosely = 1;
- if (!force_apply && (state.diffstat || state.numstat || state.summary || state.check || fake_ancestor))
+ if (!force_apply && (state.diffstat || state.numstat || state.summary || state.check || state.fake_ancestor))
  apply = 0;
  if (state.check_index && is_not_gitdir)
  die(_("--index outside a repository"));
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 27/49] builtin/apply: move 'p_context' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'p_context' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 59b0f1b..3c9f052 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -49,6 +49,7 @@ struct apply_state {
  /* Other non boolean parameters */
  const char *fake_ancestor;
  int line_termination;
+ unsigned int p_context;
 };
 
 static int newfd = -1;
@@ -56,7 +57,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 apply_usage[] = {
  N_("git apply [<options>] [<patch>...]"),
  NULL
@@ -2872,7 +2872,7 @@ static int apply_one_fragment(struct apply_state *state,
  break;
 
  /* Am I at my context limits? */
- if ((leading <= p_context) && (trailing <= p_context))
+ if ((leading <= state->p_context) && (trailing <= state->p_context))
  break;
  if (match_beginning || match_end) {
  match_beginning = match_end = 0;
@@ -4566,6 +4566,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
  state->prefix = prefix;
  state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
  state->line_termination = '\n';
+ state->p_context = UINT_MAX;
 
  git_apply_config();
  if (apply_default_whitespace)
@@ -4628,7 +4629,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  /* Think twice before adding "--nul" synonym to this */
  OPT_SET_INT('z', NULL, &state.line_termination,
  N_("paths are separated with NUL character"), '\0'),
- OPT_INTEGER('C', NULL, &p_context,
+ OPT_INTEGER('C', NULL, &state.p_context,
  N_("ensure at least <n> lines of context match")),
  { OPTION_CALLBACK, 0, "whitespace", &whitespace_option, N_("action"),
  N_("detect new or modified lines that have whitespace errors"),
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 28/49] builtin/apply: move 'apply' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'apply' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 3c9f052..c0c18ce 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -26,6 +26,7 @@ struct apply_state {
  int prefix_length;
 
  /* These control what gets looked at and modified */
+ int apply; /* this is not a dry-run */
  int cached; /* apply to the index only */
  int check; /* preimage must match working tree, don't actually apply */
  int check_index; /* preimage must match the indexed version */
@@ -56,7 +57,7 @@ static int newfd = -1;
 
 static int state_p_value = 1;
 static int p_value_known;
-static int apply = 1;
+
 static const char * const apply_usage[] = {
  N_("git apply [<options>] [<patch>...]"),
  NULL
@@ -126,10 +127,11 @@ static void parse_ignorewhitespace_option(const char *option)
  die(_("unrecognized whitespace ignore option '%s'"), option);
 }
 
-static void set_default_whitespace_mode(const char *whitespace_option)
+static void set_default_whitespace_mode(struct apply_state *state,
+ const char *whitespace_option)
 {
  if (!whitespace_option && !apply_default_whitespace)
- ws_error_action = (apply ? warn_on_ws_error : nowarn_ws_error);
+ ws_error_action = (state->apply ? warn_on_ws_error : nowarn_ws_error);
 }
 
 /*
@@ -2058,7 +2060,7 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si
  * without metadata change.  A binary patch appears
  * empty to us here.
  */
- if ((apply || state->check) &&
+ if ((state->apply || state->check) &&
     (!patch->is_binary && !metadata_changes(patch)))
  die(_("patch with only garbage at line %d"), state_linenr);
  }
@@ -2916,7 +2918,7 @@ static int apply_one_fragment(struct apply_state *state,
  * apply_data->apply_fragments->apply_one_fragment
  */
  if (ws_error_action == die_on_ws_error)
- apply = 0;
+ state->apply = 0;
  }
 
  if (state->apply_verbosely && applied_pos != pos) {
@@ -4460,9 +4462,9 @@ static int apply_patch(struct apply_state *state,
  die(_("unrecognized input"));
 
  if (whitespace_error && (ws_error_action == die_on_ws_error))
- apply = 0;
+ state->apply = 0;
 
- state->update_index = state->check_index && apply;
+ state->update_index = state->check_index && state->apply;
  if (state->update_index && newfd < 0)
  newfd = hold_locked_index(&lock_file, 1);
 
@@ -4471,12 +4473,12 @@ static int apply_patch(struct apply_state *state,
  die(_("unable to read index file"));
  }
 
- if ((state->check || apply) &&
+ if ((state->check || state->apply) &&
     check_patch_list(state, list) < 0 &&
     !state->apply_with_reject)
  exit(1);
 
- if (apply && write_out_results(state, list)) {
+ if (state->apply && write_out_results(state, list)) {
  if (state->apply_with_reject)
  exit(1);
  /* with --3way, we still need to write the index out */
@@ -4565,6 +4567,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
  memset(state, 0, sizeof(*state));
  state->prefix = prefix;
  state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
+ state->apply = 1;
  state->line_termination = '\n';
  state->p_context = UINT_MAX;
 
@@ -4676,9 +4679,9 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  state.check_index = 1;
  }
  if (state.apply_with_reject)
- apply = state.apply_verbosely = 1;
+ state.apply = state.apply_verbosely = 1;
  if (!force_apply && (state.diffstat || state.numstat || state.summary || state.check || state.fake_ancestor))
- apply = 0;
+ state.apply = 0;
  if (state.check_index && is_not_gitdir)
  die(_("--index outside a repository"));
  if (state.cached) {
@@ -4706,11 +4709,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  if (fd < 0)
  die_errno(_("can't open patch '%s'"), arg);
  read_stdin = 0;
- set_default_whitespace_mode(whitespace_option);
+ set_default_whitespace_mode(&state, whitespace_option);
  errs |= apply_patch(&state, fd, arg, options);
  close(fd);
  }
- set_default_whitespace_mode(whitespace_option);
+ set_default_whitespace_mode(&state, whitespace_option);
  if (read_stdin)
  errs |= apply_patch(&state, 0, "<stdin>", options);
  if (whitespace_error) {
@@ -4728,7 +4731,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
        "%d lines add whitespace errors.",
        whitespace_error),
     whitespace_error);
- if (applied_after_fixing_ws && apply)
+ if (applied_after_fixing_ws && state.apply)
  warning("%d line%s applied after"
  " fixing whitespace errors.",
  applied_after_fixing_ws,
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 29/49] builtin/apply: move 'patch_input_file' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'patch_input_file' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index c0c18ce..fa90028 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -49,6 +49,7 @@ struct apply_state {
 
  /* Other non boolean parameters */
  const char *fake_ancestor;
+ const char *patch_input_file;
  int line_termination;
  unsigned int p_context;
 };
@@ -79,7 +80,6 @@ static enum ws_ignore {
 } ws_ignore_action = ignore_ws_none;
 
 
-static const char *patch_input_file;
 static struct strbuf root = STRBUF_INIT;
 
 static void parse_whitespace_option(const char *option)
@@ -1525,7 +1525,11 @@ static int find_header(struct apply_state *state,
  return -1;
 }
 
-static void record_ws_error(unsigned result, const char *line, int len, int linenr)
+static void record_ws_error(struct apply_state *state,
+    unsigned result,
+    const char *line,
+    int len,
+    int linenr)
 {
  char *err;
 
@@ -1539,15 +1543,18 @@ static void record_ws_error(unsigned result, const char *line, int len, int line
 
  err = whitespace_error_string(result);
  fprintf(stderr, "%s:%d: %s.\n%.*s\n",
- patch_input_file, linenr, err, len, line);
+ state->patch_input_file, linenr, err, len, line);
  free(err);
 }
 
-static void check_whitespace(const char *line, int len, unsigned ws_rule)
+static void check_whitespace(struct apply_state *state,
+     const char *line,
+     int len,
+     unsigned ws_rule)
 {
  unsigned result = ws_check(line + 1, len - 1, ws_rule);
 
- record_ws_error(result, line + 1, len - 2, state_linenr);
+ record_ws_error(state, result, line + 1, len - 2, state_linenr);
 }
 
 /*
@@ -1602,12 +1609,12 @@ static int parse_fragment(struct apply_state *state,
  trailing++;
  if (!state->apply_in_reverse &&
     ws_error_action == correct_ws_error)
- check_whitespace(line, len, patch->ws_rule);
+ check_whitespace(state, line, len, patch->ws_rule);
  break;
  case '-':
  if (state->apply_in_reverse &&
     ws_error_action != nowarn_ws_error)
- check_whitespace(line, len, patch->ws_rule);
+ check_whitespace(state, line, len, patch->ws_rule);
  deleted++;
  oldlines--;
  trailing = 0;
@@ -1615,7 +1622,7 @@ static int parse_fragment(struct apply_state *state,
  case '+':
  if (!state->apply_in_reverse &&
     ws_error_action != nowarn_ws_error)
- check_whitespace(line, len, patch->ws_rule);
+ check_whitespace(state, line, len, patch->ws_rule);
  added++;
  newlines--;
  trailing = 0;
@@ -2904,7 +2911,7 @@ static int apply_one_fragment(struct apply_state *state,
     preimage.nr + applied_pos >= img->nr &&
     (ws_rule & WS_BLANK_AT_EOF) &&
     ws_error_action != nowarn_ws_error) {
- record_ws_error(WS_BLANK_AT_EOF, "+", 1,
+ record_ws_error(state, WS_BLANK_AT_EOF, "+", 1,
  found_new_blank_lines_at_end);
  if (ws_error_action == correct_ws_error) {
  while (new_blank_lines_at_end--)
@@ -4427,7 +4434,7 @@ static int apply_patch(struct apply_state *state,
  struct patch *list = NULL, **listp = &list;
  int skipped_patch = 0;
 
- patch_input_file = filename;
+ state->patch_input_file = filename;
  read_patch_file(&buf, fd);
  offset = 0;
  while (offset < buf.len) {
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 30/49] builtin/apply: move 'limit_by_name' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'limit_by_name' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index fa90028..0e3de17 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -52,6 +52,9 @@ struct apply_state {
  const char *patch_input_file;
  int line_termination;
  unsigned int p_context;
+
+ /* Exclude and include path parameters */
+ struct string_list limit_by_name;
 };
 
 static int newfd = -1;
@@ -1958,13 +1961,14 @@ static void prefix_patch(struct apply_state *state, struct patch *p)
  * include/exclude
  */
 
-static struct string_list limit_by_name;
 static int has_include;
-static void add_name_limit(const char *name, int exclude)
+static void add_name_limit(struct apply_state *state,
+   const char *name,
+   int exclude)
 {
  struct string_list_item *it;
 
- it = string_list_append(&limit_by_name, name);
+ it = string_list_append(&state->limit_by_name, name);
  it->util = exclude ? NULL : (void *) 1;
 }
 
@@ -1982,8 +1986,8 @@ static int use_patch(struct apply_state *state, struct patch *p)
  }
 
  /* See if it matches any of exclude/include rule */
- for (i = 0; i < limit_by_name.nr; i++) {
- struct string_list_item *it = &limit_by_name.items[i];
+ for (i = 0; i < state->limit_by_name.nr; i++) {
+ struct string_list_item *it = &state->limit_by_name.items[i];
  if (!wildmatch(it->string, pathname, 0, NULL))
  return (it->util != NULL);
  }
@@ -4520,14 +4524,16 @@ static void git_apply_config(void)
 static int option_parse_exclude(const struct option *opt,
  const char *arg, int unset)
 {
- add_name_limit(arg, 1);
+ struct apply_state *state = opt->value;
+ add_name_limit(state, arg, 1);
  return 0;
 }
 
 static int option_parse_include(const struct option *opt,
  const char *arg, int unset)
 {
- add_name_limit(arg, 0);
+ struct apply_state *state = opt->value;
+ add_name_limit(state, arg, 0);
  has_include = 1;
  return 0;
 }
@@ -4587,7 +4593,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
 
 static void clear_apply_state(struct apply_state *state)
 {
- /* empty for now */
+ string_list_clear(&state->limit_by_name, 0);
 }
 
 int cmd_apply(int argc, const char **argv, const char *prefix)
@@ -4603,10 +4609,10 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  const char *whitespace_option = NULL;
 
  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"),
  0, option_parse_exclude },
- { OPTION_CALLBACK, 0, "include", NULL, N_("path"),
+ { OPTION_CALLBACK, 0, "include", &state, N_("path"),
  N_("apply changes matching the given path"),
  0, option_parse_include },
  { OPTION_CALLBACK, 'p', NULL, NULL, N_("num"),
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 31/49] builtin/apply: move 'has_include' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'has_include' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 0e3de17..ebbc711 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -55,6 +55,7 @@ struct apply_state {
 
  /* Exclude and include path parameters */
  struct string_list limit_by_name;
+ int has_include;
 };
 
 static int newfd = -1;
@@ -1961,7 +1962,6 @@ static void prefix_patch(struct apply_state *state, struct patch *p)
  * include/exclude
  */
 
-static int has_include;
 static void add_name_limit(struct apply_state *state,
    const char *name,
    int exclude)
@@ -1997,7 +1997,7 @@ static int use_patch(struct apply_state *state, struct patch *p)
  * not used.  Otherwise, we saw bunch of exclude rules (or none)
  * and such a path is used.
  */
- return !has_include;
+ return !state->has_include;
 }
 
 
@@ -4534,7 +4534,7 @@ static int option_parse_include(const struct option *opt,
 {
  struct apply_state *state = opt->value;
  add_name_limit(state, arg, 0);
- has_include = 1;
+ state->has_include = 1;
  return 0;
 }
 
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 32/49] builtin/apply: move 'p_value' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'p_value' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 151 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 99 insertions(+), 52 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index ebbc711..843fafd 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -51,6 +51,7 @@ struct apply_state {
  const char *fake_ancestor;
  const char *patch_input_file;
  int line_termination;
+ int p_value;
  unsigned int p_context;
 
  /* Exclude and include path parameters */
@@ -60,7 +61,6 @@ struct apply_state {
 
 static int newfd = -1;
 
-static int state_p_value = 1;
 static int p_value_known;
 
 static const char * const apply_usage[] = {
@@ -881,24 +881,24 @@ static void parse_traditional_patch(struct apply_state *state,
  q = guess_p_value(state, second);
  if (p < 0) p = q;
  if (0 <= p && p == q) {
- state_p_value = p;
+ state->p_value = p;
  p_value_known = 1;
  }
  }
  if (is_dev_null(first)) {
  patch->is_new = 1;
  patch->is_delete = 0;
- name = find_name_traditional(second, NULL, state_p_value);
+ name = find_name_traditional(second, NULL, state->p_value);
  patch->new_name = name;
  } else if (is_dev_null(second)) {
  patch->is_new = 0;
  patch->is_delete = 1;
- name = find_name_traditional(first, NULL, state_p_value);
+ name = find_name_traditional(first, NULL, state->p_value);
  patch->old_name = name;
  } else {
  char *first_name;
- first_name = find_name_traditional(first, NULL, state_p_value);
- name = find_name_traditional(second, first_name, state_p_value);
+ first_name = find_name_traditional(first, NULL, state->p_value);
+ name = find_name_traditional(second, first_name, state->p_value);
  free(first_name);
  if (has_epoch_timestamp(first)) {
  patch->is_new = 1;
@@ -917,7 +917,9 @@ static void parse_traditional_patch(struct apply_state *state,
  die(_("unable to find filename in patch at line %d"), state_linenr);
 }
 
-static int gitdiff_hdrend(const char *line, struct patch *patch)
+static int gitdiff_hdrend(struct apply_state *state,
+  const char *line,
+  struct patch *patch)
 {
  return -1;
 }
@@ -934,10 +936,14 @@ static int gitdiff_hdrend(const char *line, struct patch *patch)
 #define DIFF_OLD_NAME 0
 #define DIFF_NEW_NAME 1
 
-static void gitdiff_verify_name(const char *line, int isnull, char **name, int side)
+static void gitdiff_verify_name(struct apply_state *state,
+ const char *line,
+ int isnull,
+ char **name,
+ int side)
 {
  if (!*name && !isnull) {
- *name = find_name(line, NULL, state_p_value, TERM_TAB);
+ *name = find_name(line, NULL, state->p_value, TERM_TAB);
  return;
  }
 
@@ -947,7 +953,7 @@ static void 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, state_linenr);
- another = find_name(line, NULL, state_p_value, TERM_TAB);
+ another = find_name(line, NULL, state->p_value, TERM_TAB);
  if (!another || memcmp(another, *name, len + 1))
  die((side == DIFF_NEW_NAME) ?
     _("git apply: bad git-diff - inconsistent new filename on line %d") :
@@ -960,81 +966,105 @@ static void gitdiff_verify_name(const char *line, int isnull, char **name, int s
  }
 }
 
-static int gitdiff_oldname(const char *line, struct patch *patch)
+static int gitdiff_oldname(struct apply_state *state,
+   const char *line,
+   struct patch *patch)
 {
- gitdiff_verify_name(line, patch->is_new, &patch->old_name,
+ gitdiff_verify_name(state, line,
+    patch->is_new, &patch->old_name,
     DIFF_OLD_NAME);
  return 0;
 }
 
-static int gitdiff_newname(const char *line, struct patch *patch)
+static int gitdiff_newname(struct apply_state *state,
+   const char *line,
+   struct patch *patch)
 {
- gitdiff_verify_name(line, patch->is_delete, &patch->new_name,
+ gitdiff_verify_name(state, line,
+    patch->is_delete, &patch->new_name,
     DIFF_NEW_NAME);
  return 0;
 }
 
-static int gitdiff_oldmode(const char *line, struct patch *patch)
+static int gitdiff_oldmode(struct apply_state *state,
+   const char *line,
+   struct patch *patch)
 {
  patch->old_mode = strtoul(line, NULL, 8);
  return 0;
 }
 
-static int gitdiff_newmode(const char *line, struct patch *patch)
+static int gitdiff_newmode(struct apply_state *state,
+   const char *line,
+   struct patch *patch)
 {
  patch->new_mode = strtoul(line, NULL, 8);
  return 0;
 }
 
-static int gitdiff_delete(const char *line, struct patch *patch)
+static int gitdiff_delete(struct apply_state *state,
+  const char *line,
+  struct patch *patch)
 {
  patch->is_delete = 1;
  free(patch->old_name);
  patch->old_name = xstrdup_or_null(patch->def_name);
- return gitdiff_oldmode(line, patch);
+ return gitdiff_oldmode(state, line, patch);
 }
 
-static int gitdiff_newfile(const char *line, struct patch *patch)
+static int gitdiff_newfile(struct apply_state *state,
+   const char *line,
+   struct patch *patch)
 {
  patch->is_new = 1;
  free(patch->new_name);
  patch->new_name = xstrdup_or_null(patch->def_name);
- return gitdiff_newmode(line, patch);
+ return gitdiff_newmode(state, line, patch);
 }
 
-static int gitdiff_copysrc(const char *line, struct patch *patch)
+static int gitdiff_copysrc(struct apply_state *state,
+   const char *line,
+   struct patch *patch)
 {
  patch->is_copy = 1;
  free(patch->old_name);
- patch->old_name = find_name(line, NULL, state_p_value ? state_p_value - 1 : 0, 0);
+ patch->old_name = find_name(line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
  return 0;
 }
 
-static int gitdiff_copydst(const char *line, struct patch *patch)
+static int gitdiff_copydst(struct apply_state *state,
+   const char *line,
+   struct patch *patch)
 {
  patch->is_copy = 1;
  free(patch->new_name);
- patch->new_name = find_name(line, NULL, state_p_value ? state_p_value - 1 : 0, 0);
+ patch->new_name = find_name(line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
  return 0;
 }
 
-static int gitdiff_renamesrc(const char *line, struct patch *patch)
+static int gitdiff_renamesrc(struct apply_state *state,
+     const char *line,
+     struct patch *patch)
 {
  patch->is_rename = 1;
  free(patch->old_name);
- patch->old_name = find_name(line, NULL, state_p_value ? state_p_value - 1 : 0, 0);
+ patch->old_name = find_name(line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
  return 0;
 }
 
-static int gitdiff_renamedst(const char *line, struct patch *patch)
+static int gitdiff_renamedst(struct apply_state *state,
+     const char *line,
+     struct patch *patch)
 {
  patch->is_rename = 1;
  free(patch->new_name);
- patch->new_name = find_name(line, NULL, state_p_value ? state_p_value - 1 : 0, 0);
+ patch->new_name = find_name(line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
  return 0;
 }
 
-static int gitdiff_similarity(const char *line, struct patch *patch)
+static int gitdiff_similarity(struct apply_state *state,
+      const char *line,
+      struct patch *patch)
 {
  unsigned long val = strtoul(line, NULL, 10);
  if (val <= 100)
@@ -1042,7 +1072,9 @@ static int gitdiff_similarity(const char *line, struct patch *patch)
  return 0;
 }
 
-static int gitdiff_dissimilarity(const char *line, struct patch *patch)
+static int gitdiff_dissimilarity(struct apply_state *state,
+ const char *line,
+ struct patch *patch)
 {
  unsigned long val = strtoul(line, NULL, 10);
  if (val <= 100)
@@ -1050,7 +1082,9 @@ static int gitdiff_dissimilarity(const char *line, struct patch *patch)
  return 0;
 }
 
-static int gitdiff_index(const char *line, struct patch *patch)
+static int gitdiff_index(struct apply_state *state,
+ const char *line,
+ struct patch *patch)
 {
  /*
  * index line is N hexadecimal, "..", N hexadecimal,
@@ -1087,7 +1121,9 @@ static int gitdiff_index(const char *line, struct patch *patch)
  * This is normal for a diff that doesn't change anything: we'll fall through
  * into the next diff. Tell the parser to break out.
  */
-static int gitdiff_unrecognized(const char *line, struct patch *patch)
+static int gitdiff_unrecognized(struct apply_state *state,
+ const char *line,
+ struct patch *patch)
 {
  return -1;
 }
@@ -1096,15 +1132,17 @@ static int gitdiff_unrecognized(const char *line, struct patch *patch)
  * Skip p_value leading components from "line"; as we do not accept
  * absolute paths, return NULL in that case.
  */
-static const char *skip_tree_prefix(const char *line, int llen)
+static const char *skip_tree_prefix(struct apply_state *state,
+    const char *line,
+    int llen)
 {
  int nslash;
  int i;
 
- if (!state_p_value)
+ if (!state->p_value)
  return (llen && line[0] == '/') ? NULL : line;
 
- nslash = state_p_value;
+ nslash = state->p_value;
  for (i = 0; i < llen; i++) {
  int ch = line[i];
  if (ch == '/' && --nslash <= 0)
@@ -1121,7 +1159,9 @@ static const char *skip_tree_prefix(const char *line, int llen)
  * creation or deletion of an empty file.  In any of these cases,
  * both sides are the same name under a/ and b/ respectively.
  */
-static char *git_header_name(const char *line, int llen)
+static char *git_header_name(struct apply_state *state,
+     const char *line,
+     int llen)
 {
  const char *name;
  const char *second = NULL;
@@ -1139,7 +1179,7 @@ static char *git_header_name(const char *line, int llen)
  goto free_and_fail1;
 
  /* strip the a/b prefix including trailing slash */
- cp = skip_tree_prefix(first.buf, first.len);
+ cp = skip_tree_prefix(state, first.buf, first.len);
  if (!cp)
  goto free_and_fail1;
  strbuf_remove(&first, 0, cp - first.buf);
@@ -1156,7 +1196,7 @@ static char *git_header_name(const char *line, int llen)
  if (*second == '"') {
  if (unquote_c_style(&sp, second, NULL))
  goto free_and_fail1;
- cp = skip_tree_prefix(sp.buf, sp.len);
+ cp = skip_tree_prefix(state, sp.buf, sp.len);
  if (!cp)
  goto free_and_fail1;
  /* They must match, otherwise ignore */
@@ -1167,7 +1207,7 @@ static char *git_header_name(const char *line, int llen)
  }
 
  /* unquoted second */
- cp = skip_tree_prefix(second, line + llen - second);
+ cp = skip_tree_prefix(state, second, line + llen - second);
  if (!cp)
  goto free_and_fail1;
  if (line + llen - cp != first.len ||
@@ -1182,7 +1222,7 @@ static char *git_header_name(const char *line, int llen)
  }
 
  /* unquoted first name */
- name = skip_tree_prefix(line, llen);
+ name = skip_tree_prefix(state, line, llen);
  if (!name)
  return NULL;
 
@@ -1198,7 +1238,7 @@ static char *git_header_name(const char *line, int llen)
  if (unquote_c_style(&sp, second, NULL))
  goto free_and_fail2;
 
- np = skip_tree_prefix(sp.buf, sp.len);
+ np = skip_tree_prefix(state, sp.buf, sp.len);
  if (!np)
  goto free_and_fail2;
 
@@ -1242,7 +1282,7 @@ static char *git_header_name(const char *line, int llen)
  */
  if (!name[len + 1])
  return NULL; /* no postimage name */
- second = skip_tree_prefix(name + len + 1,
+ second = skip_tree_prefix(state, name + len + 1,
   line_len - (len + 1));
  if (!second)
  return NULL;
@@ -1258,7 +1298,11 @@ static char *git_header_name(const char *line, int llen)
 }
 
 /* Verify that we recognize the lines following a git header */
-static int parse_git_header(const char *line, int len, unsigned int size, struct patch *patch)
+static int parse_git_header(struct apply_state *state,
+    const char *line,
+    int len,
+    unsigned int size,
+    struct patch *patch)
 {
  unsigned long offset;
 
@@ -1272,7 +1316,7 @@ static int parse_git_header(const char *line, int len, unsigned int size, struct
  * or removing or adding empty files), so we get
  * the default name from the header.
  */
- patch->def_name = git_header_name(line, len);
+ patch->def_name = git_header_name(state, line, len);
  if (patch->def_name && root.len) {
  char *s = xstrfmt("%s%s", root.buf, patch->def_name);
  free(patch->def_name);
@@ -1285,7 +1329,7 @@ static int parse_git_header(const char *line, int len, unsigned int size, struct
  for (offset = len ; size > 0 ; offset += len, size -= len, line += len, state_linenr++) {
  static const struct opentry {
  const char *str;
- int (*fn)(const char *, struct patch *);
+ int (*fn)(struct apply_state *, const char *, struct patch *);
  } optable[] = {
  { "@@ -", gitdiff_hdrend },
  { "--- ", gitdiff_oldname },
@@ -1315,7 +1359,7 @@ static int parse_git_header(const char *line, int len, unsigned int size, struct
  int oplen = strlen(p->str);
  if (len < oplen || memcmp(p->str, line, oplen))
  continue;
- if (p->fn(line + oplen, patch) < 0)
+ if (p->fn(state, line + oplen, patch) < 0)
  return offset;
  break;
  }
@@ -1485,7 +1529,7 @@ static int find_header(struct apply_state *state,
  * or mode change, so we handle that specially
  */
  if (!memcmp("diff --git ", line, 11)) {
- int git_hdr_len = parse_git_header(line, len, size, patch);
+ int git_hdr_len = parse_git_header(state, line, len, size, patch);
  if (git_hdr_len <= len)
  continue;
  if (!patch->old_name && !patch->new_name) {
@@ -1494,8 +1538,8 @@ static int find_header(struct apply_state *state,
        "%d leading pathname component (line %d)",
        "git diff header lacks filename information when removing "
        "%d leading pathname components (line %d)",
-       state_p_value),
-    state_p_value, state_linenr);
+       state->p_value),
+    state->p_value, state_linenr);
  patch->old_name = xstrdup(patch->def_name);
  patch->new_name = xstrdup(patch->def_name);
  }
@@ -4539,9 +4583,11 @@ static int option_parse_include(const struct option *opt,
 }
 
 static int option_parse_p(const struct option *opt,
-  const char *arg, int unset)
+  const char *arg,
+  int unset)
 {
- state_p_value = atoi(arg);
+ struct apply_state *state = opt->value;
+ state->p_value = atoi(arg);
  p_value_known = 1;
  return 0;
 }
@@ -4582,6 +4628,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
  state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
  state->apply = 1;
  state->line_termination = '\n';
+ state->p_value = 1;
  state->p_context = UINT_MAX;
 
  git_apply_config();
@@ -4615,7 +4662,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  { OPTION_CALLBACK, 0, "include", &state, N_("path"),
  N_("apply changes matching the given path"),
  0, option_parse_include },
- { OPTION_CALLBACK, 'p', NULL, NULL, N_("num"),
+ { OPTION_CALLBACK, 'p', NULL, &state, N_("num"),
  N_("remove <num> leading slashes from traditional diff paths"),
  0, option_parse_p },
  OPT_BOOL(0, "no-add", &state.no_add,
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 33/49] builtin/apply: move 'p_value_known' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'p_value_known' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 843fafd..e1b68d4 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -52,6 +52,7 @@ struct apply_state {
  const char *patch_input_file;
  int line_termination;
  int p_value;
+ int p_value_known;
  unsigned int p_context;
 
  /* Exclude and include path parameters */
@@ -61,8 +62,6 @@ struct apply_state {
 
 static int newfd = -1;
 
-static int p_value_known;
-
 static const char * const apply_usage[] = {
  N_("git apply [<options>] [<patch>...]"),
  NULL
@@ -875,14 +874,14 @@ static void parse_traditional_patch(struct apply_state *state,
 
  first += 4; /* skip "--- " */
  second += 4; /* skip "+++ " */
- if (!p_value_known) {
+ if (!state->p_value_known) {
  int p, q;
  p = guess_p_value(state, first);
  q = guess_p_value(state, second);
  if (p < 0) p = q;
  if (0 <= p && p == q) {
  state->p_value = p;
- p_value_known = 1;
+ state->p_value_known = 1;
  }
  }
  if (is_dev_null(first)) {
@@ -4588,7 +4587,7 @@ static int option_parse_p(const struct option *opt,
 {
  struct apply_state *state = opt->value;
  state->p_value = atoi(arg);
- p_value_known = 1;
+ state->p_value_known = 1;
  return 0;
 }
 
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 34/49] builtin/apply: move 'root' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'root' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 82 ++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 49 insertions(+), 33 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index e1b68d4..5dc1d89 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -51,6 +51,7 @@ struct apply_state {
  const char *fake_ancestor;
  const char *patch_input_file;
  int line_termination;
+ struct strbuf root;
  int p_value;
  int p_value_known;
  unsigned int p_context;
@@ -83,8 +84,6 @@ static enum ws_ignore {
 } ws_ignore_action = ignore_ws_none;
 
 
-static struct strbuf root = STRBUF_INIT;
-
 static void parse_whitespace_option(const char *option)
 {
  if (!option) {
@@ -474,7 +473,10 @@ static char *squash_slash(char *name)
  return name;
 }
 
-static char *find_name_gnu(const char *line, const char *def, int p_value)
+static char *find_name_gnu(struct apply_state *state,
+   const char *line,
+   const char *def,
+   int p_value)
 {
  struct strbuf name = STRBUF_INIT;
  char *cp;
@@ -498,8 +500,8 @@ static char *find_name_gnu(const char *line, const char *def, int p_value)
  }
 
  strbuf_remove(&name, 0, cp - name.buf);
- if (root.len)
- strbuf_insert(&name, 0, root.buf, root.len);
+ if (state->root.len)
+ strbuf_insert(&name, 0, state->root.buf, state->root.len);
  return squash_slash(strbuf_detach(&name, NULL));
 }
 
@@ -662,8 +664,12 @@ static size_t diff_timestamp_len(const char *line, size_t len)
  return line + len - end;
 }
 
-static char *find_name_common(const char *line, const char *def,
-      int p_value, const char *end, int terminate)
+static char *find_name_common(struct apply_state *state,
+      const char *line,
+      const char *def,
+      int p_value,
+      const char *end,
+      int terminate)
 {
  int len;
  const char *start = NULL;
@@ -701,32 +707,39 @@ static char *find_name_common(const char *line, const char *def,
  return squash_slash(xstrdup(def));
  }
 
- if (root.len) {
- char *ret = xstrfmt("%s%.*s", root.buf, len, start);
+ if (state->root.len) {
+ char *ret = xstrfmt("%s%.*s", state->root.buf, len, start);
  return squash_slash(ret);
  }
 
  return squash_slash(xmemdupz(start, len));
 }
 
-static char *find_name(const char *line, char *def, int p_value, int terminate)
+static char *find_name(struct apply_state *state,
+       const char *line,
+       char *def,
+       int p_value,
+       int terminate)
 {
  if (*line == '"') {
- char *name = find_name_gnu(line, def, p_value);
+ char *name = find_name_gnu(state, line, def, p_value);
  if (name)
  return name;
  }
 
- return find_name_common(line, def, p_value, NULL, terminate);
+ return find_name_common(state, line, def, p_value, NULL, terminate);
 }
 
-static char *find_name_traditional(const char *line, char *def, int p_value)
+static char *find_name_traditional(struct apply_state *state,
+   const char *line,
+   char *def,
+   int p_value)
 {
  size_t len;
  size_t date_len;
 
  if (*line == '"') {
- char *name = find_name_gnu(line, def, p_value);
+ char *name = find_name_gnu(state, line, def, p_value);
  if (name)
  return name;
  }
@@ -734,10 +747,10 @@ static char *find_name_traditional(const char *line, char *def, int p_value)
  len = strchrnul(line, '\n') - line;
  date_len = diff_timestamp_len(line, len);
  if (!date_len)
- return find_name_common(line, def, p_value, NULL, TERM_TAB);
+ return find_name_common(state, line, def, p_value, NULL, TERM_TAB);
  len -= date_len;
 
- return find_name_common(line, def, p_value, line + len, 0);
+ return find_name_common(state, line, def, p_value, line + len, 0);
 }
 
 static int count_slashes(const char *cp)
@@ -762,7 +775,7 @@ static int guess_p_value(struct apply_state *state, const char *nameline)
 
  if (is_dev_null(nameline))
  return -1;
- name = find_name_traditional(nameline, NULL, 0);
+ name = find_name_traditional(state, nameline, NULL, 0);
  if (!name)
  return -1;
  cp = strchr(name, '/');
@@ -887,17 +900,17 @@ static void parse_traditional_patch(struct apply_state *state,
  if (is_dev_null(first)) {
  patch->is_new = 1;
  patch->is_delete = 0;
- name = find_name_traditional(second, NULL, state->p_value);
+ name = find_name_traditional(state, second, NULL, state->p_value);
  patch->new_name = name;
  } else if (is_dev_null(second)) {
  patch->is_new = 0;
  patch->is_delete = 1;
- name = find_name_traditional(first, NULL, state->p_value);
+ name = find_name_traditional(state, first, NULL, state->p_value);
  patch->old_name = name;
  } else {
  char *first_name;
- first_name = find_name_traditional(first, NULL, state->p_value);
- name = find_name_traditional(second, first_name, state->p_value);
+ first_name = find_name_traditional(state, first, NULL, state->p_value);
+ name = find_name_traditional(state, second, first_name, state->p_value);
  free(first_name);
  if (has_epoch_timestamp(first)) {
  patch->is_new = 1;
@@ -942,7 +955,7 @@ static void gitdiff_verify_name(struct apply_state *state,
  int side)
 {
  if (!*name && !isnull) {
- *name = find_name(line, NULL, state->p_value, TERM_TAB);
+ *name = find_name(state, line, NULL, state->p_value, TERM_TAB);
  return;
  }
 
@@ -952,7 +965,7 @@ static void gitdiff_verify_name(struct apply_state *state,
  if (isnull)
  die(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
     *name, state_linenr);
- another = find_name(line, NULL, state->p_value, TERM_TAB);
+ another = find_name(state, line, NULL, state->p_value, TERM_TAB);
  if (!another || memcmp(another, *name, len + 1))
  die((side == DIFF_NEW_NAME) ?
     _("git apply: bad git-diff - inconsistent new filename on line %d") :
@@ -1027,7 +1040,7 @@ static int gitdiff_copysrc(struct apply_state *state,
 {
  patch->is_copy = 1;
  free(patch->old_name);
- patch->old_name = find_name(line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
+ patch->old_name = find_name(state, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
  return 0;
 }
 
@@ -1037,7 +1050,7 @@ static int gitdiff_copydst(struct apply_state *state,
 {
  patch->is_copy = 1;
  free(patch->new_name);
- patch->new_name = find_name(line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
+ patch->new_name = find_name(state, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
  return 0;
 }
 
@@ -1047,7 +1060,7 @@ static int gitdiff_renamesrc(struct apply_state *state,
 {
  patch->is_rename = 1;
  free(patch->old_name);
- patch->old_name = find_name(line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
+ patch->old_name = find_name(state, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
  return 0;
 }
 
@@ -1057,7 +1070,7 @@ static int gitdiff_renamedst(struct apply_state *state,
 {
  patch->is_rename = 1;
  free(patch->new_name);
- patch->new_name = find_name(line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
+ patch->new_name = find_name(state, line, NULL, state->p_value ? state->p_value - 1 : 0, 0);
  return 0;
 }
 
@@ -1316,8 +1329,8 @@ static int parse_git_header(struct apply_state *state,
  * the default name from the header.
  */
  patch->def_name = git_header_name(state, line, len);
- if (patch->def_name && root.len) {
- char *s = xstrfmt("%s%s", root.buf, patch->def_name);
+ if (patch->def_name && state->root.len) {
+ char *s = xstrfmt("%s%s", state->root.buf, patch->def_name);
  free(patch->def_name);
  patch->def_name = s;
  }
@@ -4614,9 +4627,10 @@ static int option_parse_whitespace(const struct option *opt,
 static int option_parse_directory(const struct option *opt,
   const char *arg, int unset)
 {
- strbuf_reset(&root);
- strbuf_addstr(&root, arg);
- strbuf_complete(&root, '/');
+ struct apply_state *state = opt->value;
+ strbuf_reset(&state->root);
+ strbuf_addstr(&state->root, arg);
+ strbuf_complete(&state->root, '/');
  return 0;
 }
 
@@ -4629,6 +4643,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
  state->line_termination = '\n';
  state->p_value = 1;
  state->p_context = UINT_MAX;
+ strbuf_init(&state->root, 0);
 
  git_apply_config();
  if (apply_default_whitespace)
@@ -4640,6 +4655,7 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
 static void clear_apply_state(struct apply_state *state)
 {
  string_list_clear(&state->limit_by_name, 0);
+ strbuf_release(&state->root);
 }
 
 int cmd_apply(int argc, const char **argv, const char *prefix)
@@ -4717,7 +4733,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  OPT_BIT(0, "recount", &options,
  N_("do not trust the line counts in the hunk headers"),
  RECOUNT),
- { OPTION_CALLBACK, 0, "directory", NULL, N_("root"),
+ { OPTION_CALLBACK, 0, "directory", &state, N_("root"),
  N_("prepend <root> to all filenames"),
  0, option_parse_directory },
  OPT_END()
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 35/49] builtin/apply: move 'whitespace_error' global into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'whitespace_error' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 5dc1d89..44717b2 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -59,6 +59,9 @@ struct apply_state {
  /* Exclude and include path parameters */
  struct string_list limit_by_name;
  int has_include;
+
+ /* These control whitespace errors */
+ int whitespace_error;
 };
 
 static int newfd = -1;
@@ -74,7 +77,6 @@ static enum ws_error_action {
  die_on_ws_error,
  correct_ws_error
 } ws_error_action = warn_on_ws_error;
-static int whitespace_error;
 static int squelch_whitespace_errors = 5;
 static int applied_after_fixing_ws;
 
@@ -1596,9 +1598,9 @@ static void record_ws_error(struct apply_state *state,
  if (!result)
  return;
 
- whitespace_error++;
+ state->whitespace_error++;
  if (squelch_whitespace_errors &&
-    squelch_whitespace_errors < whitespace_error)
+    squelch_whitespace_errors < state->whitespace_error)
  return;
 
  err = whitespace_error_string(result);
@@ -2855,7 +2857,7 @@ static int apply_one_fragment(struct apply_state *state,
 
  start = newlines.len;
  if (first != '+' ||
-    !whitespace_error ||
+    !state->whitespace_error ||
     ws_error_action != correct_ws_error) {
  strbuf_add(&newlines, patch + 1, plen);
  }
@@ -4528,7 +4530,7 @@ static int apply_patch(struct apply_state *state,
  if (!list && !skipped_patch)
  die(_("unrecognized input"));
 
- if (whitespace_error && (ws_error_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;
@@ -4791,11 +4793,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  set_default_whitespace_mode(&state, whitespace_option);
  if (read_stdin)
  errs |= apply_patch(&state, 0, "<stdin>", options);
- if (whitespace_error) {
+ if (state.whitespace_error) {
  if (squelch_whitespace_errors &&
-    squelch_whitespace_errors < whitespace_error) {
+    squelch_whitespace_errors < state.whitespace_error) {
  int squelched =
- whitespace_error - squelch_whitespace_errors;
+ state.whitespace_error - squelch_whitespace_errors;
  warning(Q_("squelched %d whitespace error",
    "squelched %d whitespace errors",
    squelched),
@@ -4804,18 +4806,18 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  if (ws_error_action == die_on_ws_error)
  die(Q_("%d line adds whitespace errors.",
        "%d lines add whitespace errors.",
-       whitespace_error),
-    whitespace_error);
+       state.whitespace_error),
+    state.whitespace_error);
  if (applied_after_fixing_ws && state.apply)
  warning("%d line%s applied after"
  " fixing whitespace errors.",
  applied_after_fixing_ws,
  applied_after_fixing_ws == 1 ? "" : "s");
- else if (whitespace_error)
+ else if (state.whitespace_error)
  warning(Q_("%d line adds whitespace errors.",
    "%d lines add whitespace errors.",
-   whitespace_error),
- whitespace_error);
+   state.whitespace_error),
+ state.whitespace_error);
  }
 
  if (state.update_index) {
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 36/49] builtin/apply: move 'whitespace_option' into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
This will enable further refactoring, and it is more coherent and
simpler if all the option_parse_*() functions are passed a
'struct apply_state' instance in opt->value.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 44717b2..78205f8 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -61,6 +61,7 @@ struct apply_state {
  int has_include;
 
  /* These control whitespace errors */
+ const char *whitespace_option;
  int whitespace_error;
 };
 
@@ -4619,9 +4620,9 @@ static int option_parse_space_change(const struct option *opt,
 static int option_parse_whitespace(const struct option *opt,
    const char *arg, int unset)
 {
- const char **whitespace_option = opt->value;
+ struct apply_state *state = opt->value;
 
- *whitespace_option = arg;
+ state->whitespace_option = arg;
  parse_whitespace_option(arg);
  return 0;
 }
@@ -4670,8 +4671,6 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  int read_stdin = 1;
  struct apply_state state;
 
- const char *whitespace_option = NULL;
-
  struct option builtin_apply_options[] = {
  { OPTION_CALLBACK, 0, "exclude", &state, N_("path"),
  N_("don't apply changes matching the given path"),
@@ -4711,7 +4710,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  N_("paths are separated with NUL character"), '\0'),
  OPT_INTEGER('C', NULL, &state.p_context,
  N_("ensure at least <n> lines of context match")),
- { OPTION_CALLBACK, 0, "whitespace", &whitespace_option, N_("action"),
+ { OPTION_CALLBACK, 0, "whitespace", &state, N_("action"),
  N_("detect new or modified lines that have whitespace errors"),
  0, option_parse_whitespace },
  { OPTION_CALLBACK, 0, "ignore-space-change", NULL, NULL,
@@ -4786,11 +4785,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  if (fd < 0)
  die_errno(_("can't open patch '%s'"), arg);
  read_stdin = 0;
- set_default_whitespace_mode(&state, whitespace_option);
+ set_default_whitespace_mode(&state, state.whitespace_option);
  errs |= apply_patch(&state, fd, arg, options);
  close(fd);
  }
- set_default_whitespace_mode(&state, whitespace_option);
+ set_default_whitespace_mode(&state, state.whitespace_option);
  if (read_stdin)
  errs |= apply_patch(&state, 0, "<stdin>", options);
  if (state.whitespace_error) {
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 37/49] builtin/apply: remove whitespace_option arg from set_default_whitespace_mode()

Christian Couder-2
In reply to this post by Christian Couder-2
A previous change has move the whitespace_option variable from cmd_apply
into 'struct apply_state', so that we can now avoid passing it separately
to set_default_whitespace_mode().

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 78205f8..523ed74 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -132,10 +132,9 @@ static void parse_ignorewhitespace_option(const char *option)
  die(_("unrecognized whitespace ignore option '%s'"), option);
 }
 
-static void set_default_whitespace_mode(struct apply_state *state,
- const char *whitespace_option)
+static void set_default_whitespace_mode(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);
 }
 
@@ -4785,11 +4784,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  if (fd < 0)
  die_errno(_("can't open patch '%s'"), arg);
  read_stdin = 0;
- set_default_whitespace_mode(&state, state.whitespace_option);
+ set_default_whitespace_mode(&state);
  errs |= apply_patch(&state, fd, arg, options);
  close(fd);
  }
- set_default_whitespace_mode(&state, state.whitespace_option);
+ set_default_whitespace_mode(&state);
  if (read_stdin)
  errs |= apply_patch(&state, 0, "<stdin>", options);
  if (state.whitespace_error) {
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 38/49] builtin/apply: move 'squelch_whitespace_errors' into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'squelch_whitespace_errors' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 523ed74..619b8fb 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -63,6 +63,7 @@ struct apply_state {
  /* These control whitespace errors */
  const char *whitespace_option;
  int whitespace_error;
+ int squelch_whitespace_errors;
 };
 
 static int newfd = -1;
@@ -78,7 +79,6 @@ static enum ws_error_action {
  die_on_ws_error,
  correct_ws_error
 } ws_error_action = warn_on_ws_error;
-static int squelch_whitespace_errors = 5;
 static int applied_after_fixing_ws;
 
 static enum ws_ignore {
@@ -87,7 +87,7 @@ static enum ws_ignore {
 } ws_ignore_action = ignore_ws_none;
 
 
-static void parse_whitespace_option(const char *option)
+static void parse_whitespace_option(struct apply_state *state, const char *option)
 {
  if (!option) {
  ws_error_action = warn_on_ws_error;
@@ -107,7 +107,7 @@ static void parse_whitespace_option(const char *option)
  }
  if (!strcmp(option, "error-all")) {
  ws_error_action = die_on_ws_error;
- squelch_whitespace_errors = 0;
+ state->squelch_whitespace_errors = 0;
  return;
  }
  if (!strcmp(option, "strip") || !strcmp(option, "fix")) {
@@ -1599,8 +1599,8 @@ static void record_ws_error(struct apply_state *state,
  return;
 
  state->whitespace_error++;
- if (squelch_whitespace_errors &&
-    squelch_whitespace_errors < state->whitespace_error)
+ if (state->squelch_whitespace_errors &&
+    state->squelch_whitespace_errors < state->whitespace_error)
  return;
 
  err = whitespace_error_string(result);
@@ -4620,9 +4620,8 @@ static int option_parse_whitespace(const struct option *opt,
    const char *arg, int unset)
 {
  struct apply_state *state = opt->value;
-
  state->whitespace_option = arg;
- parse_whitespace_option(arg);
+ parse_whitespace_option(state, arg);
  return 0;
 }
 
@@ -4645,11 +4644,12 @@ static void init_apply_state(struct apply_state *state, const char *prefix)
  state->line_termination = '\n';
  state->p_value = 1;
  state->p_context = UINT_MAX;
+ state->squelch_whitespace_errors = 5;
  strbuf_init(&state->root, 0);
 
  git_apply_config();
  if (apply_default_whitespace)
- parse_whitespace_option(apply_default_whitespace);
+ parse_whitespace_option(state, apply_default_whitespace);
  if (apply_default_ignorewhitespace)
  parse_ignorewhitespace_option(apply_default_ignorewhitespace);
 }
@@ -4792,10 +4792,10 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
  if (read_stdin)
  errs |= apply_patch(&state, 0, "<stdin>", options);
  if (state.whitespace_error) {
- if (squelch_whitespace_errors &&
-    squelch_whitespace_errors < state.whitespace_error) {
+ if (state.squelch_whitespace_errors &&
+    state.squelch_whitespace_errors < state.whitespace_error) {
  int squelched =
- state.whitespace_error - squelch_whitespace_errors;
+ state.whitespace_error - state.squelch_whitespace_errors;
  warning(Q_("squelched %d whitespace error",
    "squelched %d whitespace errors",
    squelched),
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH v3 39/49] builtin/apply: move 'applied_after_fixing_ws' into 'struct apply_state'

Christian Couder-2
In reply to this post by Christian Couder-2
To libify the apply functionality the 'applied_after_fixing_ws' variable should
not be static and global to the file. Let's move it into
'struct apply_state'.

Reviewed-by: Stefan Beller <[hidden email]>
Signed-off-by: Christian Couder <[hidden email]>
---
 builtin/apply.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 619b8fb..91b6283 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -64,6 +64,7 @@ struct apply_state {
  const char *whitespace_option;
  int whitespace_error;
  int squelch_whitespace_errors;
+ int applied_after_fixing_ws;
 };
 
 static int newfd = -1;
@@ -79,7 +80,6 @@ static enum ws_error_action {
  die_on_ws_error,
  correct_ws_error
 } ws_error_action = warn_on_ws_error;
-static int applied_after_fixing_ws;
 
 static enum ws_ignore {
  ignore_ws_none,
@@ -2862,7 +2862,7 @@ static int apply_one_fragment(struct apply_state *state,
  strbuf_add(&newlines, patch + 1, plen);
  }
  else {
- ws_fix_copy(&newlines, patch + 1, plen, ws_rule, &applied_after_fixing_ws);
+ ws_fix_copy(&newlines, patch + 1, plen, ws_rule, &state->applied_after_fixing_ws);
  }
  add_line_info(&postimage, newlines.buf + start, newlines.len - start,
       (first == '+' ? 0 : LINE_COMMON));
@@ -4806,11 +4806,11 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
        "%d lines add whitespace errors.",
        state.whitespace_error),
     state.whitespace_error);
- if (applied_after_fixing_ws && state.apply)
+ if (state.applied_after_fixing_ws && state.apply)
  warning("%d line%s applied after"
  " fixing whitespace errors.",
- applied_after_fixing_ws,
- applied_after_fixing_ws == 1 ? "" : "s");
+ 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.",
--
2.8.3.443.gaeee61e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
123