Skip to content

Commit 3f390a3

Browse files
avargitster
authored andcommitted
mktag: convert to parse-options
Convert the "mktag" command to use parse-options.h instead of its own ad-hoc argc handling. This doesn't matter much in practice since it doesn't support any options, but removes another special-case in our codebase, and makes it easier to add options to it in the future. It does marginally improve the situation for programs that want to execute git commands in a consistent manner and e.g. always use --end-of-options. E.g. "gitaly" does that, and has a blacklist of built-ins that don't support --end-of-options. This is one less special case for it and other similar programs to support. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a1a3a4 commit 3f390a3

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

builtin/mktag.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#include "builtin.h"
2+
#include "parse-options.h"
23
#include "tag.h"
34
#include "replace-object.h"
45
#include "object-store.h"
56
#include "fsck.h"
67
#include "config.h"
78

9+
static char const * const builtin_mktag_usage[] = {
10+
N_("git mktag"),
11+
NULL
12+
};
13+
814
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
915

1016
static int mktag_config(const char *var, const char *value, void *cb)
@@ -60,13 +66,17 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
6066

6167
int cmd_mktag(int argc, const char **argv, const char *prefix)
6268
{
69+
static struct option builtin_mktag_options[] = {
70+
OPT_END(),
71+
};
6372
struct strbuf buf = STRBUF_INIT;
6473
struct object_id tagged_oid;
6574
int tagged_type;
6675
struct object_id result;
6776

68-
if (argc != 1)
69-
usage("git mktag");
77+
argc = parse_options(argc, argv, NULL,
78+
builtin_mktag_options,
79+
builtin_mktag_usage, 0);
7080

7181
if (strbuf_read(&buf, 0, 0) < 0)
7282
die_errno("could not read from stdin");

t/t3800-mktag.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ test_expect_success 'setup' '
4545
blob=$(git rev-parse --verify HEAD:B.t)
4646
'
4747

48+
test_expect_success 'basic usage' '
49+
cat >tag.sig <<-EOF &&
50+
object $head
51+
type commit
52+
tag mytag
53+
tagger T A Gger <[email protected]> 1206478233 -0500
54+
EOF
55+
git mktag <tag.sig &&
56+
git mktag --end-of-options <tag.sig &&
57+
test_expect_code 129 git mktag --unknown-option
58+
'
59+
4860
############################################################
4961
# 1. length check
5062

0 commit comments

Comments
 (0)