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 <christian.couder@gmail.com> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karthik Nayak committed
Jul 7, 2015 at 21:36 UTC
f266c9163b34ec55e453d27e1ed246d67ee3ced0
3 files changed
+11
-24
builtin/branch.c
+2
-12
@@ -828,18 +828,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
828
OPT__COLOR(&branch_use_color, N_("use colored output")),
829
OPT_SET_INT('r', "remotes", &kinds, N_("act on remote-tracking branches"),
830
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")),
833
OPT__ABBREV(&abbrev),
834
835
OPT_GROUP(N_("Specific git-branch actions:")),
builtin/tag.c
+2
-12
@@ -595,22 +595,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
595
596
OPT_GROUP(N_("Tag listing options")),
597
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")),
600
{
601
OPTION_CALLBACK, 0, "sort", &tag_sort, N_("type"), N_("sort tags"),
602
PARSE_OPT_NONEG, parse_opt_sort
603
},
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
- },
604
{
605
OPTION_CALLBACK, 0, "points-at", &points_at, N_("object"),
606
N_("print only tags of the object"), 0, parse_opt_object_name
parse-options.h
+7
@@ -243,5 +243,12 @@ extern int parse_opt_noop_cb(const struct option *, const char *, int);
243
OPT_COLOR_FLAG(0, "color", (var), (h))
244
#define OPT_COLUMN(s, l, v, h) \
245
{ 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)
253
254
#endif