Skip to content

Commit

Permalink
config.[ch]: provide config_size_t function and use it
Browse files Browse the repository at this point in the history
For Windows compatibility.
cache.h: big_file_threshold & pack_size_limit_cfg are potentially size_t,
plus a few others convereted in this pass.

Other potential >4Gb variables are left for others.

Signed-off-by: Philip Oakley <[email protected]>
  • Loading branch information
Philip Oakley committed May 3, 2019
1 parent f54cda1 commit 2b87560
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 34 additions & 4 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion csum-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
Expand Down
4 changes: 2 additions & 2 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 2b87560

Please sign in to comment.