openscd / open-scd

A substation configuration description editor for projects using SCL IEC 61850-6 Edition 2 or greater
https://openscd.github.io
Apache License 2.0
98 stars 31 forks source link

.scd file comparison for tracking changes during engineering process #349

Open Mohit2510 opened 2 years ago

Mohit2510 commented 2 years ago

While working on the same project sometimes it is required to check/compare a new .scd(SCL) file to older one to understand the changes... This helps in keeping a track of changes made during engineering process.

Sander3003 commented 2 years ago

LF energy CoMPAS is based on OpenSCD and has a database back-end to store multiple versions (semver) and make comparisons. You can try it here: https://github.com/com-pas/compas-deployment

image

ca-d commented 2 years ago

Another possibility is to use the "Merge Project" extension to "merge" the old version into the new (or the other way around) and only select the merge type list entries (purple checkboxes).

We are planning to remove the need to individually click each element I want to check the differences of by providing the merge user interface in a single dialog with a tree view of all changes at a glance. @Mohit2510 If you don't mind, I will hijack this issue as a place to track progress on this feature.

Sander3003 commented 2 years ago

@ca-d we are currently using the "merge" function now as well and planning to build an overview as well.

Sander3003 commented 2 years ago

@dlabordus

JakobVogelsang commented 2 years ago

We will have a comparison diffing tool in the near future. If you want to see the progress on that, please follow the progress in the projects Comparison/Diffing-Tool.

danyill commented 1 year ago

A few thoughts on this:

It is sometimes very useful to have a simple, plain text comparison of XML files as well as the more sophisticated "semantic SCL differences" which has been discussed and I hope to work on soon.

We have previously discussed the possibility to use the ace-diff view to show XML differences.

I've been looking into this as part of finding a way to compare output between different tools which follow different approaches in the serialisation of XML -- e.g. order of attributes, approach to whitespace. The current state of tooling is that one tool often breaks the output of another tool 😞

Web standards define a thing called "Canonical XML" which is useful for allow a plain text comparison of XML files. (I don't think it matters so much but there is also a draft standard on "XML Normalisation" although it doesn't appear to have moved beyond draft)

If we use canonical XML then we can just do a standard text comparison to identify changes without worrying about serialisation order etc.

libxml2 includes a utility which can do this (man page) using the following option:

--c14n
Use the W3C XML Canonicalisation (C14N) to serialize the result of parsing to stdout. It keeps comments in the result.

Given that @ca-d has already turned schema validation into wasm in xmlvalidate.js it might not be a large task to do something similar here (and it would be better not to rewrite this which is probably well-tested and used code). And perhaps we could do other things (e.g. get nodes by line numbers which might be useful in some way to open wizards from a diff view!)

What I do by hand to check files at the moment is:

xmllint --c14n First.scd > First_Canonical.scd
xmllint --c14n Second.scd > Second_Canonical.scd
diff First_Canonical.scd Second_Canonical.scd > comparison.diff