summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2022-03-25 16:38:24 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2022-03-25 16:38:25 -0700
commit6e1a8952e90e5d125177dbdee21425d1ba2d3584 (patch)
treecda2c48629c1e926d5b971954a038e79f0f0a325
parentMerge branch 'ns/core-fsyncmethod' (diff)
parentcore.fsync: new option to harden references (diff)
downloadtgif-6e1a8952e90e5d125177dbdee21425d1ba2d3584.tar.xz
Merge branch 'ps/fsync-refs'
Updates to refs traditionally weren't fsync'ed, but we can configure using core.fsync variable to do so. * ps/fsync-refs: core.fsync: new option to harden references
-rw-r--r--Documentation/config/core.txt1
-rw-r--r--cache.h7
-rw-r--r--config.c1
-rw-r--r--refs/files-backend.c1
-rw-r--r--refs/packed-backend.c3
5 files changed, 10 insertions, 3 deletions
diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt
index 9a3ad71e9e..9da3e5d88f 100644
--- a/Documentation/config/core.txt
+++ b/Documentation/config/core.txt
@@ -575,6 +575,7 @@ but risks losing recent work in the event of an unclean system shutdown.
* `index` hardens the index when it is modified.
* `objects` is an aggregate option that is equivalent to
`loose-object,pack`.
+* `reference` hardens references modified in the repo.
* `derived-metadata` is an aggregate option that is equivalent to
`pack-metadata,commit-graph`.
* `committed` is an aggregate option that is currently equivalent to
diff --git a/cache.h b/cache.h
index c643268a93..ef7d34b7a0 100644
--- a/cache.h
+++ b/cache.h
@@ -1005,6 +1005,7 @@ enum fsync_component {
FSYNC_COMPONENT_PACK_METADATA = 1 << 2,
FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3,
FSYNC_COMPONENT_INDEX = 1 << 4,
+ FSYNC_COMPONENT_REFERENCE = 1 << 5,
};
#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
@@ -1017,7 +1018,8 @@ enum fsync_component {
FSYNC_COMPONENTS_DERIVED_METADATA | \
~FSYNC_COMPONENT_LOOSE_OBJECT)
-#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS)
+#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
+ FSYNC_COMPONENT_REFERENCE)
#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
FSYNC_COMPONENT_INDEX)
@@ -1026,7 +1028,8 @@ enum fsync_component {
FSYNC_COMPONENT_PACK | \
FSYNC_COMPONENT_PACK_METADATA | \
FSYNC_COMPONENT_COMMIT_GRAPH | \
- FSYNC_COMPONENT_INDEX)
+ FSYNC_COMPONENT_INDEX | \
+ FSYNC_COMPONENT_REFERENCE)
/*
* A bitmask indicating which components of the repo should be fsynced.
diff --git a/config.c b/config.c
index eb75f65338..3c9b6b589a 100644
--- a/config.c
+++ b/config.c
@@ -1333,6 +1333,7 @@ static const struct fsync_component_name {
{ "commit-graph", FSYNC_COMPONENT_COMMIT_GRAPH },
{ "index", FSYNC_COMPONENT_INDEX },
{ "objects", FSYNC_COMPONENTS_OBJECTS },
+ { "reference", FSYNC_COMPONENT_REFERENCE },
{ "derived-metadata", FSYNC_COMPONENTS_DERIVED_METADATA },
{ "committed", FSYNC_COMPONENTS_COMMITTED },
{ "added", FSYNC_COMPONENTS_ADDED },
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0457ecdb42..bc81b52591 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1809,6 +1809,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
fd = get_lock_file_fd(&lock->lk);
if (write_in_full(fd, oid_to_hex(oid), the_hash_algo->hexsz) < 0 ||
write_in_full(fd, &term, 1) < 0 ||
+ fsync_component(FSYNC_COMPONENT_REFERENCE, get_lock_file_fd(&lock->lk)) < 0 ||
close_ref_gently(lock) < 0) {
strbuf_addf(err,
"couldn't write '%s'", get_lock_file_path(&lock->lk));
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index f56e2cc635..55a1426e67 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1262,7 +1262,8 @@ static int write_with_updates(struct packed_ref_store *refs,
goto error;
}
- if (close_tempfile_gently(refs->tempfile)) {
+ if (fsync_component(FSYNC_COMPONENT_REFERENCE, get_tempfile_fd(refs->tempfile)) ||
+ close_tempfile_gently(refs->tempfile)) {
strbuf_addf(err, "error closing file %s: %s",
get_tempfile_path(refs->tempfile),
strerror(errno));