main
1// Author and committer stamps. ply's validateIdent is the gate (name, email, civil zone, non-negative time) and
2// brands the object unwrap(ident()) will accept. This module is the HTTP shape: {name, email, tz?, time?}.
3// The zone check lives in validateIdent; a bad tz is still 400 bad_request, with ply's message.
4import { plyError, ident, validateIdent } from 'ply';
5import { unwrap } from '../ply-result.ts';
6import { recordGet } from '../absent.ts';
8declare const tzBrand: unique symbol;
9declare const timeBrand: unique symbol;
11/** `+0530` / `-0800`. git ident timezone: a sign and four digits, held to the civil range ply enforces. */
12export type TzOffset = string & { readonly [tzBrand]: 'TzOffset' };
13/** Unix seconds. git ident timestamp: a non-negative safe integer. fsck refuses a date that overflows time_t. */
14export type UnixSeconds = number & { readonly [timeBrand]: 'UnixSeconds' };
16/** The object validateIdent brands. unwrap(ident()) refuses a copy, so the line is taken from this value. */
17type Person = Extract<ReturnType<typeof validateIdent>, { ok: true }>['value'];
19export type Stamp = {
20 readonly name: string;
21 readonly email: string;
22 readonly tz: TzOffset;
23 readonly time: UnixSeconds;
24 readonly person: Person;
25 readonly line: string;
26};
28export function parseTime(value: unknown, field: string): UnixSeconds {
29 if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) throw plyError('bad_request', `${field} must be a non-negative integer (unix seconds)`);
30 return value as UnixSeconds;
31}
33function rawOf(value: unknown, field: string): Record<string, unknown> {
34 if (value === null || typeof value !== 'object' || Array.isArray(value)) throw plyError('bad_request', `${field} must be {name, email}`);
35 return value as Record<string, unknown>;
36}
38/** Stamp one identity. Omitted tz is UTC. Omitted time is `now` (unix seconds). A present null is rejected. */
39export function stamp(value: unknown, field: string, now: UnixSeconds): Stamp {
40 const raw = rawOf(value, field);
41 const time = recordGet(raw, 'time');
42 const name = recordGet(raw, 'name');
43 const email = recordGet(raw, 'email');
44 const tz = recordGet(raw, 'tz');
45 // Omitted tz is validateIdent's UTC. A present tz is checked there (sign, four digits, civil range).
46 const person = unwrap(validateIdent({
47 ...(name.tag === 'some' ? { name: name.value } : {}),
48 ...(email.tag === 'some' ? { email: email.value } : {}),
49 time: time.tag === 'none' ? now : parseTime(time.value, `${field}.time`),
50 ...(tz.tag === 'some' ? { tz: tz.value } : {}),
51 }));
52 return { name: person.name, email: person.email, tz: person.tz as TzOffset, time: person.time as UnixSeconds, person, line: unwrap(ident(person)) };
53}
55export function nowSeconds(): UnixSeconds {
56 return Math.floor(Date.now() / 1000) as UnixSeconds;
57}
59/** What editFile takes. It still stamps author and committer as one person; time is a separate argument. */
60export function plyPerson(s: Stamp): { name: string; email: string; tz: TzOffset } {
61 return { name: s.name, email: s.email, tz: s.tz };
62}
64/** What mergeBranch, rebaseBranch and pickCommit take: each stamp carries its own time and zone. */
65export function plyStamp(s: Stamp): { name: string; email: string; tz: TzOffset; time: UnixSeconds } {
66 return { name: s.name, email: s.email, tz: s.tz, time: s.time };
67}
Diagnostics4 git calls · 25 ms
CallStatusSizeTime025 ms
discover200152 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=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 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=41349 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921 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=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2001.3 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=1352 git.response.cache=HIT git.response.duration_ms=19 git.fetch.wants=fd912fecf632a6a5dc0723399ae78efeaa58dc59 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=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1352 git.pkt.payload.max=1331 git.sideband.band1.bytes=1330 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://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e2e5c8ce592947
- Request
- 2278639c…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format