Repository navigation
diff by element, as text or as a JSON report - #28
Conversation
diff printed a line per change in flatxml's terms, and an element added whole as one line saying nothing of what it holds. It now gathers the changes under the referrable element each lies in: an element added or removed whole is one change holding its values and the elements in it, any other change a row of its element, a value named as `values` names it (an ECUC value by the last name of its definition). --format json writes it as a report (docs/report.md#diff, docs/diff.schema.json), --xml with each element added or removed whole as the file has it. The git diff driver prints the text without positions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 07de3976ab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return | ||
| } | ||
| el := eb.sides[s].element_of(n.parent()) | ||
| k := if s == 1 { eb.changed(flatxml.MNode{}, n) } else { eb.changed(n, flatxml.MNode{}) } |
There was a problem hiding this comment.
Create the parent entry only when it has changes to report
When an added or removed wrapper contains only referrable elements—for example, adding <ELEMENTS><LAMP><SHORT-NAME>A</SHORT-NAME></LAMP></ELEMENTS> to an existing empty package—this eagerly creates a ~ entry for the package before emitting the lamp as a whole-element addition. No rows are subsequently attached to the package, so both text and JSON report an additional changed element with no changes, and summary.changed is inflated. Defer creating the parent entry until an own-value row or the empty-element fallback actually needs it, as the move handling already does for wrappers containing only referrable elements.
Useful? React with 👍 / 👎.
| eb.put(eb.whole(s, n, sign)) | ||
| return | ||
| } | ||
| el := eb.sides[s].element_of(n.parent()) |
There was a problem hiding this comment.
Collect root-owned values when adding or removing a document
When flatxml reports a whole document root as added or removed, such as when the git diff driver compares a newly added file against the empty version, n.parent() is an empty handle. Consequently, values_of(el) returns no values, and the report silently omits all root-owned values outside referrable elements. For example, adding <MODEL><META>v</META><PACKAGES>...</PACKAGES></MODEL> reports the packages but loses META entirely; without packages, it emits only a valueless MODEL row. Use the document root as the value holder for this case so whole-file additions and removals retain these values.
Useful? React with 👍 / 👎.
| name: eb.sides[1].name_in(ne, c.new) | ||
| from: eb.sides[0].name_in(oe, c.old) |
There was a problem hiding this comment.
Preserve the source owner of non-referrable moves
When a non-referrable subtree moves between different referrable elements, both names are made relative to their respective owners, but the report retains only the destination owner's path. For example, moving an unchanged <NOTES> subtree from /Pkg/A to /Pkg/B produces a row under /Pkg/B saying > NOTES -> NOTES, with no source path in either text or JSON. Flatxml explicitly detects these cross-parent moves in Diff.moves(), and the previous path-based output retained both full paths. Preserve the source owner's path for cross-element moves, or represent them as removal and addition rows under the respective owners, so consumers can determine what actually moved.
Useful? React with 👍 / 👎.
| before: if v := ov { v.text } else { c.before } | ||
| after: if v := nv { v.text } else { c.after } |
There was a problem hiding this comment.
Preserve original text in changed-value payloads
For text changes in leaf values, replacing c.before and c.after with Value.text discards surrounding whitespace because ValueWalk.emit() trims it. Flatxml compares the original text runs, so changing <VALUE>abc</VALUE> to <VALUE> abc </VALUE> still counts as a change, but the JSON now reports identical before and after values of abc, and the text displays abc -> abc. This also loses potentially meaningful whitespace in string-valued content. Reuse the value walk for naming and tags while retaining the original change payloads for the before/after fields.
Useful? React with 👍 / 👎.
…exts as written - A list holding only referrable elements, added or removed, no longer makes an empty `~` entry of the element it went into. - A document root added or removed holds its own values, so a whole file's values outside any referrable element are its rows. - Something non-referrable moved from one element to another names where it was by that element's path (`> /Pkg/A/NOTES -> NOTES`). - A changed text's before and after are as the files have them; the text quotes a value that begins or ends in a space. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codex round on
|
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
diffprinted a line per change, in flatxml's terms: an ECUC value was/Pkg/Cfg#PARAMETERS/NUMBER-PARAM-VALUE[,/Defs/Lamp/Dim,]/VALUE, an elementadded whole was a single
+line saying nothing of what it holds, and a toolshowing a diff had to parse the lines and read the files again to say more.
diffnow gathers the changes by referrable element, as a configurationeditor shows a model:
valuesnames it: an ECUC parameter or referencevalue by the last name of its definition, anything else by the elements
down to it, an attribute after
/@.the JSON its values are its rows and the referrable elements in it are
insideit, each likewise. A list added or removed whole is a row for eachvalue in it and an element for each referrable element in it.
held stays together, in file order.
--format jsonwrites it as a report (docs/report.md, docs/diff.schema.json):each element's sign, path, element, definition, annotation origins and places
in both versions, with its rows (sign, name, element, before, after, places).
Values are whole there; the text cuts them at 120 characters.
--xmladds anelement added or removed whole as the file has it. The git diff driver prints
the text without positions.
The walk
valuesmakes is now built from any merged view, and can be limitedto one element, so
diffreuses its naming instead of writing it again.On a large real-world model, a diff of one file takes as long as before, and
a diff of a whole configuration directory takes about a fifth longer.
Tests:
test_a_diff_by_elementandtest_a_diff_by_element_of_containersonsynthetic models;
check_reports.shvalidates the JSON against its schema;git_driver_test.shchecks the driver's new text.🤖 Generated with Claude Code