Delphi-RAG-Lint

drag-lint help

Field repository: ORM preservation proof and run rollback

Since: 1.66.0-alpha

Proves an ORM generator run changed nothing outside the generator's regions (outside_changed per unit) and undoes one --apply run from its run manifest.

Read this before and after every ORM generator run: each --apply of the ORM generator verbs records a run (manifest + before-bytes), verify-preserve proves the run kept the hand code, restore --run puts the run back.

How to run it

drag-lint repo verify-preserve (--before <folder|file> --after <folder|file> | --run <run id|run folder|manifest> [--run-dir <folder>] [--repo <file> | --project <project file>]) [--json]

Example:

drag-lint repo verify-preserve --run <run id> --repo <file>

Full flag list: repo in the CLI reference.

drag-lint repo restore --run <run id|run folder|manifest> [--run-dir <folder>] [--repo <file> | --project <project file>] [--apply] [--json]

Example:

drag-lint repo restore --run <run id> --repo <file> --apply

Full flag list: repo in the CLI reference.

Flags

FlagArgumentMeaningDefault
--before<folder|file>
--after<folder|file>
--run<run id|run folder|manifest>
--run-dir<folder>
--repo<file>
--project<project file>
--json
--run<run id|run folder|manifest>
--run-dir<folder>
--repo<file>
--project<project file>
--apply
--json

Where to click

No IDE surface: this feature runs from the CLI (see How to run it).

Details

Since 1.66.

Why

The ORM generator verbs rewrite generated code inside units that also hold hand code. Two questions follow every --apply: did the run touch anything outside the generator's regions, and how do I put the run back if it did? Before 1.66 the first was answered only inside the golden test, and the second only by hand from the .BCKn copies.

The run manifest

Every --apply of repo gen-orm, update-orm, gen-dataservice, upgrade-orm-headers and adopt-regions that writes at least one file records a run, before the first file is written:

<repository folder>\dl-orm-runs\<run id>\manifest.json
<repository folder>\dl-orm-runs\<run id>\files\<n>.before    (the exact bytes the run overwrote)

The verb prints run <id>: manifest <path>; with --json the plan document carries run: {id, manifest, files}. --run-dir <folder> puts the run folder elsewhere, --no-manifest records nothing. The manifest holds, per file, whether it existed, the sha256 before and the sha256 the run writes. The snapshots end in .before, so no project and no *.pas glob picks them up.

repo restore --run

drag-lint repo restore --run <run id> --repo <file>            (dry run: what it would do)
drag-lint repo restore --run <run id> --repo <file> --apply
drag-lint repo restore --run <run folder | manifest.json> --apply   (no --repo needed)

Per recorded file:

current fileaction
the run's after-bytesrestore (the before-bytes come back), or delete when the run created it
already the before-bytes (or gone, for a file the run created)unchanged
anything elseREFUSED <file>: changed since the run -- kept as it is

A dry run exits 0 and lists the REFUSED files; --apply exits 1 when a file is REFUSED and still restores the others. The run folder is kept, so a second restore only reports unchanged. No hg revert is needed.

repo verify-preserve

drag-lint repo verify-preserve --before <folder|file> --after <folder|file> [--json]
drag-lint repo verify-preserve --run <run id> --repo <file> [--json]

With folders every *.pas is paired by file name; with --run each recorded snapshot is compared with the current file. Per unit it reports outside_changed=<n>: the lines that differ after this reduction of both texts:

  • the body of a generator region (DB-RAD / DLFR 1 .. 17 and the CL- ids) is cut; the marker lines stay, the hash on a start marker is ignored;
  • a generator region the run inserted whole (its id is not in the before text, e.g. 16 / 17) is dropped;
  • the DB-RAD A-<NAME> marker lines of adopt-regions are dropped on both sides; their bodies stay compared;
  • a uses clause is compared as a list of unit names: uses +X,-Y is listed, not counted (update-orm keeps the clauses compiling);
  • line ends count: CRLF -> LF is a change. DB-RAD 99 and every other region is hand code, compared byte for byte.

A unit gone after the run is missing (fails); one new after the run is listed and not compared. The first differing outside line is printed (first_after_line=<k>, - old / + new). Exit 0 when nothing changed outside the regions, 1 otherwise, 2 for bad arguments.

Example

A two-column table ORDERS, its units written by repo gen-orm and repo gen-dataservice into O:

> drag-lint repo adopt-regions --repo orm.dlrepo --code-dir O --server-dir O --client-dir O --table ORDERS --apply --no-backup
...
repo adopt-regions: 0 new, 3 changed, 1 unchanged, 0 skipped; 27 region(s) to adopt, 0 member(s) kept; 3 written
run 20261205-080543-702-adopt-regions: manifest C:\Projects\MyApp\dl-orm-runs\20261205-080543-702-adopt-regions\manifest.json

> drag-lint repo verify-preserve --run 20261205-080543-702-adopt-regions --repo orm.dlrepo
unit C:\Projects\MyApp\O\uORDERS.PAS outside_changed=0
unit C:\Projects\MyApp\O\uORDERS_SERVER.PAS outside_changed=0
unit C:\Projects\MyApp\O\uORDERS_CLIENT.PAS outside_changed=0
repo verify-preserve: 3 unit(s), 0 outside the regions changed, 0 failing, 0 missing, 0 new

All features | CLI reference | IDE menus