SVN.pm::parse_svn_date: allow timestamps with a single-digit hour
[gitweb.git] / builtin / config.c
index c046f54829b5ad361d81b2eceae5738c8f59ab21..92ebf23f0a9aa0e052ad68d60e17d0783f633a1c 100644 (file)
@@ -22,6 +22,7 @@ static char term = '\n';
 
 static int use_global_config, use_system_config, use_local_config;
 static const char *given_config_file;
+static const char *given_config_blob;
 static int actions, types;
 static const char *get_color_slot, *get_colorbool_slot;
 static int end_null;
@@ -51,10 +52,11 @@ static int respect_includes = -1;
 
 static struct option builtin_config_options[] = {
        OPT_GROUP(N_("Config file location")),
-       OPT_BOOLEAN(0, "global", &use_global_config, N_("use global config file")),
-       OPT_BOOLEAN(0, "system", &use_system_config, N_("use system config file")),
-       OPT_BOOLEAN(0, "local", &use_local_config, N_("use repository config file")),
+       OPT_BOOL(0, "global", &use_global_config, N_("use global config file")),
+       OPT_BOOL(0, "system", &use_system_config, N_("use system config file")),
+       OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")),
        OPT_STRING('f', "file", &given_config_file, N_("file"), N_("use given config file")),
+       OPT_STRING(0, "blob", &given_config_blob, N_("blob-id"), N_("read config from given blob object")),
        OPT_GROUP(N_("Action")),
        OPT_BIT(0, "get", &actions, N_("get value: name [value-regex]"), ACTION_GET),
        OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-regex]"), ACTION_GET_ALL),
@@ -76,7 +78,7 @@ static struct option builtin_config_options[] = {
        OPT_BIT(0, "bool-or-int", &types, N_("value is --bool or --int"), TYPE_BOOL_OR_INT),
        OPT_BIT(0, "path", &types, N_("value is a path (file or directory name)"), TYPE_PATH),
        OPT_GROUP(N_("Other")),
-       OPT_BOOLEAN('z', "null", &end_null, N_("terminate values with NUL byte")),
+       OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")),
        OPT_BOOL(0, "includes", &respect_includes, N_("respect include directives on lookup")),
        OPT_END(),
 };
@@ -117,7 +119,8 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
                must_print_delim = 1;
        }
        if (types == TYPE_INT)
-               sprintf(value, "%d", git_config_int(key_, value_ ? value_ : ""));
+               sprintf(value, "%"PRId64,
+                       git_config_int64(key_, value_ ? value_ : ""));
        else if (types == TYPE_BOOL)
                vptr = git_config_bool(key_, value_) ? "true" : "false";
        else if (types == TYPE_BOOL_OR_INT) {
@@ -221,7 +224,8 @@ static int get_value(const char *key_, const char *regex_)
        }
 
        git_config_with_options(collect_config, &values,
-                               given_config_file, respect_includes);
+                               given_config_file, given_config_blob,
+                               respect_includes);
 
        ret = !values.nr;
 
@@ -265,8 +269,8 @@ static char *normalize_value(const char *key, const char *value)
        else {
                normalized = xmalloc(64);
                if (types == TYPE_INT) {
-                       int v = git_config_int(key, value);
-                       sprintf(normalized, "%d", v);
+                       int64_t v = git_config_int64(key, value);
+                       sprintf(normalized, "%"PRId64, v);
                }
                else if (types == TYPE_BOOL)
                        sprintf(normalized, "%s",
@@ -305,7 +309,8 @@ static void get_color(const char *def_color)
        get_color_found = 0;
        parsed_color[0] = '\0';
        git_config_with_options(git_get_color_config, NULL,
-                               given_config_file, respect_includes);
+                               given_config_file, given_config_blob,
+                               respect_includes);
 
        if (!get_color_found && def_color)
                color_parse(def_color, "command line", parsed_color);
@@ -332,8 +337,10 @@ static int get_colorbool(int print)
 {
        get_colorbool_found = -1;
        get_diff_color_found = -1;
+       get_color_ui_found = -1;
        git_config_with_options(git_get_colorbool_config, NULL,
-                               given_config_file, respect_includes);
+                               given_config_file, given_config_blob,
+                               respect_includes);
 
        if (get_colorbool_found < 0) {
                if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -342,6 +349,10 @@ static int get_colorbool(int print)
                        get_colorbool_found = get_color_ui_found;
        }
 
+       if (get_colorbool_found < 0)
+               /* default value if none found in config */
+               get_colorbool_found = GIT_COLOR_AUTO;
+
        get_colorbool_found = want_color(get_colorbool_found);
 
        if (print) {
@@ -351,6 +362,12 @@ static int get_colorbool(int print)
                return get_colorbool_found ? 0 : 1;
 }
 
+static void check_blob_write(void)
+{
+       if (given_config_blob)
+               die("writing config blobs is not supported");
+}
+
 struct urlmatch_current_candidate_value {
        char value_is_null;
        struct strbuf value;
@@ -404,7 +421,7 @@ static int get_urlmatch(const char *var, const char *url)
        config.cb = &values;
 
        if (!url_normalize(url, &config.url))
-               die(config.url.err);
+               die("%s", config.url.err);
 
        config.section = dup_downcase(var);
        section_tail = strchr(config.section, '.');
@@ -418,7 +435,7 @@ static int get_urlmatch(const char *var, const char *url)
        }
 
        git_config_with_options(urlmatch_config_entry, &config,
-                               given_config_file, respect_includes);
+                               given_config_file, NULL, respect_includes);
 
        for_each_string_list_item(item, &values) {
                struct urlmatch_current_candidate_value *matched = item->util;
@@ -453,7 +470,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                             builtin_config_usage,
                             PARSE_OPT_STOP_AT_NON_OPTION);
 
-       if (use_global_config + use_system_config + use_local_config + !!given_config_file > 1) {
+       if (use_global_config + use_system_config + use_local_config +
+           !!given_config_file + !!given_config_blob > 1) {
                error("only one config file at a time.");
                usage_with_options(builtin_config_usage, builtin_config_options);
        }
@@ -473,8 +491,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                         */
                        die("$HOME not set");
 
-               if (access_or_warn(user_config, R_OK) &&
-                   xdg_config && !access_or_warn(xdg_config, R_OK))
+               if (access_or_warn(user_config, R_OK, 0) &&
+                   xdg_config && !access_or_warn(xdg_config, R_OK, 0))
                        given_config_file = xdg_config;
                else
                        given_config_file = user_config;
@@ -532,6 +550,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                check_argc(argc, 0, 0);
                if (git_config_with_options(show_all_config, NULL,
                                            given_config_file,
+                                           given_config_blob,
                                            respect_includes) < 0) {
                        if (given_config_file)
                                die_errno("unable to read config file '%s'",
@@ -544,6 +563,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                check_argc(argc, 0, 0);
                if (!given_config_file && nongit)
                        die("not in a git directory");
+               if (given_config_blob)
+                       die("editing blobs is not supported");
                git_config(git_default_config, NULL);
                launch_editor(given_config_file ?
                              given_config_file : git_path("config"),
@@ -551,6 +572,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
        }
        else if (actions == ACTION_SET) {
                int ret;
+               check_blob_write();
                check_argc(argc, 2, 2);
                value = normalize_value(argv[0], argv[1]);
                ret = git_config_set_in_file(given_config_file, argv[0], value);
@@ -560,18 +582,21 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                return ret;
        }
        else if (actions == ACTION_SET_ALL) {
+               check_blob_write();
                check_argc(argc, 2, 3);
                value = normalize_value(argv[0], argv[1]);
                return git_config_set_multivar_in_file(given_config_file,
                                                       argv[0], value, argv[2], 0);
        }
        else if (actions == ACTION_ADD) {
+               check_blob_write();
                check_argc(argc, 2, 2);
                value = normalize_value(argv[0], argv[1]);
                return git_config_set_multivar_in_file(given_config_file,
                                                       argv[0], value, "^$", 0);
        }
        else if (actions == ACTION_REPLACE_ALL) {
+               check_blob_write();
                check_argc(argc, 2, 3);
                value = normalize_value(argv[0], argv[1]);
                return git_config_set_multivar_in_file(given_config_file,
@@ -598,6 +623,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                return get_urlmatch(argv[0], argv[1]);
        }
        else if (actions == ACTION_UNSET) {
+               check_blob_write();
                check_argc(argc, 1, 2);
                if (argc == 2)
                        return git_config_set_multivar_in_file(given_config_file,
@@ -607,12 +633,14 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                                                      argv[0], NULL);
        }
        else if (actions == ACTION_UNSET_ALL) {
+               check_blob_write();
                check_argc(argc, 1, 2);
                return git_config_set_multivar_in_file(given_config_file,
                                                       argv[0], NULL, argv[1], 1);
        }
        else if (actions == ACTION_RENAME_SECTION) {
                int ret;
+               check_blob_write();
                check_argc(argc, 2, 2);
                ret = git_config_rename_section_in_file(given_config_file,
                                                        argv[0], argv[1]);
@@ -623,6 +651,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
        }
        else if (actions == ACTION_REMOVE_SECTION) {
                int ret;
+               check_blob_write();
                check_argc(argc, 1, 1);
                ret = git_config_rename_section_in_file(given_config_file,
                                                        argv[0], NULL);
@@ -642,9 +671,3 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 
        return 0;
 }
-
-int cmd_repo_config(int argc, const char **argv, const char *prefix)
-{
-       fprintf(stderr, "WARNING: git repo-config is deprecated in favor of git config.\n");
-       return cmd_config(argc, argv, prefix);
-}