aboutsummaryrefslogtreecommitdiff
path: root/network/receivepack/version.go
blob: 9a4544dc41da1064af1d3de18fa59504eaeae651 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package receivepack

import (
	"strings"

	common "codeberg.org/lindenii/furgit/network/protocol/v0v1/server"
)

func parseVersion(gitProtocol string) common.Version {
	if gitProtocol == "" {
		return common.Version0
	}

	var highestRequested uint8

	for field := range strings.SplitSeq(gitProtocol, ":") {
		switch field {
		case "version=0":
		case "version=1":
			if highestRequested < 1 {
				highestRequested = 1
			}
		case "version=2":
			if highestRequested < 2 {
				highestRequested = 2
			}
		}
	}

	if highestRequested == 1 {
		return common.Version1
	}

	return common.Version0
}