git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob ca8f9f345d4750da7f34a08a5536f004a742c7dd 1651 bytes (raw)
name: builtin/merge-octopus.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-octopus"
 *
 * Copyright (c) 2020 Alban Gruin
 *
 * Based on git-merge-octopus.sh, written by Junio C Hamano.
 *
 * Resolve two or more trees.
 */

#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "builtin.h"
#include "commit.h"
#include "merge-strategies.h"

static const char builtin_merge_octopus_usage[] =
	"git merge-octopus [<bases>...] -- <head> <remote1> <remote2> [<remotes>...]";

int cmd_merge_octopus(int argc, const char **argv, const char *prefix)
{
	int i, sep_seen = 0;
	struct commit_list *bases = NULL, *remotes = NULL;
	struct commit_list **next_base = &bases, **next_remote = &remotes;
	const char *head_arg = NULL;

	if (argc < 5)
		usage(builtin_merge_octopus_usage);

	setup_work_tree();
	if (read_cache() < 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_octopus_usage);
		else if (sep_seen && !head_arg)
			head_arg = argv[i];
		else {
			struct object_id oid;
			struct commit *commit;

			if (get_oid(argv[i], &oid))
				die("object %s not found.", argv[i]);

			commit = lookup_commit_or_die(&oid, argv[i]);

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

	/*
	 * Reject if this is not an octopus -- resolve should be used
	 * instead.
	 */
	if (commit_list_count(remotes) < 2)
		return 2;

	return merge_strategies_octopus(the_repository, bases, head_arg, remotes);
}

debug log:

solving ca8f9f345d ...
found ca8f9f345d in https://public-inbox.org/git/20201124115315.13311-10-alban.gruin@gmail.com/ ||
	https://public-inbox.org/git/20201116102158.8365-9-alban.gruin@gmail.com/ ||
	https://public-inbox.org/git/20201113110428.21265-9-alban.gruin@gmail.com/

applying [1/1] https://public-inbox.org/git/20201124115315.13311-10-alban.gruin@gmail.com/
diff --git a/builtin/merge-octopus.c b/builtin/merge-octopus.c
new file mode 100644
index 0000000000..ca8f9f345d

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

skipping https://public-inbox.org/git/20201116102158.8365-9-alban.gruin@gmail.com/ for ca8f9f345d
skipping https://public-inbox.org/git/20201113110428.21265-9-alban.gruin@gmail.com/ for ca8f9f345d
index at:
100644 ca8f9f345d4750da7f34a08a5536f004a742c7dd	builtin/merge-octopus.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).