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.
 
 
 
 
 
 

97 lines
2.4 KiB

  1. #include "cache.h"
  2. #include "lockfile.h"
  3. #include "commit.h"
  4. #include "run-command.h"
  5. #include "resolve-undo.h"
  6. #include "tree-walk.h"
  7. #include "unpack-trees.h"
  8. #include "dir.h"
  9. static const char *merge_argument(struct commit *commit)
  10. {
  11. if (commit)
  12. return oid_to_hex(&commit->object.oid);
  13. else
  14. return EMPTY_TREE_SHA1_HEX;
  15. }
  16. int try_merge_command(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_cache();
  35. if (read_cache() < 0)
  36. die(_("failed to read the cache"));
  37. resolve_undo_clear();
  38. return ret;
  39. }
  40. int checkout_fast_forward(const unsigned char *head,
  41. const unsigned char *remote,
  42. int overwrite_ignore)
  43. {
  44. struct tree *trees[MAX_UNPACK_TREES];
  45. struct unpack_trees_options opts;
  46. struct tree_desc t[MAX_UNPACK_TREES];
  47. int i, nr_trees = 0;
  48. struct dir_struct dir;
  49. struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
  50. refresh_cache(REFRESH_QUIET);
  51. hold_locked_index(lock_file, 1);
  52. memset(&trees, 0, sizeof(trees));
  53. memset(&opts, 0, sizeof(opts));
  54. memset(&t, 0, sizeof(t));
  55. if (overwrite_ignore) {
  56. memset(&dir, 0, sizeof(dir));
  57. dir.flags |= DIR_SHOW_IGNORED;
  58. setup_standard_excludes(&dir);
  59. opts.dir = &dir;
  60. }
  61. opts.head_idx = 1;
  62. opts.src_index = &the_index;
  63. opts.dst_index = &the_index;
  64. opts.update = 1;
  65. opts.verbose_update = 1;
  66. opts.merge = 1;
  67. opts.fn = twoway_merge;
  68. setup_unpack_trees_porcelain(&opts, "merge");
  69. trees[nr_trees] = parse_tree_indirect(head);
  70. if (!trees[nr_trees++])
  71. return -1;
  72. trees[nr_trees] = parse_tree_indirect(remote);
  73. if (!trees[nr_trees++])
  74. return -1;
  75. for (i = 0; i < nr_trees; i++) {
  76. parse_tree(trees[i]);
  77. init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
  78. }
  79. if (unpack_trees(nr_trees, t, &opts))
  80. return -1;
  81. if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
  82. die(_("unable to write new index file"));
  83. return 0;
  84. }