GitLabgitlab-org

cli

main
ply6 git calls36 ms97 KiB5 cachedprotocol v2
137 lines3.8 KiBRaw
1package text
3import (
4 "bytes"
5 "regexp"
6 "strings"
7 "unicode"
9 "github.com/mattn/go-runewidth"
12const ExperimentalString = `
13This feature is an experiment and is not ready for production use.
14It might be unstable or removed at any time.
15For more information, see
16https://docs.gitlab.com/policy/development_stages_support/.
19const ExperimentalFlagString = `
20The %s flag is an experiment. It might be
21unstable or removed at any time, and is not ready for production use.
22For more information, see
23https://docs.gitlab.com/policy/development_stages_support/.
26const BetaString = `
27This feature is in beta and might not be ready for production use.
28It might be unstable and breaking changes can occur outside of major releases.
29For more information, see
30https://docs.gitlab.com/policy/development_stages_support/.
33const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
35var re = regexp.MustCompile(ansi)
37var hyperlinkOSCRegexp = regexp.MustCompile("\u001B\\]8;[^;]*;.*?\u001B\\\\")
39// Join joins the list of the string with the delim provided.
40// Returns an empty string for empty list
41func Join(list []string, delim string) string {
42 if len(list) == 0 {
43 return ""
44 }
45 var buf bytes.Buffer
46 for i := range len(list) - 1 {
47 buf.WriteString(list[i] + delim)
48 }
49 buf.WriteString(list[len(list)-1])
50 return buf.String()
53// Strip strips the string of all colors
54func Strip(s string) string {
55 return re.ReplaceAllString(hyperlinkOSCRegexp.ReplaceAllString(s, ""), "")
58// SanitizeInline makes an untrusted string safe to print on a single line of
59// terminal or CI output. It removes ANSI/OSC escape sequences, drops the
60// remaining C0/C1 control characters (bell, backspace, and the like that
61// strings.Fields does not treat as whitespace), and collapses every run of
62// whitespace to a single space. Use it on any value derived from network or
63// user input before writing it to a log line, so a crafted value cannot inject
64// newlines or terminal control sequences.
65func SanitizeInline(s string) string {
66 stripped := Strip(s)
67 var b strings.Builder
68 b.Grow(len(stripped))
69 for _, r := range stripped {
70 switch {
71 case r == '\t' || r == '\n' || r == '\r':
72 b.WriteByte(' ')
73 case unicode.IsControl(r):
74 continue
75 default:
76 b.WriteRune(r)
77 }
78 }
79 return strings.Join(strings.Fields(b.String()), " ")
82// StringWidth returns the actual width of the string without colors
83func StringWidth(s string) int {
84 return runewidth.StringWidth(Strip(s))
87// RuneWidth returns the actual width of the rune
88func RuneWidth(s rune) int {
89 return runewidth.RuneWidth(s)
92func WrapString(text string, lineWidth int) string {
93 words := strings.Fields(strings.TrimSpace(text))
94 if len(words) == 0 {
95 return text
96 }
97 wrapped := words[0]
98 spaceLeft := lineWidth - StringWidth(wrapped)
99 for _, word := range words[1:] {
100 wordWidth := StringWidth(word)
101 if wordWidth+1 > spaceLeft {
102 wrapped += "\n" + word
103 spaceLeft = lineWidth - wordWidth
104 } else {
105 wrapped += " " + word
106 spaceLeft -= 1 + wordWidth
107 }
108 }
109 return wrapped
112// PadRight returns a new string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character.
113func PadRight(str string, length int, pad byte) string {
114 slen := StringWidth(str)
115 if slen >= length {
116 return str
117 }
118 buf := bytes.NewBufferString(str)
119 for range length - slen {
120 buf.WriteByte(pad)
121 }
122 return buf.String()
125// PadLeft returns a new string of a specified length in which the beginning of the current string is padded with spaces or with a specified Unicode character.
126func PadLeft(str string, length int, pad byte) string {
127 slen := StringWidth(str)
128 if slen >= length {
129 return str
130 }
131 var buf bytes.Buffer
132 for range length - slen {
133 buf.WriteByte(pad)
134 }
135 buf.WriteString(str)
136 return buf.String()
Diagnostics6 git calls · 36 ms
CallStatusSizeTime036 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
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 KiB · hit2 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=HIT
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
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
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:0200252 B · 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=252
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=e9b19a1e1947873c86e10228c1cf4366871bf7bb
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=252
git.pkt.payload.max=225
git.sideband.band1.bytes=225
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=225
git.pack.trailer=6cbb7e25b03d265a9ed411cfa3dc8c4b4af06409
Open pack map
fetch2001.5 KiB · hit27 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=27
git.response.bytes=1568
git.response.cache=HIT
git.response.duration_ms=27
git.fetch.wants=194f04975cb92722077fcc823aea26ddd21abf60
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=1568
git.pkt.payload.max=1541
git.sideband.band1.bytes=1541
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
a5e19846fc22b86e
Request
bb32757b…
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