6 static const char *pgm = NULL;
7 static const char *arguments[8];
9 static void run_program(void)
11 int pid = fork(), status;
14 die("unable to fork");
16 execlp(pgm, arguments[0],
25 die("unable to execute '%s'", pgm);
27 if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) || WEXITSTATUS(status))
28 die("merge program failed");
31 static int merge_entry(int pos, const char *path)
36 die("merge-cache: %s not in the cache", path);
47 static char hexbuf[4][60];
48 static char ownbuf[4][60];
49 struct cache_entry *ce = active_cache[pos];
50 int stage = ce_stage(ce);
52 if (strcmp(ce->name, path))
55 strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
56 sprintf(ownbuf[stage], "%o", ntohl(ce->ce_mode) & (~S_IFMT));
57 arguments[stage] = hexbuf[stage];
58 arguments[stage + 4] = ownbuf[stage];
59 } while (++pos < active_nr);
61 die("merge-cache: %s not in the cache", path);
66 static void merge_file(const char *path)
68 int pos = cache_name_pos(path, strlen(path));
71 * If it already exists in the cache as stage0, it's
72 * already merged and there is nothing to do.
75 merge_entry(-pos-1, path);
78 static void merge_all(void)
81 for (i = 0; i < active_nr; i++) {
82 struct cache_entry *ce = active_cache[i];
85 i += merge_entry(i, ce->name)-1;
89 int main(int argc, char **argv)
91 int i, force_file = 0;
94 usage("merge-cache <merge-program> (-a | <filename>*)");
99 for (i = 2; i < argc; i++) {
101 if (!force_file && *arg == '-') {
102 if (!strcmp(arg, "--")) {
106 if (!strcmp(arg, "-a")) {
110 die("merge-cache: unknown option %s", arg);