@matheusbsbs / matheus-bagliano / commits / aafe9fbaf4
Fork 0

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 <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Jun 18, 2008 at 15:18 UTC aafe9fbaf4f1d1f27a6f6e3eb3e246fff81240ef
5 files changed +17 -1
Documentation/config.txt
+8
@@ -372,6 +372,14 @@ core.whitespace::
372 does not trigger if the character before such a carriage-return
373 is not a whitespace (not enabled by default).
374
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 +
383 alias.*::
384 Command aliases for the linkgit:git[1] command wrapper - e.g.
385 after defining "alias.last = cat-file commit HEAD", the invocation
cache.h
+1
@@ -435,6 +435,7 @@ extern size_t packed_git_window_size;
435 extern size_t packed_git_limit;
436 extern size_t delta_base_cache_limit;
437 extern int auto_crlf;
438 +extern int fsync_object_files;
439
440 enum safe_crlf {
441 SAFE_CRLF_FALSE = 0,
config.c
+5
@@ -460,6 +460,11 @@ static int git_default_core_config(const char *var, const char *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 }
environment.c
+1
@@ -29,6 +29,7 @@ const char *apply_default_whitespace;
29 int zlib_compression_level = Z_BEST_SPEED;
30 int core_compression_level;
31 int core_compression_seen;
32 +int fsync_object_files;
33 size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
34 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
35 size_t delta_base_cache_limit = 16 * 1024 * 1024;
sha1_file.c
+2 -1
@@ -2083,7 +2083,8 @@ int hash_sha1_file(const void *buf, unsigned long len, const char *type,
2083 /* Finalize a file on disk, and close it. */
2084 static void close_sha1_file(int fd)
2085 {
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");
2088 fchmod(fd, 0444);
2089 if (close(fd) != 0)
2090 die("unable to write sha1 file");