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.
 
 
 
 
 
 

190 lines
5.3 KiB

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