3 #include "run-command.h"
4 #include "resolve-undo.h"
6 #include "unpack-trees.h"
9 static const char *merge_argument(struct commit
*commit
)
12 return sha1_to_hex(commit
->object
.sha1
);
14 return EMPTY_TREE_SHA1_HEX
;
17 int try_merge_command(const char *strategy
, size_t xopts_nr
,
18 const char **xopts
, struct commit_list
*common
,
19 const char *head_arg
, struct commit_list
*remotes
)
21 struct argv_array args
= ARGV_ARRAY_INIT
;
23 struct commit_list
*j
;
25 argv_array_pushf(&args
, "merge-%s", strategy
);
26 for (i
= 0; i
< xopts_nr
; i
++)
27 argv_array_pushf(&args
, "--%s", xopts
[i
]);
28 for (j
= common
; j
; j
= j
->next
)
29 argv_array_push(&args
, merge_argument(j
->item
));
30 argv_array_push(&args
, "--");
31 argv_array_push(&args
, head_arg
);
32 for (j
= remotes
; j
; j
= j
->next
)
33 argv_array_push(&args
, merge_argument(j
->item
));
35 ret
= run_command_v_opt(args
.argv
, RUN_GIT_CMD
);
36 argv_array_clear(&args
);
40 die(_("failed to read the cache"));
46 int checkout_fast_forward(const unsigned char *head
,
47 const unsigned char *remote
,
50 struct tree
*trees
[MAX_UNPACK_TREES
];
51 struct unpack_trees_options opts
;
52 struct tree_desc t
[MAX_UNPACK_TREES
];
54 struct dir_struct dir
;
55 struct lock_file
*lock_file
= xcalloc(1, sizeof(struct lock_file
));
57 refresh_cache(REFRESH_QUIET
);
59 hold_locked_index(lock_file
, 1);
61 memset(&trees
, 0, sizeof(trees
));
62 memset(&opts
, 0, sizeof(opts
));
63 memset(&t
, 0, sizeof(t
));
64 if (overwrite_ignore
) {
65 memset(&dir
, 0, sizeof(dir
));
66 dir
.flags
|= DIR_SHOW_IGNORED
;
67 setup_standard_excludes(&dir
);
72 opts
.src_index
= &the_index
;
73 opts
.dst_index
= &the_index
;
75 opts
.verbose_update
= 1;
77 opts
.fn
= twoway_merge
;
78 setup_unpack_trees_porcelain(&opts
, "merge");
80 trees
[nr_trees
] = parse_tree_indirect(head
);
81 if (!trees
[nr_trees
++])
83 trees
[nr_trees
] = parse_tree_indirect(remote
);
84 if (!trees
[nr_trees
++])
86 for (i
= 0; i
< nr_trees
; i
++) {
88 init_tree_desc(t
+i
, trees
[i
]->buffer
, trees
[i
]->size
);
90 if (unpack_trees(nr_trees
, t
, &opts
))
92 if (write_locked_index(&the_index
, lock_file
, COMMIT_LOCK
))
93 die(_("unable to write new index file"));