From 806e2ad7fe2d94e1ecae904c33b822b3dfac57f6 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 18 Jun 2008 14:37:18 -0700 Subject: Split up default "core" config parsing into helper routine It makes the code a bit easier to read, and in theory a bit faster too (no need to compare all the different "core.*" strings against non-core config options). The config system really should get something of a complete overhaul, but in the absense of that, this at least improves on it a tiny bit. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- config.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/config.c b/config.c index c2f2bbb00..c3597e043 100644 --- a/config.c +++ b/config.c @@ -332,7 +332,7 @@ int git_config_string(const char **dest, const char *var, const char *value) return 0; } -int git_default_config(const char *var, const char *value, void *dummy) +static int git_default_core_config(const char *var, const char *value) { /* This needs a better name */ if (!strcmp(var, "core.filemode")) { @@ -444,6 +444,31 @@ int git_default_config(const char *var, const char *value, void *dummy) return 0; } + if (!strcmp(var, "core.pager")) + return git_config_string(&pager_program, var, value); + + if (!strcmp(var, "core.editor")) + return git_config_string(&editor_program, var, value); + + if (!strcmp(var, "core.excludesfile")) + return git_config_string(&excludes_file, var, value); + + if (!strcmp(var, "core.whitespace")) { + if (!value) + return config_error_nonbool(var); + whitespace_rule_cfg = parse_whitespace_rule(value); + return 0; + } + + /* Add other config variables here and to Documentation/config.txt. */ + return 0; +} + +int git_default_config(const char *var, const char *value, void *dummy) +{ + if (!prefixcmp(var, "core.")) + return git_default_core_config(var, value); + if (!strcmp(var, "user.name")) { if (!value) return config_error_nonbool(var); @@ -473,21 +498,6 @@ int git_default_config(const char *var, const char *value, void *dummy) return 0; } - if (!strcmp(var, "core.pager")) - return git_config_string(&pager_program, var, value); - - if (!strcmp(var, "core.editor")) - return git_config_string(&editor_program, var, value); - - if (!strcmp(var, "core.excludesfile")) - return git_config_string(&excludes_file, var, value); - - if (!strcmp(var, "core.whitespace")) { - if (!value) - return config_error_nonbool(var); - whitespace_rule_cfg = parse_whitespace_rule(value); - return 0; - } if (!strcmp(var, "branch.autosetupmerge")) { if (value && !strcasecmp(value, "always")) { git_branch_track = BRANCH_TRACK_ALWAYS; -- cgit v1.2.1 From d1364529d06e5fa3bc054396299944a7a4861776 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 18 Jun 2008 14:40:35 -0700 Subject: Split up default "user" config parsing into helper routine This follows the example of the "core" config, and splits out the default "user" config option parsing into a helper routine. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- config.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index c3597e043..ee7642bf6 100644 --- a/config.c +++ b/config.c @@ -464,11 +464,8 @@ static int git_default_core_config(const char *var, const char *value) return 0; } -int git_default_config(const char *var, const char *value, void *dummy) +static int git_default_user_config(const char *var, const char *value) { - if (!prefixcmp(var, "core.")) - return git_default_core_config(var, value); - if (!strcmp(var, "user.name")) { if (!value) return config_error_nonbool(var); @@ -487,6 +484,18 @@ int git_default_config(const char *var, const char *value, void *dummy) return 0; } + /* Add other config variables here and to Documentation/config.txt. */ + return 0; +} + +int git_default_config(const char *var, const char *value, void *dummy) +{ + if (!prefixcmp(var, "core.")) + return git_default_core_config(var, value); + + if (!prefixcmp(var, "user.")) + return git_default_user_config(var, value); + if (!strcmp(var, "i18n.commitencoding")) return git_config_string(&git_commit_encoding, var, value); -- cgit v1.2.1 From 1141f4925c3f1d7c8cc476b10107209e56909c6d Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 18 Jun 2008 15:00:11 -0700 Subject: Split up default "i18n" and "branch" config parsing into helper routines .. just to finish it off. We'll leave the pager color config alone, since it is such an odd-ball special case anyway. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- config.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/config.c b/config.c index ee7642bf6..9d14a74f8 100644 --- a/config.c +++ b/config.c @@ -488,25 +488,20 @@ static int git_default_user_config(const char *var, const char *value) return 0; } -int git_default_config(const char *var, const char *value, void *dummy) +static int git_default_i18n_config(const char *var, const char *value) { - if (!prefixcmp(var, "core.")) - return git_default_core_config(var, value); - - if (!prefixcmp(var, "user.")) - return git_default_user_config(var, value); - if (!strcmp(var, "i18n.commitencoding")) return git_config_string(&git_commit_encoding, var, value); if (!strcmp(var, "i18n.logoutputencoding")) return git_config_string(&git_log_output_encoding, var, value); - if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { - pager_use_color = git_config_bool(var,value); - return 0; - } + /* Add other config variables here and to Documentation/config.txt. */ + return 0; +} +static int git_default_branch_config(const char *var, const char *value) +{ if (!strcmp(var, "branch.autosetupmerge")) { if (value && !strcasecmp(value, "always")) { git_branch_track = BRANCH_TRACK_ALWAYS; @@ -535,6 +530,29 @@ int git_default_config(const char *var, const char *value, void *dummy) return 0; } +int git_default_config(const char *var, const char *value, void *dummy) +{ + if (!prefixcmp(var, "core.")) + return git_default_core_config(var, value); + + if (!prefixcmp(var, "user.")) + return git_default_user_config(var, value); + + if (!prefixcmp(var, "i18n.")) + return git_default_i18n_config(var, value); + + if (!prefixcmp(var, "branch.")) + return git_default_branch_config(var, value); + + if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { + pager_use_color = git_config_bool(var,value); + return 0; + } + + /* Add other config variables here and to Documentation/config.txt. */ + return 0; +} + int git_config_from_file(config_fn_t fn, const char *filename, void *data) { int ret; -- cgit v1.2.1 From aafe9fbaf4f1d1f27a6f6e3eb3e246fff81240ef Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 18 Jun 2008 15:18:44 -0700 Subject: Add config option to enable 'fsync()' of object files As explained in the documentation[*] this is totally useless on filesystems that do ordered/journalled data writes, but it can be a useful safety feature on filesystems like HFS+ that only journal the metadata, not the actual file contents. It defaults to off, although we could presumably in theory some day auto-enable it on a per-filesystem basis. [*] Yes, I updated the docs for the thing. Hell really _has_ frozen over, and the four horsemen are probably just beyond the horizon. EVERYBODY PANIC! Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- Documentation/config.txt | 8 ++++++++ cache.h | 1 + config.c | 5 +++++ environment.c | 1 + sha1_file.c | 3 ++- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 5331b450e..2466ecfc6 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -372,6 +372,14 @@ core.whitespace:: does not trigger if the character before such a carriage-return is not a whitespace (not enabled by default). +core.fsyncobjectfiles:: + This boolean will enable 'fsync()' when writing object files. ++ +This is a total waste of time and effort on a filesystem that orders +data writes properly, but can be useful for filesystems that do not use +journalling (traditional UNIX filesystems) or that only journal metadata +and not file contents (OS X's HFS+, or Linux ext3 with "data=writeback"). + alias.*:: Command aliases for the linkgit:git[1] command wrapper - e.g. after defining "alias.last = cat-file commit HEAD", the invocation diff --git a/cache.h b/cache.h index 81b7e17de..01c8502af 100644 --- a/cache.h +++ b/cache.h @@ -435,6 +435,7 @@ extern size_t packed_git_window_size; extern size_t packed_git_limit; extern size_t delta_base_cache_limit; extern int auto_crlf; +extern int fsync_object_files; enum safe_crlf { SAFE_CRLF_FALSE = 0, diff --git a/config.c b/config.c index 9d14a74f8..b2d5b4e4e 100644 --- a/config.c +++ b/config.c @@ -460,6 +460,11 @@ static int git_default_core_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "core.fsyncobjectfiles")) { + fsync_object_files = git_config_bool(var, value); + return 0; + } + /* Add other config variables here and to Documentation/config.txt. */ return 0; } diff --git a/environment.c b/environment.c index 73feb2d03..d5c3e29e9 100644 --- a/environment.c +++ b/environment.c @@ -29,6 +29,7 @@ const char *apply_default_whitespace; int zlib_compression_level = Z_BEST_SPEED; int core_compression_level; int core_compression_seen; +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 = 16 * 1024 * 1024; diff --git a/sha1_file.c b/sha1_file.c index 191f814e0..fe4ee3ece 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2083,7 +2083,8 @@ int hash_sha1_file(const void *buf, unsigned long len, const char *type, /* Finalize a file on disk, and close it. */ static void close_sha1_file(int fd) { - /* For safe-mode, we could fsync_or_die(fd, "sha1 file") here */ + if (fsync_object_files) + fsync_or_die(fd, "sha1 file"); fchmod(fd, 0444); if (close(fd) != 0) die("unable to write sha1 file"); -- cgit v1.2.1