2 #include "run-command.h"
4 static const char *pgm;
5 static int one_shot, quiet;
8 static int merge_entry(int pos, const char *path)
11 const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
12 char hexbuf[4][GIT_MAX_HEXSZ + 1];
16 die("git merge-index: %s not in the cache", path);
19 const struct cache_entry *ce = active_cache[pos];
20 int stage = ce_stage(ce);
22 if (strcmp(ce->name, path))
25 oid_to_hex_r(hexbuf[stage], &ce->oid);
26 xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
27 arguments[stage] = hexbuf[stage];
28 arguments[stage + 4] = ownbuf[stage];
29 } while (++pos < active_nr);
31 die("git merge-index: %s not in the cache", path);
33 if (run_command_v_opt(arguments, 0)) {
38 die("merge program failed");
45 static void merge_one_path(const char *path)
47 int pos = cache_name_pos(path, strlen(path));
50 * If it already exists in the cache as stage0, it's
51 * already merged and there is nothing to do.
54 merge_entry(-pos-1, path);
57 static void merge_all(void)
60 for (i = 0; i < active_nr; i++) {
61 const struct cache_entry *ce = active_cache[i];
64 i += merge_entry(i, ce->name)-1;
68 int cmd_merge_index(int argc, const char **argv, const char *prefix)
70 int i, force_file = 0;
72 /* Without this we cannot rely on waitpid() to tell
73 * what happened to our children.
75 signal(SIGCHLD, SIG_DFL);
78 usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");
83 if (!strcmp(argv[i], "-o")) {
87 if (!strcmp(argv[i], "-q")) {
92 for (; i < argc; i++) {
93 const char *arg = argv[i];
94 if (!force_file && *arg == '-') {
95 if (!strcmp(arg, "--")) {
99 if (!strcmp(arg, "-a")) {
103 die("git merge-index: unknown option %s", arg);
108 die("merge program failed");