Codebergdnkl
foot
master
1#include "tokenize.h"
3#include <stdlib.h>
4#include <string.h>
6#define LOG_MODULE "tokenize"
7#define LOG_ENABLE_DBG 0
8#include "log.h"
9#include "xmalloc.h"
11static bool
12push_argv(char ***argv, size_t *size, const char *arg, size_t len, size_t *argc)
13{
14 if (arg != NULL && arg[0] == '%')
15 return true;
17 if (*argc >= *size) {
18 size_t new_size = *size > 0 ? 2 * *size : 10;
19 char **new_argv = realloc(*argv, new_size * sizeof(new_argv[0]));
21 if (new_argv == NULL)
22 return false;
24 *argv = new_argv;
25 *size = new_size;
26 }
28 (*argv)[(*argc)++] = arg != NULL ? xstrndup(arg, len) : NULL;
29 return true;
30}
32bool
33tokenize_cmdline(const char *cmdline, char ***argv)
34{
35 *argv = NULL;
36 size_t argv_size = 0;
38 const char *final_end = cmdline + strlen(cmdline) + 1;
40 bool first_token_is_quoted = cmdline[0] == '"' || cmdline[0] == '\'';
41 char delim = first_token_is_quoted ? cmdline[0] : ' ';
43 const char *p = first_token_is_quoted ? &cmdline[1] : &cmdline[0];
44 const char *search_start = p;
46 size_t idx = 0;
47 while (*p != '\0') {
48 char *end = (char *)strchr(search_start, delim);
49 if (end == NULL) {
50 if (delim != ' ') {
51 LOG_ERR("unterminated %s quote", delim == '"' ? "double" : "single");
52 goto err;
53 }
55 if (!push_argv(argv, &argv_size, p, final_end - p, &idx) ||
56 !push_argv(argv, &argv_size, NULL, 0, &idx))
57 {
58 goto err;
59 } else
60 return true;
61 }
63 if (end > p && *(end - 1) == '\\') {
64 /* Escaped quote, remove one level of escaping and
65 * continue searching for "our" closing quote */
66 memmove(end - 1, end, strlen(end));
67 end[strlen(end) - 1] = '\0';
68 search_start = end;
69 continue;
70 }
72 //*end = '\0';
74 if (!push_argv(argv, &argv_size, p, end - p, &idx))
75 goto err;
77 p = end + 1;
78 while (*p == delim)
79 p++;
81 while (*p == ' ')
82 p++;
84 if (*p == '"' || *p == '\'') {
85 delim = *p;
86 p++;
87 } else
88 delim = ' ';
89 search_start = p;
90 }
92 if (!push_argv(argv, &argv_size, NULL, 0, &idx))
93 goto err;
95 return true;
97err:
98 for (size_t i = 0; i < idx; i++)
99 free((*argv)[i]);
100 free(*argv);
101 *argv = NULL;
102 return false;
103}
Diagnostics5 git calls · 573 ms
CallStatusSizeTime0573 ms
discover200178 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=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 KiB546 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=511 git.response.bytes=10322 git.response.cache=EXPIRED git.response.duration_ms=546 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
fetch200962 B · hit24 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=24 git.response.bytes=962 git.response.cache=HIT git.response.duration_ms=24 git.fetch.wants=70ceb39b5151351ab49fd1bc708b5f654a329e2c 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=962 git.pkt.payload.max=935 git.sideband.band1.bytes=935 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
- a5e2512fac3fb071
- Request
- 95aa08bf…
- 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