git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 01/14] cmd_{read,write}_tree: rename "unused" variable that is used
Date: Thu, 9 May 2019 17:27:24 -0400	[thread overview]
Message-ID: <20190509212724.GA15837@sigill.intra.peff.net> (raw)
In-Reply-To: <20190509212558.GA15438@sigill.intra.peff.net>

The "prefix" variable passed by git.c into the builtin cmd_read_tree()
and cmd_write_tree() functions is named "unused_prefix". But we do in
fact pass it to parse_options(), which may use the prefix to adjust any
filename options. Let's get rid of this confusing name.

However, we can't just call it "prefix". The reason these variables were
renamed in the first place is that they shadowed local variables named
"prefix", because these commands both take a "--prefix" option.

So let's rename the parameters, but try to reduce further confusion:

  1. In both cases we'll call them "cmd_prefix" to mark that they're
     part of the cmd_* interface.

  2. In cmd_write_tree(), we'll rename the local prefix variable to
     "tree_prefix" to make it more clear that we're talking about the
     prefix to be used for the tree we're writing.

  3. In cmd_read_tree(), the "prefix" local has since migrated into
     "struct unpack_trees_options". We'll leave that alone, as the
     context within the struct makes its meaning clear (we actually
     _could_ just call the parameter "prefix" now, but that invites
     confusion in the other direction).

Signed-off-by: Jeff King <peff@peff.net>
---
I kind of hate "cmd_prefix"; I was tempted to just call it "prefix" so
that all of the cmd_* functions were consistent, but I worried that it
really would get confused with the local variables (even if those
variables are renamed, as I do here).

 builtin/read-tree.c  |  4 ++--
 builtin/write-tree.c | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 5c9c082595..ca5e655d2f 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -111,7 +111,7 @@ static int git_read_tree_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
-int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
+int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
 {
 	int i, stage = 0;
 	struct object_id oid;
@@ -165,7 +165,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 
 	git_config(git_read_tree_config, NULL);
 
-	argc = parse_options(argc, argv, unused_prefix, read_tree_options,
+	argc = parse_options(argc, argv, cmd_prefix, read_tree_options,
 			     read_tree_usage, 0);
 
 	hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 3d46d22ee5..45d61707e7 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -16,16 +16,16 @@ static const char * const write_tree_usage[] = {
 	NULL
 };
 
-int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
+int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
 {
 	int flags = 0, ret;
-	const char *prefix = NULL;
+	const char *tree_prefix = NULL;
 	struct object_id oid;
 	const char *me = "git-write-tree";
 	struct option write_tree_options[] = {
 		OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
 			WRITE_TREE_MISSING_OK),
-		OPT_STRING(0, "prefix", &prefix, N_("<prefix>/"),
+		OPT_STRING(0, "prefix", &tree_prefix, N_("<prefix>/"),
 			   N_("write tree object for a subdirectory <prefix>")),
 		{ OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
 		  N_("only useful for debugging"),
@@ -35,10 +35,10 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
 	};
 
 	git_config(git_default_config, NULL);
-	argc = parse_options(argc, argv, unused_prefix, write_tree_options,
+	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
 			     write_tree_usage, 0);
 
-	ret = write_cache_as_tree(&oid, flags, prefix);
+	ret = write_cache_as_tree(&oid, flags, tree_prefix);
 	switch (ret) {
 	case 0:
 		printf("%s\n", oid_to_hex(&oid));
@@ -50,7 +50,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
 		die("%s: error building trees", me);
 		break;
 	case WRITE_TREE_PREFIX_ERROR:
-		die("%s: prefix %s not found", me, prefix);
+		die("%s: prefix %s not found", me, tree_prefix);
 		break;
 	}
 	return ret;
-- 
2.21.0.1382.g4c6032d436


  reply	other threads:[~2019-05-09 21:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-09 21:25 [PATCH 0/14] "final" batch of unused parameter cleanups Jeff King
2019-05-09 21:27 ` Jeff King [this message]
2019-05-10 12:07   ` [PATCH 01/14] cmd_{read,write}_tree: rename "unused" variable that is used Derrick Stolee
2019-05-13  5:14   ` Junio C Hamano
2019-05-09 21:27 ` [PATCH 02/14] submodule: drop unused prefix parameter from some functions Jeff King
2019-05-09 21:28 ` [PATCH 03/14] builtin: consistently pass cmd_* prefix to parse_options Jeff King
2019-05-10 12:10   ` Derrick Stolee
2019-05-09 21:29 ` [PATCH 04/14] clone: drop dest parameter from copy_alternates() Jeff King
2019-05-09 21:29 ` [PATCH 05/14] read-cache: drop unused parameter from threaded load Jeff King
2019-05-09 21:30 ` [PATCH 06/14] wt-status: drop unused status parameter Jeff King
2019-05-09 21:30 ` [PATCH 07/14] mktree: drop unused length parameter Jeff King
2019-05-09 21:30 ` [PATCH 08/14] name-rev: drop unused parameters from is_better_name() Jeff King
2019-05-09 21:31 ` [PATCH 09/14] pack-objects: drop unused rev_info parameters Jeff King
2019-05-09 21:31 ` [PATCH 10/14] receive-pack: drop unused "commands" from prepare_shallow_update() Jeff King
2019-05-09 21:31 ` [PATCH 11/14] remove_all_fetch_refspecs(): drop unused "remote" parameter Jeff King
2019-05-09 21:32 ` [PATCH 12/14] rev-list: drop unused void pointer from finish_commit() Jeff King
2019-05-09 21:32 ` [PATCH 13/14] show-branch: drop unused parameter from show_independent() Jeff King
2019-05-09 21:32 ` [PATCH 14/14] verify-commit: simplify parameters to run_gpg_verify() Jeff King
2019-05-10 12:19   ` Derrick Stolee
2019-05-10 12:20 ` [PATCH 0/14] "final" batch of unused parameter cleanups Derrick Stolee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190509212724.GA15837@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).