Codebergdnkl
foot
master
1#include <stdlib.h>
2#include <stdio.h>
3#include <stdint.h>
4#include <stdbool.h>
5#include <string.h>
6#include <termios.h>
7#include <unistd.h>
8#include <assert.h>
9#include <errno.h>
10#include <poll.h>
11#include <ctype.h>
12#include <assert.h>
14static struct termios orig_termios;
16static void
17disable_raw_mode(void)
18{
19 if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios) < 0)
20 exit(__LINE__);
21}
23static void
24enable_raw_mode(void)
25{
26 if (tcgetattr(STDIN_FILENO, &orig_termios) < 0)
27 exit(__LINE__);
29 atexit(disable_raw_mode);
31 struct termios raw = orig_termios;
32 raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
33 raw.c_oflag &= ~(OPOST);
34 raw.c_cflag |= (CS8);
35 raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
36 raw.c_cc[VMIN] = 0;
37 raw.c_cc[VTIME] = 1;
39 if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw) < 0)
40 exit(__LINE__);
41}
43static const char *
44hexlify(const char *s)
45{
46 static char buf[1024];
48 const size_t len = strlen(s);
49 for (size_t i = 0; i < len; i++)
50 sprintf(&buf[i * 2], "%02x", s[i]);
51 buf[len * 2 + 1] = '\0';
53 return buf;
54}
56static size_t
57unhexlify(char *dst, const char *src)
58{
59 size_t count = 0;
60 for (const char *p = src; *p != '\0'; p += 2, dst++, count++)
61 sscanf(p, "%02hhx", (unsigned char *)dst);
63 *dst = '\0';
64 return count;
65}
67int
68main(int argc, const char *const *argv)
69{
70 const size_t query_count = argc - 1;
72 if (query_count == 0)
73 return 0;
75 enable_raw_mode();
77 printf("\x1bP+q");
78 for (int i = 1; i < argc; i++)
79 printf("%s%s", i > 1 ? ";" : "", hexlify(argv[i]));
80 printf("\033\\");
82 fflush(NULL);
84 size_t replies = 0;
85 while (replies < query_count) {
86 struct pollfd fds[] = {{.fd = STDIN_FILENO, .events = POLLIN}};
87 int r = poll(fds, sizeof(fds) / sizeof(fds[0]), -1);
88 if (r < 0)
89 exit(__LINE__);
91 char buf[1024] = {0};
92 ssize_t count = read(STDIN_FILENO, buf, sizeof(buf));
94 if (count < 0)
95 exit(__LINE__);
97 if (count == 1 && buf[0] == 'q')
98 break;
100 printf("reply: (%zd chars): ", count);
102 for (size_t i = 0; i < (size_t)count; i++) {
103 if (isprint(buf[i]))
104 printf("%c", buf[i]);
105 else if (buf[i] == '\033')
106 printf("\033[1;31m<ESC>\033[m");
107 else
108 printf("%02x", (uint8_t)buf[i]);
109 }
110 printf("\r\n");
112 const char *p = buf;
113 const char *end = buf + count;
115 while (p < end) {
117 const char *ST = strstr(p, "\033\\");
118 if (ST == NULL)
119 break;
121 if (count < 5 ||
122 (strncmp(p, "\033P1+r", 5) != 00 &&
123 strncmp(p, "\033P0+r", 5) != 0))
124 {
125 break;
126 }
128 const bool success = p[2] == '1';
130 char decoded[1024];
131 char copy[ST - &p[5] + 1];
132 strncpy(copy, &p[5], ST - &p[5]);
133 copy[ST - &p[5]] = '\0';
135 char *saveptr = NULL;
136 for (char *key_value = strtok_r(copy, "; ", &saveptr);
137 key_value != NULL;
138 key_value = strtok_r(NULL, "; ", &saveptr))
139 {
140 // printf("key-value=%s\n", key_value);
141 const char *key = strtok(key_value, "=");
142 const char *value = strtok(NULL, "=");
144 if (key == NULL)
145 continue;
147#if 0
148 assert((success && value != NULL) ||
149 (!success && value == NULL));
150#endif
152 //printf("key=%s, value=%s\n", key, value);
153 size_t len = unhexlify(decoded, key);
155 if (value != NULL) {
156 decoded[len++] = '=';
157 len += unhexlify(&decoded[len], value);
158 }
160 const int color = success ? 39 : 31;
162 printf(" \033[%dm", color);
163 for (size_t i = 0 ; i < len; i++) {
164 if (isprint(decoded[i])) {
165 /* All printable characters */
166 printf("%c", decoded[i]);
167 }
169 else if (decoded[i] == '\033') {
170 /* ESC */
171 printf("\033[1;31m<ESC>\033[22;%dm", color);
172 }
174 else if (decoded[i] >= '\x00' && decoded[i] <= '\x5f') {
175 /* Control characters, e.g. ^G etc */
176 printf("\033[1m^%c\033[22m", decoded[i] + '@');
177 }
179 else if (decoded[i] == '\x7f') {
180 /* Control character ^? */
181 printf("\033[1m^?\033[22m");
182 }
184 else {
185 /* Unknown: print hex representation */
186 printf("\033[1m%02x\033[22m", (uint8_t)decoded[i]);
187 }
188 }
189 printf("\033[m\r\n");
190 replies++;
191 }
193 p = ST + 2;
194 }
196 }
198 return 0;
199}
Diagnostics5 git calls · 745 ms
CallStatusSizeTime0745 ms
discover200178 B5 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=5 git.response.bytes=178 git.server.agent=git/2.56.1-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=178 git.pkt.payload.max=35
ls-refs20010 KiB723 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=705 git.response.bytes=10322 git.response.cache=EXPIRED git.response.duration_ms=723 git.protocol.version=2 git.pkt.frames=108 git.pkt.data=107 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=10322 git.pkt.payload.max=106 git.ls_refs.count=107 git.ls_refs.head=refs/heads/master
fetchcombine:blob:none+tree:2 · deepen 12008.6 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=8830 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0 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=8830 git.pkt.payload.max=8730 git.sideband.band1.bytes=8730 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=14 git.pack.bytes=8730 git.fetch.wide.objects=14 git.fetch.wide.extra_bytes=9909 git.fetch.wide.blobs=0
fetchtree:0 · deepen 102009.3 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=9489 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0 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=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=9489 git.pkt.payload.max=9389 git.sideband.band1.bytes=9389 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=10 git.pack.bytes=9389 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=de930681b6073ba5b599a0f956bfbd114762ad5a git.pack.full=10Open pack map
fetch2001.6 KiB · hit19 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=19 git.response.bytes=1641 git.response.cache=HIT git.response.duration_ms=19 git.fetch.wants=82ee0085474f587d79f3cf26a9a92985d84b0ca1 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=1641 git.pkt.payload.max=1614 git.sideband.band1.bytes=1614 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://codeberg.org/dnkl/foot
- Ref
- refs/heads/master
- Commit
- c0d2c3e95d74cb60526ff28aec9f34ee3df545e0
- cf-ray
- a5e1a2cb5cdc3cd0
- Request
- 2ce4c60c…
- Protocol
- v2 · sha1
- Agent
- git/2.56.1-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format