ref-filter: add parse_opt_merge_filter()

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>
This commit is contained in:
Karthik Nayak
2015-07-07 21:36:11 +05:30
committed by Junio C Hamano
parent d325406ef2
commit 5afcb90560
3 changed files with 34 additions and 0 deletions

View 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;
}