Forum Archive

Diff utility for Stash

ihf

Does anyone have a working diff utility (file compare) that will run under Stash?

ccc

Difflib is on of the batteries included in Python https://pymotw.com/2/difflib/

Olaf

Does standard diff provided in Python module difflib (see its help file at the very end) not provide what you need?

ihf

You are quite right. Something like this does what I need:

import difflib
import sys

with open('./f1', 'r') as f1:
    with open('./f2', 'r') as f2:
        diff = difflib.unified_diff(
            f1.readlines(),
            f2.readlines(),
            fromfile='f1',
            tofile='f2',
        )
        for line in diff:
            sys.stdout.write(line)
JonB

Take a look at gitui, which provides a visual differ, a side by side diff in a webview. I think this just uses difflib.HtmlDiff, which you then just load into a webview.

git for stash also comes with a three way diff tool, if you are into that sort of thing, which came from the interwebs somewhere.

ihf

@JonB Thanks. Were you referring to this: https://github.com/jsbain/gitview/blob/master/git_diff.py

JonB

yes. this is just a thin wrapper around difflib.Htmldiff. if you look in gitui.py, this shows you could then load the result into a webview and display it.

Also, in stash/lib/git/diff3.py is a three way differ, which I think can also be run as a two way differ