Skip to content

Commit 2b87560

Browse files
author
Philip Oakley
committed
config.[ch]: provide config_size_t function and use it
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]>
1 parent f54cda1 commit 2b87560

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,8 @@ extern int pack_compression_level;
864864
extern size_t packed_git_window_size;
865865
extern size_t packed_git_limit;
866866
extern size_t delta_base_cache_limit;
867-
extern unsigned long big_file_threshold;
868-
extern unsigned long pack_size_limit_cfg;
867+
extern size_t big_file_threshold;
868+
extern size_t pack_size_limit_cfg;
869869

870870
/*
871871
* Accessors for the core.sharedrepository config which lazy-load the value

config.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,16 @@ static int git_parse_int64(const char *value, int64_t *ret)
932932
int git_parse_ulong(const char *value, unsigned long *ret)
933933
{
934934
uintmax_t tmp;
935-
if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(long)))
935+
if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(unsigned long)))
936+
return 0;
937+
*ret = tmp;
938+
return 1;
939+
}
940+
941+
int git_parse_size_t(const char *value, size_t *ret)
942+
{
943+
uintmax_t tmp;
944+
if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(size_t)))
936945
return 0;
937946
*ret = tmp;
938947
return 1;
@@ -1005,6 +1014,15 @@ unsigned long git_config_ulong(const char *name, const char *value)
10051014
return ret;
10061015
}
10071016

1017+
/* on Windows we require size_t to cover the 64-bit range */
1018+
size_t git_config_size_t(const char *name, const char *value)
1019+
{
1020+
size_t ret;
1021+
if (!git_parse_size_t(value, &ret))
1022+
die_bad_number(name, value);
1023+
return ret;
1024+
}
1025+
10081026
ssize_t git_config_ssize_t(const char *name, const char *value)
10091027
{
10101028
ssize_t ret;
@@ -1219,12 +1237,12 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
12191237
}
12201238

12211239
if (!strcmp(var, "core.bigfilethreshold")) {
1222-
big_file_threshold = git_config_ulong(var, value);
1240+
big_file_threshold = git_config_size_t(var, value);
12231241
return 0;
12241242
}
12251243

12261244
if (!strcmp(var, "core.packedgitlimit")) {
1227-
packed_git_limit = git_config_ulong(var, value);
1245+
packed_git_limit = git_config_size_t(var, value);
12281246
return 0;
12291247
}
12301248

@@ -1467,7 +1485,7 @@ int git_default_config(const char *var, const char *value, void *cb)
14671485
}
14681486

14691487
if (!strcmp(var, "pack.packsizelimit")) {
1470-
pack_size_limit_cfg = git_config_ulong(var, value);
1488+
pack_size_limit_cfg = git_config_size_t(var, value);
14711489
return 0;
14721490
}
14731491

@@ -1651,6 +1669,18 @@ unsigned long git_env_ulong(const char *k, unsigned long val)
16511669
return val;
16521670
}
16531671

1672+
/*
1673+
* Parse environment variable 'k' as ulong with possibly a unit
1674+
* suffix; if missing, use the default value 'val'.
1675+
*/
1676+
size_t git_env_size_t(const char *k, size_t val)
1677+
{
1678+
const char *v = getenv(k);
1679+
if (v && !git_parse_size_t(v, &val))
1680+
die(_("failed to parse %s"), k);
1681+
return val;
1682+
}
1683+
16541684
int git_config_system(void)
16551685
{
16561686
return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);

config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ int config_with_options(config_fn_t fn, void *,
9494
const struct config_options *opts);
9595
int git_parse_ssize_t(const char *, ssize_t *);
9696
int git_parse_ulong(const char *, unsigned long *);
97+
int git_parse_size_t(const char *, size_t *);
9798
int git_parse_maybe_bool(const char *);
9899
int git_config_int(const char *, const char *);
99100
int64_t git_config_int64(const char *, const char *);
100101
unsigned long git_config_ulong(const char *, const char *);
102+
size_t git_config_size_t(const char *, const char *);
101103
ssize_t git_config_ssize_t(const char *, const char *);
102104
int git_config_bool_or_int(const char *, const char *, int *);
103105
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 *);
125127
const char *git_etc_gitconfig(void);
126128
int git_env_bool(const char *, int);
127129
unsigned long git_env_ulong(const char *, unsigned long);
130+
size_t git_env_size_t(const char *, size_t);
128131
int git_config_system(void);
129132
int config_error_nonbool(const char *);
133+
130134
#if defined(__GNUC__)
131135
#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
132136
#endif

csum-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void flush(struct hashfile *f, const void *buf, size_t count)
2222
if (ret != count)
2323
die("%s: sha1 file truncated", f->name);
2424
if (memcmp(buf, check_buffer, count))
25-
die("sha1 file '%s' validation error", f->name);
25+
die("sha1 file '%s' validation error, Count %"PRIuMAX, f->name, count);
2626
}
2727

2828
for (;;) {

environment.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int fsync_object_files;
4545
size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
4646
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
4747
size_t delta_base_cache_limit = 96 * 1024 * 1024;
48-
unsigned long big_file_threshold = 512 * 1024 * 1024;
48+
size_t big_file_threshold = 512 * 1024 * 1024;
4949
int pager_use_color = 1;
5050
const char *editor_program;
5151
const char *askpass_program;
@@ -69,7 +69,7 @@ int grafts_replace_parents = 1;
6969
int core_apply_sparse_checkout;
7070
int merge_log_config = -1;
7171
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
72-
unsigned long pack_size_limit_cfg;
72+
size_t pack_size_limit_cfg;
7373
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
7474

7575
#ifndef PROTECT_HFS_DEFAULT

0 commit comments

Comments
 (0)