GitLabgitlab-org

cli

main
ply7 git calls242 ms98 KiB4 cachedprotocol v2
158 lines4.2 KiBRaw
1package update
3import (
4 "os"
5 "path/filepath"
6 "strings"
7)
9// InstallMethod is the detected install method for the running glab binary.
10type InstallMethod struct {
11 Name string
12 UpgradeCommand string
15const (
16 installMethodHomebrew = "homebrew"
17 installMethodMacPorts = "macports"
18 installMethodSnap = "snap"
19 installMethodNix = "nix"
20 installMethodMise = "mise"
21 installMethodAsdf = "asdf"
22 installMethodChocolatey = "chocolatey"
23 installMethodScoop = "scoop"
24 installMethodWinGet = "winget"
25 installMethodGoInstall = "go-install"
26 installMethodUnknown = "unknown"
28 homebrewUpgradeCommand = "brew upgrade glab"
29 macportsUpgradeCommand = "sudo port selfupdate && sudo port upgrade glab"
30 snapUpgradeCommand = "sudo snap refresh glab"
31 nixUpgradeCommand = "nix profile upgrade glab"
32 miseUpgradeCommand = "mise upgrade glab"
33 asdfUpgradeCommand = "asdf install glab latest && asdf global glab latest"
34 chocolateyUpgradeCommand = "choco upgrade glab"
35 scoopUpgradeCommand = "scoop update glab"
36 wingetUpgradeCommand = "winget upgrade glab.glab"
37 goInstallUpgradeCommand = "go install gitlab.com/gitlab-org/cli/cmd/glab@latest"
40var installMethods = []struct {
41 name string
42 upgrade string
43 prefixes []string
44 contains []string
45 caseInsensitive bool
46}{
47 {
48 name: installMethodHomebrew,
49 upgrade: homebrewUpgradeCommand,
50 prefixes: []string{"/opt/homebrew/", "/usr/local/Cellar/", "/home/linuxbrew/.linuxbrew/"},
51 },
52 {
53 name: installMethodMacPorts,
54 upgrade: macportsUpgradeCommand,
55 prefixes: []string{"/opt/local/"},
56 },
57 {
58 name: installMethodSnap,
59 upgrade: snapUpgradeCommand,
60 prefixes: []string{"/snap/glab/", "/var/lib/snapd/snap/glab/"},
61 },
62 {
63 name: installMethodNix,
64 upgrade: nixUpgradeCommand,
65 prefixes: []string{"/nix/store/"},
66 },
67 {
68 name: installMethodMise,
69 upgrade: miseUpgradeCommand,
70 contains: []string{"/mise/installs/", "/mise/shims/"},
71 },
72 {
73 name: installMethodAsdf,
74 upgrade: asdfUpgradeCommand,
75 contains: []string{"/.asdf/installs/", "/.asdf/shims/"},
76 },
77 {
78 name: installMethodChocolatey,
79 upgrade: chocolateyUpgradeCommand,
80 contains: []string{"/chocolatey/lib/", "/chocolatey/bin/"},
81 caseInsensitive: true,
82 },
83 {
84 name: installMethodScoop,
85 upgrade: scoopUpgradeCommand,
86 contains: []string{"/scoop/apps/"},
87 caseInsensitive: true,
88 },
89 {
90 name: installMethodWinGet,
91 upgrade: wingetUpgradeCommand,
92 contains: []string{"/winget/packages/"},
93 caseInsensitive: true,
94 },
97// DetectInstallMethod returns the install method of the running glab binary.
98func DetectInstallMethod() InstallMethod {
99 exe, err := os.Executable()
100 if err != nil {
101 return InstallMethod{Name: installMethodUnknown}
102 }
103 if resolved, err := filepath.EvalSymlinks(exe); err == nil {
104 exe = resolved
105 }
106 return detectInstallMethodFromPath(exe, os.Getenv("GOPATH"), homeDir())
109func homeDir() string {
110 if h, err := os.UserHomeDir(); err == nil {
111 return h
112 }
113 return ""
116func detectInstallMethodFromPath(exePath, gopath, home string) InstallMethod {
117 p := filepath.ToSlash(exePath)
118 pLower := strings.ToLower(p)
120 for _, m := range installMethods {
121 target := p
122 if m.caseInsensitive {
123 target = pLower
124 }
125 for _, prefix := range m.prefixes {
126 if strings.HasPrefix(target, prefix) {
127 return InstallMethod{Name: m.name, UpgradeCommand: m.upgrade}
128 }
129 }
130 for _, sub := range m.contains {
131 if strings.Contains(target, sub) {
132 return InstallMethod{Name: m.name, UpgradeCommand: m.upgrade}
133 }
134 }
135 }
137 for _, dir := range goBinDirs(gopath, home) {
138 if dir != "" && strings.HasPrefix(p, filepath.ToSlash(dir)+"/") {
139 return InstallMethod{Name: installMethodGoInstall, UpgradeCommand: goInstallUpgradeCommand}
140 }
141 }
142 return InstallMethod{Name: installMethodUnknown}
145func goBinDirs(gopath, home string) []string {
146 var dirs []string
147 if gopath != "" {
148 for _, g := range filepath.SplitList(gopath) {
149 if g != "" {
150 dirs = append(dirs, filepath.Join(g, "bin"))
151 }
152 }
153 }
154 if home != "" {
155 dirs = append(dirs, filepath.Join(home, "go", "bin"))
156 }
157 return dirs
Diagnostics7 git calls · 242 ms
CallStatusSizeTime0242 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchtree:02001.8 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200329 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=233
git.response.bytes=329
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=8b36f3db012b2c3ab0120649b10a85336c3bf03e
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=329
git.pkt.payload.max=302
git.sideband.band1.bytes=302
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=302
git.pack.trailer=616b294f8a6e9b6163f51633333a4ad7b16f0d98
Open pack map
fetch2001.3 KiB233 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1326
git.response.cache=MISS
git.response.duration_ms=233
git.fetch.wants=04ac0edf575206077b858fe6427a40ef3cac4992
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1326
git.pkt.payload.max=1299
git.sideband.band1.bytes=1299
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e1d8179ba6a151
Request
6c0fe96f…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format