Re: [PATCH v6 1/4] submodule: add get_submodule_config helper funtion
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 3, 2012, 19:30 UTC
- Message-ID
- <7vehj7q6gr.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <436a73a8fdc8f0695aa597d53483d4c4bae16ebb.1354417618.git.wking@tremily.us>
"W. Trevor King" <wking@tremily.us> writes:
Show 35 quoted lines
> From: "W. Trevor King" <wking@tremily.us>
>
> Several submodule configuration variables
> (e.g. fetchRecurseSubmodules) are read from .gitmodules with local
> overrides from the usual git config files. This shell function mimics
> that logic to help initialize configuration variables in
> git-submodule.sh.
>
> Signed-off-by: W. Trevor King <wking@tremily.us>
> ---
> git-submodule.sh | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/git-submodule.sh b/git-submodule.sh
> index ab6b110..97ce5e4 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -152,6 +152,33 @@ die_if_unmatched ()
> }
>
> #
> +# Print a submodule configuration setting
> +#
> +# $1 = submodule name
> +# $2 = option name
> +# $3 = default value
> +#
> +# Checks in the usual git-config places first (for overrides),
> +# otherwise it falls back on .gitmodules. This allows you to
> +# distribute project-wide defaults in .gitmodules, while still
> +# customizing individual repositories if necessary. If the option is
> +# not in .gitmodules either, print a default value.
> +#
> +get_submodule_config()
> +{style (see CodingGuidelines):
get_submodule_config () {> + name="$1" > + option="$2" > + default="$3" > + value=$(git config submodule."$name"."$option")
This will get unwieldy quickly once we have submodule.$name.$var that takes a boolean option, as there are different ways to spell boolean and "git config --bool" is the way to ask for canonicalized "true" or "false".
If we never query any boolean via this helper function, it is obviously not an issue, though.
Show 12 quoted lines
> + if test -z "$value"
> + then
> + value=$(git config -f .gitmodules submodule."$name"."$option")
> + fi
> + printf '%s' "${value:-$default}"
> +}
> +
> +
> +#
> # Map submodule path to submodule name
> #
> # $1 = path