6 static const char *pgm = NULL;
7 static const char *arguments[8];
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)) {
33 die("merge program failed");
37 static int merge_entry(int pos, const char *path)
42 die("merge-cache: %s not in the cache", path);
53 static char hexbuf[4][60];
54 static char ownbuf[4][60];
55 struct cache_entry *ce = active_cache[pos];
56 int stage = ce_stage(ce);
58 if (strcmp(ce->name, path))
61 strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
62 sprintf(ownbuf[stage], "%o", ntohl(ce->ce_mode) & (~S_IFMT));
63 arguments[stage] = hexbuf[stage];
64 arguments[stage + 4] = ownbuf[stage];
65 } while (++pos < active_nr);
67 die("merge-cache: %s not in the cache", path);
72 static void merge_file(const char *path)
74 int pos = cache_name_pos(path, strlen(path));
77 * If it already exists in the cache as stage0, it's
78 * already merged and there is nothing to do.
81 merge_entry(-pos-1, path);
84 static void merge_all(void)
87 for (i = 0; i < active_nr; i++) {
88 struct cache_entry *ce = active_cache[i];
91 i += merge_entry(i, ce->name)-1;
95 int main(int argc, char **argv)
97 int i, force_file = 0;
100 usage("merge-cache [-o] <merge-program> (-a | <filename>*)");
105 if (!strcmp(argv[1], "-o")) {
110 for (; i < argc; i++) {
112 if (!force_file && *arg == '-') {
113 if (!strcmp(arg, "--")) {
117 if (!strcmp(arg, "-a")) {
121 die("merge-cache: unknown option %s", arg);
126 die("merge program failed");