All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: git cvsimport and case-insensitive config
Date: Tue, 30 Mar 2010 10:29:07 -0700	[thread overview]
Message-ID: <7vy6h9vhuk.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <hoscv7$hmn$1@dough.gmane.org> (Giuseppe Bilotta's message of "Tue\, 30 Mar 2010 10\:32\:37 +0200")

Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:

> git cvsimport looks for cvsimport.* single-letter keys that match the 
> command-line option (e.g. cvsimport.r for -r). However, since there are some 
> single-letter options which only differ by case (a vs A, r vs R) if you set 
> either you get annoying messages (and potentially also odd results, although 
> I haven't come across these yet).

Ouch.

The only sensible solution in the longer term is to eventually rename them
to spell them out e.g. cvsimport.remote vs cvsimport.userevisionmap.

The transition cost would be the same for either approach.

 (1) Introduce long options for cvsimport; the code already uses
     Getopt::Long, so this shouldn't be too bad.

 (2) Add case-sensitive variant of "git config -l" that shows the config
     variable names in the original case.

 (3) Upon startup, use "git config -l -f $GIT_DIR/config" to check for
     historical short name (e.g. "cvsimport.a" or "cvsimport.A").  If
     there are, map them to longer name, remove the short keys and write
     the conversion back to the configuration file.  You might want to do
     the same for "$HOME/.gitconfig" as well.

 (4) Then the rest of the code can stay the same.

Step (2) may look like this.  Note that I made this "list with case"
hidden and inaccessible on purpose, as this is primarily to write a tool
to recover from mistakes like this.

 builtin/config.c |   10 +++++++++-
 cache.h          |    1 +
 config.c         |   12 +++++++++---
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/builtin/config.c b/builtin/config.c
index 4bc46b1..3684c3a 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -41,6 +41,7 @@ static int end_null;
 #define ACTION_SET_ALL (1<<12)
 #define ACTION_GET_COLOR (1<<13)
 #define ACTION_GET_COLORBOOL (1<<14)
+#define ACTION_LIST_KEYS_WITH_CASE (1<<15)
 
 #define TYPE_BOOL (1<<0)
 #define TYPE_INT (1<<1)
@@ -73,6 +74,11 @@ static struct option builtin_config_options[] = {
 	OPT_BIT(0, "path", &types, "value is a path (file or directory name)", TYPE_PATH),
 	OPT_GROUP("Other"),
 	OPT_BOOLEAN('z', "null", &end_null, "terminate values with NUL byte"),
+	{
+		OPTION_BIT, 0, "list-keys-with-case", &actions,
+		NULL, "list for conversion", PARSE_OPT_NOARG|PARSE_OPT_HIDDEN,
+		NULL, ACTION_LIST_KEYS_WITH_CASE,
+	},
 	OPT_END(),
 };
 
@@ -397,7 +403,9 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
 			usage_with_options(builtin_config_usage, builtin_config_options);
 		}
 
-	if (actions == ACTION_LIST) {
+	if (actions == ACTION_LIST || actions == ACTION_LIST_KEYS_WITH_CASE) {
+		if (actions == ACTION_LIST_KEYS_WITH_CASE)
+			config_return_keys_with_case = 1;
 		check_argc(argc, 0, 0);
 		if (git_config(show_all_config, NULL) < 0) {
 			if (config_exclusive_filename)
diff --git a/cache.h b/cache.h
index 6dcb100..4320288 100644
--- a/cache.h
+++ b/cache.h
@@ -953,6 +953,7 @@ extern int git_config_system(void);
 extern int git_config_global(void);
 extern int config_error_nonbool(const char *);
 extern const char *config_exclusive_filename;
+extern int config_return_keys_with_case;
 
 #define MAX_GITNAME (1000)
 extern char git_default_email[MAX_GITNAME];
diff --git a/config.c b/config.c
index 6963fbe..c548cec 100644
--- a/config.c
+++ b/config.c
@@ -17,6 +17,11 @@ static int config_file_eof;
 static int zlib_compression_seen;
 
 const char *config_exclusive_filename = NULL;
+/*
+ * only used for config --list-case-sensitive-keys for recovering
+ * from mistakes.
+ */
+int config_return_keys_with_case;
 
 static int get_next_char(void)
 {
@@ -123,7 +128,7 @@ static int get_value(config_fn_t fn, void *data, char *name, unsigned int len)
 			break;
 		if (!iskeychar(c))
 			break;
-		name[len++] = tolower(c);
+		name[len++] = config_return_keys_with_case ? c : tolower(c);
 		if (len >= MAXNAME)
 			return -1;
 	}
@@ -193,7 +198,8 @@ static int get_base_var(char *name)
 			return -1;
 		if (baselen > MAXNAME / 2)
 			return -1;
-		name[baselen++] = tolower(c);
+		name[baselen++] = config_return_keys_with_case
+			? c : tolower(c);
 	}
 }
 
@@ -246,7 +252,7 @@ static int git_parse_file(config_fn_t fn, void *data)
 		}
 		if (!isalpha(c))
 			break;
-		var[baselen] = tolower(c);
+		var[baselen] = config_return_keys_with_case ? c : tolower(c);
 		if (get_value(fn, data, var, baselen+1) < 0)
 			break;
 	}

  reply	other threads:[~2010-03-30 17:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-30  8:32 git cvsimport and case-insensitive config Giuseppe Bilotta
2010-03-30 17:29 ` Junio C Hamano [this message]
2010-03-30 18:05   ` Giuseppe Bilotta
2010-03-30 21:20     ` Junio C Hamano
2010-03-30 22:17       ` Giuseppe Bilotta
2010-03-30 23:14         ` Junio C Hamano
2010-03-31  6:54           ` Giuseppe Bilotta
2010-03-31  9:45             ` Junio C Hamano
2010-03-31 11:17               ` Giuseppe Bilotta

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

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

  git send-email \
    --in-reply-to=7vy6h9vhuk.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=giuseppe.bilotta@gmail.com \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.