[PATCH 09/19] rev-parseopt: convert --glob

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 revision.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/revision.c b/revision.c
index bcfca8856f..013b8ec19f 100644
--- a/revision.c
+++ b/revision.c
@@ -30,6 +30,9 @@
 #include "prio-queue.h"
 #include "hashmap.h"
 
+#define OPT_REV(s, l, a, h, cb)		 \
+	OPT_CALLBACK_F(s, l, revs, a, h, PARSE_OPT_NONEG, cb)
+
 #define OPT_REV_NOARG(s, l, h, cb) \
 	OPT_CALLBACK_F(s, l, revs, NULL, h, \
 		       PARSE_OPT_NONEG | PARSE_OPT_NOARG, cb)
@@ -2425,6 +2428,20 @@ static int rev_opt_branches(const struct option *opt,
 	return 0;
 }
 
+static int rev_opt_glob(const struct option *opt,
+			const char *arg, int unset)
+{
+	struct rev_info	*revs  = opt->value;
+	int flags = *revs->pseudo_flags;
+	struct all_refs_cb cb;
+
+	BUG_ON_OPT_NEG(unset);
+	init_all_refs_cb(&cb, revs, flags);
+	for_each_glob_ref(handle_one_ref, arg, &cb);
+	clear_ref_exclusion(&revs->ref_excludes);
+	return 0;
+}
+
 static int rev_opt_remotes(const struct option *opt,
 			   const char *arg, int unset)
 {
@@ -2495,6 +2512,9 @@ static void make_pseudo_options(struct rev_info *revs)
 		OPT_REV_OPTARG(0, "remotes", N_("<pattern>"),
 			       N_("include all refs in refs/remotes (optionally matches pattern)"),
 			       rev_opt_remotes),
+		OPT_REV(0, "glob", N_("<pattern>"),
+			N_("include all refs matching shell glob"),
+			rev_opt_glob),
 		OPT_END()
 	};
 	ALLOC_ARRAY(revs->pseudo_options, ARRAY_SIZE(options));
@@ -2535,13 +2555,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
 	if (argc)
 		return argc;
 
-	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);
-		clear_ref_exclusion(&revs->ref_excludes);
-		return argcount;
-	} else if ((argcount = parse_long_opt("exclude", argv, &optarg))) {
+	if ((argcount = parse_long_opt("exclude", argv, &optarg))) {
 		add_ref_exclusion(&revs->ref_excludes, optarg);
 		return argcount;
 	} else if (!strcmp(arg, "--reflog")) {
-- 
2.21.0.1141.gd54ac2cb17




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux