📄 function.svn-diff.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Recursively diffs two paths</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.svn-commit.html">svn_commit</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.svn-fs-abort-txn.html">svn_fs_abort_txn</a></div> <div class="up"><a href="ref.svn.html">SVN Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.svn-diff" class="refentry"> <div class="refnamediv"> <h1 class="refname">svn_diff</h1> <p class="verinfo">(PECL svn:0.1-0.2)</p><p class="refpurpose"><span class="refname">svn_diff</span> — <span class="dc-title">Recursively diffs two paths</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><b><b>svn_diff</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$path1</tt></span> , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$rev1</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$path2</tt></span> , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$rev2</tt></span> )</div> <p class="para rdfs-comment"> Recursively diffs two paths, <i><tt class="parameter">path1</tt></i> and <i><tt class="parameter">path2</tt></i>. </p> <blockquote><p><b class="note">Note</b>: This is not a general-purpose diff utility. Only local files that are versioned may be diffed: other files will fail. <br /> </p></blockquote> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">path1</tt></i></span> <dd> <p class="para"> First path to diff. This can be a URL to a file/directory in an SVN repository or a local file/directory path. </p> <blockquote><p><b class="note">Note</b>: <span class="simpara">Relative paths will be resolved as if the current working directory was the one that contains the PHP binary. To use the calling script's working directory, use <a href="function.realpath.html" class="function">realpath()</a> or dirname(__FILE__).</span></p></blockquote> <div class="warning"><b class="warning">Warning</b> <p class="simpara"> If a local file path has only backslashes and no forward slashes, this extension will fail to find the path. Always replace all backslashes with forward slashes when using this function. </p> </div> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">rev1</tt></i></span> <dd> <p class="para"> First path's revision number. Use <b><tt>SVN_REVISON_HEAD</tt></b> to specify the most recent revision. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">path2</tt></i></span> <dd> <p class="para"> Second path to diff. See <i><tt class="parameter">path1</tt></i> for description. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">rev2</tt></i></span> <dd> <p class="para"> Second path's revision number. See <i><tt class="parameter">rev1</tt></i> for description. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an array-list consisting of two streams: the first is the diff output and the second contains error stream output. The streams can be read using <a href="function.fread.html" class="function">fread()</a>. Returns <b><tt>FALSE</tt></b> or <b><tt>NULL</tt></b> on error. </p> <p class="para"> The diff output will, by default, be in the form of Subversion's custom unified diff format, but an <a href="http://svnbook.red-bean.com/en/1.2/svn.advanced.externaldifftools.html" class="link external">» external diff engine</a> may be used depending on Subversion's configuration. </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <div class="warning"><b class="warning">Warning</b><p class="simpara">This function is<em class="emphasis">EXPERIMENTAL</em>. The behaviour of this function, its name, andsurrounding documentation may change without notice in a future release of PHP.This function should be used at your own risk.</p></div> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Basic example</b></p> <div class="example-contents"><p> This example demonstrates the basic usage of this function, and the retrieval of contents from the stream: </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$diff</span><span style="color: #007700">, </span><span style="color: #0000BB">$errors</span><span style="color: #007700">) = </span><span style="color: #0000BB">svn_diff</span><span style="color: #007700">(<br /> </span><span style="color: #DD0000">'http://www.example.com/svnroot/trunk/foo'</span><span style="color: #007700">, </span><span style="color: #0000BB">SVN_REVISION_HEAD</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'http://www.example.com/svnroot/branches/dev/foo'</span><span style="color: #007700">, </span><span style="color: #0000BB">SVN_REVISION_HEAD<br /></span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$diff</span><span style="color: #007700">) exit;<br /></span><span style="color: #0000BB">$contents </span><span style="color: #007700">= </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br />while (!</span><span style="color: #0000BB">feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$diff</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$contents </span><span style="color: #007700">.= </span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$diff</span><span style="color: #007700">, </span><span style="color: #0000BB">8192</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$diff</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$errors</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$contents</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>Index: http://www.example.com/svnroot/trunk/foo===================================================================--- http://www.example.com/svnroot/trunk/foo (.../foo) (revision 23)+++ http://www.example.com/svnroot/branches/dev/foo (.../foo) (revision 27) // further diff output</pre></div> </pre></div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #2 Diffing two revisions of a repository path</b></p> <div class="example-contents"><p> This example implements a wrapper function that allows a user to easily diff two revisions of the same item using an external repository path (the default syntax is somewhat verbose): </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">svn_diff_same_item</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">, </span><span style="color: #0000BB">$rev1</span><span style="color: #007700">, </span><span style="color: #0000BB">$rev2</span><span style="color: #007700">) {<br /> return </span><span style="color: #0000BB">svn_diff</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">, </span><span style="color: #0000BB">$rev1</span><span style="color: #007700">, </span><span style="color: #0000BB">$path</span><span style="color: #007700">, </span><span style="color: #0000BB">$rev2</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #3 Portably diffing two local files</b></p> <div class="example-contents"><p> This example implements a wrapper function that portably diffs two local files, compensating for the <a href="function.realpath.html" class="function">realpath()</a> fix and the backslashes bug: </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">svn_diff_local</span><span style="color: #007700">(</span><span style="color: #0000BB">$path1</span><span style="color: #007700">, </span><span style="color: #0000BB">$rev1</span><span style="color: #007700">, </span><span style="color: #0000BB">$path2</span><span style="color: #007700">, </span><span style="color: #0000BB">$rev2</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$path1 </span><span style="color: #007700">= </span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">'\\'</span><span style="color: #007700">, </span><span style="color: #DD0000">'/'</span><span style="color: #007700">, </span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #0000BB">$path1</span><span style="color: #007700">));<br /> </span><span style="color: #0000BB">$path2 </span><span style="color: #007700">= </span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">'\\'</span><span style="color: #007700">, </span><span style="color: #DD0000">'/'</span><span style="color: #007700">, </span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #0000BB">$path2</span><span style="color: #007700">));<br /> return </span><span style="color: #0000BB">svn_diff</span><span style="color: #007700">(</span><span style="color: #0000BB">$path1</span><span style="color: #007700">, </span><span style="color: #0000BB">$rev1</span><span style="color: #007700">, </span><span style="color: #0000BB">$path2</span><span style="color: #007700">, </span><span style="color: #0000BB">$rev2</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="http://svnbook.red-bean.com/en/1.2/svn.ref.svn.c.diff.html" class="link external">» SVN documentation on svn diff</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.svn-commit.html">svn_commit</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.svn-fs-abort-txn.html">svn_fs_abort_txn</a></div> <div class="up"><a href="ref.svn.html">SVN Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -