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.

103 lines
3.0KB

  1. /*
  2. * Low level 3-way in-core file merge.
  3. */
  4. #ifndef LL_MERGE_H
  5. #define LL_MERGE_H
  6. #include "xdiff/xdiff.h"
  7. /**
  8. *
  9. * Calling sequence:
  10. * ----------------
  11. *
  12. * - Prepare a `struct ll_merge_options` to record options.
  13. * If you have no special requests, skip this and pass `NULL`
  14. * as the `opts` parameter to use the default options.
  15. *
  16. * - Allocate an mmbuffer_t variable for the result.
  17. *
  18. * - Allocate and fill variables with the file's original content
  19. * and two modified versions (using `read_mmfile`, for example).
  20. *
  21. * - Call `ll_merge()`.
  22. *
  23. * - Read the merged content from `result_buf.ptr` and `result_buf.size`.
  24. *
  25. * - Release buffers when finished. A simple
  26. * `free(ancestor.ptr); free(ours.ptr); free(theirs.ptr);
  27. * free(result_buf.ptr);` will do.
  28. *
  29. * If the modifications do not merge cleanly, `ll_merge` will return a
  30. * nonzero value and `result_buf` will generally include a description of
  31. * the conflict bracketed by markers such as the traditional `<<<<<<<`
  32. * and `>>>>>>>`.
  33. *
  34. * The `ancestor_label`, `our_label`, and `their_label` parameters are
  35. * used to label the different sides of a conflict if the merge driver
  36. * supports this.
  37. */
  38. struct index_state;
  39. /**
  40. * This describes the set of options the calling program wants to affect
  41. * the operation of a low-level (single file) merge.
  42. */
  43. struct ll_merge_options {
  44. /**
  45. * Behave as though this were part of a merge between common ancestors in
  46. * a recursive merge (merges of binary files may need to be handled
  47. * differently in such cases, for example). If a helper program is
  48. * specified by the `[merge "<driver>"] recursive` configuration, it will
  49. * be used.
  50. */
  51. unsigned virtual_ancestor : 1;
  52. /**
  53. * Resolve local conflicts automatically in favor of one side or the other
  54. * (as in 'git merge-file' `--ours`/`--theirs`/`--union`). Can be `0`,
  55. * `XDL_MERGE_FAVOR_OURS`, `XDL_MERGE_FAVOR_THEIRS`,
  56. * or `XDL_MERGE_FAVOR_UNION`.
  57. */
  58. unsigned variant : 2;
  59. /**
  60. * Resmudge and clean the "base", "theirs" and "ours" files before merging.
  61. * Use this when the merge is likely to have overlapped with a change in
  62. * smudge/clean or end-of-line normalization rules.
  63. */
  64. unsigned renormalize : 1;
  65. /**
  66. * Increase the length of conflict markers so that nested conflicts
  67.  * can be differentiated.
  68. */
  69. unsigned extra_marker_size;
  70. /* Extra xpparam_t flags as defined in xdiff/xdiff.h. */
  71. long xdl_opts;
  72. };
  73. /**
  74. * Perform a three-way single-file merge in core. This is a thin wrapper
  75. * around `xdl_merge` that takes the path and any merge backend specified in
  76. * `.gitattributes` or `.git/info/attributes` into account.
  77. * Returns 0 for a clean merge.
  78. */
  79. int ll_merge(mmbuffer_t *result_buf,
  80. const char *path,
  81. mmfile_t *ancestor, const char *ancestor_label,
  82. mmfile_t *ours, const char *our_label,
  83. mmfile_t *theirs, const char *their_label,
  84. struct index_state *istate,
  85. const struct ll_merge_options *opts);
  86. int ll_merge_marker_size(struct index_state *istate, const char *path);
  87. void reset_merge_attributes(void);
  88. #endif