Skip to content

Commit aafe9fb

Browse files
torvaldsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1141f49 commit aafe9fb

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ static int git_default_core_config(const char *var, const char *value)
460460
return 0;
461461
}
462462

463+
if (!strcmp(var, "core.fsyncobjectfiles")) {
464+
fsync_object_files = git_config_bool(var, value);
465+
return 0;
466+
}
467+
463468
/* Add other config variables here and to Documentation/config.txt. */
464469
return 0;
465470
}

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
@@ -2083,7 +2083,8 @@ int hash_sha1_file(const void *buf, unsigned long len, const char *type,
20832083
/* Finalize a file on disk, and close it. */
20842084
static void close_sha1_file(int fd)
20852085
{
2086-
/* For safe-mode, we could fsync_or_die(fd, "sha1 file") here */
2086+
if (fsync_object_files)
2087+
fsync_or_die(fd, "sha1 file");
20872088
fchmod(fd, 0444);
20882089
if (close(fd) != 0)
20892090
die("unable to write sha1 file");

0 commit comments

Comments
 (0)