7 static const char *pgm = NULL;
8 static const char *arguments[8];
9 static int one_shot, quiet;
12 static void run_program(void)
14 int pid = fork(), status;
17 die("unable to fork");
19 execlp(pgm, arguments[0],
28 die("unable to execute '%s'", pgm);
30 if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) || WEXITSTATUS(status)) {
35 die("merge program failed");
41 static int merge_entry(int pos, const char *path)
46 die("git-merge-index: %s not in the cache", path);
57 static char hexbuf[4][60];
58 static char ownbuf[4][60];
59 struct cache_entry *ce = active_cache[pos];
60 int stage = ce_stage(ce);
62 if (strcmp(ce->name, path))
65 strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
66 sprintf(ownbuf[stage], "%o", ntohl(ce->ce_mode) & (~S_IFMT));
67 arguments[stage] = hexbuf[stage];
68 arguments[stage + 4] = ownbuf[stage];
69 } while (++pos < active_nr);
71 die("git-merge-index: %s not in the cache", path);
76 static void merge_file(const char *path)
78 int pos = cache_name_pos(path, strlen(path));
81 * If it already exists in the cache as stage0, it's
82 * already merged and there is nothing to do.
85 merge_entry(-pos-1, path);
88 static void merge_all(void)
91 for (i = 0; i < active_nr; i++) {
92 struct cache_entry *ce = active_cache[i];
95 i += merge_entry(i, ce->name)-1;
99 int main(int argc, char **argv)
101 int i, force_file = 0;
103 /* Without this we cannot rely on waitpid() to tell
104 * what happened to our children.
106 signal(SIGCHLD, SIG_DFL);
109 usage("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)");
111 setup_git_directory();
115 if (!strcmp(argv[i], "-o")) {
119 if (!strcmp(argv[i], "-q")) {
124 for (; i < argc; i++) {
126 if (!force_file && *arg == '-') {
127 if (!strcmp(arg, "--")) {
131 if (!strcmp(arg, "-a")) {
135 die("git-merge-index: unknown option %s", arg);
140 die("merge program failed");