Under Linux, it is very difficult to directly use the svn diff command to view code modifications, so I searched for a better solution on the Internet, which is to use vimdiff as a code viewing tool for svn diff, especially for those who are accustomed to using vim. It's really convenient for people.
When using the svn diff command to compare the modifications of a certain file, for example, execute the following command:
$ svn diff -r4420 ngx_http_limit_req_module.c
Then the following command will actually be 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 (Chinese, English):
When using an external diff command, Subversion generates a very complex command line. The first parameter is the specific --diff-cmd, followed by the specific --extensions (although extensions are ignored when using a blank -- symbol), or if --extensions is not specified or --extensions is empty, Add the '-u' parameter. For the third and fourth arguments, Subversion will pass a "-L" and the label of the first file (for example, ""project_issues.html (revision 11209)"). The fifth and sixth arguments are another " -L" and the label of the second file. The seventh and eighth arguments are the names of the first and second files respectively (for example, ".svn/text-base/project_issues.html.svn-base" and ".svn/tmp /project_issues.html.tmp").
After understanding the internal calling command of diff, it is relatively simple to use vimdiff as a diff program.
When vimdiff compares two files, you only need to know the paths and file names of the two files, which are the 7th and 8th parameters in the above diff internal command;
It also explains that it is not feasible to directly call vimdiff with --diff-cmd due to too many parameters in the diff internal command (the command is as follows).
$ svn diff --diff-cmd vimdiff -r4420 ngx_http_limit_req_module.c
So, we need to write another script ourselves, let this script be used as a diff program, obtain the internal command of diff, and then only take the 7th and 8th parameters, and then pass them to vimdiff, so that the parameters can be solved Too many questions.
The script (diffwrap.sh) is as follows:
#!/bin/sh # 去掉前5个参数 shift 5 # 使用vimdiff比较 vimdiff "$@"
In addition, svn also provides the function of modifying the default diff program in the configuration file, so that you do not need to specify --diff-cmd every time you use svn diff.
Modify ~/.subversion/config and find the following configuration line:
# diff-cmd = diff_program (diff, gdiff, etc.)
Just add the path to the above script, for example, change it to
diff-cmd = /usr/local/bin/diffwrap.sh
In the future, using the svn diff command will open vimdiff by default to compare two files.
Rendering:
The above is the detailed content of Replace svn diff with vimdiff: a tool for comparing code. For more information, please follow other related articles on the PHP Chinese website!