Skip to content

Commit 844a8ad

Browse files
neerajsi-msftgitster
authored andcommitted
core.fsync: add configuration parsing
This change introduces code to parse the core.fsync setting and configure the fsync_components variable. core.fsync is configured as a comma-separated list of component names to sync. Each time a core.fsync variable is encountered in the configuration heirarchy, we start off with a clean state with the platform default value. Passing 'none' resets the value to indicate nothing will be synced. We gather all negative and positive entries from the comma separated list and then compute the new value by removing all the negative entries and adding all of the positive entries. We issue a warning for components that are not recognized so that the configuration code is compatible with configs from future versions of Git with more repo components. Complete documentation for the new setting is included in a later patch in the series so that it can be reviewed once in final form. Signed-off-by: Neeraj Singh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 020406e commit 844a8ad

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed

Documentation/config/core.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,12 @@ core.fsyncMethod::
558558

559559
core.fsyncObjectFiles::
560560
This boolean will enable 'fsync()' when writing object files.
561+
This setting is deprecated. Use core.fsync instead.
561562
+
562-
This is a total waste of time and effort on a filesystem that orders
563-
data writes properly, but can be useful for filesystems that do not use
564-
journalling (traditional UNIX filesystems) or that only journal metadata
565-
and not file contents (OS X's HFS+, or Linux ext3 with "data=writeback").
563+
This setting affects data added to the Git repository in loose-object
564+
form. When set to true, Git will issue an fsync or similar system call
565+
to flush caches so that loose-objects remain consistent in the face
566+
of a unclean system shutdown.
566567

567568
core.preloadIndex::
568569
Enable parallel index preload for operations like 'git diff'

config.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,73 @@ static int git_parse_maybe_bool_text(const char *value)
13231323
return -1;
13241324
}
13251325

1326+
static const struct fsync_component_name {
1327+
const char *name;
1328+
enum fsync_component component_bits;
1329+
} fsync_component_names[] = {
1330+
{ "loose-object", FSYNC_COMPONENT_LOOSE_OBJECT },
1331+
{ "pack", FSYNC_COMPONENT_PACK },
1332+
{ "pack-metadata", FSYNC_COMPONENT_PACK_METADATA },
1333+
{ "commit-graph", FSYNC_COMPONENT_COMMIT_GRAPH },
1334+
};
1335+
1336+
static enum fsync_component parse_fsync_components(const char *var, const char *string)
1337+
{
1338+
enum fsync_component current = FSYNC_COMPONENTS_DEFAULT;
1339+
enum fsync_component positive = 0, negative = 0;
1340+
1341+
while (string) {
1342+
int i;
1343+
size_t len;
1344+
const char *ep;
1345+
int negated = 0;
1346+
int found = 0;
1347+
1348+
string = string + strspn(string, ", \t\n\r");
1349+
ep = strchrnul(string, ',');
1350+
len = ep - string;
1351+
if (!strcmp(string, "none")) {
1352+
current = FSYNC_COMPONENT_NONE;
1353+
goto next_name;
1354+
}
1355+
1356+
if (*string == '-') {
1357+
negated = 1;
1358+
string++;
1359+
len--;
1360+
if (!len)
1361+
warning(_("invalid value for variable %s"), var);
1362+
}
1363+
1364+
if (!len)
1365+
break;
1366+
1367+
for (i = 0; i < ARRAY_SIZE(fsync_component_names); ++i) {
1368+
const struct fsync_component_name *n = &fsync_component_names[i];
1369+
1370+
if (strncmp(n->name, string, len))
1371+
continue;
1372+
1373+
found = 1;
1374+
if (negated)
1375+
negative |= n->component_bits;
1376+
else
1377+
positive |= n->component_bits;
1378+
}
1379+
1380+
if (!found) {
1381+
char *component = xstrndup(string, len);
1382+
warning(_("ignoring unknown core.fsync component '%s'"), component);
1383+
free(component);
1384+
}
1385+
1386+
next_name:
1387+
string = ep;
1388+
}
1389+
1390+
return (current & ~negative) | positive;
1391+
}
1392+
13261393
int git_parse_maybe_bool(const char *value)
13271394
{
13281395
int v = git_parse_maybe_bool_text(value);
@@ -1600,6 +1667,13 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
16001667
return 0;
16011668
}
16021669

1670+
if (!strcmp(var, "core.fsync")) {
1671+
if (!value)
1672+
return config_error_nonbool(var);
1673+
fsync_components = parse_fsync_components(var, value);
1674+
return 0;
1675+
}
1676+
16031677
if (!strcmp(var, "core.fsyncmethod")) {
16041678
if (!value)
16051679
return config_error_nonbool(var);
@@ -1613,6 +1687,8 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
16131687
}
16141688

16151689
if (!strcmp(var, "core.fsyncobjectfiles")) {
1690+
if (fsync_object_files < 0)
1691+
warning(_("core.fsyncobjectfiles is deprecated; use core.fsync instead"));
16161692
fsync_object_files = git_config_bool(var, value);
16171693
return 0;
16181694
}

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const char *git_attributes_file;
4242
const char *git_hooks_path;
4343
int zlib_compression_level = Z_BEST_SPEED;
4444
int pack_compression_level = Z_DEFAULT_COMPRESSION;
45-
int fsync_object_files;
45+
int fsync_object_files = -1;
4646
int use_fsync = -1;
4747
enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
4848
enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;

0 commit comments

Comments
 (0)