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
);
14 if (waitpid(pid
, &status
, 0) < 0 || !WIFEXITED(status
) || WEXITSTATUS(status
)) {
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
);
40 static char hexbuf
[4][60];
41 static char ownbuf
[4][60];
42 struct cache_entry
*ce
= active_cache
[pos
];
43 int stage
= ce_stage(ce
);
45 if (strcmp(ce
->name
, path
))
48 strcpy(hexbuf
[stage
], sha1_to_hex(ce
->sha1
));
49 sprintf(ownbuf
[stage
], "%o", ntohl(ce
->ce_mode
) & (~S_IFMT
));
50 arguments
[stage
] = hexbuf
[stage
];
51 arguments
[stage
+ 4] = ownbuf
[stage
];
52 } while (++pos
< active_nr
);
54 die("git-merge-index: %s not in the cache", path
);
59 static void merge_file(const char *path
)
61 int pos
= cache_name_pos(path
, strlen(path
));
64 * If it already exists in the cache as stage0, it's
65 * already merged and there is nothing to do.
68 merge_entry(-pos
-1, path
);
71 static void merge_all(void)
74 for (i
= 0; i
< active_nr
; i
++) {
75 struct cache_entry
*ce
= active_cache
[i
];
78 i
+= merge_entry(i
, ce
->name
)-1;
82 int main(int argc
, char **argv
)
84 int i
, force_file
= 0;
86 /* Without this we cannot rely on waitpid() to tell
87 * what happened to our children.
89 signal(SIGCHLD
, SIG_DFL
);
92 usage("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)");
94 setup_git_directory();
98 if (!strcmp(argv
[i
], "-o")) {
102 if (!strcmp(argv
[i
], "-q")) {
107 for (; i
< argc
; i
++) {
109 if (!force_file
&& *arg
== '-') {
110 if (!strcmp(arg
, "--")) {
114 if (!strcmp(arg
, "-a")) {
118 die("git-merge-index: unknown option %s", arg
);
123 die("merge program failed");