Skip to content

Commit 7e956cc

Browse files
committed
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
2 parents 0397ff2 + 7cfe0c9 commit 7e956cc

File tree

6 files changed

+66
-71
lines changed

6 files changed

+66
-71
lines changed

Documentation/git-prune-packed.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-prune-packed - Remove extra objects that are already in pack files
88

99
SYNOPSIS
1010
--------
11-
'git prune-packed' [-n] [-q]
11+
'git prune-packed' [-n|--dry-run] [-q|--quiet]
1212

1313

1414
DESCRIPTION
@@ -28,10 +28,12 @@ disk storage, etc.
2828
OPTIONS
2929
-------
3030
-n::
31+
--dry-run::
3132
Don't actually remove any objects, only show those that would have been
3233
removed.
3334

3435
-q::
36+
--quiet::
3537
Squelch the progress indicator.
3638

3739
Author

Documentation/git-verify-pack.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-verify-pack - Validate packed git archive files
88

99
SYNOPSIS
1010
--------
11-
'git verify-pack' [-v] [--] <pack>.idx ...
11+
'git verify-pack' [-v|--verbose] [--] <pack>.idx ...
1212

1313

1414
DESCRIPTION
@@ -23,6 +23,7 @@ OPTIONS
2323
The idx files to verify.
2424

2525
-v::
26+
--verbose::
2627
After verifying the pack, show list of objects contained
2728
in the pack.
2829
\--::

builtin-prune-packed.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "builtin.h"
22
#include "cache.h"
33
#include "progress.h"
4+
#include "parse-options.h"
45

5-
static const char prune_packed_usage[] =
6-
"git prune-packed [-n] [-q]";
6+
static const char * const prune_packed_usage[] = {
7+
"git prune-packed [-n|--dry-run] [-q|--quiet]",
8+
NULL
9+
};
710

811
#define DRY_RUN 01
912
#define VERBOSE 02
@@ -68,24 +71,16 @@ void prune_packed_objects(int opts)
6871

6972
int cmd_prune_packed(int argc, const char **argv, const char *prefix)
7073
{
71-
int i;
7274
int opts = VERBOSE;
75+
const struct option prune_packed_options[] = {
76+
OPT_BIT('n', "dry-run", &opts, "dry run", DRY_RUN),
77+
OPT_NEGBIT('q', "quiet", &opts, "be quiet", VERBOSE),
78+
OPT_END()
79+
};
7380

74-
for (i = 1; i < argc; i++) {
75-
const char *arg = argv[i];
81+
argc = parse_options(argc, argv, prefix, prune_packed_options,
82+
prune_packed_usage, 0);
7683

77-
if (*arg == '-') {
78-
if (!strcmp(arg, "-n"))
79-
opts |= DRY_RUN;
80-
else if (!strcmp(arg, "-q"))
81-
opts &= ~VERBOSE;
82-
else
83-
usage(prune_packed_usage);
84-
continue;
85-
}
86-
/* Handle arguments here .. */
87-
usage(prune_packed_usage);
88-
}
8984
prune_packed_objects(opts);
9085
return 0;
9186
}

builtin-verify-pack.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "cache.h"
33
#include "pack.h"
44
#include "pack-revindex.h"
5+
#include "parse-options.h"
56

67
#define MAX_CHAIN 50
78

@@ -107,36 +108,31 @@ static int verify_one_pack(const char *path, int verbose)
107108
return err;
108109
}
109110

110-
static const char verify_pack_usage[] = "git verify-pack [-v] <pack>...";
111+
static const char * const verify_pack_usage[] = {
112+
"git verify-pack [-v|--verbose] <pack>...",
113+
NULL
114+
};
111115

112116
int cmd_verify_pack(int argc, const char **argv, const char *prefix)
113117
{
114118
int err = 0;
115119
int verbose = 0;
116-
int no_more_options = 0;
117-
int nothing_done = 1;
120+
int i;
121+
const struct option verify_pack_options[] = {
122+
OPT__VERBOSE(&verbose),
123+
OPT_END()
124+
};
118125

119126
git_config(git_default_config, NULL);
120-
while (1 < argc) {
121-
if (!no_more_options && argv[1][0] == '-') {
122-
if (!strcmp("-v", argv[1]))
123-
verbose = 1;
124-
else if (!strcmp("--", argv[1]))
125-
no_more_options = 1;
126-
else
127-
usage(verify_pack_usage);
128-
}
129-
else {
130-
if (verify_one_pack(argv[1], verbose))
131-
err = 1;
132-
discard_revindex();
133-
nothing_done = 0;
134-
}
135-
argc--; argv++;
127+
argc = parse_options(argc, argv, prefix, verify_pack_options,
128+
verify_pack_usage, 0);
129+
if (argc < 1)
130+
usage_with_options(verify_pack_usage, verify_pack_options);
131+
for (i = 0; i < argc; i++) {
132+
if (verify_one_pack(argv[i], verbose))
133+
err = 1;
134+
discard_revindex();
136135
}
137136

138-
if (nothing_done)
139-
usage(verify_pack_usage);
140-
141137
return err;
142138
}

builtin-verify-tag.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
#include "tag.h"
1111
#include "run-command.h"
1212
#include <signal.h>
13+
#include "parse-options.h"
1314

14-
static const char builtin_verify_tag_usage[] =
15-
"git verify-tag [-v|--verbose] <tag>...";
15+
static const char * const verify_tag_usage[] = {
16+
"git verify-tag [-v|--verbose] <tag>...",
17+
NULL
18+
};
1619

1720
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
1821

@@ -89,17 +92,17 @@ static int verify_tag(const char *name, int verbose)
8992
int cmd_verify_tag(int argc, const char **argv, const char *prefix)
9093
{
9194
int i = 1, verbose = 0, had_error = 0;
95+
const struct option verify_tag_options[] = {
96+
OPT__VERBOSE(&verbose),
97+
OPT_END()
98+
};
9299

93100
git_config(git_default_config, NULL);
94101

95-
if (argc > 1 &&
96-
(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose"))) {
97-
verbose = 1;
98-
i++;
99-
}
100-
102+
argc = parse_options(argc, argv, prefix, verify_tag_options,
103+
verify_tag_usage, PARSE_OPT_KEEP_ARGV0);
101104
if (argc <= i)
102-
usage(builtin_verify_tag_usage);
105+
usage_with_options(verify_tag_usage, verify_tag_options);
103106

104107
/* sometimes the program was terminated because this signal
105108
* was received in the process of writing the gpg input: */

builtin-write-tree.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,35 @@
77
#include "cache.h"
88
#include "tree.h"
99
#include "cache-tree.h"
10+
#include "parse-options.h"
1011

11-
static const char write_tree_usage[] =
12-
"git write-tree [--missing-ok] [--prefix=<prefix>/]";
12+
static const char * const write_tree_usage[] = {
13+
"git write-tree [--missing-ok] [--prefix=<prefix>/]",
14+
NULL
15+
};
1316

1417
int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
1518
{
1619
int flags = 0, ret;
1720
const char *prefix = NULL;
1821
unsigned char sha1[20];
1922
const char *me = "git-write-tree";
23+
struct option write_tree_options[] = {
24+
OPT_BIT(0, "missing-ok", &flags, "allow missing objects",
25+
WRITE_TREE_MISSING_OK),
26+
{ OPTION_STRING, 0, "prefix", &prefix, "<prefix>/",
27+
"write tree object for a subdirectory <prefix>" ,
28+
PARSE_OPT_LITERAL_ARGHELP },
29+
{ OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
30+
"only useful for debugging",
31+
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
32+
WRITE_TREE_IGNORE_CACHE_TREE },
33+
OPT_END()
34+
};
2035

2136
git_config(git_default_config, NULL);
22-
while (1 < argc) {
23-
const char *arg = argv[1];
24-
if (!strcmp(arg, "--missing-ok"))
25-
flags |= WRITE_TREE_MISSING_OK;
26-
else if (!prefixcmp(arg, "--prefix="))
27-
prefix = arg + 9;
28-
else if (!prefixcmp(arg, "--ignore-cache-tree"))
29-
/*
30-
* This is only useful for debugging, so I
31-
* do not bother documenting it.
32-
*/
33-
flags |= WRITE_TREE_IGNORE_CACHE_TREE;
34-
else
35-
usage(write_tree_usage);
36-
argc--; argv++;
37-
}
38-
39-
if (argc > 2)
40-
die("too many options");
37+
argc = parse_options(argc, argv, unused_prefix, write_tree_options,
38+
write_tree_usage, 0);
4139

4240
ret = write_cache_as_tree(sha1, flags, prefix);
4341
switch (ret) {

0 commit comments

Comments
 (0)