7 static const char *pgm
;
8 static const char *arguments
[8];
9 static int one_shot
, quiet
;
12 static void run_program(void)
18 die("unable to fork");
20 execlp(pgm
, arguments
[0],
29 die("unable to execute '%s'", pgm
);
31 if (waitpid(pid
, &status
, 0) < 0 || !WIFEXITED(status
) || WEXITSTATUS(status
)) {
36 die("merge program failed");
42 static int merge_entry(int pos
, const char *path
)
47 die("git-merge-index: %s not in the cache", path
);
58 static char hexbuf
[4][60];
59 static char ownbuf
[4][60];
60 struct cache_entry
*ce
= active_cache
[pos
];
61 int stage
= ce_stage(ce
);
63 if (strcmp(ce
->name
, path
))
66 strcpy(hexbuf
[stage
], sha1_to_hex(ce
->sha1
));
67 sprintf(ownbuf
[stage
], "%o", ntohl(ce
->ce_mode
) & (~S_IFMT
));
68 arguments
[stage
] = hexbuf
[stage
];
69 arguments
[stage
+ 4] = ownbuf
[stage
];
70 } while (++pos
< active_nr
);
72 die("git-merge-index: %s not in the cache", path
);
77 static void merge_file(const char *path
)
79 int pos
= cache_name_pos(path
, strlen(path
));
82 * If it already exists in the cache as stage0, it's
83 * already merged and there is nothing to do.
86 merge_entry(-pos
-1, path
);
89 static void merge_all(void)
92 for (i
= 0; i
< active_nr
; i
++) {
93 struct cache_entry
*ce
= active_cache
[i
];
96 i
+= merge_entry(i
, ce
->name
)-1;
100 int main(int argc
, char **argv
)
102 int i
, force_file
= 0;
104 /* Without this we cannot rely on waitpid() to tell
105 * what happened to our children.
107 signal(SIGCHLD
, SIG_DFL
);
110 usage("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)");
112 setup_git_directory();
116 if (!strcmp(argv
[i
], "-o")) {
120 if (!strcmp(argv
[i
], "-q")) {
125 for (; i
< argc
; i
++) {
127 if (!force_file
&& *arg
== '-') {
128 if (!strcmp(arg
, "--")) {
132 if (!strcmp(arg
, "-a")) {
136 die("git-merge-index: unknown option %s", arg
);
141 die("merge program failed");