]>
| Commit | Line | Data |
|---|---|---|
| 8bc9a0c7 LT |
1 | /* |
| 2 | * GIT - The information manager from hell | |
| 3 | * | |
| 4 | * Copyright (C) Linus Torvalds, 2005 | |
| 5 | */ | |
| 03eae9af | 6 | #define USE_THE_REPOSITORY_VARIABLE |
| 8ed05fb5 | 7 | #include "builtin.h" |
| b2141fc1 | 8 | #include "config.h" |
| 08b77586 | 9 | #include "environment.h" |
| f394e093 | 10 | #include "gettext.h" |
| 41771fa4 | 11 | #include "hex.h" |
| 8e440259 | 12 | #include "tree.h" |
| a52139b4 | 13 | #include "cache-tree.h" |
| 404d42e5 | 14 | #include "parse-options.h" |
| e83c5163 | 15 | |
| 404d42e5 | 16 | static const char * const write_tree_usage[] = { |
| b5625d07 | 17 | N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"), |
| 404d42e5 SB |
18 | NULL |
| 19 | }; | |
| 75a46f6b | 20 | |
| 9b1cb507 JC |
21 | int cmd_write_tree(int argc, |
| 22 | const char **argv, | |
| 23 | const char *cmd_prefix, | |
| 24 | struct repository *repo UNUSED) | |
| 8ed05fb5 | 25 | { |
| d11b8d34 | 26 | int flags = 0, ret; |
| 76a7bc09 | 27 | const char *tree_prefix = NULL; |
| 38b471fa | 28 | struct object_id oid; |
| 45525bd0 | 29 | const char *me = "git-write-tree"; |
| 404d42e5 | 30 | struct option write_tree_options[] = { |
| b5625d07 | 31 | OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"), |
| 404d42e5 | 32 | WRITE_TREE_MISSING_OK), |
| 76a7bc09 | 33 | OPT_STRING(0, "prefix", &tree_prefix, N_("<prefix>/"), |
| 5f0df44c | 34 | N_("write tree object for a subdirectory <prefix>")), |
| d012ceb5 PS |
35 | { |
| 36 | .type = OPTION_BIT, | |
| 37 | .long_name = "ignore-cache-tree", | |
| 38 | .value = &flags, | |
| 5228211c | 39 | .precision = sizeof(flags), |
| d012ceb5 PS |
40 | .help = N_("only useful for debugging"), |
| 41 | .flags = PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, | |
| 42 | .defval = WRITE_TREE_IGNORE_CACHE_TREE, | |
| 43 | }, | |
| 404d42e5 SB |
44 | OPT_END() |
| 45 | }; | |
| 8ed05fb5 | 46 | |
| 9ce196e8 | 47 | repo_config(the_repository, git_default_config, NULL); |
| 76a7bc09 | 48 | argc = parse_options(argc, argv, cmd_prefix, write_tree_options, |
| 404d42e5 | 49 | write_tree_usage, 0); |
| 8ed05fb5 | 50 | |
| 1a65b41b SL |
51 | prepare_repo_settings(the_repository); |
| 52 | the_repository->settings.command_requires_full_index = 0; | |
| 53 | ||
| 1dc4ec21 PS |
54 | ret = write_index_as_tree(&oid, the_repository->index, |
| 55 | repo_get_index_file(the_repository), | |
| f59aa5e0 | 56 | flags, tree_prefix); |
| 45525bd0 JH |
57 | switch (ret) { |
| 58 | case 0: | |
| 38b471fa | 59 | printf("%s\n", oid_to_hex(&oid)); |
| 45525bd0 JH |
60 | break; |
| 61 | case WRITE_TREE_UNREADABLE_INDEX: | |
| 62 | die("%s: error reading the index", me); | |
| 63 | break; | |
| 64 | case WRITE_TREE_UNMERGED_INDEX: | |
| 331fcb59 | 65 | die("%s: error building trees", me); |
| 45525bd0 JH |
66 | break; |
| 67 | case WRITE_TREE_PREFIX_ERROR: | |
| 76a7bc09 | 68 | die("%s: prefix %s not found", me, tree_prefix); |
| 45525bd0 JH |
69 | break; |
| 70 | } | |
| 8ed05fb5 LS |
71 | return ret; |
| 72 | } |