Merge branch 'sb/parse-options'
* sb/parse-options: prune-packed: migrate to parse-options verify-pack: migrate to parse-options verify-tag: migrate to parse-options write-tree: migrate to parse-options
This commit is contained in:
@ -8,7 +8,7 @@ git-prune-packed - Remove extra objects that are already in pack files
|
|||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
'git prune-packed' [-n] [-q]
|
'git prune-packed' [-n|--dry-run] [-q|--quiet]
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
@ -28,10 +28,12 @@ disk storage, etc.
|
|||||||
OPTIONS
|
OPTIONS
|
||||||
-------
|
-------
|
||||||
-n::
|
-n::
|
||||||
|
--dry-run::
|
||||||
Don't actually remove any objects, only show those that would have been
|
Don't actually remove any objects, only show those that would have been
|
||||||
removed.
|
removed.
|
||||||
|
|
||||||
-q::
|
-q::
|
||||||
|
--quiet::
|
||||||
Squelch the progress indicator.
|
Squelch the progress indicator.
|
||||||
|
|
||||||
Author
|
Author
|
||||||
|
@ -8,7 +8,7 @@ git-verify-pack - Validate packed git archive files
|
|||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
'git verify-pack' [-v] [--] <pack>.idx ...
|
'git verify-pack' [-v|--verbose] [--] <pack>.idx ...
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
@ -23,6 +23,7 @@ OPTIONS
|
|||||||
The idx files to verify.
|
The idx files to verify.
|
||||||
|
|
||||||
-v::
|
-v::
|
||||||
|
--verbose::
|
||||||
After verifying the pack, show list of objects contained
|
After verifying the pack, show list of objects contained
|
||||||
in the pack.
|
in the pack.
|
||||||
\--::
|
\--::
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "progress.h"
|
#include "progress.h"
|
||||||
|
#include "parse-options.h"
|
||||||
|
|
||||||
static const char prune_packed_usage[] =
|
static const char * const prune_packed_usage[] = {
|
||||||
"git prune-packed [-n] [-q]";
|
"git prune-packed [-n|--dry-run] [-q|--quiet]",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#define DRY_RUN 01
|
#define DRY_RUN 01
|
||||||
#define VERBOSE 02
|
#define VERBOSE 02
|
||||||
@ -68,24 +71,16 @@ void prune_packed_objects(int opts)
|
|||||||
|
|
||||||
int cmd_prune_packed(int argc, const char **argv, const char *prefix)
|
int cmd_prune_packed(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int opts = VERBOSE;
|
int opts = VERBOSE;
|
||||||
|
const struct option prune_packed_options[] = {
|
||||||
|
OPT_BIT('n', "dry-run", &opts, "dry run", DRY_RUN),
|
||||||
|
OPT_NEGBIT('q', "quiet", &opts, "be quiet", VERBOSE),
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
argc = parse_options(argc, argv, prefix, prune_packed_options,
|
||||||
const char *arg = argv[i];
|
prune_packed_usage, 0);
|
||||||
|
|
||||||
if (*arg == '-') {
|
|
||||||
if (!strcmp(arg, "-n"))
|
|
||||||
opts |= DRY_RUN;
|
|
||||||
else if (!strcmp(arg, "-q"))
|
|
||||||
opts &= ~VERBOSE;
|
|
||||||
else
|
|
||||||
usage(prune_packed_usage);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Handle arguments here .. */
|
|
||||||
usage(prune_packed_usage);
|
|
||||||
}
|
|
||||||
prune_packed_objects(opts);
|
prune_packed_objects(opts);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
#include "pack-revindex.h"
|
#include "pack-revindex.h"
|
||||||
|
#include "parse-options.h"
|
||||||
|
|
||||||
#define MAX_CHAIN 50
|
#define MAX_CHAIN 50
|
||||||
|
|
||||||
@ -107,36 +108,31 @@ static int verify_one_pack(const char *path, int verbose)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char verify_pack_usage[] = "git verify-pack [-v] <pack>...";
|
static const char * const verify_pack_usage[] = {
|
||||||
|
"git verify-pack [-v|--verbose] <pack>...",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
int cmd_verify_pack(int argc, const char **argv, const char *prefix)
|
int cmd_verify_pack(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
int no_more_options = 0;
|
int i;
|
||||||
int nothing_done = 1;
|
const struct option verify_pack_options[] = {
|
||||||
|
OPT__VERBOSE(&verbose),
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
while (1 < argc) {
|
argc = parse_options(argc, argv, prefix, verify_pack_options,
|
||||||
if (!no_more_options && argv[1][0] == '-') {
|
verify_pack_usage, 0);
|
||||||
if (!strcmp("-v", argv[1]))
|
if (argc < 1)
|
||||||
verbose = 1;
|
usage_with_options(verify_pack_usage, verify_pack_options);
|
||||||
else if (!strcmp("--", argv[1]))
|
for (i = 0; i < argc; i++) {
|
||||||
no_more_options = 1;
|
if (verify_one_pack(argv[i], verbose))
|
||||||
else
|
|
||||||
usage(verify_pack_usage);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (verify_one_pack(argv[1], verbose))
|
|
||||||
err = 1;
|
err = 1;
|
||||||
discard_revindex();
|
discard_revindex();
|
||||||
nothing_done = 0;
|
|
||||||
}
|
}
|
||||||
argc--; argv++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nothing_done)
|
|
||||||
usage(verify_pack_usage);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,12 @@
|
|||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "run-command.h"
|
#include "run-command.h"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include "parse-options.h"
|
||||||
|
|
||||||
static const char builtin_verify_tag_usage[] =
|
static const char * const verify_tag_usage[] = {
|
||||||
"git verify-tag [-v|--verbose] <tag>...";
|
"git verify-tag [-v|--verbose] <tag>...",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
|
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
|
||||||
|
|
||||||
@ -89,17 +92,17 @@ static int verify_tag(const char *name, int verbose)
|
|||||||
int cmd_verify_tag(int argc, const char **argv, const char *prefix)
|
int cmd_verify_tag(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
int i = 1, verbose = 0, had_error = 0;
|
int i = 1, verbose = 0, had_error = 0;
|
||||||
|
const struct option verify_tag_options[] = {
|
||||||
|
OPT__VERBOSE(&verbose),
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
|
|
||||||
if (argc > 1 &&
|
argc = parse_options(argc, argv, prefix, verify_tag_options,
|
||||||
(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose"))) {
|
verify_tag_usage, PARSE_OPT_KEEP_ARGV0);
|
||||||
verbose = 1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc <= i)
|
if (argc <= i)
|
||||||
usage(builtin_verify_tag_usage);
|
usage_with_options(verify_tag_usage, verify_tag_options);
|
||||||
|
|
||||||
/* sometimes the program was terminated because this signal
|
/* sometimes the program was terminated because this signal
|
||||||
* was received in the process of writing the gpg input: */
|
* was received in the process of writing the gpg input: */
|
||||||
|
@ -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) {
|
||||||
|
Reference in New Issue
Block a user