git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/6] parse-options: allow OPTION_ARGUMENT to take argument

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Nov 10, 2011, 07:12 UTC
Message-ID
<1320909155-4575-5-git-send-email-pclouds@gmail.com>
In-Reply-To
<1320909155-4575-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 58bb83d..3a1575a 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -218,11 +218,23 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
 		if (options->type == OPTION_ARGUMENT) {
 			if (!rest)
 				continue;
-			if (*rest == '=')
-				return opterror(options, "takes no value", flags);
+			if (*rest == '=') {
+				if (options->flags & PARSE_OPT_NOARG)
+					return opterror(options, "takes no value", flags);
+				p->out[p->cpidx++] = *p->argv;
+				return 0;
+			}
+
 			if (*rest)
 				continue;
-			p->out[p->cpidx++] = arg - 2;
+			p->out[p->cpidx++] = *p->argv;
+			if (!(options->flags & PARSE_OPT_NOARG)) {
+				p->argv++;
+				p->argc--;
+				if (!*p->argv)
+					return opterror(options, "takes no value", flags);
+				p->out[p->cpidx++] = *p->argv;
+			}
 			return 0;
 		}
 		if (!rest) {
-- 
1.7.4.74.g639db
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 5 of 6 in “Print trace in rev-list machinery”
  1. 1/6 Print trace in rev-list machineryNguyễn Thái Ngọc Duy, Nov 10, 2011
  2. 2/6 find_pack_entry(): do not keep packed_git pointer locallyNguyễn Thái Ngọc Duy, Nov 10, 2011
  3. 3/6 parse-options: add OPT_ULONGNguyễn Thái Ngọc Duy, Nov 10, 2011
  4. 4/6 pack-objects: use parse_options()Nguyễn Thái Ngọc Duy, Nov 10, 2011
  5. 5/6 parse-options: allow OPTION_ARGUMENT to take argumentNguyễn Thái Ngọc Duy, Nov 10, 2011
  6. 6/6 Build in git-repackNguyễn Thái Ngọc Duy, Nov 10, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.