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

[PATCH 2/2] pack-objects: Use git_config_magic_int()

From
Andreas Ericsson <ae@op5.se>
Date
Feb 12, 2008, 08:23 UTC
Message-ID
<47B1579F.8030407@op5.se>
In-Reply-To
<1202804110-3715-1-git-send-email-ae@op5.se>

This lets users specify "auto" as a valid parameter to --threads and pack.threads instead of having to remember what the magic number 0 actually meant. 0 still works. This is just a nicer way of saying it.

Signed-off-by: Andreas Ericsson <ae@op5.se>
---
 Documentation/config.txt           |    4 ++--
 Documentation/git-pack-objects.txt |    4 ++--
 builtin-pack-objects.c             |   16 ++++++++++------
 3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index e9f26ed..398c6e0 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -756,8 +756,8 @@ pack.threads::
 	warning. This is meant to reduce packing time on multiprocessor
 	machines. The required amount of memory for the delta search window
 	is however multiplied by the number of threads.
-	Specifying 0 will cause git to auto-detect the number of CPU's
-	and set the number of threads accordingly.
+	Specifying 'auto' or 0 will cause git to auto-detect the number
+	of CPU's and set the number of threads accordingly.
 
 pack.indexVersion::
 	Specify the default pack index version.  Valid values are 1 for
diff --git a/Documentation/git-pack-objects.txt b/Documentation/git-pack-objects.txt
index 5c1bd3b..e4b6fe9 100644
--- a/Documentation/git-pack-objects.txt
+++ b/Documentation/git-pack-objects.txt
@@ -177,8 +177,8 @@ base-name::
 	This is meant to reduce packing time on multiprocessor machines.
 	The required amount of memory for the delta search window is
 	however multiplied by the number of threads.
-	Specifying 0 will cause git to auto-detect the number of CPU's
-	and set the number of threads accordingly.
+	Specifying 'auto' or 0 will cause git to auto-detect the number
+	of CPU's and set the number of threads accordingly.
 
 --index-version=<version>[,<offset>]::
 	This is intended to be used by the test suite only. It allows
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index a7ffb53..be04829 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -1857,7 +1857,7 @@ static int git_pack_config(const char *k, const char *v)
 		return 0;
 	}
 	if (!strcmp(k, "pack.threads")) {
-		delta_search_threads = git_config_int(k, v);
+		delta_search_threads = git_config_magic_int(k, v, "auto", 0);
 		if (delta_search_threads < 0)
 			die("invalid number of threads specified (%d)",
 			    delta_search_threads);
@@ -2128,11 +2128,15 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 		if (!prefixcmp(arg, "--threads=")) {
-			char *end;
-			delta_search_threads = strtoul(arg+10, &end, 0);
-
-			if (!arg[10] || *end || delta_search_threads < 0)
-				usage(pack_usage);
+			if (!strcasecmp(arg+10, "auto"))
+				delta_search_threads = 0;
+			else {
+				char *end;
+				delta_search_threads = strtoul(arg+10, &end, 0);
+
+				if (!arg[10] || *end || delta_search_threads < 0)
+					usage(pack_usage);
+			}
 #ifndef THREADED_DELTA_SEARCH
 			if (delta_search_threads > 1)
 				warning("no threads support, "
-- 
1.5.4.rc5.11.g0eab8
Message 1 of 1 in “pack-objects: Use git_config_magic_int()”
  1. 2/2 pack-objects: Use git_config_magic_int()Andreas Ericsson, Feb 12, 2008

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.