From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: christian.couder@gmail.com, Matthieu.Moy@grenoble-inp.fr,
Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH v4 05/19] ref-filter: add parse_opt_merge_filter()
Date: Mon, 22 Jun 2015 02:18:19 +0530 [thread overview]
Message-ID: <1434919705-4884-5-git-send-email-karthik.188@gmail.com> (raw)
In-Reply-To: <1434919705-4884-1-git-send-email-karthik.188@gmail.com>
Add 'parse_opt_merge_filter()' to parse '--merged' and '--no-merged'
options and write MACROS for the same.
This is copied from 'builtin/branch.c' which will eventually be removed
when we port 'branch.c' to use ref-filter APIs.
Based-on-patch-by: Jeff King <peff@peff.net>
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>
---
builtin/branch.c | 4 ++++
ref-filter.c | 21 +++++++++++++++++++++
ref-filter.h | 11 +++++++++++
3 files changed, 36 insertions(+)
diff --git a/builtin/branch.c b/builtin/branch.c
index b42e5b6..ddd90e6 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -745,6 +745,10 @@ static void rename_branch(const char *oldname, const char *newname, int force)
strbuf_release(&newsection);
}
+/*
+ * This function is duplicated in ref-filter. It will eventually be removed
+ * when we port branch.c to use ref-filter APIs.
+ */
static int opt_parse_merge_filter(const struct option *opt, const char *arg, int unset)
{
merge_filter = ((opt->long_name[0] == 'n')
diff --git a/ref-filter.c b/ref-filter.c
index 591e281..6502179 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1125,3 +1125,24 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
s->atom = parse_ref_filter_atom(arg, arg+len);
return 0;
}
+
+int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
+{
+ struct ref_filter *rf = opt->value;
+ unsigned char sha1[20];
+
+ rf->merge = starts_with(opt->long_name, "no")
+ ? REF_FILTER_MERGED_OMIT
+ : REF_FILTER_MERGED_INCLUDE;
+
+ if (!arg)
+ arg = "HEAD";
+ if (get_sha1(arg, sha1))
+ die(_("malformed object name %s"), arg);
+
+ rf->merge_commit = lookup_commit_reference_gently(sha1, 0);
+ if (!rf->merge_commit)
+ return opterror(opt, "must point to a commit", 0);
+
+ return 0;
+}
diff --git a/ref-filter.h b/ref-filter.h
index c2856b8..ad2902b 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -50,6 +50,15 @@ struct ref_filter_cbdata {
struct ref_filter *filter;
};
+/* Macros for checking --merged and --no-merged options */
+#define _OPT_MERGED_NO_MERGED(option, filter, h) \
+ { OPTION_CALLBACK, 0, option, (filter), N_("commit"), (h), \
+ PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, \
+ parse_opt_merge_filter, (intptr_t) "HEAD" \
+ }
+#define OPT_MERGED(f, h) _OPT_MERGED_NO_MERGED("merged", f, h)
+#define OPT_NO_MERGED(f, h) _OPT_MERGED_NO_MERGED("no-merged", f, h)
+
/*
* API for filtering a set of refs. Based on the type of refs the user
* has requested, we iterate through those refs and apply filters
@@ -71,5 +80,7 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
/* Default sort option based on refname */
struct ref_sorting *ref_default_sorting(void);
+/* Function to parse --merged and --no-merged options */
+int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
#endif /* REF_FILTER_H */
--
2.4.3.439.gfea0c2a.dirty
next prev parent reply other threads:[~2015-06-21 20:48 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-21 20:45 [PATCH v4 00/11] add options to for-each-ref Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 01/19] t6301: for-each-ref tests for ref-filter APIs Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 02/19] tag: libify parse_opt_points_at() Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 03/19] ref-filter: implement '--points-at' option Karthik Nayak
2015-06-22 22:36 ` Eric Sunshine
2015-06-23 10:49 ` Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 04/19] for-each-ref: add " Karthik Nayak
2015-06-22 0:45 ` Junio C Hamano
2015-06-22 19:03 ` Karthik Nayak
2015-06-22 19:21 ` Matthieu Moy
2015-06-22 19:24 ` Junio C Hamano
2015-06-22 19:27 ` Karthik Nayak
2015-06-22 19:51 ` Junio C Hamano
2015-06-22 22:38 ` Eric Sunshine
2015-06-23 10:52 ` Karthik Nayak
2015-06-21 20:48 ` Karthik Nayak [this message]
2015-06-22 0:55 ` [PATCH v4 05/19] ref-filter: add parse_opt_merge_filter() Junio C Hamano
2015-06-22 11:13 ` Matthieu Moy
2015-06-22 16:15 ` Junio C Hamano
2015-06-22 19:00 ` Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 06/19] ref-filter: implement '--merged' and '--no-merged' options Karthik Nayak
2015-06-22 1:00 ` Junio C Hamano
2015-06-22 15:11 ` Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 07/19] for-each-ref: add " Karthik Nayak
2015-06-22 22:41 ` Eric Sunshine
2015-06-23 11:05 ` Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 08/19] parse-option: rename parse_opt_with_commit() Karthik Nayak
2015-06-22 1:04 ` Junio C Hamano
2015-06-22 15:38 ` Karthik Nayak
2015-06-22 16:27 ` Junio C Hamano
2015-06-22 16:37 ` Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 09/19] parse-options.h: add macros for '--contains' option Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 10/19] ref-filter: implement " Karthik Nayak
2015-06-21 20:48 ` [PATCH v4 11/19] for-each-ref: add " Karthik Nayak
2015-06-21 20:51 ` [PATCH v4 00/11] add options to for-each-ref Karthik Nayak
2015-06-22 0:41 ` Junio C Hamano
2015-06-22 14:48 ` Karthik Nayak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1434919705-4884-5-git-send-email-karthik.188@gmail.com \
--to=karthik.188@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).