2 #include "spawn-pipe.h"
4 static const char *pgm
;
5 static const char *arguments
[9]; /* last one is always NULL */
6 static int one_shot
, quiet
;
9 static void run_program(void)
11 pid_t pid
= spawnvpe_pipe(pgm
, arguments
, environ
, NULL
, NULL
);
15 die("unable to fork");
17 if (waitpid(pid
, &status
, 0) < 0 || !WIFEXITED(status
) || WEXITSTATUS(status
)) {
22 die("merge program failed");
28 static int merge_entry(int pos
, const char *path
)
33 die("git-merge-index: %s not in the cache", path
);
43 static char hexbuf
[4][60];
44 static char ownbuf
[4][60];
45 struct cache_entry
*ce
= active_cache
[pos
];
46 int stage
= ce_stage(ce
);
48 if (strcmp(ce
->name
, path
))
51 strcpy(hexbuf
[stage
], sha1_to_hex(ce
->sha1
));
52 sprintf(ownbuf
[stage
], "%o", ntohl(ce
->ce_mode
));
53 arguments
[stage
] = hexbuf
[stage
];
54 arguments
[stage
+ 4] = ownbuf
[stage
];
55 } while (++pos
< active_nr
);
57 die("git-merge-index: %s not in the cache", path
);
62 static void merge_file(const char *path
)
64 int pos
= cache_name_pos(path
, strlen(path
));
67 * If it already exists in the cache as stage0, it's
68 * already merged and there is nothing to do.
71 merge_entry(-pos
-1, path
);
74 static void merge_all(void)
77 for (i
= 0; i
< active_nr
; i
++) {
78 struct cache_entry
*ce
= active_cache
[i
];
81 i
+= merge_entry(i
, ce
->name
)-1;
85 int main(int argc
, char **argv
)
87 int i
, force_file
= 0;
89 /* Without this we cannot rely on waitpid() to tell
90 * what happened to our children.
92 signal(SIGCHLD
, SIG_DFL
);
95 usage("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)");
97 setup_git_directory();
101 if (!strcmp(argv
[i
], "-o")) {
105 if (!strcmp(argv
[i
], "-q")) {
110 for (; i
< argc
; i
++) {
112 if (!force_file
&& *arg
== '-') {
113 if (!strcmp(arg
, "--")) {
117 if (!strcmp(arg
, "-a")) {
121 die("git-merge-index: unknown option %s", arg
);
126 die("merge program failed");