git

Форк
0
/
write-tree.c 
64 строки · 1.7 Кб
1
/*
2
 * GIT - The information manager from hell
3
 *
4
 * Copyright (C) Linus Torvalds, 2005
5
 */
6

7
#include "builtin.h"
8
#include "config.h"
9
#include "environment.h"
10
#include "gettext.h"
11
#include "hex.h"
12
#include "tree.h"
13
#include "cache-tree.h"
14
#include "parse-options.h"
15
#include "repository.h"
16

17
static const char * const write_tree_usage[] = {
18
	N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
19
	NULL
20
};
21

22
int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
23
{
24
	int flags = 0, ret;
25
	const char *tree_prefix = NULL;
26
	struct object_id oid;
27
	const char *me = "git-write-tree";
28
	struct option write_tree_options[] = {
29
		OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
30
			WRITE_TREE_MISSING_OK),
31
		OPT_STRING(0, "prefix", &tree_prefix, N_("<prefix>/"),
32
			   N_("write tree object for a subdirectory <prefix>")),
33
		{ OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
34
		  N_("only useful for debugging"),
35
		  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
36
		  WRITE_TREE_IGNORE_CACHE_TREE },
37
		OPT_END()
38
	};
39

40
	git_config(git_default_config, NULL);
41
	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
42
			     write_tree_usage, 0);
43

44
	prepare_repo_settings(the_repository);
45
	the_repository->settings.command_requires_full_index = 0;
46

47
	ret = write_index_as_tree(&oid, the_repository->index, get_index_file(),
48
				  flags, tree_prefix);
49
	switch (ret) {
50
	case 0:
51
		printf("%s\n", oid_to_hex(&oid));
52
		break;
53
	case WRITE_TREE_UNREADABLE_INDEX:
54
		die("%s: error reading the index", me);
55
		break;
56
	case WRITE_TREE_UNMERGED_INDEX:
57
		die("%s: error building trees", me);
58
		break;
59
	case WRITE_TREE_PREFIX_ERROR:
60
		die("%s: prefix %s not found", me, tree_prefix);
61
		break;
62
	}
63
	return ret;
64
}
65

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

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

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

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