2 #include "run-command.h"
5 static const char *pgm
;
6 static const char *arguments
[9];
7 static int one_shot
, quiet
;
10 static void run_program(void)
12 struct child_process child
;
13 memset(&child
, 0, sizeof(child
));
14 child
.argv
= arguments
;
15 if (run_command(&child
)) {
20 die("merge program failed");
26 static int merge_entry(int pos
, const char *path
)
31 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", 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 if (argv
[0] && *argv
[0])
98 git_extract_argv0_path(argv
[0]);
100 setup_git_directory();
104 if (!strcmp(argv
[i
], "-o")) {
108 if (!strcmp(argv
[i
], "-q")) {
113 for (; i
< argc
; i
++) {
115 if (!force_file
&& *arg
== '-') {
116 if (!strcmp(arg
, "--")) {
120 if (!strcmp(arg
, "-a")) {
124 die("git merge-index: unknown option %s", arg
);
129 die("merge program failed");