3 static const char *pgm
;
4 static const char *arguments
[8];
5 static int one_shot
, quiet
;
8 static void run_program(void)
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
)) {
32 die("merge program failed");
38 static int merge_entry(int pos
, const char *path
)
43 die("git-merge-index: %s not in the cache", path
);
54 static char hexbuf
[4][60];
55 static char ownbuf
[4][60];
56 struct cache_entry
*ce
= active_cache
[pos
];
57 int stage
= ce_stage(ce
);
59 if (strcmp(ce
->name
, path
))
62 strcpy(hexbuf
[stage
], sha1_to_hex(ce
->sha1
));
63 sprintf(ownbuf
[stage
], "%o", ntohl(ce
->ce_mode
) & (~S_IFMT
));
64 arguments
[stage
] = hexbuf
[stage
];
65 arguments
[stage
+ 4] = ownbuf
[stage
];
66 } while (++pos
< active_nr
);
68 die("git-merge-index: %s not in the cache", path
);
73 static void merge_file(const char *path
)
75 int pos
= cache_name_pos(path
, strlen(path
));
78 * If it already exists in the cache as stage0, it's
79 * already merged and there is nothing to do.
82 merge_entry(-pos
-1, path
);
85 static void merge_all(void)
88 for (i
= 0; i
< active_nr
; i
++) {
89 struct cache_entry
*ce
= active_cache
[i
];
92 i
+= merge_entry(i
, ce
->name
)-1;
96 int main(int argc
, char **argv
)
98 int i
, force_file
= 0;
100 /* Without this we cannot rely on waitpid() to tell
101 * what happened to our children.
103 signal(SIGCHLD
, SIG_DFL
);
106 usage("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)");
108 setup_git_directory();
112 if (!strcmp(argv
[i
], "-o")) {
116 if (!strcmp(argv
[i
], "-q")) {
121 for (; i
< argc
; i
++) {
123 if (!force_file
&& *arg
== '-') {
124 if (!strcmp(arg
, "--")) {
128 if (!strcmp(arg
, "-a")) {
132 die("git-merge-index: unknown option %s", arg
);
137 die("merge program failed");