sahilm/yamldiff

Needs some way to show location of diffs

Closed this issue ยท 10 comments

I've found this very handy for a few diffs, where the structure lets me easily identify the changed lines, but it's trickier when there are similar sections.
Example output chunk based on a couple of the files I'm diffin' today:

-  readonly: true,
+  readonly: false,
-  readonly: true,
+  readonly: false,
-  readonly: true,
+  readonly: false,

These are deep in sub-structures - but yamldiff gives no clue as to where, or even that these are in different chunks. I can use this output to go back and target a further manual search, but that's unwieldy for anything larger than an already trivial diff.

Adding source line numbers to each +/- line might be one way; or more usefully, preceding each diff chunk with an annotation, similar to the normal diff style:

23,24c23,24
< file1 oldvalue1
< file1 oldvalue2
---
> file2 newvalue1
> file2 newvalue2

giving something like this, identifying the element and line numbers in each file

# appconfig.userdb.user.[2].properties @23 @428
- readonly: true
+ readonly: false
# appconfig.userdb.user.[7].properties @53 @463
- readonly: true
+ readonly: false

Is that achievable using the available interfaces?

/remind me about this tomorrow

@sahilm set a reminder for Dec 20th 2018

๐Ÿ‘‹ @sahilm, about this

Yamldiff is structure-aware.
Unix diff is line-based. I vote against a line-based "patch file format" for Yamldiff.

Instead of 23,24c23,24 you can use a "patch file format" that uses a YAMP Pointer (similar to a JSON Pointer). See https://github.com/krishicks/yaml-patch for details.

This would enable us to use the Yamldiff tool to generate patch files and to use yaml-patch tool to apply that patch to another YAML file in a structure-aware manner.
In a line-based approach it is required that elements in the patch-target are sorted equally to the file that was used to create the patch file. With YAML Pointer based approach you could apply the patch to a YAML file that has a different element sort order.

This could help e.g. when someone want to solve git merge conflicts for SOPS-encrypted yaml files automatically (get rid of conflicts for SOPS encrypted values, when there was no semantical change to the value, just encryption-changed).

/remind in 2020 ;)

@kivagant-ba we had trouble parsing your reminder. Try:

/remind me [what] [when]

kronn commented

๐Ÿ‘‹ @kivagant-ba @sahilm about this ;)

I vote against a line-based "patch file format" for Yamldiff.

Instead of 23,24c23,24 you can use a "patch file format" that uses a YAMP Pointer

That's exactly what I was describing. The 23,24c23,24 is the example of a regular diff, where appconfig.userdb.user.[2].properties @23 @428 is one path format (JSON-like) for identifying an element.

Hey, I'd love this too. I think it would be invaluable for my use case.

I will take a look and see if I can add it myself, but I'm not super experienced with Go so no promises.

sahilm commented

know this is super late but I just incorporated this change in #19. Sorry ๐Ÿ˜.