uTools-Manuals/docs/php/svn_diff.html
2019-04-28 19:00:34 +08:00

213 lines
12 KiB
HTML

<!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 class="docs"><div id="layout">
<div id="layout-content"><div id="function.svn-diff" class="refentry">
<div class="refnamediv">
<h1 class="refname">svn_diff</h1>
<p class="verinfo">(PECL svn &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">svn_diff</span> &mdash; <span class="dc-title">Recursively diffs two paths</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.svn-diff-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<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>
) : <span class="type">array</span></div>
<p class="para rdfs-comment">
Recursively diffs two paths, <code class="parameter">path1</code> and
<code class="parameter">path2</code>.
</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">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">path1</code></dt>
<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">相对路径将会以PHP执行文件所在目录作为当前工作目录进行解析。如果希望依据脚本所在目录解析, 使用<span class="function"><a href="realpath.html" class="function">realpath()</a></span> 或 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>
<code class="parameter">rev1</code></dt>
<dd>
<p class="para">
First path&#039;s revision number. Use <strong><code>SVN_REVISION_HEAD</code></strong>
to specify the most recent revision.
</p>
</dd>
<dt>
<code class="parameter">path2</code></dt>
<dd>
<p class="para">
Second path to diff. See <code class="parameter">path1</code> for description.
</p>
</dd>
<dt>
<code class="parameter">rev2</code></dt>
<dd>
<p class="para">
Second path&#039;s revision number. See <code class="parameter">rev1</code>
for description.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.svn-diff-returnvalues">
<h3 class="title">返回值</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="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&#039;s
custom unified diff format, but an
<a href="http://svnbook.red_bean.com/en/1.2/svn.advanced.externaldifftools.html" class="link external">&raquo;&nbsp;external
diff engine</a> may be
used depending on Subversion&#039;s configuration.
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.svn-diff-notes">
<h3 class="title">注释</h3>
<div class="warning"><strong class="warning">Warning</strong><p class="simpara">此函数是<em class="emphasis">实验性</em>的。此函数的表象,包括名称及其相关文档都可能在未来的
PHP 发布版本中未通知就被修改。使用本函数风险自担 。</p></div>
</div>
<div class="refsect1 examples" id="refsect1-function.svn-diff-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-5669">
<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"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$diff</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$errors</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">svn_diff</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'http://www.example.com/svnroot/trunk/foo'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SVN_REVISION_HEAD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'http://www.example.com/svnroot/branches/dev/foo'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SVN_REVISION_HEAD<br /></span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$diff</span><span style="color: #007700">)&nbsp;exit;<br /></span><span style="color: #0000BB">$contents&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;<br />while&nbsp;(!</span><span style="color: #0000BB">feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$diff</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$contents&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$diff</span><span style="color: #007700">,&nbsp;</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">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</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-5670">
<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"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</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">,&nbsp;</span><span style="color: #0000BB">$rev1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$rev2</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">svn_diff</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$rev1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$path</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$rev2</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
<p class="para">
<div class="example" id="example-5671">
<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="realpath.html" class="function">realpath()</a></span>
fix and the backslashes bug:
</p></div>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">svn_diff_local</span><span style="color: #007700">(</span><span style="color: #0000BB">$path1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$rev1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$path2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$rev2</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$path1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">'\\'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'/'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #0000BB">$path1</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$path2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">'\\'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'/'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #0000BB">$path2</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">svn_diff</span><span style="color: #007700">(</span><span style="color: #0000BB">$path1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$rev1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$path2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$rev2</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.svn-diff-seealso">
<h3 class="title">参见</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">&raquo;&nbsp;SVN documentation on svn diff</a></li>
</ul>
</p>
</div>
</div></div></div></body></html>