Skip to content

Commit a85708c

Browse files
Philip Oakleydscho
Philip Oakley
authored andcommitted
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 a8e0ee7 commit a85708c

File tree

5 files changed

+44
-9
lines changed

5 files changed

+44
-9
lines changed

cache.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,8 @@ extern int pack_compression_level;
865865
extern size_t packed_git_window_size;
866866
extern size_t packed_git_limit;
867867
extern size_t delta_base_cache_limit;
868-
extern unsigned long big_file_threshold;
869-
extern unsigned long pack_size_limit_cfg;
868+
extern size_t big_file_threshold;
869+
extern size_t pack_size_limit_cfg;
870870

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

config.c

+34-4
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,16 @@ static int git_parse_int64(const char *value, int64_t *ret)
931931
int git_parse_ulong(const char *value, unsigned long *ret)
932932
{
933933
uintmax_t tmp;
934-
if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(long)))
934+
if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(unsigned long)))
935+
return 0;
936+
*ret = tmp;
937+
return 1;
938+
}
939+
940+
int git_parse_size_t(const char *value, size_t *ret)
941+
{
942+
uintmax_t tmp;
943+
if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(size_t)))
935944
return 0;
936945
*ret = tmp;
937946
return 1;
@@ -1004,6 +1013,15 @@ unsigned long git_config_ulong(const char *name, const char *value)
10041013
return ret;
10051014
}
10061015

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

12201238
if (!strcmp(var, "core.bigfilethreshold")) {
1221-
big_file_threshold = git_config_ulong(var, value);
1239+
big_file_threshold = git_config_size_t(var, value);
12221240
return 0;
12231241
}
12241242

12251243
if (!strcmp(var, "core.packedgitlimit")) {
1226-
packed_git_limit = git_config_ulong(var, value);
1244+
packed_git_limit = git_config_size_t(var, value);
12271245
return 0;
12281246
}
12291247

@@ -1471,7 +1489,7 @@ int git_default_config(const char *var, const char *value, void *cb)
14711489
}
14721490

14731491
if (!strcmp(var, "pack.packsizelimit")) {
1474-
pack_size_limit_cfg = git_config_ulong(var, value);
1492+
pack_size_limit_cfg = git_config_size_t(var, value);
14751493
return 0;
14761494
}
14771495

@@ -1655,6 +1673,18 @@ unsigned long git_env_ulong(const char *k, unsigned long val)
16551673
return val;
16561674
}
16571675

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

config.h

+4
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 *);
@@ -122,8 +124,10 @@ int git_config_copy_section_in_file(const char *, const char *, const char *);
122124
const char *git_etc_gitconfig(void);
123125
int git_env_bool(const char *, int);
124126
unsigned long git_env_ulong(const char *, unsigned long);
127+
size_t git_env_size_t(const char *, size_t);
125128
int git_config_system(void);
126129
int config_error_nonbool(const char *);
130+
127131
#if defined(__GNUC__)
128132
#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
129133
#endif

csum-file.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ 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,
26+
f->name, (uintmax_t)count);
2627
}
2728

2829
for (;;) {

environment.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int fsync_object_files;
4747
size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
4848
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
4949
size_t delta_base_cache_limit = 96 * 1024 * 1024;
50-
unsigned long big_file_threshold = 512 * 1024 * 1024;
50+
size_t big_file_threshold = 512 * 1024 * 1024;
5151
int pager_use_color = 1;
5252
const char *editor_program;
5353
const char *askpass_program;
@@ -71,7 +71,7 @@ int grafts_replace_parents = 1;
7171
int core_apply_sparse_checkout;
7272
int merge_log_config = -1;
7373
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
74-
unsigned long pack_size_limit_cfg;
74+
size_t pack_size_limit_cfg;
7575
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
7676

7777
#ifndef PROTECT_HFS_DEFAULT

0 commit comments

Comments
 (0)