svenssonaxel / diff-format

Specification, reference implementations and test battery for Hintful diff format.
Other
10 stars 1 forks source link

Annotations perhaps needed #5

Open svenssonaxel opened 1 year ago

svenssonaxel commented 1 year ago

There is a case for adding syntax to annotate content lines, hunks, file comparisons and diff files.

First, there is the use case of diff tools that need to communicate more semantic information than what is possible using just content and snippet lines. This might be necessary in order to make a generic merge tool that takes hintful diffs as input, for example to override the default indentation handling. It would probably be necessary to allow annotations for individual content lines.

Second, it would be good if the format could be made useful for next-generation version control software. Even if we don't expect it will be common to produce patches that work in more than one version control system, at least some consumers such as visualizers and highlighters would not care about the version control system.

Since we don't necessarily know what features might be needed for this, we might want to aim for extensibility. Unified diff format is already extensible, since comments can be inserted at least between file comparisons - this is what the compat format uses. Taking pijul as an example, it seems that it would be necessary to annotate the diff file, as well as hunks.

Proposal:

svenssonaxel commented 1 year ago

Perhaps an annotation @=<snippet-name> for more succinct tagging of individual content lines as equal to a named snippet.

This could make it efficient to e.g. tag all changed uses and the definition for an identifier, at least in order to create merge conflicts where otherwise automatic merges produce the wrong result, and perhaps even produce correct merges. Example: One change renames a variable, another change adds a use of that variable.