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.

496 lines
15KB

  1. /*
  2. * Copyright (C) 2005 Junio C Hamano
  3. */
  4. #ifndef DIFF_H
  5. #define DIFF_H
  6. #include "tree-walk.h"
  7. #include "pathspec.h"
  8. #include "object.h"
  9. #include "oidset.h"
  10. struct combine_diff_path;
  11. struct commit;
  12. struct diff_filespec;
  13. struct diff_options;
  14. struct diff_queue_struct;
  15. struct oid_array;
  16. struct option;
  17. struct repository;
  18. struct rev_info;
  19. struct strbuf;
  20. struct userdiff_driver;
  21. typedef int (*pathchange_fn_t)(struct diff_options *options,
  22. struct combine_diff_path *path);
  23. typedef void (*change_fn_t)(struct diff_options *options,
  24. unsigned old_mode, unsigned new_mode,
  25. const struct object_id *old_oid,
  26. const struct object_id *new_oid,
  27. int old_oid_valid, int new_oid_valid,
  28. const char *fullpath,
  29. unsigned old_dirty_submodule, unsigned new_dirty_submodule);
  30. typedef void (*add_remove_fn_t)(struct diff_options *options,
  31. int addremove, unsigned mode,
  32. const struct object_id *oid,
  33. int oid_valid,
  34. const char *fullpath, unsigned dirty_submodule);
  35. typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
  36. struct diff_options *options, void *data);
  37. typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
  38. #define DIFF_FORMAT_RAW 0x0001
  39. #define DIFF_FORMAT_DIFFSTAT 0x0002
  40. #define DIFF_FORMAT_NUMSTAT 0x0004
  41. #define DIFF_FORMAT_SUMMARY 0x0008
  42. #define DIFF_FORMAT_PATCH 0x0010
  43. #define DIFF_FORMAT_SHORTSTAT 0x0020
  44. #define DIFF_FORMAT_DIRSTAT 0x0040
  45. /* These override all above */
  46. #define DIFF_FORMAT_NAME 0x0100
  47. #define DIFF_FORMAT_NAME_STATUS 0x0200
  48. #define DIFF_FORMAT_CHECKDIFF 0x0400
  49. /* Same as output_format = 0 but we know that -s flag was given
  50. * and we should not give default value to output_format.
  51. */
  52. #define DIFF_FORMAT_NO_OUTPUT 0x0800
  53. #define DIFF_FORMAT_CALLBACK 0x1000
  54. #define DIFF_FLAGS_INIT { 0 }
  55. struct diff_flags {
  56. unsigned recursive;
  57. unsigned tree_in_recursive;
  58. unsigned binary;
  59. unsigned text;
  60. unsigned full_index;
  61. unsigned silent_on_remove;
  62. unsigned find_copies_harder;
  63. unsigned follow_renames;
  64. unsigned rename_empty;
  65. unsigned has_changes;
  66. unsigned quick;
  67. unsigned no_index;
  68. unsigned allow_external;
  69. unsigned exit_with_status;
  70. unsigned reverse_diff;
  71. unsigned check_failed;
  72. unsigned relative_name;
  73. unsigned ignore_submodules;
  74. unsigned dirstat_cumulative;
  75. unsigned dirstat_by_file;
  76. unsigned allow_textconv;
  77. unsigned textconv_set_via_cmdline;
  78. unsigned diff_from_contents;
  79. unsigned dirty_submodules;
  80. unsigned ignore_untracked_in_submodules;
  81. unsigned ignore_dirty_submodules;
  82. unsigned override_submodule_config;
  83. unsigned dirstat_by_line;
  84. unsigned funccontext;
  85. unsigned default_follow_renames;
  86. unsigned stat_with_summary;
  87. unsigned suppress_diff_headers;
  88. unsigned dual_color_diffed_diffs;
  89. unsigned suppress_hunk_header_line_count;
  90. };
  91. static inline void diff_flags_or(struct diff_flags *a,
  92. const struct diff_flags *b)
  93. {
  94. char *tmp_a = (char *)a;
  95. const char *tmp_b = (const char *)b;
  96. int i;
  97. for (i = 0; i < sizeof(struct diff_flags); i++)
  98. tmp_a[i] |= tmp_b[i];
  99. }
  100. #define DIFF_XDL_TST(opts, flag) ((opts)->xdl_opts & XDF_##flag)
  101. #define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag)
  102. #define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag)
  103. #define DIFF_WITH_ALG(opts, flag) (((opts)->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | XDF_##flag)
  104. enum diff_words_type {
  105. DIFF_WORDS_NONE = 0,
  106. DIFF_WORDS_PORCELAIN,
  107. DIFF_WORDS_PLAIN,
  108. DIFF_WORDS_COLOR
  109. };
  110. enum diff_submodule_format {
  111. DIFF_SUBMODULE_SHORT = 0,
  112. DIFF_SUBMODULE_LOG,
  113. DIFF_SUBMODULE_INLINE_DIFF
  114. };
  115. struct diff_options {
  116. const char *orderfile;
  117. const char *pickaxe;
  118. const char *single_follow;
  119. const char *a_prefix, *b_prefix;
  120. const char *line_prefix;
  121. size_t line_prefix_length;
  122. struct diff_flags flags;
  123. /* diff-filter bits */
  124. unsigned int filter;
  125. int use_color;
  126. int context;
  127. int interhunkcontext;
  128. int break_opt;
  129. int detect_rename;
  130. int irreversible_delete;
  131. int skip_stat_unmatch;
  132. int line_termination;
  133. int output_format;
  134. unsigned pickaxe_opts;
  135. int rename_score;
  136. int rename_limit;
  137. int needed_rename_limit;
  138. int degraded_cc_to_c;
  139. int show_rename_progress;
  140. int dirstat_permille;
  141. int setup;
  142. int abbrev;
  143. int ita_invisible_in_index;
  144. /* white-space error highlighting */
  145. #define WSEH_NEW (1<<12)
  146. #define WSEH_CONTEXT (1<<13)
  147. #define WSEH_OLD (1<<14)
  148. unsigned ws_error_highlight;
  149. const char *prefix;
  150. int prefix_length;
  151. const char *stat_sep;
  152. int xdl_opts;
  153. /* see Documentation/diff-options.txt */
  154. char **anchors;
  155. size_t anchors_nr, anchors_alloc;
  156. int stat_width;
  157. int stat_name_width;
  158. int stat_graph_width;
  159. int stat_count;
  160. const char *word_regex;
  161. enum diff_words_type word_diff;
  162. enum diff_submodule_format submodule_format;
  163. struct oidset *objfind;
  164. /* this is set by diffcore for DIFF_FORMAT_PATCH */
  165. int found_changes;
  166. /* to support internal diff recursion by --follow hack*/
  167. int found_follow;
  168. void (*set_default)(struct diff_options *);
  169. FILE *file;
  170. int close_file;
  171. #define OUTPUT_INDICATOR_NEW 0
  172. #define OUTPUT_INDICATOR_OLD 1
  173. #define OUTPUT_INDICATOR_CONTEXT 2
  174. char output_indicators[3];
  175. struct pathspec pathspec;
  176. pathchange_fn_t pathchange;
  177. change_fn_t change;
  178. add_remove_fn_t add_remove;
  179. void *change_fn_data;
  180. diff_format_fn_t format_callback;
  181. void *format_callback_data;
  182. diff_prefix_fn_t output_prefix;
  183. void *output_prefix_data;
  184. int diff_path_counter;
  185. struct emitted_diff_symbols *emitted_symbols;
  186. enum {
  187. COLOR_MOVED_NO = 0,
  188. COLOR_MOVED_PLAIN = 1,
  189. COLOR_MOVED_BLOCKS = 2,
  190. COLOR_MOVED_ZEBRA = 3,
  191. COLOR_MOVED_ZEBRA_DIM = 4,
  192. } color_moved;
  193. #define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
  194. #define COLOR_MOVED_MIN_ALNUM_COUNT 20
  195. /* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
  196. #define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
  197. #define COLOR_MOVED_WS_ERROR (1<<0)
  198. unsigned color_moved_ws_handling;
  199. struct repository *repo;
  200. struct option *parseopts;
  201. };
  202. unsigned diff_filter_bit(char status);
  203. void diff_emit_submodule_del(struct diff_options *o, const char *line);
  204. void diff_emit_submodule_add(struct diff_options *o, const char *line);
  205. void diff_emit_submodule_untracked(struct diff_options *o, const char *path);
  206. void diff_emit_submodule_modified(struct diff_options *o, const char *path);
  207. void diff_emit_submodule_header(struct diff_options *o, const char *header);
  208. void diff_emit_submodule_error(struct diff_options *o, const char *err);
  209. void diff_emit_submodule_pipethrough(struct diff_options *o,
  210. const char *line, int len);
  211. enum color_diff {
  212. DIFF_RESET = 0,
  213. DIFF_CONTEXT = 1,
  214. DIFF_METAINFO = 2,
  215. DIFF_FRAGINFO = 3,
  216. DIFF_FILE_OLD = 4,
  217. DIFF_FILE_NEW = 5,
  218. DIFF_COMMIT = 6,
  219. DIFF_WHITESPACE = 7,
  220. DIFF_FUNCINFO = 8,
  221. DIFF_FILE_OLD_MOVED = 9,
  222. DIFF_FILE_OLD_MOVED_ALT = 10,
  223. DIFF_FILE_OLD_MOVED_DIM = 11,
  224. DIFF_FILE_OLD_MOVED_ALT_DIM = 12,
  225. DIFF_FILE_NEW_MOVED = 13,
  226. DIFF_FILE_NEW_MOVED_ALT = 14,
  227. DIFF_FILE_NEW_MOVED_DIM = 15,
  228. DIFF_FILE_NEW_MOVED_ALT_DIM = 16,
  229. DIFF_CONTEXT_DIM = 17,
  230. DIFF_FILE_OLD_DIM = 18,
  231. DIFF_FILE_NEW_DIM = 19,
  232. DIFF_CONTEXT_BOLD = 20,
  233. DIFF_FILE_OLD_BOLD = 21,
  234. DIFF_FILE_NEW_BOLD = 22,
  235. };
  236. const char *diff_get_color(int diff_use_color, enum color_diff ix);
  237. #define diff_get_color_opt(o, ix) \
  238. diff_get_color((o)->use_color, ix)
  239. const char *diff_line_prefix(struct diff_options *);
  240. extern const char mime_boundary_leader[];
  241. struct combine_diff_path *diff_tree_paths(
  242. struct combine_diff_path *p, const struct object_id *oid,
  243. const struct object_id **parents_oid, int nparent,
  244. struct strbuf *base, struct diff_options *opt);
  245. int diff_tree_oid(const struct object_id *old_oid,
  246. const struct object_id *new_oid,
  247. const char *base, struct diff_options *opt);
  248. int diff_root_tree_oid(const struct object_id *new_oid, const char *base,
  249. struct diff_options *opt);
  250. struct combine_diff_path {
  251. struct combine_diff_path *next;
  252. char *path;
  253. unsigned int mode;
  254. struct object_id oid;
  255. struct combine_diff_parent {
  256. char status;
  257. unsigned int mode;
  258. struct object_id oid;
  259. struct strbuf path;
  260. } parent[FLEX_ARRAY];
  261. };
  262. #define combine_diff_path_size(n, l) \
  263. st_add4(sizeof(struct combine_diff_path), (l), 1, \
  264. st_mult(sizeof(struct combine_diff_parent), (n)))
  265. void show_combined_diff(struct combine_diff_path *elem, int num_parent,
  266. int dense, struct rev_info *);
  267. void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, int dense, struct rev_info *rev);
  268. void diff_tree_combined_merge(const struct commit *commit, int dense, struct rev_info *rev);
  269. void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
  270. int diff_can_quit_early(struct diff_options *);
  271. void diff_addremove(struct diff_options *,
  272. int addremove,
  273. unsigned mode,
  274. const struct object_id *oid,
  275. int oid_valid,
  276. const char *fullpath, unsigned dirty_submodule);
  277. void diff_change(struct diff_options *,
  278. unsigned mode1, unsigned mode2,
  279. const struct object_id *old_oid,
  280. const struct object_id *new_oid,
  281. int old_oid_valid, int new_oid_valid,
  282. const char *fullpath,
  283. unsigned dirty_submodule1, unsigned dirty_submodule2);
  284. struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
  285. #define DIFF_SETUP_REVERSE 1
  286. #define DIFF_SETUP_USE_SIZE_CACHE 4
  287. /*
  288. * Poor man's alternative to parse-option, to allow both stuck form
  289. * (--option=value) and separate form (--option value).
  290. */
  291. int parse_long_opt(const char *opt, const char **argv,
  292. const char **optarg);
  293. int git_diff_basic_config(const char *var, const char *value, void *cb);
  294. int git_diff_heuristic_config(const char *var, const char *value, void *cb);
  295. void init_diff_ui_defaults(void);
  296. int git_diff_ui_config(const char *var, const char *value, void *cb);
  297. #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
  298. #define diff_setup(diffopts) repo_diff_setup(the_repository, diffopts)
  299. #endif
  300. void repo_diff_setup(struct repository *, struct diff_options *);
  301. int diff_opt_parse(struct diff_options *, const char **, int, const char *);
  302. void diff_setup_done(struct diff_options *);
  303. int git_config_rename(const char *var, const char *value);
  304. #define DIFF_DETECT_RENAME 1
  305. #define DIFF_DETECT_COPY 2
  306. #define DIFF_PICKAXE_ALL 1
  307. #define DIFF_PICKAXE_REGEX 2
  308. #define DIFF_PICKAXE_KIND_S 4 /* traditional plumbing counter */
  309. #define DIFF_PICKAXE_KIND_G 8 /* grep in the patch */
  310. #define DIFF_PICKAXE_KIND_OBJFIND 16 /* specific object IDs */
  311. #define DIFF_PICKAXE_KINDS_MASK (DIFF_PICKAXE_KIND_S | \
  312. DIFF_PICKAXE_KIND_G | \
  313. DIFF_PICKAXE_KIND_OBJFIND)
  314. #define DIFF_PICKAXE_IGNORE_CASE 32
  315. void diffcore_std(struct diff_options *);
  316. void diffcore_fix_diff_index(void);
  317. #define COMMON_DIFF_OPTIONS_HELP \
  318. "\ncommon diff options:\n" \
  319. " -z output diff-raw with lines terminated with NUL.\n" \
  320. " -p output patch format.\n" \
  321. " -u synonym for -p.\n" \
  322. " --patch-with-raw\n" \
  323. " output both a patch and the diff-raw format.\n" \
  324. " --stat show diffstat instead of patch.\n" \
  325. " --numstat show numeric diffstat instead of patch.\n" \
  326. " --patch-with-stat\n" \
  327. " output a patch and prepend its diffstat.\n" \
  328. " --name-only show only names of changed files.\n" \
  329. " --name-status show names and status of changed files.\n" \
  330. " --full-index show full object name on index lines.\n" \
  331. " --abbrev=<n> abbreviate object names in diff-tree header and diff-raw.\n" \
  332. " -R swap input file pairs.\n" \
  333. " -B detect complete rewrites.\n" \
  334. " -M detect renames.\n" \
  335. " -C detect copies.\n" \
  336. " --find-copies-harder\n" \
  337. " try unchanged files as candidate for copy detection.\n" \
  338. " -l<n> limit rename attempts up to <n> paths.\n" \
  339. " -O<file> reorder diffs according to the <file>.\n" \
  340. " -S<string> find filepair whose only one side contains the string.\n" \
  341. " --pickaxe-all\n" \
  342. " show all files diff when -S is used and hit is found.\n" \
  343. " -a --text treat all files as text.\n"
  344. int diff_queue_is_empty(void);
  345. void diff_flush(struct diff_options*);
  346. void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc);
  347. /* diff-raw status letters */
  348. #define DIFF_STATUS_ADDED 'A'
  349. #define DIFF_STATUS_COPIED 'C'
  350. #define DIFF_STATUS_DELETED 'D'
  351. #define DIFF_STATUS_MODIFIED 'M'
  352. #define DIFF_STATUS_RENAMED 'R'
  353. #define DIFF_STATUS_TYPE_CHANGED 'T'
  354. #define DIFF_STATUS_UNKNOWN 'X'
  355. #define DIFF_STATUS_UNMERGED 'U'
  356. /* these are not diff-raw status letters proper, but used by
  357. * diffcore-filter insn to specify additional restrictions.
  358. */
  359. #define DIFF_STATUS_FILTER_AON '*'
  360. #define DIFF_STATUS_FILTER_BROKEN 'B'
  361. /*
  362. * This is different from find_unique_abbrev() in that
  363. * it stuffs the result with dots for alignment.
  364. */
  365. const char *diff_aligned_abbrev(const struct object_id *sha1, int);
  366. /* do not report anything on removed paths */
  367. #define DIFF_SILENT_ON_REMOVED 01
  368. /* report racily-clean paths as modified */
  369. #define DIFF_RACY_IS_MODIFIED 02
  370. int run_diff_files(struct rev_info *revs, unsigned int option);
  371. int run_diff_index(struct rev_info *revs, int cached);
  372. int do_diff_cache(const struct object_id *, struct diff_options *);
  373. int diff_flush_patch_id(struct diff_options *, struct object_id *, int, int);
  374. void flush_one_hunk(struct object_id *, git_SHA_CTX *);
  375. int diff_result_code(struct diff_options *, int);
  376. int diff_no_index(struct rev_info *,
  377. int implicit_no_index, int, const char **);
  378. int index_differs_from(struct repository *r, const char *def,
  379. const struct diff_flags *flags,
  380. int ita_invisible_in_index);
  381. /*
  382. * Fill the contents of the filespec "df", respecting any textconv defined by
  383. * its userdiff driver. The "driver" parameter must come from a
  384. * previous call to get_textconv(), and therefore should either be NULL or have
  385. * textconv enabled.
  386. *
  387. * Note that the memory ownership of the resulting buffer depends on whether
  388. * the driver field is NULL. If it is, then the memory belongs to the filespec
  389. * struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
  390. * that should be freed by the caller.
  391. */
  392. size_t fill_textconv(struct repository *r,
  393. struct userdiff_driver *driver,
  394. struct diff_filespec *df,
  395. char **outbuf);
  396. /*
  397. * Look up the userdiff driver for the given filespec, and return it if
  398. * and only if it has textconv enabled (otherwise return NULL). The result
  399. * can be passed to fill_textconv().
  400. */
  401. struct userdiff_driver *get_textconv(struct repository *r,
  402. struct diff_filespec *one);
  403. /*
  404. * Prepare diff_filespec and convert it using diff textconv API
  405. * if the textconv driver exists.
  406. * Return 1 if the conversion succeeds, 0 otherwise.
  407. */
  408. int textconv_object(struct repository *repo,
  409. const char *path,
  410. unsigned mode,
  411. const struct object_id *oid, int oid_valid,
  412. char **buf, unsigned long *buf_size);
  413. int parse_rename_score(const char **cp_p);
  414. long parse_algorithm_value(const char *value);
  415. void print_stat_summary(FILE *fp, int files,
  416. int insertions, int deletions);
  417. void setup_diff_pager(struct diff_options *);
  418. #endif /* DIFF_H */