yamldiff icon indicating copy to clipboard operation
yamldiff copied to clipboard

Needs some way to show location of diffs

Open hackery opened this issue 5 years ago • 9 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?

hackery avatar Dec 12 '18 12:12 hackery

/remind me about this tomorrow

sahilm avatar Dec 19 '18 20:12 sahilm

@sahilm set a reminder for Dec 20th 2018

reminders[bot] avatar Dec 19 '18 20:12 reminders[bot]

:wave: @sahilm, about this

reminders[bot] avatar Dec 20 '18 09:12 reminders[bot]

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).

ChristianWeissCG avatar Mar 01 '19 14:03 ChristianWeissCG

/remind in 2020 ;)

kivagant-ba avatar May 31 '19 10:05 kivagant-ba

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

/remind me [what] [when]

reminders[bot] avatar May 31 '19 10:05 reminders[bot]

:wave: @kivagant-ba @sahilm about this ;)

kronn avatar Jun 17 '20 12:06 kronn

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.

hackery avatar Jun 17 '20 20:06 hackery

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.

tyler-boyd avatar Jul 20 '20 19:07 tyler-boyd

know this is super late but I just incorporated this change in https://github.com/sahilm/yamldiff/pull/19. Sorry 😐.

sahilm avatar Oct 02 '23 11:10 sahilm