2 #include "run-command.h"
4 static const char *pgm
;
5 static const char *arguments
[9];
6 static int one_shot
, quiet
;
9 static void run_program(void)
11 struct child_process child
;
12 memset(&child
, 0, sizeof(child
));
13 child
.argv
= arguments
;
14 if (run_command(&child
)) {
19 die("merge program failed");
25 static int merge_entry(int pos
, const char *path
)
30 die("git-merge-index: %s not in the cache", path
);
42 static char hexbuf
[4][60];
43 static char ownbuf
[4][60];
44 struct cache_entry
*ce
= active_cache
[pos
];
45 int stage
= ce_stage(ce
);
47 if (strcmp(ce
->name
, path
))
50 strcpy(hexbuf
[stage
], sha1_to_hex(ce
->sha1
));
51 sprintf(ownbuf
[stage
], "%o", ce
->ce_mode
);
52 arguments
[stage
] = hexbuf
[stage
];
53 arguments
[stage
+ 4] = ownbuf
[stage
];
54 } while (++pos
< active_nr
);
56 die("git-merge-index: %s not in the cache", path
);
61 static void merge_file(const char *path
)
63 int pos
= cache_name_pos(path
, strlen(path
));
66 * If it already exists in the cache as stage0, it's
67 * already merged and there is nothing to do.
70 merge_entry(-pos
-1, path
);
73 static void merge_all(void)
76 for (i
= 0; i
< active_nr
; i
++) {
77 struct cache_entry
*ce
= active_cache
[i
];
80 i
+= merge_entry(i
, ce
->name
)-1;
84 int main(int argc
, char **argv
)
86 int i
, force_file
= 0;
88 /* Without this we cannot rely on waitpid() to tell
89 * what happened to our children.
91 signal(SIGCHLD
, SIG_DFL
);
94 usage("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)");
96 setup_git_directory();
100 if (!strcmp(argv
[i
], "-o")) {
104 if (!strcmp(argv
[i
], "-q")) {
109 for (; i
< argc
; i
++) {
111 if (!force_file
&& *arg
== '-') {
112 if (!strcmp(arg
, "--")) {
116 if (!strcmp(arg
, "-a")) {
120 die("git-merge-index: unknown option %s", arg
);
125 die("merge program failed");