git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob 59f734473bad6a1087cb44d293a4f023c0dab31e 1680 bytes (raw)
name: builtin/merge-resolve.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
 
/*
 * 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 "merge-strategies.h"

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);

	setup_work_tree();
	if (repo_read_index(the_repository) < 0)
		die("invalid index");

	/* 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_strategies_resolve(the_repository, bases, head, remote);
}

debug log:

solving 59f734473b ...
found 59f734473b in https://public-inbox.org/git/20201005122646.27994-6-alban.gruin@gmail.com/ ||
	https://public-inbox.org/git/20200901105705.6059-6-alban.gruin@gmail.com/ ||
	https://public-inbox.org/git/20200625121953.16991-10-alban.gruin@gmail.com/

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

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

skipping https://public-inbox.org/git/20200901105705.6059-6-alban.gruin@gmail.com/ for 59f734473b
skipping https://public-inbox.org/git/20200625121953.16991-10-alban.gruin@gmail.com/ for 59f734473b
index at:
100644 59f734473bad6a1087cb44d293a4f023c0dab31e	builtin/merge-resolve.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).