In Linux, it’s very difficult to use SVN diff command to view the code modification directly, so we found a better solution on the Internet, that is to use vimdiff as the code viewing tool of SVN diff, especially for people who are used to using vim.
When using the SVN diff command to compare before and after modification of a file, for example, execute the following command:
$ svn diff -r4420 ngx_http_limit_req_module.c
Then, the following command is actually sent to the default diff program:
-u -L ngx_http_limit_req_module.c (revision 4420) -L ngx_http_limit_req_module.c (working copy) .svn/tmp/tempfile.tmp ngx_http_limit_req_module.c
When using an external diff command, subversion generates a very complex command line. The first parameter is the concrete — diff CMD, and then the concrete — extensions (although the extension is ignored when using the blank — symbol), or if — extensions is not specified or — extensions is empty, the ‘- U’ parameter is added. For the third and fourth parameters, subversion will pass a “- L” and the label of the first file (for example, “project”_ issues.html (revision 11209)”)。 The fifth and sixth are the labels of another “- L” and the second file. The seventh and eighth parameters are the names of the first and second files, respectively (for example,. SVN / text base / project)_ issues.html.svn –Svn / TMP / Project_ issues.html.tmp ”）。
Knowing the internal calling command of diff, it is easy to use vimdiff as diff program.
When comparing two files, vimdiff only needs to know the path and file name of the two files, that is, the seventh and eighth parameters in the above diff internal command;
At the same time, it also shows that it is not feasible to call vimdiff directly with — diff CMD due to too many parameters of diff internal command (the command is as follows).
$ svn diff –diff-cmd vimdiff -r4420 ngx_http_limit_req_module.c
Therefore, we need to write another script as a diff program to get the internal command of diff, and then only take the seventh and eighth parameters and pass them to vimdiff, so that we can solve the problem of too many parameters.
Script（ diffwrap.sh ）As follows:
#!/bin/sh #Remove the first five parameters shift 5 #Compare with vimdiff vimdiff "[email protected]"
In addition, SVN also provides the function of modifying the default diff program in the configuration file, so that you don’t need to specify — diff CMD every time you use SVN diff.
Modify ~ /. Subversion / config to find the following configuration line:
# diff-cmd = diff_program (diff, gdiff, etc.)
Just add the path of the script above, for example, modify it to
diff-cmd = /usr/local/bin/diffwrap.sh
Later, using the SVN diff command will open vimdiff to compare two files by default.
This article about using vimdiff instead of SVN diff to view the code tool is introduced here. For more relevant vimdiff code comparison content, please search previous articles of developer or continue to browse the following related articles. I hope you can support developer more in the future!