Skip to content

code/editor/patch-parse

import { … } from 'zidane-ui/code/editor'ui/src/code/editor/patch-parse.ts

Functions#

createPatchParserFunction#

A parser that runs parseWorkingTree in a worker (one, made on first use), so a burst of re-reads on a repository with a large diff never parses megabytes on the main thread. Without createWorker, or once the worker failed (a load error, a crash), it parses on this thread: what a dead worker held is settled there.

The worker is an app's module that answers each ParseRequest with parseWorkingTree(request).

TypeScript
function createPatchParser(createWorker: (() => Worker) | null): PatchParser
Parameters
NameTypeDescription
createWorker(() => Worker) | null

Makes the worker; null: parse on this thread.

ui/src/code/editor/patch-parse.ts:141

hashTextFunction#

FNV-1a, 32 bits, as hex: fast, and collisions only cost a reused parse of the same path.

TypeScript
function hashText(text: string): string
Parameters
NameTypeDescription
textstring

The text to hash.

string

ui/src/code/editor/patch-parse.ts:23

parseFilePatchFunction#

Parses a one-file patch (a file's working-tree diff); undefined when it holds no file.

TypeScript
function parseFilePatch(patch: string, cacheKey: string): FileDiffMetadata | undefined
Parameters
NameTypeDescription
patchstring

A unified patch of one file.

cacheKeystring

Prefix of pierre's cache keys for it.

FileDiffMetadata | undefined

ui/src/code/editor/patch-parse.ts:125

parseSectionFunction#

Parse one file section; null when pierre can't read it (that file is left out, the others still show).

TypeScript
function parseSection(key: string, text: string): FileDiffMetadata | null
Parameters
NameTypeDescription
keystring

The section's content key (pierre's cache key).

textstring

The section.

FileDiffMetadata | null

ui/src/code/editor/patch-parse.ts:78

parseWorkingTreeFunction#

Parses the sections of a patch the caller doesn't hold yet. What a parser worker runs on each message.

TypeScript
function parseWorkingTree(req: ParseRequest): ParseResponse
Parameters
NameTypeDescription
reqParseRequest

The patch and the keys already held.

ui/src/code/editor/patch-parse.ts:109

sectionKeysFunction#

The file sections of a patch with their content keys.

TypeScript
function sectionKeys(patch: string): SectionKey[]
Parameters
NameTypeDescription
patchstring

A unified patch of any number of files.

ui/src/code/editor/patch-parse.ts:62

splitPatchFunction#

Split a multi-file patch at its diff --git headers (text before the first one is dropped).

TypeScript
function splitPatch(patch: string): string[]
Parameters
NameTypeDescription
patchstring

A unified patch of any number of files.

string[]

ui/src/code/editor/patch-parse.ts:37

Interfaces#

ParseRequestInterface#

What a parser worker receives.

TypeScript
interface ParseRequest
ParseRequest properties
NameTypeDescription
idnumber

Matches the response to the request.

knownstring[]

Sections the caller already holds parsed: sent back as keys only.

patchstring

The working-tree patch.

ui/src/code/editor/patch-parse.ts:87

ParseResponseInterface#

What a parser worker answers.

TypeScript
interface ParseResponse
ParseResponse properties
NameTypeDescription
files{ file?: FileDiffMetadata | null; key: string }[]

In patch order: a key the caller knows, or a freshly parsed file (null when unreadable).

idnumber

The request's id.

ui/src/code/editor/patch-parse.ts:97

SectionKeyInterface#

One file section of a patch, keyed by its content.

TypeScript
interface SectionKey
SectionKey properties
NameTypeDescription
keystring

Content hash plus the section's index among equal hashes (two identical sections stay distinct).

textstring

The section's text.

ui/src/code/editor/patch-parse.ts:50

Types#

PatchParserType#

Parses a working-tree patch, the sections it doesn't hold yet only.

TypeScript
type PatchParser = (patch: string, known: string[]) => Promise<ParseResponse>

ui/src/code/editor/patch-parse.ts:130