Using vimdiff instead of SVN diff to view code


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

Explanation of SVN diff in SVN official FAQ(chineseenglish):

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( )As follows:

#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/

Later, using the SVN diff command will open vimdiff to compare two files by default.

design sketch:

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!

Recommended Today

Video compatibility in wechat

1. In line properties of video tag SRC: URL of video Poster: Video cover, no picture displayed when playing Preload: preload Autoplay: autoplay Loop: loop playback Controls: browser’s own control bar Width: video width Height: video height style=”object-fit:fill” /Adding this style will make the Android / Web video full screen in wechat. If it is […]