Question
Fabio Care · Mar 29

Compare .mac /.int routines and show differences

Hello, 
I'm currently working on a custom version control implementation. 
I'd like to show differences between a copy of a previously saved routine as a merge of the ^ROUTINE Global and the current version of that same routine. 

I've found legacy Documentation for %RCMP which does the trick in the terminal but I'd like a similar result stored inside a variable. 
I also want to show differences, not only see if they are the same or not. 

The management portal has that exact feature, so maybe someone can direct me to the function that is being used there. 

I've seen solutions with files, and one way to do it would be to write the routines to files, and compare those, but I'd like to avoid that if possible.

Thank you. 

Product version: Caché 2018.1
0
0 366
Discussion (19)5
Log in or sign up to continue

I guess all you need is to redirect the ouput of %RCMP  to some %Stream of SPOOL:
In addition, you have %RCMP in your installation and just pick out what you need.

Thank you @Robert Cemper for the quick response,

I was hoping to avoid using the %RCMP Routine as it uses GOTO commands. 


One of our Senior Developers pointed me in the right direction. He recommended I use:

Class %Library.Routine
query Compare(Nsp1 As %String, RouName1 As %String, Nsp2 As %String, RouName2 As %String)

Selects LineNo1 As %String, Line1 As %String, LineNo2 As %String, Line2 As %String
This query provides a list of all lines that differ between two given routines.
Nsp1 and RouName1 specify the first routine.
Nsp2 and RouName2 specify the second routine.
Nsp1 and RouName2 can be either an explicit or an implied namespace.

I will try this and see if it works. If anyone has further advice feel free to add them. 
 

just checked %Library.Routine
- a sample of many %R* routines
- lots of @ indirections
- DO with . (dot) syntax
- and of course GOTO.
Just to qualify the code inside.

You're right, i should have looked into that aswell. 
I got it to work with the Query now, since the %RCMP file was locked for me. 

 Set statement=##class(%SQL.Statement).%New()
 Set status=statement.%PrepareClassQuery("%Library.Routine","Compare")
  
 result
 SET result=##class(%Library.ProcedureContext).%New()
 
 SET result = statement.%Execute(NSP1,ROUTINE1,NSP2,ROUTINE2)
 DO result.DumpResults()
 

>>>>>>  "since the %RCMP file was locked"

USER>ZLOAD %RCMP PRINT

I've seen solutions with files, and one way to do it would be to write the routines to files, and compare those, but I'd like to avoid that if possible.

I would highly recommend you use a file approach, i.e. git. Write routines to files and compare them using git diff tools.

One of the best tools that I have found for comparing routines is called "Beyond Compare".  You can create a small CSP that will serve up the a routine depending on the routine name in the query string of the URL.  Then you can put that URL directly in the file open dialog of "Beyond Compare" that it will bring up the routines and display a nice side-by-side compare.  It can also save the comparison in an HTML file for sharing with others.

See Studio Compare

With an external program WinMerge also works fine. You can compare any elements (mac, cls, css, js, css, etc.) located both inside the database and in external files.

This is really helpful Vitaliy Serdtsev.  Thanks for this information.  I set this up with Beyond Compare and it works great.  Do you know of anyway to get it to work across namespaces?  It would be nice to be able to compare a routine from one namespace to another.

Compare

Compares an open file to one that you select with Browse. You must have specified an external compare tool with the Compare setting in Options > Environment > General. To work correctly, the compare tool must be able to accept command line parameters as tool.exe file1 file2. Tested compare tools are Microsoft Windiff and Perforce p4Diff.exe.

This Compare only works when working with the studio, correct? 
I was thinking of something for people who don't have direct access to the studio and maybe just want to check out differences made, like a supervisor. 
As I said, I managed to implement the query from my answer above, but the code is very old. Just curious if there is a newer version. 

This Compare only works when working with the studio, correct?

Yes, Studio does the following:

  1. uploads the first source code to a temporary directory (for example c:\windows\temp)
  2. uploads the second source code to a temporary directory
  3. starts WinMerge by passing in the command line links to previously uploaded files: WinMerge Command line

You can do all this yourself from a batch file.
In this case, you can compare items not only in different databases, but also on different servers.

Beyond Compare works outside of Studio and can compare files, folders, and it even does an Ok compare of Word files.  I have used it to track project changes as a manager to keep track of the changes the developers were making.  It worked great and we were able to catch some issues early in the project so that they could be fixed quickly.

Most of the above is true for WinMerge, with one exception - WinMerge is free.
WinMerge has plugins for comparing images, PDF, Word, Visio, Excel, PowerPoint, etc.

For us all, the common denominator is Cache/IRIS and we have, as you know, Cache/IRIS for Win, Linux, AIX and MAC platforms. It's nice to know about existing external tools, but for some of us the COS solutions remains as the last resort, especially if those (external) tools do not exists for the OS, one works on (Just My2Cents).

My choice of a comparison tool was determined by the OS on which Studio is running. But you are free to choose something more platform-independent, such as Java or Qt.

By the way, SQL Data Lens (written in Java) already has the ability to view and upload sources to a file. It would be nice to add integration with a third-party tool for comparing items (by analogy with Studio).

I hope @Andreas Schneider will read this wish.

@Vitaliy.Serdtsev thanks for this great idea! In the past i have also missed this feature myself from time to time. So far the pain has not been great enough ;-) 
But now I know that other users also miss this feature...


 

Agree, Beyond Compare is a great diff tool. We have interfaced it to Deltanji source control - so it goes direct to code in InterSystems namespaces, rather than exporting the code into files and then diffing the files.  

The solo edition (free to use) is available from our website if you're using Studio. Or you can download it as a VS Code extension by installing Serenji

I'm a fan of beyond compare but it is not always available on some of the sites I log in to. I'm not a fan of RCMP. I've got a Diff program that works in a terminal session that I use when I log on to a Cache version 5 site. Feel free to take this and do what you want with it (.MAC routines can be found on ^rMAC):

 
Code