]>
Commit | Line | Data |
---|---|---|
e7da9385 PS |
1 | #define USE_THE_REPOSITORY_VARIABLE |
2 | ||
bc5c5ec0 | 3 | #include "git-compat-util.h" |
f394e093 | 4 | #include "gettext.h" |
df6e8744 | 5 | #include "hash.h" |
41771fa4 | 6 | #include "hex.h" |
697cc8ef | 7 | #include "lockfile.h" |
750324dd | 8 | #include "merge.h" |
db699a8a | 9 | #include "commit.h" |
df6e8744 | 10 | #include "repository.h" |
db699a8a NTND |
11 | #include "run-command.h" |
12 | #include "resolve-undo.h" | |
d4a4f929 | 13 | #include "tree.h" |
db699a8a NTND |
14 | #include "tree-walk.h" |
15 | #include "unpack-trees.h" | |
db699a8a NTND |
16 | |
17 | static const char *merge_argument(struct commit *commit) | |
18 | { | |
e9fe6f26 | 19 | return oid_to_hex(commit ? &commit->object.oid : the_hash_algo->empty_tree); |
db699a8a NTND |
20 | } |
21 | ||
7e196c3a NTND |
22 | int try_merge_command(struct repository *r, |
23 | const char *strategy, size_t xopts_nr, | |
db699a8a NTND |
24 | const char **xopts, struct commit_list *common, |
25 | const char *head_arg, struct commit_list *remotes) | |
26 | { | |
0e906739 | 27 | struct child_process cmd = CHILD_PROCESS_INIT; |
80c9e70e | 28 | int ret; |
db699a8a | 29 | struct commit_list *j; |
db699a8a | 30 | |
0e906739 | 31 | strvec_pushf(&cmd.args, "merge-%s", strategy); |
80c9e70e | 32 | for (size_t i = 0; i < xopts_nr; i++) |
0e906739 | 33 | strvec_pushf(&cmd.args, "--%s", xopts[i]); |
db699a8a | 34 | for (j = common; j; j = j->next) |
0e906739 RS |
35 | strvec_push(&cmd.args, merge_argument(j->item)); |
36 | strvec_push(&cmd.args, "--"); | |
37 | strvec_push(&cmd.args, head_arg); | |
db699a8a | 38 | for (j = remotes; j; j = j->next) |
0e906739 | 39 | strvec_push(&cmd.args, merge_argument(j->item)); |
5c1753b1 | 40 | |
0e906739 RS |
41 | cmd.git_cmd = 1; |
42 | ret = run_command(&cmd); | |
5c1753b1 | 43 | |
7e196c3a | 44 | discard_index(r->index); |
e1ff0a32 | 45 | if (repo_read_index(r) < 0) |
db699a8a | 46 | die(_("failed to read the cache")); |
7e196c3a | 47 | resolve_undo_clear_index(r->index); |
db699a8a NTND |
48 | |
49 | return ret; | |
50 | } | |
51 | ||
7e196c3a NTND |
52 | int checkout_fast_forward(struct repository *r, |
53 | const struct object_id *head, | |
f06e90da | 54 | const struct object_id *remote, |
db699a8a NTND |
55 | int overwrite_ignore) |
56 | { | |
57 | struct tree *trees[MAX_UNPACK_TREES]; | |
58 | struct unpack_trees_options opts; | |
59 | struct tree_desc t[MAX_UNPACK_TREES]; | |
03b86647 | 60 | int i, nr_trees = 0; |
837e34eb | 61 | struct lock_file lock_file = LOCK_INIT; |
db699a8a | 62 | |
7e196c3a | 63 | refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); |
db699a8a | 64 | |
3a95f31d | 65 | if (repo_hold_locked_index(r, &lock_file, LOCK_REPORT_ON_ERROR) < 0) |
55f5704d | 66 | return -1; |
db699a8a NTND |
67 | |
68 | memset(&trees, 0, sizeof(trees)); | |
db699a8a | 69 | memset(&t, 0, sizeof(t)); |
89e653da MÅ |
70 | |
71 | trees[nr_trees] = parse_tree_indirect(head); | |
72 | if (!trees[nr_trees++]) { | |
73 | rollback_lock_file(&lock_file); | |
74 | return -1; | |
75 | } | |
76 | trees[nr_trees] = parse_tree_indirect(remote); | |
77 | if (!trees[nr_trees++]) { | |
78 | rollback_lock_file(&lock_file); | |
79 | return -1; | |
80 | } | |
81 | for (i = 0; i < nr_trees; i++) { | |
aa9f6189 JS |
82 | if (parse_tree(trees[i]) < 0) { |
83 | rollback_lock_file(&lock_file); | |
84 | return -1; | |
85 | } | |
efed687e EB |
86 | init_tree_desc(t+i, &trees[i]->object.oid, |
87 | trees[i]->buffer, trees[i]->size); | |
89e653da MÅ |
88 | } |
89 | ||
90 | memset(&opts, 0, sizeof(opts)); | |
04988c8d | 91 | opts.preserve_ignored = !overwrite_ignore; |
db699a8a NTND |
92 | |
93 | opts.head_idx = 1; | |
7e196c3a NTND |
94 | opts.src_index = r->index; |
95 | opts.dst_index = r->index; | |
db699a8a NTND |
96 | opts.update = 1; |
97 | opts.verbose_update = 1; | |
98 | opts.merge = 1; | |
99 | opts.fn = twoway_merge; | |
13e7ed6a | 100 | init_checkout_metadata(&opts.meta, NULL, remote, NULL); |
db699a8a NTND |
101 | setup_unpack_trees_porcelain(&opts, "merge"); |
102 | ||
5790d258 MÅ |
103 | if (unpack_trees(nr_trees, t, &opts)) { |
104 | rollback_lock_file(&lock_file); | |
1c41d280 | 105 | clear_unpack_trees_porcelain(&opts); |
db699a8a | 106 | return -1; |
5790d258 | 107 | } |
1c41d280 MÅ |
108 | clear_unpack_trees_porcelain(&opts); |
109 | ||
7e196c3a | 110 | if (write_locked_index(r->index, &lock_file, COMMIT_LOCK)) |
55f5704d | 111 | return error(_("unable to write new index file")); |
db699a8a NTND |
112 | return 0; |
113 | } |