Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- revision.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/revision.c b/revision.c index 5183cdf66d..bcfca8856f 100644 --- a/revision.c +++ b/revision.c @@ -2425,6 +2425,27 @@ static int rev_opt_branches(const struct option *opt, return 0; } +static int rev_opt_remotes(const struct option *opt, + const char *arg, int unset) +{ + struct rev_info *revs = opt->value; + int flags = *revs->pseudo_flags; + struct ref_store *refs = revs->pseudo_refs; + + BUG_ON_OPT_NEG(unset); + if (arg) { + struct all_refs_cb cb; + + init_all_refs_cb(&cb, revs, flags); + for_each_glob_ref_in(handle_one_ref, arg, "refs/remotes/", &cb); + clear_ref_exclusion(&revs->ref_excludes); + } else { + handle_refs(refs, revs, flags, refs_for_each_remote_ref); + clear_ref_exclusion(&revs->ref_excludes); + } + return 0; +} + static int rev_opt_tags(const struct option *opt, const char *arg, int unset) { @@ -2471,6 +2492,9 @@ static void make_pseudo_options(struct rev_info *revs) OPT_REV_OPTARG(0, "tags", N_("<pattern>"), N_("include all refs in refs/tags (optionally matches pattern)"), rev_opt_tags), + OPT_REV_OPTARG(0, "remotes", N_("<pattern>"), + N_("include all refs in refs/remotes (optionally matches pattern)"), + rev_opt_remotes), OPT_END() }; ALLOC_ARRAY(revs->pseudo_options, ARRAY_SIZE(options)); @@ -2511,10 +2535,7 @@ static int handle_revision_pseudo_opt(const char *submodule, if (argc) return argc; - if (!strcmp(arg, "--remotes")) { - handle_refs(refs, revs, *flags, refs_for_each_remote_ref); - clear_ref_exclusion(&revs->ref_excludes); - } else if ((argcount = parse_long_opt("glob", argv, &optarg))) { + if ((argcount = parse_long_opt("glob", argv, &optarg))) { struct all_refs_cb cb; init_all_refs_cb(&cb, revs, *flags); for_each_glob_ref(handle_one_ref, optarg, &cb); @@ -2523,11 +2544,6 @@ static int handle_revision_pseudo_opt(const char *submodule, } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) { add_ref_exclusion(&revs->ref_excludes, optarg); return argcount; - } else if (skip_prefix(arg, "--remotes=", &optarg)) { - struct all_refs_cb cb; - init_all_refs_cb(&cb, revs, *flags); - for_each_glob_ref_in(handle_one_ref, optarg, "refs/remotes/", &cb); - clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--reflog")) { add_reflogs_to_pending(revs, *flags); } else if (!strcmp(arg, "--indexed-objects")) { -- 2.21.0.1141.gd54ac2cb17