4 #include "run-command.h"
5 #include "resolve-undo.h"
7 #include "unpack-trees.h"
10 static const char *merge_argument(struct commit
*commit
)
13 return sha1_to_hex(commit
->object
.sha1
);
15 return EMPTY_TREE_SHA1_HEX
;
18 int try_merge_command(const char *strategy
, size_t xopts_nr
,
19 const char **xopts
, struct commit_list
*common
,
20 const char *head_arg
, struct commit_list
*remotes
)
22 struct argv_array args
= ARGV_ARRAY_INIT
;
24 struct commit_list
*j
;
26 argv_array_pushf(&args
, "merge-%s", strategy
);
27 for (i
= 0; i
< xopts_nr
; i
++)
28 argv_array_pushf(&args
, "--%s", xopts
[i
]);
29 for (j
= common
; j
; j
= j
->next
)
30 argv_array_push(&args
, merge_argument(j
->item
));
31 argv_array_push(&args
, "--");
32 argv_array_push(&args
, head_arg
);
33 for (j
= remotes
; j
; j
= j
->next
)
34 argv_array_push(&args
, merge_argument(j
->item
));
36 ret
= run_command_v_opt(args
.argv
, RUN_GIT_CMD
);
37 argv_array_clear(&args
);
41 die(_("failed to read the cache"));
47 int checkout_fast_forward(const unsigned char *head
,
48 const unsigned char *remote
,
51 struct tree
*trees
[MAX_UNPACK_TREES
];
52 struct unpack_trees_options opts
;
53 struct tree_desc t
[MAX_UNPACK_TREES
];
55 struct dir_struct dir
;
56 struct lock_file
*lock_file
= xcalloc(1, sizeof(struct lock_file
));
58 refresh_cache(REFRESH_QUIET
);
60 hold_locked_index(lock_file
, 1);
62 memset(&trees
, 0, sizeof(trees
));
63 memset(&opts
, 0, sizeof(opts
));
64 memset(&t
, 0, sizeof(t
));
65 if (overwrite_ignore
) {
66 memset(&dir
, 0, sizeof(dir
));
67 dir
.flags
|= DIR_SHOW_IGNORED
;
68 setup_standard_excludes(&dir
);
73 opts
.src_index
= &the_index
;
74 opts
.dst_index
= &the_index
;
76 opts
.verbose_update
= 1;
78 opts
.fn
= twoway_merge
;
79 setup_unpack_trees_porcelain(&opts
, "merge");
81 trees
[nr_trees
] = parse_tree_indirect(head
);
82 if (!trees
[nr_trees
++])
84 trees
[nr_trees
] = parse_tree_indirect(remote
);
85 if (!trees
[nr_trees
++])
87 for (i
= 0; i
< nr_trees
; i
++) {
89 init_tree_desc(t
+i
, trees
[i
]->buffer
, trees
[i
]->size
);
91 if (unpack_trees(nr_trees
, t
, &opts
))
93 if (write_locked_index(&the_index
, lock_file
, COMMIT_LOCK
))
94 die(_("unable to write new index file"));