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.

102 lines
2.0KB

  1. #include "cache.h"
  2. #include "run-command.h"
  3. #include "xdiff-interface.h"
  4. #include "ll-merge.h"
  5. #include "blob.h"
  6. #include "merge-blobs.h"
  7. #include "object-store.h"
  8. static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
  9. {
  10. void *buf;
  11. unsigned long size;
  12. enum object_type type;
  13. buf = read_object_file(&obj->object.oid, &type, &size);
  14. if (!buf)
  15. return -1;
  16. if (type != OBJ_BLOB) {
  17. free(buf);
  18. return -1;
  19. }
  20. f->ptr = buf;
  21. f->size = size;
  22. return 0;
  23. }
  24. static void free_mmfile(mmfile_t *f)
  25. {
  26. free(f->ptr);
  27. }
  28. static void *three_way_filemerge(struct index_state *istate,
  29. const char *path,
  30. mmfile_t *base,
  31. mmfile_t *our,
  32. mmfile_t *their,
  33. unsigned long *size)
  34. {
  35. int merge_status;
  36. mmbuffer_t res;
  37. /*
  38. * This function is only used by cmd_merge_tree, which
  39. * does not respect the merge.conflictstyle option.
  40. * There is no need to worry about a label for the
  41. * common ancestor.
  42. */
  43. merge_status = ll_merge(&res, path, base, NULL,
  44. our, ".our", their, ".their",
  45. istate, NULL);
  46. if (merge_status < 0)
  47. return NULL;
  48. *size = res.size;
  49. return res.ptr;
  50. }
  51. void *merge_blobs(struct index_state *istate, const char *path,
  52. struct blob *base, struct blob *our,
  53. struct blob *their, unsigned long *size)
  54. {
  55. void *res = NULL;
  56. mmfile_t f1, f2, common;
  57. /*
  58. * Removed in either branch?
  59. *
  60. * NOTE! This depends on the caller having done the
  61. * proper warning about removing a file that got
  62. * modified in the other branch!
  63. */
  64. if (!our || !their) {
  65. enum object_type type;
  66. if (base)
  67. return NULL;
  68. if (!our)
  69. our = their;
  70. return read_object_file(&our->object.oid, &type, size);
  71. }
  72. if (fill_mmfile_blob(&f1, our) < 0)
  73. goto out_no_mmfile;
  74. if (fill_mmfile_blob(&f2, their) < 0)
  75. goto out_free_f1;
  76. if (base) {
  77. if (fill_mmfile_blob(&common, base) < 0)
  78. goto out_free_f2_f1;
  79. } else {
  80. common.ptr = xstrdup("");
  81. common.size = 0;
  82. }
  83. res = three_way_filemerge(istate, path, &common, &f1, &f2, size);
  84. free_mmfile(&common);
  85. out_free_f2_f1:
  86. free_mmfile(&f2);
  87. out_free_f1:
  88. free_mmfile(&f1);
  89. out_no_mmfile:
  90. return res;
  91. }