completion: split _git_config()

_git_config() contains two enormous case statements, one to complete configuration sections and variable names, and the other to complete their values. Split these out into two separate helper functions, so in the next patches we can use them to implement completion for 'git -c <TAB>'. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Aug 13, 2019 at 14:26 UTC 42d0efec592ecd6bc8858ffb5d64fb0bbca827d4
1 file changed +30 -9
contrib/completion/git-completion.bash
+30 -9
@@ -2228,7 +2228,8 @@ __git_compute_config_vars ()
2228 __git_config_vars="$(git help --config-for-completion | sort -u)"
2229 }
2230
2231 -_git_config ()
2231 +# Completes possible values of various configuration variables.
2232 +__git_complete_config_variable_value ()
2233 {
2234 local varname
2235
@@ -2320,19 +2321,16 @@ _git_config ()
2321 __gitcomp "7bit 8bit quoted-printable base64"
2322 return
2323 ;;
2323 - --get|--get-all|--unset|--unset-all)
2324 - __gitcomp_nl "$(__git_config_get_set_variables)"
2325 - return
2326 - ;;
2324 *.*)
2325 return
2326 ;;
2327 esac
2328 +}
2329 +
2330 +# Completes configuration sections, subsections, variable names.
2331 +__git_complete_config_variable_name ()
2332 +{
2333 case "$cur" in
2332 - --*)
2333 - __gitcomp_builtin config
2334 - return
2335 - ;;
2334 branch.*.*)
2335 local pfx="${cur%.*}." cur_="${cur##*.}"
2336 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_"
@@ -2407,6 +2405,29 @@ _git_config ()
2405 print s "."
2406 }
2407 ')"
2408 + ;;
2409 + esac
2410 +}
2411 +
2412 +_git_config ()
2413 +{
2414 + case "$prev" in
2415 + --get|--get-all|--unset|--unset-all)
2416 + __gitcomp_nl "$(__git_config_get_set_variables)"
2417 + return
2418 + ;;
2419 + *.*)
2420 + __git_complete_config_variable_value
2421 + return
2422 + ;;
2423 + esac
2424 + case "$cur" in
2425 + --*)
2426 + __gitcomp_builtin config
2427 + ;;
2428 + *)
2429 + __git_complete_config_variable_name
2430 + ;;
2431 esac
2432 }
2433