Skip to content

Commit f266c91

Browse files
KarthikNayakgitster
authored andcommitted
parse-options.h: add macros for '--contains' option
Add a macro for using the '--contains' option in parse-options.h also include an optional '--with' option macro which performs the same action as '--contains'. Make tag.c and branch.c use this new macro. Mentored-by: Christian Couder <[email protected]> Mentored-by: Matthieu Moy <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9d306b5 commit f266c91

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

builtin/branch.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -828,18 +828,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
828828
OPT__COLOR(&branch_use_color, N_("use colored output")),
829829
OPT_SET_INT('r', "remotes", &kinds, N_("act on remote-tracking branches"),
830830
REF_REMOTE_BRANCH),
831-
{
832-
OPTION_CALLBACK, 0, "contains", &with_commit, N_("commit"),
833-
N_("print only branches that contain the commit"),
834-
PARSE_OPT_LASTARG_DEFAULT,
835-
parse_opt_commits, (intptr_t)"HEAD",
836-
},
837-
{
838-
OPTION_CALLBACK, 0, "with", &with_commit, N_("commit"),
839-
N_("print only branches that contain the commit"),
840-
PARSE_OPT_HIDDEN | PARSE_OPT_LASTARG_DEFAULT,
841-
parse_opt_commits, (intptr_t) "HEAD",
842-
},
831+
OPT_CONTAINS(&with_commit, N_("print only branches that contain the commit")),
832+
OPT_WITH(&with_commit, N_("print only branches that contain the commit")),
843833
OPT__ABBREV(&abbrev),
844834

845835
OPT_GROUP(N_("Specific git-branch actions:")),

builtin/tag.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -595,22 +595,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
595595

596596
OPT_GROUP(N_("Tag listing options")),
597597
OPT_COLUMN(0, "column", &colopts, N_("show tag list in columns")),
598+
OPT_CONTAINS(&with_commit, N_("print only tags that contain the commit")),
599+
OPT_WITH(&with_commit, N_("print only tags that contain the commit")),
598600
{
599601
OPTION_CALLBACK, 0, "sort", &tag_sort, N_("type"), N_("sort tags"),
600602
PARSE_OPT_NONEG, parse_opt_sort
601603
},
602-
{
603-
OPTION_CALLBACK, 0, "contains", &with_commit, N_("commit"),
604-
N_("print only tags that contain the commit"),
605-
PARSE_OPT_LASTARG_DEFAULT,
606-
parse_opt_commits, (intptr_t)"HEAD",
607-
},
608-
{
609-
OPTION_CALLBACK, 0, "with", &with_commit, N_("commit"),
610-
N_("print only tags that contain the commit"),
611-
PARSE_OPT_HIDDEN | PARSE_OPT_LASTARG_DEFAULT,
612-
parse_opt_commits, (intptr_t)"HEAD",
613-
},
614604
{
615605
OPTION_CALLBACK, 0, "points-at", &points_at, N_("object"),
616606
N_("print only tags of the object"), 0, parse_opt_object_name

parse-options.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,12 @@ extern int parse_opt_noop_cb(const struct option *, const char *, int);
243243
OPT_COLOR_FLAG(0, "color", (var), (h))
244244
#define OPT_COLUMN(s, l, v, h) \
245245
{ OPTION_CALLBACK, (s), (l), (v), N_("style"), (h), PARSE_OPT_OPTARG, parseopt_column_callback }
246+
#define _OPT_CONTAINS_OR_WITH(name, variable, help, flag) \
247+
{ OPTION_CALLBACK, 0, name, (variable), N_("commit"), (help), \
248+
PARSE_OPT_LASTARG_DEFAULT | flag, \
249+
parse_opt_commits, (intptr_t) "HEAD" \
250+
}
251+
#define OPT_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("contains", v, h, 0)
252+
#define OPT_WITH(v, h) _OPT_CONTAINS_OR_WITH("with", v, h, PARSE_OPT_HIDDEN)
246253

247254
#endif

0 commit comments

Comments
 (0)