]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ref-filter: add parse_opt_merge_filter()
authorKarthik Nayak <karthik.188@gmail.com>
Tue, 7 Jul 2015 16:06:11 +0000 (21:36 +0530)
committerJunio C Hamano <gitster@pobox.com>
Mon, 3 Aug 2015 17:25:28 +0000 (10:25 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c
ref-filter.c
ref-filter.h

index b42e5b6dbc76016ca18e5ddd7ded2af613013eb7..ddd90e6b1c7bf172f4db5131f7c59495b93a5dab 100644 (file)
@@ -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')
index 2efe30a67e6d4e3c674cbb94dc9141696ae010dc..4fe5a7a1f2706a317a70582fd49a98d1d29b6506 100644 (file)
@@ -1134,3 +1134,22 @@ 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 (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;
+}
index c2856b829570a58789629928c8cca5fd8dd9482f..443cfa7179290c821ee75820a9715047b8057906 100644 (file)
@@ -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  */