<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Recursively diffs two paths</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.svn-delete.html">svn_delete</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.svn-export.html">svn_export</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)</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" id="refsect1-function.svn-diff-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>svn_diff</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$path1</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$rev1</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$path2</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$rev2</code></span> )</div> <p class="para rdfs-comment"> Recursively diffs two paths, <em><code class="parameter">path1</code></em> and <em><code class="parameter">path2</code></em>. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> This is not a general-purpose diff utility. Only local files that are versioned may be diffed: other files will fail. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-function.svn-diff-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">path1</code></em></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 class="note"><p><strong class="note">Note</strong>: <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 <span class="function"><a href="function.realpath.html" class="function">realpath()</a></span> or dirname(__FILE__).</span></p></blockquote> <div class="warning"><strong class="warning">Warning</strong> <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"><em><code class="parameter">rev1</code></em></span> <dd> <p class="para"> First path's revision number. Use <strong><code>SVN_REVISION_HEAD</code></strong> to specify the most recent revision. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">path2</code></em></span> <dd> <p class="para"> Second path to diff. See <em><code class="parameter">path1</code></em> for description. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">rev2</code></em></span> <dd> <p class="para"> Second path's revision number. See <em><code class="parameter">rev1</code></em> for description. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.svn-diff-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 <span class="function"><a href="function.fread.html" class="function">fread()</a></span>. Returns <strong><code>FALSE</code></strong> or <strong><code>NULL</code></strong> 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" id="refsect1-function.svn-diff-notes"> <h3 class="title">Notes</h3> <div class="warning"><strong class="warning">Warning</strong><p class="simpara">This function is <em class="emphasis">EXPERIMENTAL</em>. The behaviour of this function, its name, and surrounding 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" id="refsect1-function.svn-diff-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4664"> <p><strong>Example #1 Basic example</strong></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 screen"> <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> </div> </div> </p> <p class="para"> <div class="example" id="example-4665"> <p><strong>Example #2 Diffing two revisions of a repository path</strong></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" id="example-4666"> <p><strong>Example #3 Portably diffing two local files</strong></p> <div class="example-contents"><p> This example implements a wrapper function that portably diffs two local files, compensating for the <span class="function"><a href="function.realpath.html" class="function">realpath()</a></span> 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" id="refsect1-function.svn-diff-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 class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.svn-delete.html">svn_delete</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.svn-export.html">svn_export</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>