summaryrefslogtreecommitdiffstats
path: root/config.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2024-05-23 23:26:39 +0200
committerJunio C Hamano <gitster@pobox.com>2024-05-24 20:40:42 +0200
commit5831f8ac41a137b93d5481cc48078cb5628538e3 (patch)
tree6b1bfd4ceb72d6cb81e3fac887b3e0916b91801f /config.c
parentpack-bitmap: make `bitmap_writer_push_bitmapped_commit()` public (diff)
downloadgit-5831f8ac41a137b93d5481cc48078cb5628538e3.tar.xz
git-5831f8ac41a137b93d5481cc48078cb5628538e3.zip
config: introduce `git_config_double()`
Future commits will want to parse a double-precision floating point value from configuration, but we have no way to parse such a value prior to this patch. The core of the routine is implemented in git_parse_double(). Unlike git_parse_unsigned() and git_parse_signed(), however, the function implemented here only works on type "double", and not related types like "float", or "long double". This is because "float" and "long double" use different functions to convert from ASCII strings to floating point values (strtof() and strtold(), respectively). Likewise, there is no pointer type that can assign to any of these values (except for "void *"), so the only way to define this trio of functions would be with a macro expansion that is parameterized over the floating point type and conversion function. That is all doable, but likely to be overkill given our current needs, which is only to parse double-precision floats. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/config.c b/config.c
index ae3652b08f..8a8332617f 100644
--- a/config.c
+++ b/config.c
@@ -1243,6 +1243,15 @@ ssize_t git_config_ssize_t(const char *name, const char *value,
return ret;
}
+double git_config_double(const char *name, const char *value,
+ const struct key_value_info *kvi)
+{
+ double ret;
+ if (!git_parse_double(value, &ret))
+ die_bad_number(name, value, kvi);
+ return ret;
+}
+
static const struct fsync_component_name {
const char *name;
enum fsync_component component_bits;