git-pull.c: introduce git_pull_config()

git-pull makes a seperate call to git_config_get_bool() to read the value of "rebase.autostash". This can be reduced as a call to git_config() is already there in the code. Introduce a callback function git_pull_config() to read "rebase.autostash" along with other variables. Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Paul Tan <pyokagan@gmail.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Mehul Jain <mehul.jain2029@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mehul Jain committed Mar 21, 2016 at 23:48 UTC c48d73bdececb38af237450724b1a67307d7a013
1 file changed +15 -3
builtin/pull.c
+15 -3
@@ -86,6 +86,7 @@ static char *opt_commit;
86 static char *opt_edit;
87 static char *opt_ff;
88 static char *opt_verify_signatures;
89 +static int config_autostash;
90 static struct argv_array opt_strategies = ARGV_ARRAY_INIT;
91 static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;
92 static char *opt_gpg_sign;
@@ -305,6 +306,18 @@ static enum rebase_type config_get_rebase(void)
306 return REBASE_FALSE;
307 }
308
309 +/**
310 + * Read config variables.
311 + */
312 +static int git_pull_config(const char *var, const char *value, void *cb)
313 +{
314 + if (!strcmp(var, "rebase.autostash")) {
315 + config_autostash = git_config_bool(var, value);
316 + return 0;
317 + }
318 + return git_default_config(var, value, cb);
319 +}
320 +
321 /**
322 * Returns 1 if there are unstaged changes, 0 otherwise.
323 */
@@ -823,7 +836,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
836 if (opt_rebase < 0)
837 opt_rebase = config_get_rebase();
838
826 - git_config(git_default_config, NULL);
839 + git_config(git_pull_config, NULL);
840
841 if (read_cache_unmerged())
842 die_resolve_conflict("Pull");
@@ -835,12 +848,11 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
848 hashclr(orig_head);
849
850 if (opt_rebase) {
838 - int autostash = 0;
851 + int autostash = config_autostash;
852
853 if (is_null_sha1(orig_head) && !is_cache_unborn())
854 die(_("Updating an unborn branch with changes added to the index."));
855
843 - git_config_get_bool("rebase.autostash", &autostash);
856 if (!autostash)
857 die_on_unclean_work_tree(prefix);
858