Diff between two commits in lines

Answered

Hello!
I am trying to get diff between two files in order to use it in my plugin. I saw this thread: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206756695-Get-diff-between-two-files?input_string=Diff%20between%20two%20files%20in%20lines
but it seems to be deprecated as I can't find method compareWithCache() in DiffUtil.

So, my question is: what can I use from Intellij open-api to obtain diff between two states of file (before and after commit) in whatever form (but preferable in lines, and even better if it possible to get this lines with their line numbers in file).

Thanks!

0
5 comments

You can use `com.intellij.diff.comparison.ComparisonManager`.
Ex: `ComparisonManager#compareLines(CharSequence, CharSequence, ComparisonPolicy, ProgressIndicator)`  method.

1

Thank you for quick response, Aleksey!

Can you please tell me how I can create ProgressIndicator? I don't need any visualization of this diff, just like List<String> with changed strings.

 

 

0

OK, I feel like I just found it already by myself. Is it OK if I use just EmptyProgressIndicator?

 

0

Yes, you can pass new EmptyProgressIndicator (or just `com.intellij.openapi.progress.DumbProgressIndicator#INSTANCE`).

Or you can use `com.intellij.openapi.progress.Task.Backgroundable` / `com.intellij.openapi.progress.Task.Modal` to compute this in background (and use passed indicatior).

1

OK, Thank you a lot!

 

0

Please sign in to leave a comment.