From mboxrd@z Thu Jan 1 00:00:00 1970 From: Karthik Nayak Subject: [PATCH v7 09/11] parse-options.h: add macros for '--contains' option Date: Thu, 2 Jul 2015 20:51:08 +0530 Message-ID: <1435850470-5175-9-git-send-email-karthik.188@gmail.com> References: <1435850470-5175-1-git-send-email-karthik.188@gmail.com> Cc: christian.couder@gmail.com, Matthieu.Moy@grenoble-inp.fr, Karthik Nayak To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Thu Jul 02 17:22:18 2015 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZAgJd-0000NW-0f for gcvg-git-2@plane.gmane.org; Thu, 02 Jul 2015 17:22:17 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753433AbbGBPWO (ORCPT ); Thu, 2 Jul 2015 11:22:14 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:36207 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751179AbbGBPWL (ORCPT ); Thu, 2 Jul 2015 11:22:11 -0400 Received: by paceq1 with SMTP id eq1so41989789pac.3 for ; Thu, 02 Jul 2015 08:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9uHqoHSbZvcVboJeOFFk7cdVl3KjIkypnaGjKay/vHY=; b=YYvlvogrV9FrGu7+fA37BKw5sfbSN8zKXwXotDqBtpmgkLvR0U4x4dmzhrci0ocPKN SywPW2Xf3OqPihZCzaXveX6cmwRc1TuIekF8dOlQgydz1AVcYVLYjCjkj4GS/U2P1mcQ kVu33pOaUE4RXH0U5UTOeG3gXBmuray9ae21KOWxxNoc6PTQ0ZsoWwjwdT609/NvnF2p t/kMZF7F1wIsOyS2yXrdku2ouFXXPeFZKHhKHbbPAGT5Hsewd1PO9mYUooOicHWzfJYP yeT7KR2Fn4whgaz7s49yPOVhOYXVgO1W+pPf9MXqMVWOpfNrrQPS3mtcMt+5tqB38o4u cPJg== X-Received: by 10.68.235.38 with SMTP id uj6mr67464651pbc.57.1435850530014; Thu, 02 Jul 2015 08:22:10 -0700 (PDT) Received: from ashley.localdomain ([106.51.130.23]) by mx.google.com with ESMTPSA id fu2sm635208pdb.32.2015.07.02.08.22.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Jul 2015 08:22:08 -0700 (PDT) X-Mailer: git-send-email 2.4.4 In-Reply-To: <1435850470-5175-1-git-send-email-karthik.188@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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 Mentored-by: Matthieu Moy Signed-off-by: Karthik Nayak --- builtin/branch.c | 14 ++------------ builtin/tag.c | 14 ++------------ parse-options.h | 7 +++++++ 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index ae9a0eb..c443cd8 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -828,18 +828,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix) OPT__COLOR(&branch_use_color, N_("use colored output")), OPT_SET_INT('r', "remotes", &kinds, N_("act on remote-tracking branches"), REF_REMOTE_BRANCH), - { - OPTION_CALLBACK, 0, "contains", &with_commit, N_("commit"), - N_("print only branches that contain the commit"), - PARSE_OPT_LASTARG_DEFAULT, - parse_opt_commits, (intptr_t)"HEAD", - }, - { - OPTION_CALLBACK, 0, "with", &with_commit, N_("commit"), - N_("print only branches that contain the commit"), - PARSE_OPT_HIDDEN | PARSE_OPT_LASTARG_DEFAULT, - parse_opt_commits, (intptr_t) "HEAD", - }, + OPT_CONTAINS(&with_commit, N_("print only branches that contain the commit")), + OPT_WITH(&with_commit, N_("print only branches that contain the commit")), OPT__ABBREV(&abbrev), OPT_GROUP(N_("Specific git-branch actions:")), diff --git a/builtin/tag.c b/builtin/tag.c index 7af45a0..767162e 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -595,23 +595,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_commits, (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_commits, (intptr_t)"HEAD", - }, - { OPTION_CALLBACK, 0, "points-at", &points_at, N_("object"), N_("print only tags of the object"), 0, parse_opt_object_name }, diff --git a/parse-options.h b/parse-options.h index 583690c..6aeec6a 100644 --- a/parse-options.h +++ b/parse-options.h @@ -246,5 +246,12 @@ extern int parse_opt_noop_cb(const struct option *, const char *, int); OPT_COLOR_FLAG(0, "color", (var), (h)) #define OPT_COLUMN(s, l, v, h) \ { OPTION_CALLBACK, (s), (l), (v), N_("style"), (h), PARSE_OPT_OPTARG, parseopt_column_callback } +#define _OPT_CONTAINS_OR_WITH(name, variable, help, flag) \ + { OPTION_CALLBACK, 0, name, (variable), N_("commit"), (help), \ + PARSE_OPT_LASTARG_DEFAULT | flag, \ + parse_opt_commits, (intptr_t) "HEAD" \ + } +#define OPT_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("contains", v, h, 0) +#define OPT_WITH(v, h) _OPT_CONTAINS_OR_WITH("with", v, h, PARSE_OPT_HIDDEN) #endif -- 2.4.4