Skip to content

Commit

Permalink
Merge branch 'lt/config-fsync' into maint
Browse files Browse the repository at this point in the history
* lt/config-fsync:
  Add config option to enable 'fsync()' of object files
  Split up default "i18n" and "branch" config parsing into helper routines
  Split up default "user" config parsing into helper routine
  Split up default "core" config parsing into helper routine
  • Loading branch information
Junio C Hamano committed Aug 7, 2008
2 parents 7be9467 + aafe9fb commit e19b92b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
8 changes: 8 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
82 changes: 62 additions & 20 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -444,6 +444,33 @@ 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, "core.fsyncobjectfiles")) {
fsync_object_files = git_config_bool(var, value);
return 0;
}

/* Add other config variables here and to Documentation/config.txt. */
return 0;
}

static int git_default_user_config(const char *var, const char *value)
{
if (!strcmp(var, "user.name")) {
if (!value)
return config_error_nonbool(var);
Expand All @@ -462,32 +489,24 @@ 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;
}

static int git_default_i18n_config(const char *var, const char *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;
}

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);
/* Add other config variables here and to Documentation/config.txt. */
return 0;
}

if (!strcmp(var, "core.whitespace")) {
if (!value)
return config_error_nonbool(var);
whitespace_rule_cfg = parse_whitespace_rule(value);
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;
Expand Down Expand Up @@ -516,6 +535,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;
Expand Down
1 change: 1 addition & 0 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,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");
Expand Down

0 comments on commit e19b92b

Please sign in to comment.