Jump to content

how to diff on console to stdout


JanReimer

Recommended Posts

Hello,

 

is there a way to let 'cm diff ' outout to console (i.e. stdout). The format we need is either normal diff, unified diff, or contextual diff. We need this for integration of our inspection tool.

Currently, I haven't found a way the merge tool not to open a gui window. I've tried to integrate other diff tools with no success. An option on the cm diff command would be convenient.

 

Best regards

Jan

Link to comment
Share on other sites

I don't know if this is going to help you, but after a little tweaking this is what I got. I use GTKPlastic in Ubuntu 14.04. I'll write it entirely (regarding that you know how to set up other diff tools) in case somebody, someday, find this useful too.

 

It seems that there is no way to make the integrated diff tool (mergetool) to show the result using stdout, as it is heavily focused as a GUI utility. However, you can set any other text differences tool to work with plastic and the 'cm diff' command should use it. In the following example, I'll use the 'diff' command installed by default in many GNU/Linux flavours (as well as OS X I think).

 

First of all, we must set PlasticSCM to use other diff tool. You'll find that setting under Preferences > Diff Tools (At least in MacPlastic and GTKPlastic).

 

KEBHo8o.png

 

I'll set up diff clicking on "Add" and write the command that will be executed to perform a diff. There're some useful keywords, but I'll only use two: @sourcefile and @destinationfile, which will be replaced with the full path of the files we're going to compare. So this is the final command:

diff @sourcefile @destinationfile

You can set it to run only when you're comparing two files with a specific file extension, but in any case, we have to do something very important: change the order of the command. It seems that Plastic chooses the first diff tool that matches the kind of file or extension to diff. $text represents ALL text files, so if we want our custom command to be chosen, it must be the first in the list.

 

NECPzOk.png

 

Now it's the turn to test it! In my wkspaces I have one named Redburger with some Android code. I'll compare a *.java (text) file form the changeset 10 with the same file on changeset 9.

cm diff rev:./LoginActivity.java#cs:10 rev:./LoginActivity.java#cs:9

aKPjNlm.png

 

Looks good right? I hope you'll find this useful. Diff is not the mightiest tool, but this proofs you can configure any tool you want to show differences though stdout :)

Link to comment
Share on other sites

Hi S_Louis,

 

thanks for your post. I've tried it under Windows 7, however cm diff seems to swollow the output that is written to stdout by the diff tool. This might be because cm diff waits for the diff tool (i.e. the GUI in standard configuration) to finish. While waiting the output seems to be silently captured.

Link to comment
Share on other sites

Hi S_Louis,

 

thanks for your post. I've tried it under Windows 7, however cm diff seems to swollow the output that is written to stdout by the diff tool. This might be because cm diff waits for the diff tool (i.e. the GUI in standard configuration) to finish. While waiting the output seems to be silently captured.

 

What diff tool are you trying to use in Windows? I'm actually curious if can configure it... :ph34r:

Link to comment
Share on other sites

You're completely right, nothing shows up. If I had your problem I'd probably write a small Python script that calls diff and recolects the stdout, writing it were needed. Then I'd set that script as the diff tool in Plastic, but I understand that this approach is not the best solution to your problem :/

Link to comment
Share on other sites

I wrote this tiny script and it works. Little hacky, but works.

import sys
from subprocess import Popen, PIPE


_difftool = "C:\\Program Files (x86)\\GnuWin32\\bin\\diff.exe"

def main():
    f = open("C:\\Users\\sergio\\Desktop\\diff_output.txt", "w")
    source = sys.argv[1]
    destination = sys.argv[2]

    p = Popen([_difftool, source, destination], stdout=PIPE)
    out, err = p.communicate()

    # Ugly 'replace', p.communicate is not beautiful
    f.write(str(out).replace("\\r\\n", "\n"))
    f.close()

    sys.exit(0)

if __name__ == "__main__":
    main()

I tried to redirect the stdout of the difftools without success. And, it seems that difftools always exists with code 1, indicating some kind of error. In the first place I thought that was the cause of cm not being able to show the output, as it might be considering a non 0 exit code as an irrecuperable error, but it didn't show my Python's stdout either, so :(

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...