diff mbox series

[03/19] revision.c: prepare to convert handle_revision_pseudo_opt()

Message ID 20190508111249.15262-4-pclouds@gmail.com (mailing list archive)
State New, archived
Headers show
Series Convert revision.c to parseopt part 1/4 | expand

Commit Message

Duy Nguyen May 8, 2019, 11:12 a.m. UTC
This patch is essentially no-op. It allows to parse_options() to handle
some options. But the new option list remains empty. The option will be
moved one by one from the old manual parsing code to this list.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 revision.c | 44 ++++++++++++++++++++++++++++++++++----------
 revision.h |  2 ++
 2 files changed, 36 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/revision.c b/revision.c
index d4aaf0ef25..65d40c9255 100644
--- a/revision.c
+++ b/revision.c
@@ -26,6 +26,7 @@ 
 #include "argv-array.h"
 #include "commit-reach.h"
 #include "commit-graph.h"
+#include "parse-options.h"
 #include "prio-queue.h"
 #include "hashmap.h"
 
@@ -1598,6 +1599,8 @@  static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
 	return 1;
 }
 
+static void make_pseudo_options(struct rev_info *revs);
+
 void repo_init_revisions(struct repository *r,
 			 struct rev_info *revs,
 			 const char *prefix)
@@ -1638,6 +1641,7 @@  void repo_init_revisions(struct repository *r,
 	}
 
 	revs->notes_opt.use_default_notes = -1;
+	make_pseudo_options(revs);
 }
 
 static void add_pending_commit_list(struct rev_info *revs,
@@ -2355,6 +2359,25 @@  static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void
 	return for_each_bisect_ref(refs, fn, cb_data, term_good);
 }
 
+static void make_pseudo_options(struct rev_info *revs)
+{
+	/*
+	 * NOTE!
+	 *
+	 * Commands like "git shortlog" will not accept the options below
+	 * unless parse_revision_opt queues them (as opposed to erroring
+	 * out).
+	 *
+	 * When implementing your new pseudo-option, remember to
+	 * register it in the list at the top of handle_revision_opt.
+	 */
+	struct option options[] = {
+		OPT_END()
+	};
+	ALLOC_ARRAY(revs->pseudo_options, ARRAY_SIZE(options));
+	memcpy(revs->pseudo_options, options, sizeof(options));
+}
+
 static int handle_revision_pseudo_opt(const char *submodule,
 				struct rev_info *revs,
 				int argc, const char **argv, int *flags)
@@ -2377,16 +2400,16 @@  static int handle_revision_pseudo_opt(const char *submodule,
 	} else
 		refs = get_main_ref_store(revs->repo);
 
-	/*
-	 * NOTE!
-	 *
-	 * Commands like "git shortlog" will not accept the options below
-	 * unless parse_revision_opt queues them (as opposed to erroring
-	 * out).
-	 *
-	 * When implementing your new pseudo-option, remember to
-	 * register it in the list at the top of handle_revision_opt.
-	 */
+	argc = parse_options(argc, argv, revs->prefix,
+			     revs->pseudo_options, NULL,
+			     PARSE_OPT_KEEP_DASHDASH |
+			     PARSE_OPT_KEEP_UNKNOWN |
+			     PARSE_OPT_NO_INTERNAL_HELP |
+			     PARSE_OPT_ONE_SHOT |
+			     PARSE_OPT_STOP_AT_NON_OPTION);
+	if (argc)
+		return argc;
+
 	if (!strcmp(arg, "--all")) {
 		handle_refs(refs, revs, *flags, refs_for_each_ref);
 		handle_refs(refs, revs, *flags, refs_head_ref);
@@ -2685,6 +2708,7 @@  int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 	if (revs->expand_tabs_in_log < 0)
 		revs->expand_tabs_in_log = revs->expand_tabs_in_log_default;
 
+	FREE_AND_NULL(revs->pseudo_options);
 	return left;
 }
 
diff --git a/revision.h b/revision.h
index 71e724c59c..0769c97dee 100644
--- a/revision.h
+++ b/revision.h
@@ -39,6 +39,7 @@ 
 #define DECORATE_FULL_REFS	2
 
 struct log_info;
+struct option;
 struct repository;
 struct rev_info;
 struct string_list;
@@ -279,6 +280,7 @@  struct rev_info {
 	struct topo_walk_info *topo_walk_info;
 
 	struct repository *repo;
+	struct option *pseudo_options;
 };
 
 int ref_excluded(struct string_list *, const char *path);