// IsVersionAtLeast returns whether the git version is the one specified or higher
// argument is plain version string separated by '.' e.g. "2.3.1" but can omit minor/patch
9783
func IsGitVersionAtLeast(ver string) bool {
	gitver, err := Version()
	if err != nil {
		tracerx.Printf("Error getting git version: %v", err)
		return false
	}
	return IsVersionAtLeast(gitver, ver)
}
102453
func isVersion(s string) bool {
	hasPunct := false
	onlyNumber := true
	onlyHexLetter := true
	for _, r := range s {
		isNumber := unicode.IsNumber(r)
		isLetter := unicode.IsLetter(r)

		hasPunct = hasPunct || unicode.IsPunct(r)
		onlyNumber = onlyNumber && isNumber

		if isLetter {
			low := unicode.ToLower(r)
			onlyHexLetter = onlyHexLetter && low <= 'f'
		}
	}
	if hasPunct {
		return true
	}
	if !onlyHexLetter {
		return true
	}

	num, err := strconv.ParseInt(s, 10, 64)
	if err == nil {
		if num > 100 {
			return false // numeric revision.
		}
	}

	if len(s) > 5 && onlyHexLetter {
		return false // hex revision
	}
	return true
}
857930
func (g *GithubUpdater) GetCurrentVersion() string {
	g.RLock()
	defer g.RUnlock()
	return g.version
}
571218
func versionAtMost(version, max []int) (bool, error) {
	if comp, err := versionCompare(version, max); err != nil {
		return false, err
	} else if comp == 1 {
		return false, nil
	}
	return true, nil
}
1272159
func (c *commandeer) isThemeVsHugoVersionMismatch(fs afero.Fs) (dir string, mismatch bool, requiredMinVersion string) {
	if !c.hugo.PathSpec.ThemeSet() {
		return
	}

	for _, absThemeDir := range c.hugo.BaseFs.AbsThemeDirs {

		path := filepath.Join(absThemeDir, "theme.toml")

		exists, err := helpers.Exists(path, fs)

		if err != nil || !exists {
			continue
		}

		b, err := afero.ReadFile(fs, path)
		if err != nil {
			continue
		}

		tomlMeta, err := metadecoders.Default.UnmarshalToMap(b, metadecoders.TOML)
		if err != nil {
			continue
		}

		if minVersion, ok := tomlMeta["min_version"]; ok {
			if hugo.CompareVersion(minVersion) > 0 {
				return absThemeDir, true, fmt.Sprint(minVersion)
			}
		}

	}

	return
}
1230941
func StringTLSVersion(version string) uint16 {
	switch version {
	case "1.2":
		return tls.VersionTLS12
	case "1.1":
		return tls.VersionTLS11
	default:
		return tls.VersionTLS10
	}
}
799705
func checkAttributeVersionMatch(ctx Context, lVal, rVal *psstructs.Attribute) bool {
	// Parse the version
	var versionStr string
	if s, ok := lVal.GetString(); ok {
		versionStr = s
	} else if i, ok := lVal.GetInt(); ok {
		versionStr = fmt.Sprintf("%d", i)
	} else {
		return false
	}

	// Parse the version
	vers, err := version.NewVersion(versionStr)
	if err != nil {
		return false
	}

	// Constraint must be a string
	constraintStr, ok := rVal.GetString()
	if !ok {
		return false
	}

	// Check the cache for a match
	cache := ctx.VersionConstraintCache()
	constraints := cache[constraintStr]

	// Parse the constraints
	if constraints == nil {
		constraints, err = version.NewConstraint(constraintStr)
		if err != nil {
			return false
		}
		cache[constraintStr] = constraints
	}

	// Check the constraints against the version
	return constraints.Check(vers)
}
1035008
func (d *diagnosticsCollector) CheckVersion() error {
	var rsp versionResponse
	req, err := http.NewRequest("GET", d.VersionURL, nil)
	if err != nil {
		return errors.Wrap(err, "making request")
	}
	resp, err := d.client.Do(req)
	if err != nil {
		return errors.Wrap(err, "getting version")
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("http: status=%d", resp.StatusCode)
	} else if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil {
		return fmt.Errorf("json decode: %s", err)
	}

	// If version has not changed since the last check, return
	if rsp.Version == d.lastVersion {
		return nil
	}

	d.lastVersion = rsp.Version
	if err := d.compareVersion(rsp.Version); err != nil {
		d.Logger.Printf("%s\n", err.Error())
	}

	return nil
}
146428
func CompareVersions(a, b string) Relation {
	arel, apre := versionParts(a)
	brel, bpre := versionParts(b)

	minlen := len(arel)
	if l := len(brel); l < minlen {
		minlen = l
	}

	// First compare major-minor-patch versions
	for i := 0; i < minlen; i++ {
		if arel[i] < brel[i] {
			if i == 0 {
				// major version difference
				if arel[0] == 0 && brel[0] == 1 {
					// special case, v0.x is equivalent in majorness to v1.x.
					return Older
				}
				return MajorOlder
			}
			// minor or patch version difference
			return Older
		}
		if arel[i] > brel[i] {
			if i == 0 {
				// major version difference
				if arel[0] == 1 && brel[0] == 0 {
					// special case, v0.x is equivalent in majorness to v1.x.
					return Newer
				}
				return MajorNewer
			}
			// minor or patch version difference
			return Newer
		}
	}

	// Longer version is newer, when the preceding parts are equal
	if len(arel) < len(brel) {
		return Older
	}
	if len(arel) > len(brel) {
		return Newer
	}

	// Prerelease versions are older, if the versions are the same
	if len(apre) == 0 && len(bpre) > 0 {
		return Newer
	}
	if len(apre) > 0 && len(bpre) == 0 {
		return Older
	}

	minlen = len(apre)
	if l := len(bpre); l < minlen {
		minlen = l
	}

	// Compare prerelease strings
	for i := 0; i < minlen; i++ {
		switch av := apre[i].(type) {
		case int:
			switch bv := bpre[i].(type) {
			case int:
				if av < bv {
					return Older
				}
				if av > bv {
					return Newer
				}
			case string:
				return Older
			}
		case string:
			switch bv := bpre[i].(type) {
			case int:
				return Newer
			case string:
				if av < bv {
					return Older
				}
				if av > bv {
					return Newer
				}
			}
		}
	}

	// If all else is equal, longer prerelease string is newer
	if len(apre) < len(bpre) {
		return Older
	}
	if len(apre) > len(bpre) {
		return Newer
	}

	// Looks like they're actually the same
	return Equal
}
858522
func (c *Client) ValidateVersion(i *ValidateVersionInput) (bool, string, error) {
	var msg string

	if i.Service == "" {
		return false, msg, ErrMissingService
	}

	if i.Version == 0 {
		return false, msg, ErrMissingVersion
	}

	path := fmt.Sprintf("/service/%s/version/%d/validate", i.Service, i.Version)
	resp, err := c.Get(path, nil)
	if err != nil {
		return false, msg, err
	}

	var r *statusResp
	if err := decodeJSON(&r, resp.Body); err != nil {
		return false, msg, err
	}

	msg = r.Msg
	return r.Ok(), msg, nil
}
182809
func IsVersionInconsistentError(e interface{}) bool {
	value := e
	// In case of a wrapped error, check the cause first.
	cause := errors.Cause(e.(error))
	if cause != nil {
		value = cause
	}
	_, ok := value.(*versionInconsistentError)
	return ok
}
760187
func (b *builtinVersionSig) evalString(row chunk.Row) (string, bool, error) {
	return mysql.ServerVersion, false, nil
}
641379
func CheckKernelMajorVersionGreaterOrEqualThen(kernelVersion int, majorVersion int) bool {
	kv, err := kernel.GetKernelVersion()
	if err != nil {
		return false
	}
	if kv.Kernel < kernelVersion || (kv.Kernel == kernelVersion && kv.Major < majorVersion) {
		return false
	}
	return true
}
1058137
func GetVersionProto() *version.Version {
	return &version.Version{
		SemVer:       GetVersion(),
		GitCommit:    GitCommit,
		GitTreeState: GitTreeState,
	}
}
930767
func CompareVersions(version1, version2 string) (int, error) {
	version1Slice := strings.Split(version1, ".")
	version2Slice := strings.Split(version2, ".")

	lenDiff := len(version1Slice) - len(version2Slice)
	if lenDiff != 0 {
		makeDefVerComps := func(compLen int) []string {
			comps := make([]string, compLen, compLen)
			for idx := len(comps) - 1; idx >= 0; idx-- {
				comps[idx] = "0"
			}
			return comps
		}
		if lenDiff > 0 {
			// v1 slice is longer
			version2Slice = append(version2Slice, makeDefVerComps(lenDiff)...)
		} else {
			// v2 slice is longer
			version1Slice = append(version1Slice, makeDefVerComps(-lenDiff)...)
		}
	}

	cnt := len(version1Slice)
	for i, num := range version1Slice {
		num1, err := strconv.ParseInt(num, 0, 64)
		if err != nil {
			log.Println("Failed to parse int:", err)
			return -2, err
		}

		num2, err2 := strconv.ParseInt(version2Slice[i], 0, 64)
		if err2 != nil {
			log.Println("Failed to parse int:", err2)
			return -2, err
		}

		if num2 > num1 {
			return 1, nil
		} else if num2 < num1 {
			return -1, nil
		}

		if i == cnt-1 {
			// last one
			if num2 == num1 {
				return 0, nil
			}
		}
	}
	return -1, nil
}
376488
func checkMinVersion(vstring string) bool {
	version, err := utilversion.ParseGeneric(vstring)
	if err != nil {
		klog.Errorf("vstring (%s) is not a valid version string: %v", vstring, err)
		return false
	}

	minVersion, err := utilversion.ParseGeneric(MinIPSetCheckVersion)
	if err != nil {
		klog.Errorf("MinCheckVersion (%s) is not a valid version string: %v", MinIPSetCheckVersion, err)
		return false
	}
	return !version.LessThan(minVersion)
}
1051861
func (h VersionString) Compare(other interface{}) int {
	v := MustParseVersion(h.String())
	return compareVersionsWithSuffix(v.Number, v.PatchLevel, v.Suffix, other)
}