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

[PATCH 1/6 v5] revision.c: do not update argv with unknown option

From
Siddharth Kannan <kannan.siddharth12@gmail.com>
Date
Feb 25, 2017, 07:32 UTC
Message-ID
<1488007921-13432-1-git-send-email-kannan.siddharth12@gmail.com>
In-Reply-To
<1488007487-12965-1-git-send-email-kannan.siddharth12@gmail.com>

handle_revision_opt() tries to recognize and handle the given argument. If an option was unknown to it, it used to add the option to unkv[(*unkc)++]. This increment of unkc causes the variable in the caller to change.

Teach handle_revision_opt to not update unknown arguments inside unkc anymore. This is now the responsibility of the caller.

There are two callers of this function:
1. setup_revision: Changes have been made so that setup_revision will now
update the unknown option in argv
2. parse_revision_opt: No changes are required here. This function throws an
error whenever the option provided as argument was unknown to
handle_revision_opt().
Signed-off-by: Siddharth Kannan <kannan.siddharth12@gmail.com>
---
 revision.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index b37dbec..5674a9a 100644
--- a/revision.c
+++ b/revision.c
@@ -2016,8 +2016,6 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->ignore_missing = 1;
 	} else {
 		int opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix);
-		if (!opts)
-			unkv[(*unkc)++] = arg;
 		return opts;
 	}
 	if (revs->graph && revs->track_linear)
@@ -2234,6 +2232,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 			}
 			if (opts < 0)
 				exit(128);
+			/* arg is an unknown option */
+			argv[left++] = arg;
 			continue;
 		}
 
-- 
2.1.4
Previous: Siddharth Kannan
Message 12 of 12 in “allow "-" as a shorthand for "previous branch"”
  1. 0/6 allow "-" as a shorthand for "previous branch"Siddharth Kannan, Feb 25, 2017
  2. 3/6 revision.c: args starting with "-" might be a revisionSiddharth Kannan, Feb 25, 2017
  3. 6/6 revert.c: delegate handling of "-" shorthand to setup_revisionsSiddharth Kannan, Feb 25, 2017
  4. Junio C HamanoMar 1, 2017
  5. 5/6 merge.c: delegate handling of "-" shorthand to revision.c:get_sha1Siddharth Kannan, Feb 25, 2017
  6. Junio C HamanoMar 1, 2017
  7. Junio C HamanoMar 1, 2017
  8. 4/6 sha1_name.c: teach get_sha1_1 "-" shorthand for "@{-1}"Siddharth Kannan, Feb 25, 2017
  9. 6/6 sha1_name.c: avoid parsing @{-1} unnecessarilymash, Mar 14, 2017
  10. 2/6 revision.c: swap if/else blocksSiddharth Kannan, Feb 25, 2017
  11. 1/6 revision.c: do not update argv with unknown optionSiddharth Kannan, Feb 25, 2017
  12. 1/6 revision.c: do not update argv with unknown optionSiddharth Kannan, Feb 25, 2017

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.