Re: [RFC/PATCH 7/9] parse-options.h: add macros for '--contains' option

2015-06-09 Thread Karthik Nayak

On 06/09/2015 01:02 AM, Junio C Hamano wrote:

Karthik Nayak  writes:


+#define OPT_CONTAINS(filter, h) \
+   { OPTION_CALLBACK, 0, "contains", (filter), N_("commit"), (h), \
+ PARSE_OPT_LASTARG_DEFAULT, \
+ parse_opt_with_commit, (intptr_t) "HEAD" \
+   }
+#define OPT_WITH(filter, h) \
+   { OPTION_CALLBACK, 0, "with", (filter), N_("commit"), (h), \
+ PARSE_OPT_LASTARG_DEFAULT, \
+ parse_opt_with_commit, (intptr_t) "HEAD" \
+   }


The redundancy bothers me.  Can't we do a bit better than that,
perhaps like this?

#define _OPT_CONTAINS_OR_WITH(name, variable, help) \
{ OPTION_CALLBACK, 0, name, (variable), N_("commit"), (help), \
  PARSE_OPT_LASTARG_DEFAULT, \
  parse_opt_with_commit, (intptr_t) "HEAD" \
}
#define OPT_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("contains", v, h)



This seems better, thanks!

--
Regards,
Karthik
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 7/9] parse-options.h: add macros for '--contains' option

2015-06-08 Thread Junio C Hamano
Karthik Nayak  writes:

> +#define OPT_CONTAINS(filter, h) \
> + { OPTION_CALLBACK, 0, "contains", (filter), N_("commit"), (h), \
> +   PARSE_OPT_LASTARG_DEFAULT, \
> +   parse_opt_with_commit, (intptr_t) "HEAD" \
> + }
> +#define OPT_WITH(filter, h) \
> + { OPTION_CALLBACK, 0, "with", (filter), N_("commit"), (h), \
> +   PARSE_OPT_LASTARG_DEFAULT, \
> +   parse_opt_with_commit, (intptr_t) "HEAD" \
> + }

The redundancy bothers me.  Can't we do a bit better than that,
perhaps like this?

#define _OPT_CONTAINS_OR_WITH(name, variable, help) \
{ OPTION_CALLBACK, 0, name, (variable), N_("commit"), (help), \
  PARSE_OPT_LASTARG_DEFAULT, \
  parse_opt_with_commit, (intptr_t) "HEAD" \
}
#define OPT_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("contains", v, h)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC/PATCH 7/9] parse-options.h: add macros for '--contains' option

2015-06-06 Thread Karthik Nayak
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 use this new macro

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 builtin/tag.c   | 14 ++
 parse-options.h | 10 ++
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index eda76ba..e16668b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -591,23 +591,13 @@ int cmd_tag(int argc, const char **argv, const char 
*prefix)
 
OPT_GROUP(N_("Tag listing options")),
OPT_COLUMN(0, "column", &colopts, N_("show tag list in 
columns")),
+   OPT_CONTAINS(&with_commit, N_("print only tags that contain the 
commit")),
+   OPT_WITH(&with_commit, N_("print only tags that contain the 
commit")),
{
OPTION_CALLBACK, 0, "sort", &tag_sort, N_("type"), 
N_("sort tags"),
PARSE_OPT_NONEG, parse_opt_sort
},
{
-   OPTION_CALLBACK, 0, "contains", &with_commit, 
N_("commit"),
-   N_("print only tags that contain the commit"),
-   PARSE_OPT_LASTARG_DEFAULT,
-   parse_opt_with_commit, (intptr_t)"HEAD",
-   },
-   {
-   OPTION_CALLBACK, 0, "with", &with_commit, N_("commit"),
-   N_("print only tags that contain the commit"),
-   PARSE_OPT_HIDDEN | PARSE_OPT_LASTARG_DEFAULT,
-   parse_opt_with_commit, (intptr_t)"HEAD",
-   },
-   {
OPTION_CALLBACK, 0, "points-at", &points_at, 
N_("object"),
N_("print only tags of the object"), 0, 
parse_opt_points_at
},
diff --git a/parse-options.h b/parse-options.h
index 7bcf0f3..d8389ad 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -254,5 +254,15 @@ extern int parse_opt_noop_cb(const struct option *, const 
char *, int);
  PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
  parse_opt_merge_filter, (intptr_t) "HEAD" \
}
+#define OPT_CONTAINS(filter, h) \
+   { OPTION_CALLBACK, 0, "contains", (filter), N_("commit"), (h), \
+ PARSE_OPT_LASTARG_DEFAULT, \
+ parse_opt_with_commit, (intptr_t) "HEAD" \
+   }
+#define OPT_WITH(filter, h) \
+   { OPTION_CALLBACK, 0, "with", (filter), N_("commit"), (h), \
+ PARSE_OPT_LASTARG_DEFAULT, \
+ parse_opt_with_commit, (intptr_t) "HEAD" \
+   }
 
 #endif
-- 
2.4.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html