git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Christian Couder <christian.couder@gmail.com>
Date
May 24, 2016, 08:59 UTC
Message-ID
<CAP8UFD0oU4BM=k=+9ijz86ZH8o63i3EVxqL-XMZaZKdyD7_x-w@mail.gmail.com>
In-Reply-To
<20160524081126.16973-1-chriscool@tuxfamily.org>

On Tue, May 24, 2016 at 10:10 AM, Christian Couder <christian.couder@gmail.com> wrote:

>
> I will send a diff between this version and the 50 first patches of v2
> soon as a reply to this email.
Here is the diff:
diff --git a/builtin/apply.c b/builtin/apply.c
index ec55768..c1c5592 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -59,44 +59,44 @@ struct apply_state {
     struct lock_file *lock_file;
     int newfd;

-    int apply;
+    /* 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 */
+    int update_index; /* check_index && apply */
+
+    /* 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;
     int apply_in_reverse;
     int apply_with_reject;
     int apply_verbosely;
-
-    /* --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;
-
-    /* --numstat does numeric diffstat, and doesn't actually apply */
-    int numstat;
-
-    int summary;
-    int threeway;
     int no_add;
+    int threeway;
+    int unidiff_zero;
+    int unsafe_paths;
+
+    /* Other non boolean parameters */
     const char *fake_ancestor;
     const char *patch_input_file;
-    struct string_list limit_by_name;
-    int has_include;
+    int line_termination;
     struct strbuf root;
-    struct string_list symlink_changes;
-
-    /*
-     *  --check turns on checking that the working tree matches the
-     *    files that are being modified, but doesn't apply the patch
-     */
-    int check;
+    int p_value;
+    int p_value_known;
+    unsigned int p_context;

-    /* --index updates the cache as well. */
-    int check_index;
+    /* Exclude and include path parameters */
+    struct string_list limit_by_name;
+    int has_include;

-    int unidiff_zero;
-    int update_index;
-    int unsafe_paths;
-    int line_termination;
+    /* Various "current state" */
+    int linenr; /* current line number */
+    struct string_list symlink_changes; /* we have to track symlinks */

     /*
      * For "diff-stat" like behaviour, we keep track of the biggest change
@@ -106,30 +106,19 @@ struct apply_state {
     int max_change;
     int max_len;

-    /*
-     * Various "current state", notably line numbers and what
-     * file (and how) we're patching right now.. The "is_xxxx"
-     * things are flags, where -1 means "don't know yet".
-     */
-    int linenr;
-
     /*
      * Records filenames that have been touched, in order to handle
      * the case where more than one patches touch the same file.
      */
     struct string_list fn_table;
-
-    int p_value;
-    int p_value_known;
-    unsigned int p_context;

+    /* These control whitespace errors */
+    enum ws_error_action ws_error_action;
+    enum ws_ignore ws_ignore_action;
     const char *whitespace_option;
     int whitespace_error;
     int squelch_whitespace_errors;
     int applied_after_fixing_ws;
-
-    enum ws_error_action ws_error_action;
-    enum ws_ignore ws_ignore_action;
 };

 static const char * const apply_usage[] = {
@@ -4688,6 +4677,15 @@ static void init_apply_state(struct apply_state *state,
         parse_ignorewhitespace_option(state, apply_default_ignorewhitespace);
 }

+static void clear_apply_state(struct apply_state *state)
+{
+    string_list_clear(&state->limit_by_name, 0);
+    string_list_clear(&state->symlink_changes, 0);
+    strbuf_release(&state->root);
+
+    /* &state->fn_table is cleared at the end of apply_patch() */
+}
+
 static void check_apply_state(struct apply_state *state, int force_apply)
 {
     int is_not_gitdir = !startup_info->have_repository;
@@ -4790,6 +4788,7 @@ int cmd_apply(int argc, const char **argv, const
char *prefix)
 {
     int force_apply = 0;
     int options = 0;
+    int ret;
     struct apply_state state;

     struct option builtin_apply_options[] = {
@@ -4868,5 +4867,9 @@ int cmd_apply(int argc, const char **argv, const
char *prefix)

     check_apply_state(&state, force_apply);

-    return apply_all_patches(&state, argc, argv, options);
+    ret = apply_all_patches(&state, argc, argv, options);
+
+    clear_apply_state(&state);
+
+    return ret;
 }
Previous: Christian Couder
Message 53 of 53 in “libify apply and use lib in am, part 1”
  1. 00/49 libify apply and use lib in am, part 1Christian Couder, May 24, 2016
  2. 01/49 builtin/apply: make gitdiff_verify_name() return voidChristian Couder, May 24, 2016
  3. 02/49 builtin/apply: avoid parameter shadowing 'p_value' globalChristian Couder, May 24, 2016
  4. 03/49 builtin/apply: avoid parameter shadowing 'linenr' globalChristian Couder, May 24, 2016
  5. 04/49 builtin/apply: avoid local variable shadowing 'len' parameterChristian Couder, May 24, 2016
  6. 05/49 builtin/apply: extract line_by_line_fuzzy_match() from match_fragment()Christian Couder, May 24, 2016
  7. 06/49 builtin/apply: move 'options' variable into cmd_apply()Christian Couder, May 24, 2016
  8. 07/49 builtin/apply: move 'read_stdin' global into cmd_apply()Christian Couder, May 24, 2016
  9. 08/49 builtin/apply: introduce 'struct apply_state' to start libifyingChristian Couder, May 24, 2016
  10. 09/49 builtin/apply: move 'state' init into init_apply_state()Christian Couder, May 24, 2016
  11. 10/49 builtin/apply: move 'unidiff_zero' global into 'struct apply_state'Christian Couder, May 24, 2016
  12. 11/49 builtin/apply: move 'check' global into 'struct apply_state'Christian Couder, May 24, 2016
  13. 12/49 builtin/apply: move 'check_index' global into 'struct apply_state'Christian Couder, May 24, 2016
  14. 13/49 builtin/apply: move 'apply_in_reverse' global into 'struct apply_state'Christian Couder, May 24, 2016
  15. 14/49 builtin/apply: move 'apply_with_reject' global into 'struct apply_state'Christian Couder, May 24, 2016
  16. 15/49 builtin/apply: move 'apply_verbosely' global into 'struct apply_state'Christian Couder, May 24, 2016
  17. 16/49 builtin/apply: move 'update_index' global into 'struct apply_state'Christian Couder, May 24, 2016
  18. 17/49 builtin/apply: move 'allow_overlap' global into 'struct apply_state'Christian Couder, May 24, 2016
  19. 18/49 builtin/apply: move 'cached' global into 'struct apply_state'Christian Couder, May 24, 2016
  20. 19/49 builtin/apply: move 'diffstat' global into 'struct apply_state'Christian Couder, May 24, 2016
  21. 20/49 builtin/apply: move 'numstat' global into 'struct apply_state'Christian Couder, May 24, 2016
  22. 21/49 builtin/apply: move 'summary' global into 'struct apply_state'Christian Couder, May 24, 2016
  23. 22/49 builtin/apply: move 'threeway' global into 'struct apply_state'Christian Couder, May 24, 2016
  24. 23/49 builtin/apply: move 'no_add' global into 'struct apply_state'Christian Couder, May 24, 2016
  25. 24/49 builtin/apply: move 'unsafe_paths' global into 'struct apply_state'Christian Couder, May 24, 2016
  26. 25/49 builtin/apply: move 'line_termination' global into 'struct apply_state'Christian Couder, May 24, 2016
  27. 26/49 builtin/apply: move 'fake_ancestor' global into 'struct apply_state'Christian Couder, May 24, 2016
  28. 27/49 builtin/apply: move 'p_context' global into 'struct apply_state'Christian Couder, May 24, 2016
  29. 28/49 builtin/apply: move 'apply' global into 'struct apply_state'Christian Couder, May 24, 2016
  30. 29/49 builtin/apply: move 'patch_input_file' global into 'struct apply_state'Christian Couder, May 24, 2016
  31. 30/49 builtin/apply: move 'limit_by_name' global into 'struct apply_state'Christian Couder, May 24, 2016
  32. 31/49 builtin/apply: move 'has_include' global into 'struct apply_state'Christian Couder, May 24, 2016
  33. 32/49 builtin/apply: move 'p_value' global into 'struct apply_state'Christian Couder, May 24, 2016
  34. 33/49 builtin/apply: move 'p_value_known' global into 'struct apply_state'Christian Couder, May 24, 2016
  35. 34/49 builtin/apply: move 'root' global into 'struct apply_state'Christian Couder, May 24, 2016
  36. 35/49 builtin/apply: move 'whitespace_error' global into 'struct apply_state'Christian Couder, May 24, 2016
  37. 36/49 builtin/apply: move 'whitespace_option' into 'struct apply_state'Christian Couder, May 24, 2016
  38. 37/49 builtin/apply: remove whitespace_option arg from set_default_whitespace_mode()Christian Couder, May 24, 2016
  39. 38/49 builtin/apply: move 'squelch_whitespace_errors' into 'struct apply_state'Christian Couder, May 24, 2016
  40. 39/49 builtin/apply: move 'applied_after_fixing_ws' into 'struct apply_state'Christian Couder, May 24, 2016
  41. 40/49 builtin/apply: move 'ws_error_action' into 'struct apply_state'Christian Couder, May 24, 2016
  42. 41/49 builtin/apply: move 'ws_ignore_action' into 'struct apply_state'Christian Couder, May 24, 2016
  43. 42/49 builtin/apply: move 'max_change' and 'max_len' into 'struct apply_state'Christian Couder, May 24, 2016
  44. 43/49 builtin/apply: move 'state_linenr' global into 'struct apply_state'Christian Couder, May 24, 2016
  45. 44/49 builtin/apply: move 'fn_table' global into 'struct apply_state'Christian Couder, May 24, 2016
  46. 45/49 builtin/apply: move 'symlink_changes' global into 'struct apply_state'Christian Couder, May 24, 2016
  47. 46/49 builtin/apply: move 'state' check into check_apply_state()Christian Couder, May 24, 2016
  48. 47/49 builtin/apply: move applying patches into apply_all_patches()Christian Couder, May 24, 2016
  49. 48/49 builtin/apply: move 'lock_file' global into 'struct apply_state'Christian Couder, May 24, 2016
  50. Junio C HamanoJun 1, 2016
  51. Christian CouderJun 3, 2016
  52. 49/49 builtin/apply: move 'newfd' global into 'struct apply_state'Christian Couder, May 24, 2016
  53. Christian CouderMay 24, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.