git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob fd5b1a5a92efeaf5c5b612b705dd5cbd9c970458 2550 bytes (raw)
name: builtin/merge-index.c 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
 
#include "builtin.h"
#include "lockfile.h"
#include "merge-strategies.h"
#include "run-command.h"

static const char *pgm;

static int merge_one_file_spawn(struct index_state *istate,
				const struct object_id *orig_blob,
				const struct object_id *our_blob,
				const struct object_id *their_blob, const char *path,
				unsigned int orig_mode, unsigned int our_mode, unsigned int their_mode,
				void *data)
{
	char oids[3][GIT_MAX_HEXSZ + 1] = {{0}};
	char modes[3][10] = {{0}};
	const char *arguments[] = { pgm, oids[0], oids[1], oids[2],
				    path, modes[0], modes[1], modes[2], NULL };

	if (orig_blob) {
		oid_to_hex_r(oids[0], orig_blob);
		xsnprintf(modes[0], sizeof(modes[0]), "%06o", orig_mode);
	}

	if (our_blob) {
		oid_to_hex_r(oids[1], our_blob);
		xsnprintf(modes[1], sizeof(modes[1]), "%06o", our_mode);
	}

	if (their_blob) {
		oid_to_hex_r(oids[2], their_blob);
		xsnprintf(modes[2], sizeof(modes[2]), "%06o", their_mode);
	}

	return run_command_v_opt(arguments, 0);
}

int cmd_merge_index(int argc, const char **argv, const char *prefix)
{
	int i, force_file = 0, err = 0, one_shot = 0, quiet = 0;
	merge_fn merge_action = merge_one_file_spawn;
	struct lock_file lock = LOCK_INIT;
	struct repository *r = the_repository;
	const char *use_internal = NULL;

	/* Without this we cannot rely on waitpid() to tell
	 * what happened to our children.
	 */
	signal(SIGCHLD, SIG_DFL);

	if (argc < 3)
		usage("git merge-index [-o] [-q] (<merge-program> | --use=merge-one-file) (-a | [--] [<filename>...])");

	if (repo_read_index(r) < 0)
		die("invalid index");

	i = 1;
	if (!strcmp(argv[i], "-o")) {
		one_shot = 1;
		i++;
	}
	if (!strcmp(argv[i], "-q")) {
		quiet = 1;
		i++;
	}

	pgm = argv[i++];
	setup_work_tree();

	if (skip_prefix(pgm, "--use=", &use_internal)) {
		if (!strcmp(use_internal, "merge-one-file"))
			pgm = "git-merge-one-file";
		else
			die(_("git merge-index: unknown internal program %s"), use_internal);
	}

	for (; i < argc; i++) {
		const char *arg = argv[i];
		if (!force_file && *arg == '-') {
			if (!strcmp(arg, "--")) {
				force_file = 1;
				continue;
			}
			if (!strcmp(arg, "-a")) {
				err |= merge_all_index(r->index, one_shot, quiet,
						       merge_action, NULL);
				continue;
			}
			die("git merge-index: unknown option %s", arg);
		}
		err |= merge_index_path(r->index, one_shot, quiet, arg,
					merge_action, NULL);
	}

	if (is_lock_file_locked(&lock)) {
		if (err)
			rollback_lock_file(&lock);
		else
			return write_locked_index(r->index, &lock, COMMIT_LOCK);
	}

	return err;
}

debug log:

solving fd5b1a5a92 ...
found fd5b1a5a92 in https://public-inbox.org/git/20210317204939.17890-7-alban.gruin@gmail.com/
found 49ddf3f9cd in https://public-inbox.org/git/20210317204939.17890-6-alban.gruin@gmail.com/
found 70f440d9a0 in https://public-inbox.org/git/20210317204939.17890-5-alban.gruin@gmail.com/
found 38ea6ad6ca in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100644 38ea6ad6ca25d5a969afdbfc5b3510ba44e49a33	builtin/merge-index.c

applying [1/3] https://public-inbox.org/git/20210317204939.17890-5-alban.gruin@gmail.com/
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index 38ea6ad6ca..70f440d9a0 100644


applying [2/3] https://public-inbox.org/git/20210317204939.17890-6-alban.gruin@gmail.com/
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index 70f440d9a0..49ddf3f9cd 100644


applying [3/3] https://public-inbox.org/git/20210317204939.17890-7-alban.gruin@gmail.com/
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index 49ddf3f9cd..fd5b1a5a92 100644

Checking patch builtin/merge-index.c...
Applied patch builtin/merge-index.c cleanly.
Checking patch builtin/merge-index.c...
Applied patch builtin/merge-index.c cleanly.
Checking patch builtin/merge-index.c...
Applied patch builtin/merge-index.c cleanly.

index at:
100644 fd5b1a5a92efeaf5c5b612b705dd5cbd9c970458	builtin/merge-index.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).