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

[PATCH 03/12] update-index: drop unused argc from do_reupdate()

From
Jeff King <peff@peff.net>
Date
Oct 18, 2022, 01:04 UTC
Message-ID
<Y037rXjvUthkNuCW@coredump.intra.peff.net>
In-Reply-To
<Y036whEorZV0rOgB@coredump.intra.peff.net>

The parse-options callback for --again soaks up all remaining options by manipulating the parse_opt_ctx's argc and argv fields. Even though it has to look at both, the actual parsing happens via the do_reupdate() helper, which only looks at the argv half (by passing it along to parse_pathspec). So that helper doesn't need to see argc at all.

Note that the helper does look at "argv + 1" without confirming that argc is greater than 0. We know this is correct because it is skipping past the actual "--again" string, which will always be present. However, to make what's going on more obvious, let's move that "+1" into the caller, which has the matching "-1" when fixing up the ctx's argc/argv.

Signed-off-by: Jeff King <peff@peff.net>
---
Generate with -U5 so you can see the context I mentioned in
reupdate_callback().
 builtin/update-index.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/builtin/update-index.c b/builtin/update-index.c
index b62249905f..7b0c924d7d 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -730,23 +730,23 @@ static int do_unresolve(int ac, const char **av,
 		free(p);
 	}
 	return err;
 }
 
-static int do_reupdate(int ac, const char **av,
+static int do_reupdate(const char **paths,
 		       const char *prefix)
 {
 	/* Read HEAD and run update-index on paths that are
 	 * merged and already different between index and HEAD.
 	 */
 	int pos;
 	int has_head = 1;
 	struct pathspec pathspec;
 
 	parse_pathspec(&pathspec, 0,
 		       PATHSPEC_PREFER_CWD,
-		       prefix, av + 1);
+		       prefix, paths);
 
 	if (read_ref("HEAD", &head_oid))
 		/* If there is no HEAD, that means it is an initial
 		 * commit.  Update everything in the index.
 		 */
@@ -968,11 +968,11 @@ static enum parse_opt_result reupdate_callback(
 	BUG_ON_OPT_NEG(unset);
 	BUG_ON_OPT_ARG(arg);
 
 	/* consume remaining arguments. */
 	setup_work_tree();
-	*has_errors = do_reupdate(ctx->argc, ctx->argv, prefix);
+	*has_errors = do_reupdate(ctx->argv + 1, prefix);
 	if (*has_errors)
 		active_cache_changed = 0;
 
 	ctx->argv += ctx->argc - 1;
 	ctx->argc = 1;
-- 
2.38.0.371.g300879f34e
Previous: Jeff KingNext: Jeff King
Message 4 of 13 in “more unused-parameter fixes / annotations”
  1. 0/12 more unused-parameter fixes / annotationsJeff King, Oct 18, 2022
  2. 01/12 diffstat_consume(): assert non-zero lengthJeff King, Oct 18, 2022
  3. 02/12 submodule--helper: drop unused argc from module_list_compute()Jeff King, Oct 18, 2022
  4. 03/12 update-index: drop unused argc from do_reupdate()Jeff King, Oct 18, 2022
  5. 04/12 mark unused parameters in trivial compat functionsJeff King, Oct 18, 2022
  6. 05/12 object-file: mark unused parameters in hash_unknown functionsJeff King, Oct 18, 2022
  7. 06/12 string-list: mark unused callback parametersJeff King, Oct 18, 2022
  8. 07/12 date: mark unused parameters in handler functionsJeff King, Oct 18, 2022
  9. 08/12 apply: mark unused parameters in handlersJeff King, Oct 18, 2022
  10. 09/12 apply: mark unused parameters in noop error/warning routineJeff King, Oct 18, 2022
  11. 11/12 diffcore-pickaxe: mark unused parameters in pickaxe functionsJeff King, Oct 18, 2022
  12. 10/12 convert: mark unused parameter in null stream filterJeff King, Oct 18, 2022
  13. 12/12 ll-merge: mark unused parameters in callbacksJeff King, Oct 18, 2022

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.