2005-04-08 02:16:10 +04:00
|
|
|
/*
|
|
|
|
* GIT - The information manager from hell
|
|
|
|
*
|
|
|
|
* Copyright (C) Linus Torvalds, 2005
|
|
|
|
*/
|
cocci & cache-tree.h: migrate "write_cache_as_tree" to "*_index_*"
Add a trivial rule for "write_cache_as_tree" to
"index-compatibility.cocci", and apply it. This was left out of the
rules added in 0e6550a2c63 (cocci: add a
index-compatibility.pending.cocci, 2022-11-19) because this
compatibility wrapper lived in "cache-tree.h", not "cache.h"
But it's like the other "USE_THE_INDEX_COMPATIBILITY_MACROS", so let's
migrate it too.
The replacement of "USE_THE_INDEX_COMPATIBILITY_MACROS" here with
"USE_THE_INDEX_VARIABLE" is a manual change on top, now that these
files only use "&the_index", and don't need any compatibility
macros (or functions).
The wrapping of some argument lists is likewise manual, as coccinelle
would otherwise give us overly long argument lists.
The reason for putting the "O" in the cocci rule on the "-" and "+"
lines is because I couldn't get correct whitespacing otherwise,
i.e. I'd end up with "oid,&the_index", not "oid, &the_index".
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-02-10 13:28:37 +03:00
|
|
|
#define USE_THE_INDEX_VARIABLE
|
2006-06-14 00:21:42 +04:00
|
|
|
#include "builtin.h"
|
2017-06-14 21:07:36 +03:00
|
|
|
#include "config.h"
|
2023-03-21 09:26:03 +03:00
|
|
|
#include "environment.h"
|
2023-03-21 09:25:54 +03:00
|
|
|
#include "gettext.h"
|
2023-02-24 03:09:27 +03:00
|
|
|
#include "hex.h"
|
2006-04-02 16:44:09 +04:00
|
|
|
#include "tree.h"
|
2006-04-24 03:52:35 +04:00
|
|
|
#include "cache-tree.h"
|
2009-07-08 09:15:38 +04:00
|
|
|
#include "parse-options.h"
|
2023-05-10 02:45:45 +03:00
|
|
|
#include "repository.h"
|
2005-04-08 02:13:13 +04:00
|
|
|
|
2009-07-08 09:15:38 +04:00
|
|
|
static const char * const write_tree_usage[] = {
|
2012-08-20 16:32:53 +04:00
|
|
|
N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
|
2009-07-08 09:15:38 +04:00
|
|
|
NULL
|
|
|
|
};
|
2005-12-06 09:30:07 +03:00
|
|
|
|
2019-05-10 00:27:24 +03:00
|
|
|
int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
|
2006-06-14 00:21:42 +04:00
|
|
|
{
|
2009-05-20 22:04:35 +04:00
|
|
|
int flags = 0, ret;
|
2019-05-10 00:27:24 +03:00
|
|
|
const char *tree_prefix = NULL;
|
2018-03-12 05:27:22 +03:00
|
|
|
struct object_id oid;
|
2008-01-11 09:49:35 +03:00
|
|
|
const char *me = "git-write-tree";
|
2009-07-08 09:15:38 +04:00
|
|
|
struct option write_tree_options[] = {
|
2012-08-20 16:32:53 +04:00
|
|
|
OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
|
2009-07-08 09:15:38 +04:00
|
|
|
WRITE_TREE_MISSING_OK),
|
2019-05-10 00:27:24 +03:00
|
|
|
OPT_STRING(0, "prefix", &tree_prefix, N_("<prefix>/"),
|
2018-08-02 22:18:14 +03:00
|
|
|
N_("write tree object for a subdirectory <prefix>")),
|
2009-07-08 09:15:38 +04:00
|
|
|
{ OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
|
2012-08-20 16:32:53 +04:00
|
|
|
N_("only useful for debugging"),
|
2009-07-08 09:15:38 +04:00
|
|
|
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
|
|
|
|
WRITE_TREE_IGNORE_CACHE_TREE },
|
|
|
|
OPT_END()
|
|
|
|
};
|
2006-06-14 00:21:42 +04:00
|
|
|
|
2008-05-14 21:46:53 +04:00
|
|
|
git_config(git_default_config, NULL);
|
2019-05-10 00:27:24 +03:00
|
|
|
argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
|
2009-07-08 09:15:38 +04:00
|
|
|
write_tree_usage, 0);
|
2006-06-14 00:21:42 +04:00
|
|
|
|
2023-04-04 03:35:39 +03:00
|
|
|
prepare_repo_settings(the_repository);
|
|
|
|
the_repository->settings.command_requires_full_index = 0;
|
|
|
|
|
cocci & cache-tree.h: migrate "write_cache_as_tree" to "*_index_*"
Add a trivial rule for "write_cache_as_tree" to
"index-compatibility.cocci", and apply it. This was left out of the
rules added in 0e6550a2c63 (cocci: add a
index-compatibility.pending.cocci, 2022-11-19) because this
compatibility wrapper lived in "cache-tree.h", not "cache.h"
But it's like the other "USE_THE_INDEX_COMPATIBILITY_MACROS", so let's
migrate it too.
The replacement of "USE_THE_INDEX_COMPATIBILITY_MACROS" here with
"USE_THE_INDEX_VARIABLE" is a manual change on top, now that these
files only use "&the_index", and don't need any compatibility
macros (or functions).
The wrapping of some argument lists is likewise manual, as coccinelle
would otherwise give us overly long argument lists.
The reason for putting the "O" in the cocci rule on the "-" and "+"
lines is because I couldn't get correct whitespacing otherwise,
i.e. I'd end up with "oid,&the_index", not "oid, &the_index".
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-02-10 13:28:37 +03:00
|
|
|
ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
|
|
|
|
tree_prefix);
|
2008-01-11 09:49:35 +03:00
|
|
|
switch (ret) {
|
|
|
|
case 0:
|
2018-03-12 05:27:22 +03:00
|
|
|
printf("%s\n", oid_to_hex(&oid));
|
2008-01-11 09:49:35 +03:00
|
|
|
break;
|
|
|
|
case WRITE_TREE_UNREADABLE_INDEX:
|
|
|
|
die("%s: error reading the index", me);
|
|
|
|
break;
|
|
|
|
case WRITE_TREE_UNMERGED_INDEX:
|
2008-11-29 06:56:34 +03:00
|
|
|
die("%s: error building trees", me);
|
2008-01-11 09:49:35 +03:00
|
|
|
break;
|
|
|
|
case WRITE_TREE_PREFIX_ERROR:
|
2019-05-10 00:27:24 +03:00
|
|
|
die("%s: prefix %s not found", me, tree_prefix);
|
2008-01-11 09:49:35 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-06-14 00:21:42 +04:00
|
|
|
return ret;
|
|
|
|
}
|