diff --git a/cache.h b/cache.h index 9b7eec4254a1ce..d8d22a52a67093 100644 --- a/cache.h +++ b/cache.h @@ -864,8 +864,8 @@ extern int pack_compression_level; extern size_t packed_git_window_size; extern size_t packed_git_limit; extern size_t delta_base_cache_limit; -extern unsigned long big_file_threshold; -extern unsigned long pack_size_limit_cfg; +extern size_t big_file_threshold; +extern size_t pack_size_limit_cfg; /* * Accessors for the core.sharedrepository config which lazy-load the value diff --git a/config.c b/config.c index e4ff9cedb232dd..38ee827186deb0 100644 --- a/config.c +++ b/config.c @@ -932,7 +932,16 @@ static int git_parse_int64(const char *value, int64_t *ret) int git_parse_ulong(const char *value, unsigned long *ret) { uintmax_t tmp; - if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(long))) + if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(unsigned long))) + return 0; + *ret = tmp; + return 1; +} + +int git_parse_size_t(const char *value, size_t *ret) +{ + uintmax_t tmp; + if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(size_t))) return 0; *ret = tmp; return 1; @@ -1005,6 +1014,15 @@ unsigned long git_config_ulong(const char *name, const char *value) return ret; } +/* on Windows we require size_t to cover the 64-bit range */ +size_t git_config_size_t(const char *name, const char *value) +{ + size_t ret; + if (!git_parse_size_t(value, &ret)) + die_bad_number(name, value); + return ret; +} + ssize_t git_config_ssize_t(const char *name, const char *value) { ssize_t ret; @@ -1219,12 +1237,12 @@ static int git_default_core_config(const char *var, const char *value, void *cb) } if (!strcmp(var, "core.bigfilethreshold")) { - big_file_threshold = git_config_ulong(var, value); + big_file_threshold = git_config_size_t(var, value); return 0; } if (!strcmp(var, "core.packedgitlimit")) { - packed_git_limit = git_config_ulong(var, value); + packed_git_limit = git_config_size_t(var, value); return 0; } @@ -1467,7 +1485,7 @@ int git_default_config(const char *var, const char *value, void *cb) } if (!strcmp(var, "pack.packsizelimit")) { - pack_size_limit_cfg = git_config_ulong(var, value); + pack_size_limit_cfg = git_config_size_t(var, value); return 0; } @@ -1651,6 +1669,18 @@ unsigned long git_env_ulong(const char *k, unsigned long val) return val; } +/* + * Parse environment variable 'k' as ulong with possibly a unit + * suffix; if missing, use the default value 'val'. + */ +size_t git_env_size_t(const char *k, size_t val) +{ + const char *v = getenv(k); + if (v && !git_parse_size_t(v, &val)) + die(_("failed to parse %s"), k); + return val; +} + int git_config_system(void) { return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0); diff --git a/config.h b/config.h index ede9e40d968d0a..1a842f37c3523f 100644 --- a/config.h +++ b/config.h @@ -94,10 +94,12 @@ int config_with_options(config_fn_t fn, void *, const struct config_options *opts); int git_parse_ssize_t(const char *, ssize_t *); int git_parse_ulong(const char *, unsigned long *); +int git_parse_size_t(const char *, size_t *); int git_parse_maybe_bool(const char *); int git_config_int(const char *, const char *); int64_t git_config_int64(const char *, const char *); unsigned long git_config_ulong(const char *, const char *); +size_t git_config_size_t(const char *, const char *); ssize_t git_config_ssize_t(const char *, const char *); int git_config_bool_or_int(const char *, const char *, int *); int git_config_bool(const char *, const char *); @@ -125,8 +127,10 @@ int git_config_copy_section_in_file(const char *, const char *, const char *); const char *git_etc_gitconfig(void); int git_env_bool(const char *, int); unsigned long git_env_ulong(const char *, unsigned long); +size_t git_env_size_t(const char *, size_t); int git_config_system(void); int config_error_nonbool(const char *); + #if defined(__GNUC__) #define config_error_nonbool(s) (config_error_nonbool(s), const_error()) #endif diff --git a/csum-file.c b/csum-file.c index ab777dc2102195..b2b66b075afb94 100644 --- a/csum-file.c +++ b/csum-file.c @@ -22,7 +22,7 @@ static void flush(struct hashfile *f, const void *buf, size_t count) if (ret != count) die("%s: sha1 file truncated", f->name); if (memcmp(buf, check_buffer, count)) - die("sha1 file '%s' validation error", f->name); + die("sha1 file '%s' validation error, Count %"PRIuMAX, f->name, count); } for (;;) { diff --git a/environment.c b/environment.c index efa072680a2bca..b1ccfde8f24b91 100644 --- a/environment.c +++ b/environment.c @@ -45,7 +45,7 @@ int fsync_object_files; size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE; size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT; size_t delta_base_cache_limit = 96 * 1024 * 1024; -unsigned long big_file_threshold = 512 * 1024 * 1024; +size_t big_file_threshold = 512 * 1024 * 1024; int pager_use_color = 1; const char *editor_program; const char *askpass_program; @@ -69,7 +69,7 @@ int grafts_replace_parents = 1; int core_apply_sparse_checkout; int merge_log_config = -1; int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ -unsigned long pack_size_limit_cfg; +size_t pack_size_limit_cfg; enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET; #ifndef PROTECT_HFS_DEFAULT