git

Форк
0
/
merge-recursive.c 
91 строка · 2.4 Кб
1
#include "builtin.h"
2
#include "advice.h"
3
#include "gettext.h"
4
#include "hash.h"
5
#include "merge-recursive.h"
6
#include "object-name.h"
7
#include "repository.h"
8

9
static const char builtin_merge_recursive_usage[] =
10
	"git %s <base>... -- <head> <remote> ...";
11

12
static char *better_branch_name(const char *branch)
13
{
14
	static char githead_env[8 + GIT_MAX_HEXSZ + 1];
15
	char *name;
16

17
	if (strlen(branch) != the_hash_algo->hexsz)
18
		return xstrdup(branch);
19
	xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
20
	name = getenv(githead_env);
21
	return xstrdup(name ? name : branch);
22
}
23

24
int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED)
25
{
26
	struct object_id bases[21];
27
	unsigned bases_count = 0;
28
	int i, failed;
29
	struct object_id h1, h2;
30
	struct merge_options o;
31
	char *better1, *better2;
32
	struct commit *result;
33

34
	init_basic_merge_options(&o, the_repository);
35
	if (argv[0] && ends_with(argv[0], "-subtree"))
36
		o.subtree_shift = "";
37

38
	if (argc < 4)
39
		usagef(builtin_merge_recursive_usage, argv[0]);
40

41
	for (i = 1; i < argc; ++i) {
42
		const char *arg = argv[i];
43

44
		if (starts_with(arg, "--")) {
45
			if (!arg[2])
46
				break;
47
			if (parse_merge_opt(&o, arg + 2))
48
				die(_("unknown option %s"), arg);
49
			continue;
50
		}
51
		if (bases_count < ARRAY_SIZE(bases)-1) {
52
			if (repo_get_oid(the_repository, argv[i], &bases[bases_count++]))
53
				die(_("could not parse object '%s'"), argv[i]);
54
		}
55
		else
56
			warning(Q_("cannot handle more than %d base. "
57
				   "Ignoring %s.",
58
				   "cannot handle more than %d bases. "
59
				   "Ignoring %s.",
60
				    ARRAY_SIZE(bases)-1),
61
				(int)ARRAY_SIZE(bases)-1, argv[i]);
62
	}
63
	if (argc - i != 3) /* "--" "<head>" "<remote>" */
64
		die(_("not handling anything other than two heads merge."));
65

66
	if (repo_read_index_unmerged(the_repository))
67
		die_resolve_conflict("merge");
68

69
	o.branch1 = argv[++i];
70
	o.branch2 = argv[++i];
71

72
	if (repo_get_oid(the_repository, o.branch1, &h1))
73
		die(_("could not resolve ref '%s'"), o.branch1);
74
	if (repo_get_oid(the_repository, o.branch2, &h2))
75
		die(_("could not resolve ref '%s'"), o.branch2);
76

77
	o.branch1 = better1 = better_branch_name(o.branch1);
78
	o.branch2 = better2 = better_branch_name(o.branch2);
79

80
	if (o.verbosity >= 3)
81
		printf(_("Merging %s with %s\n"), o.branch1, o.branch2);
82

83
	failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
84

85
	free(better1);
86
	free(better2);
87

88
	if (failed < 0)
89
		return 128; /* die() error code */
90
	return failed;
91
}
92

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.