6 static const char *pgm = NULL;
7 static const char *arguments[5];
9 static void run_program(void)
11 int pid = fork(), status;
14 die("unable to fork");
16 execlp(pgm, arguments[0],
22 die("unable to execute '%s'", pgm);
24 if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) || WEXITSTATUS(status))
25 die("merge program failed");
28 static int merge_entry(int pos, const char *path)
33 die("merge-cache: %s not in the cache", path);
41 static char hexbuf[4][60];
42 struct cache_entry *ce = active_cache[pos];
43 int stage = ce_stage(ce);
45 if (strcmp(ce->name, path))
48 strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
49 arguments[stage] = hexbuf[stage];
50 } while (++pos < active_nr);
52 die("merge-cache: %s not in the cache", path);
57 static void merge_file(const char *path)
59 int pos = cache_name_pos(path, strlen(path));
62 * If it already exists in the cache as stage0, it's
63 * already merged and there is nothing to do.
66 merge_entry(-pos-1, path);
69 static void merge_all(void)
72 for (i = 0; i < active_nr; i++) {
73 struct cache_entry *ce = active_cache[i];
76 i += merge_entry(i, ce->name)-1;
80 int main(int argc, char **argv)
82 int i, force_file = 0;
85 usage("merge-cache <merge-program> (-a | <filename>*)");
90 for (i = 2; i < argc; i++) {
92 if (!force_file && *arg == '-') {
93 if (!strcmp(arg, "--")) {
97 if (!strcmp(arg, "-a")) {
101 die("merge-cache: unknown option %s", arg);