Skip to content

Commit 6e1a895

Browse files
committed
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
2 parents eb804cd + bc22d84 commit 6e1a895

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

Documentation/config/core.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ but risks losing recent work in the event of an unclean system shutdown.
575575
* `index` hardens the index when it is modified.
576576
* `objects` is an aggregate option that is equivalent to
577577
`loose-object,pack`.
578+
* `reference` hardens references modified in the repo.
578579
* `derived-metadata` is an aggregate option that is equivalent to
579580
`pack-metadata,commit-graph`.
580581
* `committed` is an aggregate option that is currently equivalent to

cache.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ enum fsync_component {
10051005
FSYNC_COMPONENT_PACK_METADATA = 1 << 2,
10061006
FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3,
10071007
FSYNC_COMPONENT_INDEX = 1 << 4,
1008+
FSYNC_COMPONENT_REFERENCE = 1 << 5,
10081009
};
10091010

10101011
#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
@@ -1017,7 +1018,8 @@ enum fsync_component {
10171018
FSYNC_COMPONENTS_DERIVED_METADATA | \
10181019
~FSYNC_COMPONENT_LOOSE_OBJECT)
10191020

1020-
#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS)
1021+
#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
1022+
FSYNC_COMPONENT_REFERENCE)
10211023

10221024
#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
10231025
FSYNC_COMPONENT_INDEX)
@@ -1026,7 +1028,8 @@ enum fsync_component {
10261028
FSYNC_COMPONENT_PACK | \
10271029
FSYNC_COMPONENT_PACK_METADATA | \
10281030
FSYNC_COMPONENT_COMMIT_GRAPH | \
1029-
FSYNC_COMPONENT_INDEX)
1031+
FSYNC_COMPONENT_INDEX | \
1032+
FSYNC_COMPONENT_REFERENCE)
10301033

10311034
/*
10321035
* A bitmask indicating which components of the repo should be fsynced.

config.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,7 @@ static const struct fsync_component_name {
13331333
{ "commit-graph", FSYNC_COMPONENT_COMMIT_GRAPH },
13341334
{ "index", FSYNC_COMPONENT_INDEX },
13351335
{ "objects", FSYNC_COMPONENTS_OBJECTS },
1336+
{ "reference", FSYNC_COMPONENT_REFERENCE },
13361337
{ "derived-metadata", FSYNC_COMPONENTS_DERIVED_METADATA },
13371338
{ "committed", FSYNC_COMPONENTS_COMMITTED },
13381339
{ "added", FSYNC_COMPONENTS_ADDED },

refs/files-backend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
18091809
fd = get_lock_file_fd(&lock->lk);
18101810
if (write_in_full(fd, oid_to_hex(oid), the_hash_algo->hexsz) < 0 ||
18111811
write_in_full(fd, &term, 1) < 0 ||
1812+
fsync_component(FSYNC_COMPONENT_REFERENCE, get_lock_file_fd(&lock->lk)) < 0 ||
18121813
close_ref_gently(lock) < 0) {
18131814
strbuf_addf(err,
18141815
"couldn't write '%s'", get_lock_file_path(&lock->lk));

refs/packed-backend.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,8 @@ static int write_with_updates(struct packed_ref_store *refs,
12621262
goto error;
12631263
}
12641264

1265-
if (close_tempfile_gently(refs->tempfile)) {
1265+
if (fsync_component(FSYNC_COMPONENT_REFERENCE, get_tempfile_fd(refs->tempfile)) ||
1266+
close_tempfile_gently(refs->tempfile)) {
12661267
strbuf_addf(err, "error closing file %s: %s",
12671268
get_tempfile_path(refs->tempfile),
12681269
strerror(errno));

0 commit comments

Comments
 (0)