6 static const char *pgm = NULL;
7 static const char *arguments[8];
8 static int one_shot, quiet;
11 static void run_program(void)
13 int pid = fork(), status;
16 die("unable to fork");
18 execlp(pgm, arguments[0],
27 die("unable to execute '%s'", pgm);
29 if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) || WEXITSTATUS(status)) {
34 die("merge program failed");
40 static int merge_entry(int pos, const char *path)
45 die("git-merge-index: %s not in the cache", path);
56 static char hexbuf[4][60];
57 static char ownbuf[4][60];
58 struct cache_entry *ce = active_cache[pos];
59 int stage = ce_stage(ce);
61 if (strcmp(ce->name, path))
64 strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
65 sprintf(ownbuf[stage], "%o", ntohl(ce->ce_mode) & (~S_IFMT));
66 arguments[stage] = hexbuf[stage];
67 arguments[stage + 4] = ownbuf[stage];
68 } while (++pos < active_nr);
70 die("git-merge-index: %s not in the cache", path);
75 static void merge_file(const char *path)
77 int pos = cache_name_pos(path, strlen(path));
80 * If it already exists in the cache as stage0, it's
81 * already merged and there is nothing to do.
84 merge_entry(-pos-1, path);
87 static void merge_all(void)
90 for (i = 0; i < active_nr; i++) {
91 struct cache_entry *ce = active_cache[i];
94 i += merge_entry(i, ce->name)-1;
98 int main(int argc, char **argv)
100 int i, force_file = 0;
103 usage("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)");
108 if (!strcmp(argv[i], "-o")) {
112 if (!strcmp(argv[i], "-q")) {
117 for (; i < argc; i++) {
119 if (!force_file && *arg == '-') {
120 if (!strcmp(arg, "--")) {
124 if (!strcmp(arg, "-a")) {
128 die("git-merge-index: unknown option %s", arg);
133 die("merge program failed");