]> git.ipfire.org Git - thirdparty/git.git/blobdiff - config.c
Merge branch 'gc/branch-recurse-submodules-fix'
[thirdparty/git.git] / config.c
index e78397725c955e3976fab4016c37cc3870f26ea7..9eb0dbb448bd9f8fe54ba36536ffba5fd7d50bfa 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1323,6 +1323,80 @@ static int git_parse_maybe_bool_text(const char *value)
        return -1;
 }
 
+static const struct fsync_component_name {
+       const char *name;
+       enum fsync_component component_bits;
+} fsync_component_names[] = {
+       { "loose-object", FSYNC_COMPONENT_LOOSE_OBJECT },
+       { "pack", FSYNC_COMPONENT_PACK },
+       { "pack-metadata", FSYNC_COMPONENT_PACK_METADATA },
+       { "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 },
+       { "all", FSYNC_COMPONENTS_ALL },
+};
+
+static enum fsync_component parse_fsync_components(const char *var, const char *string)
+{
+       enum fsync_component current = FSYNC_COMPONENTS_DEFAULT;
+       enum fsync_component positive = 0, negative = 0;
+
+       while (string) {
+               int i;
+               size_t len;
+               const char *ep;
+               int negated = 0;
+               int found = 0;
+
+               string = string + strspn(string, ", \t\n\r");
+               ep = strchrnul(string, ',');
+               len = ep - string;
+               if (!strcmp(string, "none")) {
+                       current = FSYNC_COMPONENT_NONE;
+                       goto next_name;
+               }
+
+               if (*string == '-') {
+                       negated = 1;
+                       string++;
+                       len--;
+                       if (!len)
+                               warning(_("invalid value for variable %s"), var);
+               }
+
+               if (!len)
+                       break;
+
+               for (i = 0; i < ARRAY_SIZE(fsync_component_names); ++i) {
+                       const struct fsync_component_name *n = &fsync_component_names[i];
+
+                       if (strncmp(n->name, string, len))
+                               continue;
+
+                       found = 1;
+                       if (negated)
+                               negative |= n->component_bits;
+                       else
+                               positive |= n->component_bits;
+               }
+
+               if (!found) {
+                       char *component = xstrndup(string, len);
+                       warning(_("ignoring unknown core.fsync component '%s'"), component);
+                       free(component);
+               }
+
+next_name:
+               string = ep;
+       }
+
+       return (current & ~negative) | positive;
+}
+
 int git_parse_maybe_bool(const char *value)
 {
        int v = git_parse_maybe_bool_text(value);
@@ -1600,7 +1674,28 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (!strcmp(var, "core.fsync")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               fsync_components = parse_fsync_components(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.fsyncmethod")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               if (!strcmp(value, "fsync"))
+                       fsync_method = FSYNC_METHOD_FSYNC;
+               else if (!strcmp(value, "writeout-only"))
+                       fsync_method = FSYNC_METHOD_WRITEOUT_ONLY;
+               else
+                       warning(_("ignoring unknown core.fsyncMethod value '%s'"), value);
+
+       }
+
        if (!strcmp(var, "core.fsyncobjectfiles")) {
+               if (fsync_object_files < 0)
+                       warning(_("core.fsyncObjectFiles is deprecated; use core.fsync instead"));
                fsync_object_files = git_config_bool(var, value);
                return 0;
        }