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.

110 lines
2.8KB

  1. #include "cache.h"
  2. #include "diff.h"
  3. #include "diffcore.h"
  4. #include "lockfile.h"
  5. #include "commit.h"
  6. #include "run-command.h"
  7. #include "resolve-undo.h"
  8. #include "tree-walk.h"
  9. #include "unpack-trees.h"
  10. #include "dir.h"
  11. static const char *merge_argument(struct commit *commit)
  12. {
  13. return oid_to_hex(commit ? &commit->object.oid : the_hash_algo->empty_tree);
  14. }
  15. int try_merge_command(struct repository *r,
  16. const char *strategy, size_t xopts_nr,
  17. const char **xopts, struct commit_list *common,
  18. const char *head_arg, struct commit_list *remotes)
  19. {
  20. struct argv_array args = ARGV_ARRAY_INIT;
  21. int i, ret;
  22. struct commit_list *j;
  23. argv_array_pushf(&args, "merge-%s", strategy);
  24. for (i = 0; i < xopts_nr; i++)
  25. argv_array_pushf(&args, "--%s", xopts[i]);
  26. for (j = common; j; j = j->next)
  27. argv_array_push(&args, merge_argument(j->item));
  28. argv_array_push(&args, "--");
  29. argv_array_push(&args, head_arg);
  30. for (j = remotes; j; j = j->next)
  31. argv_array_push(&args, merge_argument(j->item));
  32. ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
  33. argv_array_clear(&args);
  34. discard_index(r->index);
  35. if (repo_read_index(r) < 0)
  36. die(_("failed to read the cache"));
  37. resolve_undo_clear_index(r->index);
  38. return ret;
  39. }
  40. int checkout_fast_forward(struct repository *r,
  41. const struct object_id *head,
  42. const struct object_id *remote,
  43. int overwrite_ignore)
  44. {
  45. struct tree *trees[MAX_UNPACK_TREES];
  46. struct unpack_trees_options opts;
  47. struct tree_desc t[MAX_UNPACK_TREES];
  48. int i, nr_trees = 0;
  49. struct dir_struct dir;
  50. struct lock_file lock_file = LOCK_INIT;
  51. refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
  52. if (repo_hold_locked_index(r, &lock_file, LOCK_REPORT_ON_ERROR) < 0)
  53. return -1;
  54. memset(&trees, 0, sizeof(trees));
  55. memset(&t, 0, sizeof(t));
  56. trees[nr_trees] = parse_tree_indirect(head);
  57. if (!trees[nr_trees++]) {
  58. rollback_lock_file(&lock_file);
  59. return -1;
  60. }
  61. trees[nr_trees] = parse_tree_indirect(remote);
  62. if (!trees[nr_trees++]) {
  63. rollback_lock_file(&lock_file);
  64. return -1;
  65. }
  66. for (i = 0; i < nr_trees; i++) {
  67. parse_tree(trees[i]);
  68. init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
  69. }
  70. memset(&opts, 0, sizeof(opts));
  71. if (overwrite_ignore) {
  72. memset(&dir, 0, sizeof(dir));
  73. dir.flags |= DIR_SHOW_IGNORED;
  74. setup_standard_excludes(&dir);
  75. opts.dir = &dir;
  76. }
  77. opts.head_idx = 1;
  78. opts.src_index = r->index;
  79. opts.dst_index = r->index;
  80. opts.update = 1;
  81. opts.verbose_update = 1;
  82. opts.merge = 1;
  83. opts.fn = twoway_merge;
  84. setup_unpack_trees_porcelain(&opts, "merge");
  85. if (unpack_trees(nr_trees, t, &opts)) {
  86. rollback_lock_file(&lock_file);
  87. clear_unpack_trees_porcelain(&opts);
  88. return -1;
  89. }
  90. clear_unpack_trees_porcelain(&opts);
  91. if (write_locked_index(r->index, &lock_file, COMMIT_LOCK))
  92. return error(_("unable to write new index file"));
  93. return 0;
  94. }