mirror of
https://github.com/cheat/cheat.git
synced 2026-05-27 19:48:44 +02:00
4799c2cb17
Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) from 5.16.5 to 5.19.1. - [Release notes](https://github.com/go-git/go-git/releases) - [Changelog](https://github.com/go-git/go-git/blob/main/HISTORY.md) - [Commits](https://github.com/go-git/go-git/compare/v5.16.5...v5.19.1) --- updated-dependencies: - dependency-name: github.com/go-git/go-git/v5 dependency-version: 5.19.1 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
package config
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// OptBool is a tri-state boolean: unset, explicitly false, or explicitly true.
|
|
// Its zero value (OptBoolUnset) means the setting was not specified, which
|
|
// allows merge logic based on reflect.Value.IsZero to skip unset fields while
|
|
// still letting an explicit "false" override a previously set "true".
|
|
type OptBool byte
|
|
|
|
const (
|
|
// OptBoolUnset indicates the setting was not specified.
|
|
OptBoolUnset OptBool = iota
|
|
// OptBoolFalse indicates the setting was explicitly set to false.
|
|
OptBoolFalse
|
|
// OptBoolTrue indicates the setting was explicitly set to true.
|
|
OptBoolTrue
|
|
)
|
|
|
|
// NewOptBool converts a plain bool into an OptBool.
|
|
func NewOptBool(v bool) OptBool {
|
|
if v {
|
|
return OptBoolTrue
|
|
}
|
|
return OptBoolFalse
|
|
}
|
|
|
|
// IsTrue returns whether the value is explicitly true.
|
|
func (o OptBool) IsTrue() bool { return o == OptBoolTrue }
|
|
|
|
// IsSet returns whether the value was explicitly specified (true or false).
|
|
func (o OptBool) IsSet() bool { return o != OptBoolUnset }
|
|
|
|
func (o OptBool) String() string {
|
|
switch o {
|
|
case OptBoolTrue:
|
|
return "true"
|
|
case OptBoolFalse:
|
|
return "false"
|
|
default:
|
|
return "unset"
|
|
}
|
|
}
|
|
|
|
// FormatBool returns the strconv-formatted value. Only meaningful when IsSet.
|
|
func (o OptBool) FormatBool() string {
|
|
return strconv.FormatBool(o.IsTrue())
|
|
}
|
|
|
|
// parseConfigBool mirrors upstream Git's git_parse_maybe_bool: it
|
|
// accepts true/yes/on (→ OptBoolTrue) and false/no/off (→
|
|
// OptBoolFalse) case-insensitively, plus any decimal integer (zero
|
|
// → OptBoolFalse, non-zero → OptBoolTrue). Empty or otherwise
|
|
// unrecognised values return OptBoolUnset, leaving the caller's
|
|
// platform default in place. The empty-string handling is the only
|
|
// intentional divergence from upstream, which returns false for
|
|
// empty: in our unmarshalCore caller, an empty value means the key
|
|
// is unset and the platform default should apply.
|
|
//
|
|
// Reference: upstream Git git_parse_maybe_bool_text at parse.c
|
|
// L157-L173 and git_parse_maybe_bool at parse.c L174-L182 in tag
|
|
// v2.54.0[1].
|
|
//
|
|
// [1]: https://github.com/git/git/blob/v2.54.0/parse.c#L157-L182
|
|
func parseConfigBool(v string) OptBool {
|
|
switch strings.ToLower(v) {
|
|
case "true", "yes", "on":
|
|
return OptBoolTrue
|
|
case "false", "no", "off":
|
|
return OptBoolFalse
|
|
}
|
|
if i, err := strconv.Atoi(v); err == nil {
|
|
if i != 0 {
|
|
return OptBoolTrue
|
|
}
|
|
return OptBoolFalse
|
|
}
|
|
return OptBoolUnset
|
|
}
|