Merge branch 'na/strtoimax' into maint

* na/strtoimax:
  Support sizes >=2G in various config options accepting 'g' sizes.
  Compatibility: declare strtoimax() under NO_STRTOUMAX
  Add strtoimax() compatibility function.
This commit is contained in:
Junio C Hamano 2011-12-28 11:32:33 -08:00
commit e39888ba21
4 changed files with 46 additions and 13 deletions

View file

@ -57,8 +57,8 @@ all::
# #
# Define NO_STRLCPY if you don't have strlcpy. # Define NO_STRLCPY if you don't have strlcpy.
# #
# Define NO_STRTOUMAX if you don't have strtoumax in the C library. # Define NO_STRTOUMAX if you don't have both strtoimax and strtoumax in the
# If your compiler also does not support long long or does not have # C library. If your compiler also does not support long long or does not have
# strtoull, define NO_STRTOULL. # strtoull, define NO_STRTOULL.
# #
# Define NO_SETENV if you don't have setenv in the C library. # Define NO_SETENV if you don't have setenv in the C library.
@ -1478,7 +1478,7 @@ ifdef NO_STRLCPY
endif endif
ifdef NO_STRTOUMAX ifdef NO_STRTOUMAX
COMPAT_CFLAGS += -DNO_STRTOUMAX COMPAT_CFLAGS += -DNO_STRTOUMAX
COMPAT_OBJS += compat/strtoumax.o COMPAT_OBJS += compat/strtoumax.o compat/strtoimax.o
endif endif
ifdef NO_STRTOULL ifdef NO_STRTOULL
COMPAT_CFLAGS += -DNO_STRTOULL COMPAT_CFLAGS += -DNO_STRTOULL

10
compat/strtoimax.c Normal file
View file

@ -0,0 +1,10 @@
#include "../git-compat-util.h"
intmax_t gitstrtoimax (const char *nptr, char **endptr, int base)
{
#if defined(NO_STRTOULL)
return strtol(nptr, endptr, base);
#else
return strtoll(nptr, endptr, base);
#endif
}

View file

@ -333,7 +333,7 @@ static int git_parse_file(config_fn_t fn, void *data)
die("bad config file line %d in %s", cf->linenr, cf->name); die("bad config file line %d in %s", cf->linenr, cf->name);
} }
static int parse_unit_factor(const char *end, unsigned long *val) static int parse_unit_factor(const char *end, uintmax_t *val)
{ {
if (!*end) if (!*end)
return 1; return 1;
@ -356,11 +356,23 @@ static int git_parse_long(const char *value, long *ret)
{ {
if (value && *value) { if (value && *value) {
char *end; char *end;
long val = strtol(value, &end, 0); intmax_t val;
unsigned long factor = 1; uintmax_t uval;
uintmax_t factor = 1;
errno = 0;
val = strtoimax(value, &end, 0);
if (errno == ERANGE)
return 0;
if (!parse_unit_factor(end, &factor)) if (!parse_unit_factor(end, &factor))
return 0; return 0;
*ret = val * factor; uval = abs(val);
uval *= factor;
if ((uval > maximum_signed_value_of_type(long)) ||
(abs(val) > uval))
return 0;
val *= factor;
*ret = val;
return 1; return 1;
} }
return 0; return 0;
@ -370,9 +382,19 @@ int git_parse_ulong(const char *value, unsigned long *ret)
{ {
if (value && *value) { if (value && *value) {
char *end; char *end;
unsigned long val = strtoul(value, &end, 0); uintmax_t val;
uintmax_t oldval;
errno = 0;
val = strtoumax(value, &end, 0);
if (errno == ERANGE)
return 0;
oldval = val;
if (!parse_unit_factor(end, &val)) if (!parse_unit_factor(end, &val))
return 0; return 0;
if ((val > maximum_unsigned_value_of_type(long)) ||
(oldval > val))
return 0;
*ret = val; *ret = val;
return 1; return 1;
} }
@ -553,7 +575,7 @@ static int git_default_core_config(const char *var, const char *value)
if (!strcmp(var, "core.packedgitwindowsize")) { if (!strcmp(var, "core.packedgitwindowsize")) {
int pgsz_x2 = getpagesize() * 2; int pgsz_x2 = getpagesize() * 2;
packed_git_window_size = git_config_int(var, value); packed_git_window_size = git_config_ulong(var, value);
/* This value must be multiple of (pagesize * 2) */ /* This value must be multiple of (pagesize * 2) */
packed_git_window_size /= pgsz_x2; packed_git_window_size /= pgsz_x2;
@ -564,18 +586,17 @@ static int git_default_core_config(const char *var, const char *value)
} }
if (!strcmp(var, "core.bigfilethreshold")) { if (!strcmp(var, "core.bigfilethreshold")) {
long n = git_config_int(var, value); big_file_threshold = git_config_ulong(var, value);
big_file_threshold = 0 < n ? n : 0;
return 0; return 0;
} }
if (!strcmp(var, "core.packedgitlimit")) { if (!strcmp(var, "core.packedgitlimit")) {
packed_git_limit = git_config_int(var, value); packed_git_limit = git_config_ulong(var, value);
return 0; return 0;
} }
if (!strcmp(var, "core.deltabasecachelimit")) { if (!strcmp(var, "core.deltabasecachelimit")) {
delta_base_cache_limit = git_config_int(var, value); delta_base_cache_limit = git_config_ulong(var, value);
return 0; return 0;
} }

View file

@ -351,6 +351,8 @@ extern size_t gitstrlcpy(char *, const char *, size_t);
#ifdef NO_STRTOUMAX #ifdef NO_STRTOUMAX
#define strtoumax gitstrtoumax #define strtoumax gitstrtoumax
extern uintmax_t gitstrtoumax(const char *, char **, int); extern uintmax_t gitstrtoumax(const char *, char **, int);
#define strtoimax gitstrtoimax
extern intmax_t gitstrtoimax(const char *, char **, int);
#endif #endif
#ifdef NO_STRTOK_R #ifdef NO_STRTOK_R