Skip to content

diff by element, as text or as a JSON report - #28

Merged
MartenH merged 2 commits into
mainfrom
diff-by-element
Nov 3, 2026
Merged

MartenH merged 2 commits into
mainfrom
diff-by-element

Conversation

@MartenH

@MartenH MartenH commented Nov 3, 2026

Copy link
Copy Markdown
Owner

diff printed a line per change, in flatxml's terms: an ECUC value was
/Pkg/Cfg#PARAMETERS/NUMBER-PARAM-VALUE[,/Defs/Lamp/Dim,]/VALUE, an element
added whole was a single + line saying nothing of what it holds, and a tool
showing a diff had to parse the lines and read the files again to say more.

diff now gathers the changes by referrable element, as a configuration
editor shows a model:

~ /Cfg/Mod/Ch1  Channel  b.arxml:5:9
    Id: 8 -> 10
    + PartitionRef = /Cfg/Partition_1
+ /Cfg/Mod/Ch9  Channel, 1 inside  b.arxml:12:9
  • A value is named as values names it: an ECUC parameter or reference
    value by the last name of its definition, anything else by the elements
    down to it, an attribute after /@.
  • An element added or removed whole is one change, however much it holds. In
    the JSON its values are its rows and the referrable elements in it are
    inside it, each likewise. A list added or removed whole is a row for each
    value in it and an element for each referrable element in it.
  • A moved list is each referrable element in it moved from its old path.
  • Rows are sorted by the first step of their name, so what one removed list
    held stays together, in file order.

--format json writes 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. --xml adds an
element added or removed whole as the file has it. The git diff driver prints
the text without positions.

The walk values makes is now built from any merged view, and can be limited
to one element, so diff reuses 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_element and test_a_diff_by_element_of_containers on
synthetic models; check_reports.sh validates the JSON against its schema;
git_driver_test.sh checks the driver's new text.

🤖 Generated with Claude Code

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T12:29:00.100485Z a8b8886 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread arxmodel/elementdiff.v Outdated
return
}
el := eb.sides[s].element_of(n.parent())
k := if s == 1 { eb.changed(flatxml.MNode{}, n) } else { eb.changed(n, flatxml.MNode{}) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread arxmodel/elementdiff.v Outdated
eb.put(eb.whole(s, n, sign))
return
}
el := eb.sides[s].element_of(n.parent())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread arxmodel/elementdiff.v Outdated
Comment on lines +387 to +388
name: eb.sides[1].name_in(ne, c.new)
from: eb.sides[0].name_in(oe, c.old)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread arxmodel/elementdiff.v Outdated
Comment on lines +426 to +427
before: if v := ov { v.text } else { c.before }
after: if v := nv { v.text } else { c.after }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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>
@MartenH

MartenH commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Codex round on 07de3976ab, fixed in a8b8886 (all four true, all 👍):

finding what was done
empty parent entry for a wrapper of referrable elements the parent entry is made only when a row needs it
root-owned values lost when a document root is added/removed the root holds its own values; rows are named from the root (MODEL/META) as values names them
cross-element move loses its source owner from carries the old element's path when it differs (> /Pkg/A/NOTES -> NOTES)
whitespace-only text change shows abc -> abc before/after are the raw texts; the text output quotes a value with leading/trailing space

test_a_diff_by_element_at_its_edges covers each, and fails on the old code.

@MartenH

MartenH commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: a8b8886019

ℹ️ 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".

@MartenH
MartenH merged commit e5279d2 into main Nov 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant