GitLabgitlab-org

cli

main
ply6 git calls197 ms96 KiB3 cachedprotocol v2
130 lines3.1 KiBRaw
1package glrepo
3import (
4 "fmt"
5 "net/url"
6 "strings"
8 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
10 "gitlab.com/gitlab-org/cli/internal/config"
11 "gitlab.com/gitlab-org/cli/internal/git"
14// Remotes represents a set of git remotes
15type Remotes []*Remote
17// FindByName returns the first Remote whose name matches the list
18func (r Remotes) FindByName(names ...string) (*Remote, error) {
19 for _, name := range names {
20 for _, rem := range r {
21 if rem.Name == name || name == "*" {
22 return rem, nil
23 }
24 }
25 }
26 return nil, fmt.Errorf("no GitLab remotes found")
29// UniqueHosts returns a string of unique hostnames
30func (r Remotes) UniqueHosts() string {
31 unique := make(map[string]bool, r.Len())
32 var uniqueHosts []string
33 for _, remote := range r {
34 if !unique[remote.RepoHost()] {
35 uniqueHosts = append(uniqueHosts, remote.RepoHost())
36 unique[remote.RepoHost()] = true
37 }
38 }
40 return strings.Join(uniqueHosts, ", ")
43// FindByRepo returns the first Remote that points to a specific GitLab repository
44func (r Remotes) FindByRepo(owner, name string) (*Remote, error) {
45 for _, rem := range r {
46 if strings.EqualFold(rem.RepoOwner(), owner) && strings.EqualFold(rem.RepoName(), name) {
47 return rem, nil
48 }
49 }
50 return nil, fmt.Errorf("no matching remote found")
53func remoteNameSortScore(name string) int {
54 switch strings.ToLower(name) {
55 case "upstream":
56 return 3
57 case "gitlab":
58 return 2
59 case "origin":
60 return 1
61 default:
62 return 0
63 }
66// https://golang.org/pkg/sort/#Interface
67func (r Remotes) Len() int { return len(r) }
68func (r Remotes) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
69func (r Remotes) Less(i, j int) bool {
70 return remoteNameSortScore(r[i].Name) > remoteNameSortScore(r[j].Name)
73// Remote represents a git remote mapped to a GitLab repository
74type Remote struct {
75 *git.Remote
76 Repo Interface
79func (r Remote) Project(client *gitlab.Client) (*gitlab.Project, error) {
80 return r.Repo.Project(client)
83func (r Remote) RepoNamespace() string {
84 return r.Repo.RepoNamespace()
87func (r Remote) RepoGroup() string {
88 return r.Repo.RepoGroup()
91func (r Remote) FullName() string {
92 return r.Repo.FullName()
95// RepoName is the name of the GitLab repository
96func (r Remote) RepoName() string {
97 return r.Repo.RepoName()
100// RepoOwner is the name of the GitLab account that owns the repo
101func (r Remote) RepoOwner() string {
102 return r.Repo.RepoOwner()
105// RepoHost is the GitLab hostname that the remote points to
106func (r Remote) RepoHost() string {
107 return r.Repo.RepoHost()
110// TODO: accept an interface instead of git.RemoteSet
111func TranslateRemotes(gitRemotes git.RemoteSet, urlTranslate func(*url.URL) *url.URL, defaultHostname string, cfg config.Config) Remotes {
112 remotes := Remotes{}
113 for _, r := range gitRemotes {
114 var repo Interface
115 if r.FetchURL != nil {
116 repo, _ = FromURL(urlTranslate(r.FetchURL), defaultHostname, cfg)
117 }
118 if r.PushURL != nil && repo == nil {
119 repo, _ = FromURL(urlTranslate(r.PushURL), defaultHostname, cfg)
120 }
121 if repo == nil {
122 continue
123 }
124 remotes = append(remotes, &Remote{
125 Remote: r,
126 Repo: repo,
127 })
128 }
129 return remotes
Diagnostics6 git calls · 197 ms
CallStatusSizeTime0197 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
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 KiB3 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=3
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
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=3
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
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=4
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:0200314 B · 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=314
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=93a3fb44940eceae81f0a58fd4df1d50fbd7ccb5
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=314
git.pkt.payload.max=287
git.sideband.band1.bytes=287
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=287
git.pack.trailer=0a0d545706824b859dbb83ba13169780ef407392
Open pack map
fetch2001.2 KiB188 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=188
git.response.bytes=1195
git.response.cache=MISS
git.response.duration_ms=188
git.fetch.wants=d5ff629f88e13126bc8451be3e5d02d6c381fdb8
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=1195
git.pkt.payload.max=1168
git.sideband.band1.bytes=1168
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
a5e2528b6bb71ae0
Request
73abbc3a…
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