2 #include "run-command.h"
5 static const char *pgm
;
6 static int one_shot
, quiet
;
9 static int merge_entry(int pos
, const char *path
)
12 const char *arguments
[] = { pgm
, "", "", "", path
, "", "", "", NULL
};
17 die("git merge-index: %s not in the cache", path
);
20 struct cache_entry
*ce
= active_cache
[pos
];
21 int stage
= ce_stage(ce
);
23 if (strcmp(ce
->name
, path
))
26 strcpy(hexbuf
[stage
], sha1_to_hex(ce
->sha1
));
27 sprintf(ownbuf
[stage
], "%o", ce
->ce_mode
);
28 arguments
[stage
] = hexbuf
[stage
];
29 arguments
[stage
+ 4] = ownbuf
[stage
];
30 } while (++pos
< active_nr
);
32 die("git merge-index: %s not in the cache", path
);
34 if (run_command_v_opt(arguments
, 0)) {
39 die("merge program failed");
46 static void merge_file(const char *path
)
48 int pos
= cache_name_pos(path
, strlen(path
));
51 * If it already exists in the cache as stage0, it's
52 * already merged and there is nothing to do.
55 merge_entry(-pos
-1, path
);
58 static void merge_all(void)
61 for (i
= 0; i
< active_nr
; i
++) {
62 struct cache_entry
*ce
= active_cache
[i
];
65 i
+= merge_entry(i
, ce
->name
)-1;
69 int cmd_merge_index(int argc
, const char **argv
, const char *prefix
)
71 int i
, force_file
= 0;
73 /* Without this we cannot rely on waitpid() to tell
74 * what happened to our children.
76 signal(SIGCHLD
, SIG_DFL
);
79 usage("git merge-index [-o] [-q] <merge-program> (-a | [--] <filename>*)");
84 if (!strcmp(argv
[i
], "-o")) {
88 if (!strcmp(argv
[i
], "-q")) {
93 for (; i
< argc
; i
++) {
94 const char *arg
= argv
[i
];
95 if (!force_file
&& *arg
== '-') {
96 if (!strcmp(arg
, "--")) {
100 if (!strcmp(arg
, "-a")) {
104 die("git merge-index: unknown option %s", arg
);
109 die("merge program failed");