]> git.ipfire.org Git - thirdparty/git.git/blobdiff - diff.c
diff: introduce diff.submodule configuration variable
[thirdparty/git.git] / diff.c
diff --git a/diff.c b/diff.c
index 32142dba64e0a6e926101c38b6efd95d21e0dc82..178df851aeaabb5a51b72599bde9feb2ef6e678f 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -25,7 +25,8 @@
 static int diff_detect_rename_default;
 static int diff_rename_limit_default = 400;
 static int diff_suppress_blank_empty;
-int diff_use_color_default = -1;
+static int diff_use_color_default = -1;
+static int diff_context_default = 3;
 static const char *diff_word_regex_cfg;
 static const char *external_diff_cmd_cfg;
 int diff_auto_refresh_index = 1;
@@ -120,6 +121,17 @@ static int parse_dirstat_params(struct diff_options *options, const char *params
        return ret;
 }
 
+static int parse_submodule_params(struct diff_options *options, const char *value)
+{
+       if (!strcmp(value, "log"))
+               DIFF_OPT_SET(options, SUBMODULE_LOG);
+       else if (!strcmp(value, "short"))
+               DIFF_OPT_CLR(options, SUBMODULE_LOG);
+       else
+               return -1;
+       return 0;
+}
+
 static int git_config_rename(const char *var, const char *value)
 {
        if (!value)
@@ -141,6 +153,12 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
                diff_use_color_default = git_config_colorbool(var, value);
                return 0;
        }
+       if (!strcmp(var, "diff.context")) {
+               diff_context_default = git_config_int(var, value);
+               if (diff_context_default < 0)
+                       return -1;
+               return 0;
+       }
        if (!strcmp(var, "diff.renames")) {
                diff_detect_rename_default = git_config_rename(var, value);
                return 0;
@@ -169,6 +187,13 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
        if (!strcmp(var, "diff.ignoresubmodules"))
                handle_ignore_submodules_arg(&default_diff_options, value);
 
+       if (!strcmp(var, "diff.submodule")) {
+               if (parse_submodule_params(&default_diff_options, value))
+                       warning(_("Unknown value for 'diff.submodule' config variable: '%s'"),
+                               value);
+               return 0;
+       }
+
        if (git_color_config(var, value, cb) < 0)
                return -1;
 
@@ -3170,7 +3195,7 @@ void diff_setup(struct diff_options *options)
        options->break_opt = -1;
        options->rename_limit = -1;
        options->dirstat_permille = diff_dirstat_permille_default;
-       options->context = 3;
+       options->context = diff_context_default;
        DIFF_OPT_SET(options, RENAME_EMPTY);
 
        options->change = diff_change;
@@ -3466,6 +3491,14 @@ static int parse_dirstat_opt(struct diff_options *options, const char *params)
        return 1;
 }
 
+static int parse_submodule_opt(struct diff_options *options, const char *value)
+{
+       if (parse_submodule_params(options, value))
+               die(_("Failed to parse --submodule option parameter: '%s'"),
+                       value);
+       return 1;
+}
+
 int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 {
        const char *arg = av[0];
@@ -3646,10 +3679,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                handle_ignore_submodules_arg(options, arg + 20);
        } else if (!strcmp(arg, "--submodule"))
                DIFF_OPT_SET(options, SUBMODULE_LOG);
-       else if (!prefixcmp(arg, "--submodule=")) {
-               if (!strcmp(arg + 12, "log"))
-                       DIFF_OPT_SET(options, SUBMODULE_LOG);
-       }
+       else if (!prefixcmp(arg, "--submodule="))
+               return parse_submodule_opt(options, arg + 12);
 
        /* misc options */
        else if (!strcmp(arg, "-z"))