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

[PATCH v8 1/2] parse-options.c: make OPTION__COUNTUP consider negative values

From
Pranit Bauva <pranit.bauva@gmail.com>
Date
Mar 18, 2016, 21:19 UTC
Message-ID
<010201538b98a7e5-ee604368-5a27-4884-b01e-027fa02bf1c6-000000@eu-west-1.amazonses.com>
In-Reply-To
<010201537710be08-f31428b3-5df3-4694-8c4a-0e8f058131b3-000000@eu-west-1.amazonses.com>

The reason to make it consider negative values or more specifically "unspecified" values is to give the ability to differentiate between once, multiple time or with --no-option.

Eg. : initialize verbose = -1 `git commit` => verbose = -1 `git commit -v` => verbose = 1 `git commit -v -v` => verbose = 2 `git commit --no-verbose` => verbose = 0

Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>

--- The discussion about this patch: [1] : http://thread.gmane.org/gmane.comp.version-control.git/289027

Previous version of the patch: [v1] : http://thread.gmane.org/gmane.comp.version-control.git/289061

Changes introduced:
Use a different language in commit message to make the change and its
utility more clear.
---
 Documentation/technical/api-parse-options.txt | 6 ++++--
 parse-options.c                               | 8 +++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
index 5f0757d..a908d8a 100644
--- a/Documentation/technical/api-parse-options.txt
+++ b/Documentation/technical/api-parse-options.txt
@@ -144,8 +144,10 @@ There are some macros to easily define options:
 
 `OPT_COUNTUP(short, long, &int_var, description)`::
 	Introduce a count-up option.
-	`int_var` is incremented on each use of `--option`, and
-	reset to zero with `--no-option`.
+	If the `int_var` is negative and `--option` is absent,
+	then it will retain its value. Otherwise it will first set
+	`int_var` to 0 and then increment it on each use of `--option`,
+	and reset to zero with `--no-option`.
 
 `OPT_BIT(short, long, &int_var, description, mask)`::
 	Introduce a boolean option.
diff --git a/parse-options.c b/parse-options.c
index 47a9192..86d30bd 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -110,7 +110,13 @@ static int get_value(struct parse_opt_ctx_t *p,
 		return 0;
 
 	case OPTION_COUNTUP:
-		*(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
+		if (unset)
+			*(int *)opt->value = 0;
+		else {
+			if (*(int *)opt->value < 0)
+				*(int *)opt->value = 0;
+			*(int *)opt->value += 1;
+		}
 		return 0;
 
 	case OPTION_SET_INT:

--
https://github.com/git/git/pull/213
Next: Pranit Bauva
Message 1 of 11 in “parse-options.c: make OPTION__COUNTUP consider negative values”
  1. 1/2 parse-options.c: make OPTION__COUNTUP consider negative valuesPranit Bauva, Mar 18, 2016
  2. 2/2 commit: add a commit.verbose config variablePranit Bauva, Mar 18, 2016
  3. Eric SunshineMar 20, 2016
  4. Pranit BauvaMar 20, 2016
  5. Eric SunshineMar 20, 2016
  6. Pranit BauvaMar 20, 2016
  7. Junio C HamanoMar 23, 2016
  8. Pranit BauvaMar 23, 2016
  9. Junio C HamanoMar 23, 2016
  10. Junio C HamanoMar 18, 2016
  11. Pranit BauvaMar 19, 2016

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.