You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.2 KiB
112 lines
2.2 KiB
20 years ago
|
#include "cache.h"
|
||
18 years ago
|
#include "run-command.h"
|
||
16 years ago
|
#include "exec_cmd.h"
|
||
20 years ago
|
|
||
19 years ago
|
static const char *pgm;
|
||
20 years ago
|
static int one_shot, quiet;
|
||
20 years ago
|
static int err;
|
||
20 years ago
|
|
||
|
static int merge_entry(int pos, const char *path)
|
||
|
{
|
||
|
int found;
|
||
16 years ago
|
const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
|
||
|
char hexbuf[4][60];
|
||
|
char ownbuf[4][60];
|
||
18 years ago
|
|
||
20 years ago
|
if (pos >= active_nr)
|
||
17 years ago
|
die("git merge-index: %s not in the cache", path);
|
||
20 years ago
|
found = 0;
|
||
|
do {
|
||
|
struct cache_entry *ce = active_cache[pos];
|
||
|
int stage = ce_stage(ce);
|
||
|
|
||
|
if (strcmp(ce->name, path))
|
||
|
break;
|
||
|
found++;
|
||
20 years ago
|
strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
|
||
17 years ago
|
sprintf(ownbuf[stage], "%o", ce->ce_mode);
|
||
20 years ago
|
arguments[stage] = hexbuf[stage];
|
||
20 years ago
|
arguments[stage + 4] = ownbuf[stage];
|
||
20 years ago
|
} while (++pos < active_nr);
|
||
|
if (!found)
|
||
17 years ago
|
die("git merge-index: %s not in the cache", path);
|
||
16 years ago
|
|
||
|
if (run_command_v_opt(arguments, 0)) {
|
||
|
if (one_shot)
|
||
|
err++;
|
||
|
else {
|
||
|
if (!quiet)
|
||
|
die("merge program failed");
|
||
|
exit(1);
|
||
|
}
|
||
|
}
|
||
20 years ago
|
return found;
|
||
|
}
|
||
|
|
||
|
static void merge_file(const char *path)
|
||
|
{
|
||
|
int pos = cache_name_pos(path, strlen(path));
|
||
|
|
||
|
/*
|
||
|
* If it already exists in the cache as stage0, it's
|
||
|
* already merged and there is nothing to do.
|
||
|
*/
|
||
|
if (pos < 0)
|
||
|
merge_entry(-pos-1, path);
|
||
|
}
|
||
|
|
||
|
static void merge_all(void)
|
||
|
{
|
||
|
int i;
|
||
|
for (i = 0; i < active_nr; i++) {
|
||
|
struct cache_entry *ce = active_cache[i];
|
||
|
if (!ce_stage(ce))
|
||
|
continue;
|
||
|
i += merge_entry(i, ce->name)-1;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
int cmd_merge_index(int argc, const char **argv, const char *prefix)
|
||
20 years ago
|
{
|
||
|
int i, force_file = 0;
|
||
|
|
||
19 years ago
|
/* Without this we cannot rely on waitpid() to tell
|
||
|
* what happened to our children.
|
||
|
*/
|
||
|
signal(SIGCHLD, SIG_DFL);
|
||
|
|
||
20 years ago
|
if (argc < 3)
|
||
16 years ago
|
usage("git merge-index [-o] [-q] <merge-program> (-a | [--] <filename>*)");
|
||
20 years ago
|
|
||
|
read_cache();
|
||
|
|
||
20 years ago
|
i = 1;
|
||
20 years ago
|
if (!strcmp(argv[i], "-o")) {
|
||
20 years ago
|
one_shot = 1;
|
||
|
i++;
|
||
|
}
|
||
20 years ago
|
if (!strcmp(argv[i], "-q")) {
|
||
|
quiet = 1;
|
||
|
i++;
|
||
|
}
|
||
20 years ago
|
pgm = argv[i++];
|
||
|
for (; i < argc; i++) {
|
||
15 years ago
|
const char *arg = argv[i];
|
||
20 years ago
|
if (!force_file && *arg == '-') {
|
||
|
if (!strcmp(arg, "--")) {
|
||
|
force_file = 1;
|
||
|
continue;
|
||
|
}
|
||
|
if (!strcmp(arg, "-a")) {
|
||
|
merge_all();
|
||
|
continue;
|
||
|
}
|
||
17 years ago
|
die("git merge-index: unknown option %s", arg);
|
||
20 years ago
|
}
|
||
|
merge_file(arg);
|
||
|
}
|
||
20 years ago
|
if (err && !quiet)
|
||
20 years ago
|
die("merge program failed");
|
||
20 years ago
|
return err;
|
||
20 years ago
|
}
|