fast-import.c: replace `git_config()` with `git_config_get_*()` family

Use `git_config_get_*()` family instead of `git_config()` to take advantage of the config-set API which provides a cleaner control flow. Signed-off-by: Tanay Abhra <tanayabh@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tanay Abhra committed Aug 13, 2014 at 17:52 UTC 536900e5b24f8341bcaf2a26371fcd3ca417eef9
1 file changed +21 -23
fast-import.c
+21 -23
@@ -3274,36 +3274,34 @@ static void parse_option(const char *option)
3274 die("This version of fast-import does not support option: %s", option);
3275 }
3276
3277 -static int git_pack_config(const char *k, const char *v, void *cb)
3277 +static void git_pack_config(void)
3278 {
3279 - if (!strcmp(k, "pack.depth")) {
3280 - max_depth = git_config_int(k, v);
3279 + int indexversion_value;
3280 + unsigned long packsizelimit_value;
3281 +
3282 + if (!git_config_get_ulong("pack.depth", &max_depth)) {
3283 if (max_depth > MAX_DEPTH)
3284 max_depth = MAX_DEPTH;
3283 - return 0;
3285 }
3285 - if (!strcmp(k, "pack.compression")) {
3286 - int level = git_config_int(k, v);
3287 - if (level == -1)
3288 - level = Z_DEFAULT_COMPRESSION;
3289 - else if (level < 0 || level > Z_BEST_COMPRESSION)
3290 - die("bad pack compression level %d", level);
3291 - pack_compression_level = level;
3286 + if (!git_config_get_int("pack.compression", &pack_compression_level)) {
3287 + if (pack_compression_level == -1)
3288 + pack_compression_level = Z_DEFAULT_COMPRESSION;
3289 + else if (pack_compression_level < 0 ||
3290 + pack_compression_level > Z_BEST_COMPRESSION)
3291 + git_die_config("pack.compression",
3292 + "bad pack compression level %d", pack_compression_level);
3293 pack_compression_seen = 1;
3293 - return 0;
3294 }
3295 - if (!strcmp(k, "pack.indexversion")) {
3296 - pack_idx_opts.version = git_config_int(k, v);
3295 + if (!git_config_get_int("pack.indexversion", &indexversion_value)) {
3296 + pack_idx_opts.version = indexversion_value;
3297 if (pack_idx_opts.version > 2)
3298 - die("bad pack.indexversion=%"PRIu32,
3299 - pack_idx_opts.version);
3300 - return 0;
3298 + git_die_config("pack.indexversion",
3299 + "bad pack.indexversion=%"PRIu32, pack_idx_opts.version);
3300 }
3302 - if (!strcmp(k, "pack.packsizelimit")) {
3303 - max_packsize = git_config_ulong(k, v);
3304 - return 0;
3305 - }
3306 - return git_default_config(k, v, cb);
3301 + if (!git_config_get_ulong("pack.packsizelimit", &packsizelimit_value))
3302 + max_packsize = packsizelimit_value;
3303 +
3304 + git_config(git_default_config, NULL);
3305 }
3306
3307 static const char fast_import_usage[] =
@@ -3356,7 +3354,7 @@ int main(int argc, char **argv)
3354
3355 setup_git_directory();
3356 reset_pack_idx_option(&pack_idx_opts);
3359 - git_config(git_pack_config, NULL);
3357 + git_pack_config();
3358 if (!pack_compression_seen && core_compression_seen)
3359 pack_compression_level = core_compression_level;
3360