write-tree: migrate to parse-options
A check for extra options has been dropped, it could never be triggered in the original code as the usage message would be printed instead. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
4ecbc17870
commit
404d42e5ef
@ -7,9 +7,12 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
#include "cache-tree.h"
|
#include "cache-tree.h"
|
||||||
|
#include "parse-options.h"
|
||||||
|
|
||||||
static const char write_tree_usage[] =
|
static const char * const write_tree_usage[] = {
|
||||||
"git write-tree [--missing-ok] [--prefix=<prefix>/]";
|
"git write-tree [--missing-ok] [--prefix=<prefix>/]",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
|
int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
|
||||||
{
|
{
|
||||||
@ -17,27 +20,22 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
|
|||||||
const char *prefix = NULL;
|
const char *prefix = NULL;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
const char *me = "git-write-tree";
|
const char *me = "git-write-tree";
|
||||||
|
struct option write_tree_options[] = {
|
||||||
|
OPT_BIT(0, "missing-ok", &flags, "allow missing objects",
|
||||||
|
WRITE_TREE_MISSING_OK),
|
||||||
|
{ OPTION_STRING, 0, "prefix", &prefix, "<prefix>/",
|
||||||
|
"write tree object for a subdirectory <prefix>" ,
|
||||||
|
PARSE_OPT_LITERAL_ARGHELP },
|
||||||
|
{ OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
|
||||||
|
"only useful for debugging",
|
||||||
|
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
|
||||||
|
WRITE_TREE_IGNORE_CACHE_TREE },
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
while (1 < argc) {
|
argc = parse_options(argc, argv, unused_prefix, write_tree_options,
|
||||||
const char *arg = argv[1];
|
write_tree_usage, 0);
|
||||||
if (!strcmp(arg, "--missing-ok"))
|
|
||||||
flags |= WRITE_TREE_MISSING_OK;
|
|
||||||
else if (!prefixcmp(arg, "--prefix="))
|
|
||||||
prefix = arg + 9;
|
|
||||||
else if (!prefixcmp(arg, "--ignore-cache-tree"))
|
|
||||||
/*
|
|
||||||
* This is only useful for debugging, so I
|
|
||||||
* do not bother documenting it.
|
|
||||||
*/
|
|
||||||
flags |= WRITE_TREE_IGNORE_CACHE_TREE;
|
|
||||||
else
|
|
||||||
usage(write_tree_usage);
|
|
||||||
argc--; argv++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 2)
|
|
||||||
die("too many options");
|
|
||||||
|
|
||||||
ret = write_cache_as_tree(sha1, flags, prefix);
|
ret = write_cache_as_tree(sha1, flags, prefix);
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
|
Loading…
Reference in New Issue
Block a user