3
#include "read-cache-ll.h"
5
#include "run-command.h"
6
#include "sparse-index.h"
9
static int one_shot, quiet;
12
static int merge_entry(int pos, const char *path)
15
const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
16
char hexbuf[4][GIT_MAX_HEXSZ + 1];
18
struct child_process cmd = CHILD_PROCESS_INIT;
20
if (pos >= the_repository->index->cache_nr)
21
die("git merge-index: %s not in the cache", path);
24
const struct cache_entry *ce = the_repository->index->cache[pos];
25
int stage = ce_stage(ce);
27
if (strcmp(ce->name, path))
30
oid_to_hex_r(hexbuf[stage], &ce->oid);
31
xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
32
arguments[stage] = hexbuf[stage];
33
arguments[stage + 4] = ownbuf[stage];
34
} while (++pos < the_repository->index->cache_nr);
36
die("git merge-index: %s not in the cache", path);
38
strvec_pushv(&cmd.args, arguments);
39
if (run_command(&cmd)) {
44
die("merge program failed");
51
static void merge_one_path(const char *path)
53
int pos = index_name_pos(the_repository->index, path, strlen(path));
56
* If it already exists in the cache as stage0, it's
57
* already merged and there is nothing to do.
60
merge_entry(-pos-1, path);
63
static void merge_all(void)
66
/* TODO: audit for interaction with sparse-index. */
67
ensure_full_index(the_repository->index);
68
for (i = 0; i < the_repository->index->cache_nr; i++) {
69
const struct cache_entry *ce = the_repository->index->cache[i];
72
i += merge_entry(i, ce->name)-1;
76
int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED)
78
int i, force_file = 0;
80
/* Without this we cannot rely on waitpid() to tell
81
* what happened to our children.
83
signal(SIGCHLD, SIG_DFL);
86
usage("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])");
88
repo_read_index(the_repository);
90
/* TODO: audit for interaction with sparse-index. */
91
ensure_full_index(the_repository->index);
94
if (!strcmp(argv[i], "-o")) {
98
if (!strcmp(argv[i], "-q")) {
103
for (; i < argc; i++) {
104
const char *arg = argv[i];
105
if (!force_file && *arg == '-') {
106
if (!strcmp(arg, "--")) {
110
if (!strcmp(arg, "-a")) {
114
die("git merge-index: unknown option %s", arg);
119
die("merge program failed");