Skip to content

Commit e19b92b

Browse files
committed
Merge branch 'lt/config-fsync' into maint
* 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
2 parents 7be9467 + aafe9fb commit e19b92b

File tree

5 files changed

+74
-21
lines changed

5 files changed

+74
-21
lines changed

Documentation/config.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ core.whitespace::
372372
does not trigger if the character before such a carriage-return
373373
is not a whitespace (not enabled by default).
374374

375+
core.fsyncobjectfiles::
376+
This boolean will enable 'fsync()' when writing object files.
377+
+
378+
This is a total waste of time and effort on a filesystem that orders
379+
data writes properly, but can be useful for filesystems that do not use
380+
journalling (traditional UNIX filesystems) or that only journal metadata
381+
and not file contents (OS X's HFS+, or Linux ext3 with "data=writeback").
382+
375383
alias.*::
376384
Command aliases for the linkgit:git[1] command wrapper - e.g.
377385
after defining "alias.last = cat-file commit HEAD", the invocation

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ extern size_t packed_git_window_size;
435435
extern size_t packed_git_limit;
436436
extern size_t delta_base_cache_limit;
437437
extern int auto_crlf;
438+
extern int fsync_object_files;
438439

439440
enum safe_crlf {
440441
SAFE_CRLF_FALSE = 0,

config.c

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ int git_config_string(const char **dest, const char *var, const char *value)
332332
return 0;
333333
}
334334

335-
int git_default_config(const char *var, const char *value, void *dummy)
335+
static int git_default_core_config(const char *var, const char *value)
336336
{
337337
/* This needs a better name */
338338
if (!strcmp(var, "core.filemode")) {
@@ -444,6 +444,33 @@ int git_default_config(const char *var, const char *value, void *dummy)
444444
return 0;
445445
}
446446

447+
if (!strcmp(var, "core.pager"))
448+
return git_config_string(&pager_program, var, value);
449+
450+
if (!strcmp(var, "core.editor"))
451+
return git_config_string(&editor_program, var, value);
452+
453+
if (!strcmp(var, "core.excludesfile"))
454+
return git_config_string(&excludes_file, var, value);
455+
456+
if (!strcmp(var, "core.whitespace")) {
457+
if (!value)
458+
return config_error_nonbool(var);
459+
whitespace_rule_cfg = parse_whitespace_rule(value);
460+
return 0;
461+
}
462+
463+
if (!strcmp(var, "core.fsyncobjectfiles")) {
464+
fsync_object_files = git_config_bool(var, value);
465+
return 0;
466+
}
467+
468+
/* Add other config variables here and to Documentation/config.txt. */
469+
return 0;
470+
}
471+
472+
static int git_default_user_config(const char *var, const char *value)
473+
{
447474
if (!strcmp(var, "user.name")) {
448475
if (!value)
449476
return config_error_nonbool(var);
@@ -462,32 +489,24 @@ int git_default_config(const char *var, const char *value, void *dummy)
462489
return 0;
463490
}
464491

492+
/* Add other config variables here and to Documentation/config.txt. */
493+
return 0;
494+
}
495+
496+
static int git_default_i18n_config(const char *var, const char *value)
497+
{
465498
if (!strcmp(var, "i18n.commitencoding"))
466499
return git_config_string(&git_commit_encoding, var, value);
467500

468501
if (!strcmp(var, "i18n.logoutputencoding"))
469502
return git_config_string(&git_log_output_encoding, var, value);
470503

471-
if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
472-
pager_use_color = git_config_bool(var,value);
473-
return 0;
474-
}
475-
476-
if (!strcmp(var, "core.pager"))
477-
return git_config_string(&pager_program, var, value);
478-
479-
if (!strcmp(var, "core.editor"))
480-
return git_config_string(&editor_program, var, value);
481-
482-
if (!strcmp(var, "core.excludesfile"))
483-
return git_config_string(&excludes_file, var, value);
504+
/* Add other config variables here and to Documentation/config.txt. */
505+
return 0;
506+
}
484507

485-
if (!strcmp(var, "core.whitespace")) {
486-
if (!value)
487-
return config_error_nonbool(var);
488-
whitespace_rule_cfg = parse_whitespace_rule(value);
489-
return 0;
490-
}
508+
static int git_default_branch_config(const char *var, const char *value)
509+
{
491510
if (!strcmp(var, "branch.autosetupmerge")) {
492511
if (value && !strcasecmp(value, "always")) {
493512
git_branch_track = BRANCH_TRACK_ALWAYS;
@@ -516,6 +535,29 @@ int git_default_config(const char *var, const char *value, void *dummy)
516535
return 0;
517536
}
518537

538+
int git_default_config(const char *var, const char *value, void *dummy)
539+
{
540+
if (!prefixcmp(var, "core."))
541+
return git_default_core_config(var, value);
542+
543+
if (!prefixcmp(var, "user."))
544+
return git_default_user_config(var, value);
545+
546+
if (!prefixcmp(var, "i18n."))
547+
return git_default_i18n_config(var, value);
548+
549+
if (!prefixcmp(var, "branch."))
550+
return git_default_branch_config(var, value);
551+
552+
if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
553+
pager_use_color = git_config_bool(var,value);
554+
return 0;
555+
}
556+
557+
/* Add other config variables here and to Documentation/config.txt. */
558+
return 0;
559+
}
560+
519561
int git_config_from_file(config_fn_t fn, const char *filename, void *data)
520562
{
521563
int ret;

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const char *apply_default_whitespace;
2929
int zlib_compression_level = Z_BEST_SPEED;
3030
int core_compression_level;
3131
int core_compression_seen;
32+
int fsync_object_files;
3233
size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
3334
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
3435
size_t delta_base_cache_limit = 16 * 1024 * 1024;

sha1_file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,8 @@ int hash_sha1_file(const void *buf, unsigned long len, const char *type,
20932093
/* Finalize a file on disk, and close it. */
20942094
static void close_sha1_file(int fd)
20952095
{
2096-
/* For safe-mode, we could fsync_or_die(fd, "sha1 file") here */
2096+
if (fsync_object_files)
2097+
fsync_or_die(fd, "sha1 file");
20972098
fchmod(fd, 0444);
20982099
if (close(fd) != 0)
20992100
die("unable to write sha1 file");

0 commit comments

Comments
 (0)