Skip to contentSkip to conversation

config: add support for --bool and --int while setting values

PATCH In review Frank Lichtenheld 3 participants 5 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 config: add support for --bool and --int while setting values

---
 Documentation/git-config.txt    |    9 +++---
 builtin-config.c                |   54 +++++++++++++++++++++++++++++---------
 t/t1300-repo-config.sh          |   48 +++++++++++++++++++++++++++++++++-
 t/t9400-git-cvsserver-server.sh |    4 +-
 4 files changed, 94 insertions(+), 21 deletions(-)

There are probably more elegant ways to do this... But it seems to work.

Documentation/git-config.txt +4 -5
index f2c6717..ddb1dea 100644
@@ -9,9 +9,9 @@ git-config - Get and set repository or global options
 SYNOPSIS
 --------
 [verse]
-'git-config' [--system | --global] name [value [value_regex]]
-'git-config' [--system | --global] --add name value
-'git-config' [--system | --global] --replace-all name [value [value_regex]]
+'git-config' [--system | --global] [type] name [value [value_regex]]
+'git-config' [--system | --global] [type] --add name value
+'git-config' [--system | --global] [type] --replace-all name [value [value_regex]]
 'git-config' [--system | --global] [type] --get name [value_regex]
 'git-config' [--system | --global] [type] --get-all name [value_regex]
 'git-config' [--system | --global] --unset name [value_regex]
@@ -36,8 +36,7 @@ prepend a single exclamation mark in front (see also <<EXAMPLES>>).
 The type specifier can be either '--int' or '--bool', which will make
 'git-config' ensure that the variable(s) are of the given type and
 convert the value to the canonical form (simple decimal number for int,
-a "true" or "false" string for bool).  Type specifiers currently only
-take effect for reading operations.  If no type specifier is passed,
+a "true" or "false" string for bool).  If no type specifier is passed,
 no checks or transformations are performed on the value.
 
 This command will fail if:
builtin-config.c +41 -13

76 lines not on this page · raw message

t/t1300-repo-config.sh +47 -1

58 lines not on this page · raw message

t/t9400-git-cvsserver-server.sh +2 -2
index 0331770..641303e 100755
@@ -38,7 +38,7 @@ echo >empty &&
   git commit -q -m "First Commit" &&
   git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
-  GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
+  GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
   exit 1
 
 # note that cvs doesn't accept absolute pathnames
@@ -255,7 +255,7 @@ rm -fr "$SERVERDIR"
 cd "$WORKDIR" &&
 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
-GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
+GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
 exit 1
 
 test_expect_success 'cvs update (create new file)' \
Signature · 1 line
1.5.2.1
#2 lore raw
Quoted 6 lines · Johannes Sixt
Quoted 2 lines · Frank Lichtenheld

Please excuse if I'm missing the big picture, but why do we need this change?

- Of course the user or script calling git-config can do the normalization and error checking, if they want to. But I would prefer to have it available in git-config.
- I would prefer that these options wouldn't be silently ignored, because that can be confusing (at least it is documented now, but still). So we should either using them or error out. I prefer the former.

Something that I forgot to mention in the previous mail:
One real problem with the patch is that it expands the k,m,g suffixes for integer values. It probably shouldn't do that.

Gruesse,

Signature · 2 lines
Frank Lichtenheld <[email protected]>
www: http://www.djpig.de/
#3 lore raw
Quoted 15 lines · Frank Lichtenheld
Quoted 6 lines · Johannes Sixt
Quoted 2 lines · Frank Lichtenheld

Please excuse if I'm missing the big picture, but why do we need this change?

- Of course the user or script calling git-config can do the normalization and error checking, if they want to. But I would prefer to have it available in git-config.
- I would prefer that these options wouldn't be silently ignored, because that can be confusing (at least it is documented now, but still). So we should either using them or error out. I prefer the former.

Quoted 3 lines

Something that I forgot to mention in the previous mail:
One real problem with the patch is that it expands the k,m,g suffixes for integer values. It probably shouldn't do that.

How about doing something like this, then?

git_config_int() knows that a missing value is a nonsense and barfs on such an input, so (value ? value : "") is redundant here. Besides, you check value == NULL much earlier in this function.

builtin-config.c +5 -4
index 9973f94..33b60ec 100644
@@ -148,10 +148,11 @@ char* normalize_value(const char* key, const char* value)
 	if (type == T_RAW)
 		normalized = xstrdup(value);
 	else {
-		normalized = xmalloc(64);
-		if (type == T_INT)
-			sprintf(normalized, "%d",
-				git_config_int(key, value?value:""));
+		normalized = xmalloc(64 + strlen(value));
+		if (type == T_INT) {
+			int v = git_config_int(key, value);
+			sprintf(normalized, "%d # %s", v, value);
+		}
 		else if (type == T_BOOL)
 			sprintf(normalized, "%s",
 				git_config_bool(key, value) ? "true" : "false");
#4 lore raw
Quoted 7 lines · Junio C Hamano
Quoted 3 lines · Frank Lichtenheld

Something that I forgot to mention in the previous mail:
One real problem with the patch is that it expands the k,m,g suffixes for integer values. It probably shouldn't do that.

How about doing something like this, then?

Nah, that wouldn't work, as normalize_value's return value is parsed and quoted. Grumble....