THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
5.3KB

  1. #ifndef APPLY_H
  2. #define APPLY_H
  3. #include "hash.h"
  4. #include "lockfile.h"
  5. #include "string-list.h"
  6. struct repository;
  7. enum apply_ws_error_action {
  8. nowarn_ws_error,
  9. warn_on_ws_error,
  10. die_on_ws_error,
  11. correct_ws_error
  12. };
  13. enum apply_ws_ignore {
  14. ignore_ws_none,
  15. ignore_ws_change
  16. };
  17. enum apply_verbosity {
  18. verbosity_silent = -1,
  19. verbosity_normal = 0,
  20. verbosity_verbose = 1
  21. };
  22. /*
  23. * We need to keep track of how symlinks in the preimage are
  24. * manipulated by the patches. A patch to add a/b/c where a/b
  25. * is a symlink should not be allowed to affect the directory
  26. * the symlink points at, but if the same patch removes a/b,
  27. * it is perfectly fine, as the patch removes a/b to make room
  28. * to create a directory a/b so that a/b/c can be created.
  29. *
  30. * See also "struct string_list symlink_changes" in "struct
  31. * apply_state".
  32. */
  33. #define APPLY_SYMLINK_GOES_AWAY 01
  34. #define APPLY_SYMLINK_IN_RESULT 02
  35. struct apply_state {
  36. const char *prefix;
  37. /* Lock file */
  38. struct lock_file lock_file;
  39. /* These control what gets looked at and modified */
  40. int apply; /* this is not a dry-run */
  41. int cached; /* apply to the index only */
  42. int check; /* preimage must match working tree, don't actually apply */
  43. int check_index; /* preimage must match the indexed version */
  44. int update_index; /* check_index && apply */
  45. int ita_only; /* add intent-to-add entries to the index */
  46. /* These control cosmetic aspect of the output */
  47. int diffstat; /* just show a diffstat, and don't actually apply */
  48. int numstat; /* just show a numeric diffstat, and don't actually apply */
  49. int summary; /* just report creation, deletion, etc, and don't actually apply */
  50. /* These boolean parameters control how the apply is done */
  51. int allow_overlap;
  52. int apply_in_reverse;
  53. int apply_with_reject;
  54. int no_add;
  55. int threeway;
  56. int unidiff_zero;
  57. int unsafe_paths;
  58. /* Other non boolean parameters */
  59. struct repository *repo;
  60. const char *index_file;
  61. enum apply_verbosity apply_verbosity;
  62. const char *fake_ancestor;
  63. const char *patch_input_file;
  64. int line_termination;
  65. struct strbuf root;
  66. int p_value;
  67. int p_value_known;
  68. unsigned int p_context;
  69. /* Exclude and include path parameters */
  70. struct string_list limit_by_name;
  71. int has_include;
  72. /* Various "current state" */
  73. int linenr; /* current line number */
  74. struct string_list symlink_changes; /* we have to track symlinks */
  75. /*
  76. * For "diff-stat" like behaviour, we keep track of the biggest change
  77. * we've seen, and the longest filename. That allows us to do simple
  78. * scaling.
  79. */
  80. int max_change;
  81. int max_len;
  82. /*
  83. * Records filenames that have been touched, in order to handle
  84. * the case where more than one patches touch the same file.
  85. */
  86. struct string_list fn_table;
  87. /*
  88. * This is to save reporting routines before using
  89. * set_error_routine() or set_warn_routine() to install muting
  90. * routines when in verbosity_silent mode.
  91. */
  92. void (*saved_error_routine)(const char *err, va_list params);
  93. void (*saved_warn_routine)(const char *warn, va_list params);
  94. /* These control whitespace errors */
  95. enum apply_ws_error_action ws_error_action;
  96. enum apply_ws_ignore ws_ignore_action;
  97. const char *whitespace_option;
  98. int whitespace_error;
  99. int squelch_whitespace_errors;
  100. int applied_after_fixing_ws;
  101. };
  102. /*
  103. * This represents a "patch" to a file, both metainfo changes
  104. * such as creation/deletion, filemode and content changes represented
  105. * as a series of fragments.
  106. */
  107. struct patch {
  108. char *new_name, *old_name, *def_name;
  109. unsigned int old_mode, new_mode;
  110. int is_new, is_delete; /* -1 = unknown, 0 = false, 1 = true */
  111. int rejected;
  112. unsigned ws_rule;
  113. int lines_added, lines_deleted;
  114. int score;
  115. int extension_linenr; /* first line specifying delete/new/rename/copy */
  116. unsigned int is_toplevel_relative:1;
  117. unsigned int inaccurate_eof:1;
  118. unsigned int is_binary:1;
  119. unsigned int is_copy:1;
  120. unsigned int is_rename:1;
  121. unsigned int recount:1;
  122. unsigned int conflicted_threeway:1;
  123. unsigned int direct_to_threeway:1;
  124. unsigned int crlf_in_old:1;
  125. struct fragment *fragments;
  126. char *result;
  127. size_t resultsize;
  128. char old_oid_prefix[GIT_MAX_HEXSZ + 1];
  129. char new_oid_prefix[GIT_MAX_HEXSZ + 1];
  130. struct patch *next;
  131. /* three-way fallback result */
  132. struct object_id threeway_stage[3];
  133. };
  134. int apply_parse_options(int argc, const char **argv,
  135. struct apply_state *state,
  136. int *force_apply, int *options,
  137. const char * const *apply_usage);
  138. int init_apply_state(struct apply_state *state,
  139. struct repository *repo,
  140. const char *prefix);
  141. void clear_apply_state(struct apply_state *state);
  142. int check_apply_state(struct apply_state *state, int force_apply);
  143. /*
  144. * Parse a git diff header, starting at line. Fills the relevant
  145. * metadata information in 'struct patch'.
  146. *
  147. * Returns -1 on failure, the length of the parsed header otherwise.
  148. */
  149. int parse_git_diff_header(struct strbuf *root,
  150. int *linenr,
  151. int p_value,
  152. const char *line,
  153. int len,
  154. unsigned int size,
  155. struct patch *patch);
  156. /*
  157. * Some aspects of the apply behavior are controlled by the following
  158. * bits in the "options" parameter passed to apply_all_patches().
  159. */
  160. #define APPLY_OPT_INACCURATE_EOF (1<<0) /* accept inaccurate eof */
  161. #define APPLY_OPT_RECOUNT (1<<1) /* accept inaccurate line count */
  162. int apply_all_patches(struct apply_state *state,
  163. int argc, const char **argv,
  164. int options);
  165. #endif