+26
Completed

add support for diff filter texconv [SG-14488]

Honigmelone 7 years ago updated by Marc Strapetz 3 years ago 14

It is possible to tell git diff how to convert files into a readable form for the diff command.  For example with the following lines slx files are unzipped before the diff is shown

[diff "slx"]
textconv = unzip -c -a

See also this topic

https://stackoverflow.com/questions/34356401/diff-between-simulink-models-slx

A similar but more specific idea is already on this site

https://smartgit.userecho.com/topics/369-support-smudge-filter-for-git-crypt-diff/

I'm generally disappointed by the lack of support for GIT functionality outside core requirements in SmartGIT. 
It's becoming quite a bother in anything but the simplest of repositories. Whenever we run into an issue that is solved in minutes in a normal git repository (e.g. the above, or alternatively, commit templates) the solution in SmartGIT is either non-existant because of ill-support of default git functionality, or workarounds are convoluted and brittle.

With that in mind, my question then is whether SmartGIT will properly support Git functionality like the above in the (near) future?
Or, which given the timeline on this issues and related ones seems more likely, is this not planned at all, and is SmartGIT aimed at more casual users? I.e.: more experience users should look elsewhere?


Unfortunately, we need to sort the requests by priority. Regarding this topic, a work-around would be: create an external tool that does what you want and invoke that, or another: configure an external compare tool that does the compare.

In our case, one of the usecases is minified JSON that we want to have properly diffed for the content creators inside SmartGit. Natively, it's shown as a single compressed line in SmartGit.

Is there a way to mimic `text conv` functionality such that the JSON file is pretty-formatted for the purposes of the diff shown inside SmartGit?

The external tools as I understand it launch a separate process (not-smartGit).


To be clear, with:

> create an external tool that does what you want and invoke that

Do you mean that I can have the output of some tool piped into SmartGITs "Changes" window?

No, I mean to create a script that pipes the output to files and then invokes your preferred compare tool. If the compare tool shows the result to the command line, SmartGit can show the output.

Would it be possible to get an example of setting up a script that shows the output in SmartGIT's "Changes" tab (and how to configure it in SmartGIT)?
I'm running into issue where the commandline script is properly setup, returning a diff to commandline, but I can't seem to get it setup in SmartGIT.

> If the compare tool shows the result to the command line, SmartGit can show the output.

If setup in `Diff Tools` as an `External diff tool`, using `${leftFile} ${rightFile}` as arguments I don't get the output piped in the "Changes" tab.

@echo off
REM Simple script that prettifies JSON and sorts it so the DIFFs make more sense, requires jq
REM Sort JSON on key, and pretty print to temp file
setlocal enabledelayedexpansion
jq-win64 . -S %1% >tmpFileA
set v1=
for /f "delims=" %%i in ('type tmpFileA') do set v1=!v1! %%i
REM Same for second argument
jq-win64 . -S %2% >tmpFileB
set v2=
for /f "delims=" %%i in ('type tmpFileB') do set v2=!v2! %%i
REM Diff and cleanup
diff tmpFileA tmpFileB
del tmpFileA
del tmpFileB

CLI output: 

8c8
<       "$type": "A"
---
>       "$type": "B"

There is no way (yet) to get it displayed in the Changes tab. But you can invoke the script as a external tool upon request which is configured to show the command's output.

> If the compare tool shows the result to the command line, SmartGit can show the output.

As per the request, could you maybe elaborate / provide a working example? The above provided script simply doesn't do anything if I double click the changed file. It runs in the background upon double-click, given that the tmp files get generated, but SmartGIT doesn't do anything

You need to select the option "Show output and wait until finished" in the external tool configuration dialog, similar to the "Print Git version" default external tool.

I'm writing this comment for future reference and to verify I understand things correctly / for others who are in the same situation:

While there is a "Diff Tools" setup, which provides the arguments one would want for writing a diff tool, namely:

- Access to the contents of both sides of the diff.

- Context auto-running. (Only opens when you double click a file that has changes)

You should NOT set it up under this tab.

You should create a script under External Tools that:

- In someway accesses the proper contents required from the diff given the filepath & commit.  

      - I don't seem to have access to the same script variables as in the Diff Tools

      - I'm not sure whether this would work for diffing in history / log (?), I only seem to be able to have access to a single file path & commit.

      - Note that we use SmartGIT for different types of repos, so I will need to write scripts for all: Git, Git LFS, etc

- Set "Show output and wait until finished" 


Remaining questions, for external tools:
- Outside manually triggering them, when are External Tools called?

- Are they called when double-clicking a file that is changed? As the setup seems to be that the Diff Tool is called then.

- What is the output format accepted by SmartGIT?  

     - You mention that "SmartGit can show the output."

        How does it display this? What is required?
- "similar to the "Print Git version" default external tool.".  I have no idea where this exists, nor can I find it in my default settings.

Alternatively, if you have SmartSynchronize, it's probably better to write a script under Diff Tools that does the diffing, and then feeds the information into SmartSynchronize.

The external application configured on the "Tools" page ("external tool") only is launched if you invoke it explicitly. Double clicking a modified file will use the matching tool from the "Diff Tools" page ("diff tool"). For an "external tool" the output should be passed to the stdout or stderr channel and use UTF-8 encoding. If there is no "Print Git Version" default external tool for you, please click "Re-Add Defaults".

Regarding SmartSynchronize: no, SmartSynchronize performs the diff, so you would need a script (configurable as "diff tool") that first converts the binary file to a text format and then let SmartSynchronize (or any other text file compare) do the diff display.

Completed

For 22.1, the Changes View will support diff.<type>.textconv.

That's excellent news!
What is the release date for 22.1 as I'll be upgrading the moment it comes out.

We do not have any release date planned. But the first Preview might not be too far away. You may follow the Blog's RSS feed or @smartgithg on Twitter to get informed as soon as it is available.