git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
c66fef7b7f79ca19fdd48cf6e3519dd3f8241d42 blob 2838 bytes (raw)

  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
104
105
106
107
108
109
110
111
112
 
/*
 * Builtin "git merge-resolve"
 *
 * Copyright (c) 2020 Alban Gruin
 *
 * Based on git-merge-resolve.sh, written by Linus Torvalds and Junio C
 * Hamano.
 *
 * Resolve two trees, using enhanced multi-base read-tree.
 */

#include "cache.h"
#include "builtin.h"
#include "run-command.h"

static int merge_resolve(struct commit_list *bases, const char *head_arg,
			 struct commit_list *remote)
{
	struct commit_list *j;
	struct child_process cp_update = CHILD_PROCESS_INIT,
		cp_read = CHILD_PROCESS_INIT,
		cp_write = CHILD_PROCESS_INIT;

	cp_update.git_cmd = 1;
	argv_array_pushl(&cp_update.args, "update-index", "-q", "--refresh", NULL);
	run_command(&cp_update);

	cp_read.git_cmd = 1;
	argv_array_pushl(&cp_read.args, "read-tree", "-u", "-m", "--aggressive", NULL);

	for (j = bases; j && j->item; j = j->next)
		argv_array_push(&cp_read.args, oid_to_hex(&j->item->object.oid));

	if (head_arg)
		argv_array_push(&cp_read.args, head_arg);
	if (remote && remote->item)
		argv_array_push(&cp_read.args, oid_to_hex(&remote->item->object.oid));

	if (run_command(&cp_read))
		return 2;

	puts("Trying simple merge.");

	cp_write.git_cmd = 1;
	cp_write.no_stdout = 1;
	cp_write.no_stderr = 1;
	argv_array_push(&cp_write.args, "write-tree");
	if (run_command(&cp_write)) {
		struct child_process cp_merge = CHILD_PROCESS_INIT;

		puts("Simple merge failed, trying Automatic merge.");

		cp_merge.git_cmd = 1;
		argv_array_pushl(&cp_merge.args, "merge-index", "-o",
				 "git-merge-one-file", "-a", NULL);
		if (run_command(&cp_merge))
			return 1;
	}

	return 0;
}

static const char builtin_merge_resolve_usage[] =
	"git merge-resolve <bases>... -- <head> <remote>";

int cmd_merge_resolve(int argc, const char **argv, const char *prefix)
{
	int i, is_baseless = 1, sep_seen = 0;
	const char *head = NULL;
	struct commit_list *bases = NULL, *remote = NULL;
	struct commit_list **next_base = &bases;

	if (argc < 5)
		usage(builtin_merge_resolve_usage);

	/* The first parameters up to -- are merge bases; the rest are
	 * heads. */
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "--") == 0)
			sep_seen = 1;
		else if (strcmp(argv[i], "-h") == 0)
			usage(builtin_merge_resolve_usage);
		else if (sep_seen && !head)
			head = argv[i];
		else if (remote) {
			/* Give up if we are given two or more remotes.
			 * Not handling octopus. */
			return 2;
		} else {
			struct object_id oid;

			get_oid(argv[i], &oid);
			is_baseless &= sep_seen;

			if (!oideq(&oid, the_hash_algo->empty_tree)) {
				struct commit *commit;
				commit = lookup_commit_or_die(&oid, argv[i]);

				if (sep_seen)
					commit_list_append(commit, &remote);
				else
					next_base = commit_list_append(commit, next_base);
			}
		}
	}

	/* Give up if this is a baseless merge. */
	if (is_baseless)
		return 2;

	return merge_resolve(bases, head, remote);
}
debug log:

solving c66fef7b7f ...
found c66fef7b7f in https://public-inbox.org/git/20200625121953.16991-8-alban.gruin@gmail.com/

applying [1/1] https://public-inbox.org/git/20200625121953.16991-8-alban.gruin@gmail.com/
diff --git a/builtin/merge-resolve.c b/builtin/merge-resolve.c
new file mode 100644
index 0000000000..c66fef7b7f

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

index at:
100644 c66fef7b7f79ca19fdd48cf6e3519dd3f8241d42	builtin/merge-resolve.c

Code repositories for project(s) associated with this 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).