1 Requirement Description

Currently, when fixing a bug, the company process requires a before and after comparison report. At the beginning, I directly used the DIff command of SVN to generate the comparison report. This method can also be seen, but the display effect is not good, and other colleagues look inconvenient. When viewing code differences at ordinary times, the Beyond Compare tool is generally used to check, and the comparison results are relatively clear. It can also export reports, but you need to manually do this, which is not as convenient as a one-line command from SVN DIff. When I discovered that Beyond Compare also supported scripting reports, I looked into it and implemented a script.

2 Implementation Effect

Generate a comparison report in HTML format with context directly from a single command, as shown below:The operations on the corresponding interface are as follows:

3 Script implementation Points

3.1 Beyond Compare Command line tool Installation (Beyond Compare version: 4.3.5)

Click on theBeyond Compare -> Install command line tools, you can install the CLI directly and follow the instructions.

3.2 Beyond Compare command

Bcomp-silent @compare_script.txt folder-1 folder-2 report. HTML command: for Mac, there are two main commands to use bcompare: Start the comparison and return bcomp immediately: Start the comparison and wait for it to complete. I want to generate the report and send it to the specified mailbox.

Parameters: -silent: tell Beyond Compare not to open the user interface, background run to generate the report @compare_script.txt: The path of the Beyond Compare script needs to be preceded by @ to indicate that it is a script file rather than a common file. If the path contains Spaces, you need to wrap folder-1 Folder-2 report.html with “” : These three parameters are not bCOMp parameters, but parameters passed to the script, which will be described later.

3.3 Writing of Beyond Compare script

See the notes for detailed explanations

# Turn logging on. Write the log to beyond_compare_log.txt Log normal "beyond_compare_log.txt" # Set up basic comparison features. [1] Criteria rules-based # Filter out log files. [2] Criteria "-*.xCuserDatad; -*IDEWorkspaceChecks.plist; -.DS_Store;" # Load first comparison. Load the comparison object with %1 %2 as a placeholder. Recursively traverse all folders as per load %1 %2 # expand all in 3.2. Diff # Generate a report of the differences. # file-report Generate a report of the differences. # layout: [3] side by side # options: Optional parameters, specifying the context and number of lines to display [4]; Note: the optional display-context parameter in the official document is not available in file-report, but if you # compare a text file, you can normally generate a comparison report with context. If there is a binary such as an image, a script error will be reported. # I don't know if it's a Bug or I didn't find the right parameter. # output-to: specifies the path to export the file. # output-options: Export this is an optional parameter, which is specified here [5] to be automatically wrapped and exported in multicolor HTML format. File-report layout:side-by-side options:display-context,line-numbers output-to:%3 output-options:wrap-word,html-colorCopy the code

[1] The following figure shows the configuration on the corresponding interface[2] The following figure shows the configuration on the corresponding interface[3] The following figure shows the configuration on the corresponding interface

[4] The following figure shows the configuration on the corresponding interface

[5] The following figure shows the configuration on the corresponding interface

4. Use of scripts

Execute the following command in the shell: bcomp-silent@compare_script. TXT folder-1 folder-2 report. HTML You can also use scripts such as Python to perform subsequent operations, such as opening the file in a browser or sending the file to a specified mailbox.

Here all commands and parameters can be found in the official documentation: www.scootersoftware.com/v4help/inde…

Can also be here to see the official script example: www.scootersoftware.com/v4help/ (found Using Beyond Comapre – > Scripts – > Sample Scripts)