<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post/4989/</link>
<title><![CDATA[ php操作SVN类]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 15 Feb 2012 15:05:39 +0000</pubDate> 
<guid>http://jackxiang.com/post/4989/</guid> 
<description>
<![CDATA[ 
	代码发布上线，用PHP来做的话很可能会用到。<br/>使用PHP完成SVN的操作，包括复制，查看列表，删除，移动，创建目录，查看diff,更新，合并，提交，获取状态，获取commit log,获取当前版本号操作。在svn 1.6.11版本中测试通过。<br/>来自Url：http://www.oschina.net/code/snippet_162844_7312<br/>代码如下：<br/><br/><br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
&nbsp;&nbsp;/**
&nbsp;&nbsp; *
&nbsp;&nbsp; * This class for execute the external program of svn
&nbsp;&nbsp; * 
&nbsp;&nbsp; * @auth Seven Yang &lt;qineer@gmail.com&gt;
&nbsp;&nbsp; *
&nbsp;&nbsp; */
class SvnPeer
&#123;

&nbsp;&nbsp;/**
&nbsp;&nbsp; * List directory entries in the repository
&nbsp;&nbsp; *
&nbsp;&nbsp; * @param string a specific project repository path
&nbsp;&nbsp; * @return bool true, if validated successfully, otherwise false
&nbsp;&nbsp; */
&nbsp;&nbsp;static public function ls($repository)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;svn ls &quot; . $repository;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&quot;&lt;br&gt;&quot;, $output);
&nbsp;&nbsp;&nbsp;&nbsp;if (strpos($output, &#039;non-existent in that revision&#039;)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;return &quot;&lt;br&gt;&quot; . $command . &quot;&lt;br&gt;&quot; . $output;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;/**
&nbsp;&nbsp; * Duplicate something in working copy or repository, remembering history
&nbsp;&nbsp; * 
&nbsp;&nbsp; * @param $src
&nbsp;&nbsp; * @param $dst
&nbsp;&nbsp; * @param $comment string specify log message
&nbsp;&nbsp; * @return bool true, if copy successfully, otherwise return the error message
&nbsp;&nbsp; *
&nbsp;&nbsp; * @todo comment need addslashes for svn commit
&nbsp;&nbsp; */
&nbsp;&nbsp;static public function copy($src, $dst, $comment)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;svn cp $src $dst -m &#039;$comment&#039;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&quot;&lt;br&gt;&quot;, $output);

&nbsp;&nbsp;&nbsp;&nbsp;if (strpos($output, &#039;Committed revision&#039;)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;return &quot;&lt;br&gt;&quot; . $command . &quot;&lt;br&gt;&quot; . $output;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;/**
&nbsp;&nbsp; * Remove files and directories from version control
&nbsp;&nbsp; * 
&nbsp;&nbsp; * @param $url
&nbsp;&nbsp; * @return bool true, if delete successfully, otherwise return the error message
&nbsp;&nbsp; *
&nbsp;&nbsp; * @todo comment need addslashes for svn commit
&nbsp;&nbsp; */
&nbsp;&nbsp;static public function delete($url, $comment)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;svn del $url -m &#039;$comment&#039;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&#039;&lt;br&gt;&#039;, $output);
&nbsp;&nbsp;&nbsp;&nbsp;if (strpos($output, &#039;Committed revision&#039;)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&nbsp;&nbsp;&#125; 

&nbsp;&nbsp;&nbsp;&nbsp;return &quot;&lt;br&gt;&quot; . $command . &quot;&lt;br&gt;&quot; . $output;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;/**
&nbsp;&nbsp; * Move and/or rename something in working copy or repository
&nbsp;&nbsp; * 
&nbsp;&nbsp; * @param $src string trunk path
&nbsp;&nbsp; * @param $dst string new branch path
&nbsp;&nbsp; * @param $comment string specify log message
&nbsp;&nbsp; * @return bool true, if move successfully, otherwise return the error message
&nbsp;&nbsp; *
&nbsp;&nbsp; * @todo comment need addslashes for svn commit
&nbsp;&nbsp; */
&nbsp;&nbsp;static public function move($src, $dst, $comment)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;svn mv $src $dst -m &#039;$comment&#039;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&#039;&lt;br&gt;&#039;, $output);

&nbsp;&nbsp;&nbsp;&nbsp;if (strpos($output, &#039;Committed revision&#039;)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;return &quot;&lt;br&gt;&quot; . $command . &quot;&lt;br&gt;&quot; . $output;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;/**
&nbsp;&nbsp; * Create a new directory under version control
&nbsp;&nbsp; *
&nbsp;&nbsp; * @param $url string 
&nbsp;&nbsp; * @param $comment string the svn message
&nbsp;&nbsp; * @return bool true, if create successfully, otherwise return the error message
&nbsp;&nbsp; *
&nbsp;&nbsp; * @todo comment need addslashes for svn commit
&nbsp;&nbsp; */
&nbsp;&nbsp;static public function mkdir($url, $comment)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;svn mkdir $url -m &#039;$comment&#039;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&#039;&lt;br&gt;&#039;, $output);

&nbsp;&nbsp;&nbsp;&nbsp;if (strpos($output, &#039;Committed revision&#039;)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;return &quot;&lt;br&gt;&quot; . $command . &quot;&lt;br&gt;&quot; . $output;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;static public function diff($pathA, $pathB)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$output = SvnPeer::runCmd(&quot;svn diff $pathA $pathB&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;return implode(&#039;&lt;br&gt;&#039;, $output);
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;static public function checkout($url, $dir)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;cd $dir &amp;&amp; svn co $url&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&#039;&lt;br&gt;&#039;, $output);
&nbsp;&nbsp;&nbsp;&nbsp;if (strstr($output, &#039;Checked out revision&#039;)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;return &quot;&lt;br&gt;&quot; . $command . &quot;&lt;br&gt;&quot; . $output;
&nbsp;&nbsp;&#125;


&nbsp;&nbsp;static public function update($path)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;cd $path &amp;&amp; svn up&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&#039;&lt;br&gt;&#039;, $output);

&nbsp;&nbsp;&nbsp;&nbsp;preg_match_all(&quot;/[0-9]+/&quot;, $output, $ret);
&nbsp;&nbsp;&nbsp;&nbsp;if (!$ret[0][0])&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return &quot;&lt;br&gt;&quot; . $command . &quot;&lt;br&gt;&quot; . $output;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;return $ret[0][0];
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;static public function merge($revision, $url, $dir)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;cd $dir &amp;&amp; svn merge -r1:$revision $url&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&#039;&lt;br&gt;&#039;, SvnPeer::runCmd($command));
&nbsp;&nbsp;&nbsp;&nbsp;if (strstr($output, &#039;Text conflicts&#039;)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return &#039;Command: &#039; . $command .&#039;&lt;br&gt;&#039;. $output;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;static public function commit($dir, $comment)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;cd $dir &amp;&amp; svn commit -m&#039;$comment&#039;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&#039;&lt;br&gt;&#039;, SvnPeer::runCmd($command));

&nbsp;&nbsp;&nbsp;&nbsp;if (strpos($output, &#039;Committed revision&#039;) &#124;&#124; empty($output)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return $output;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;static public function getStatus($dir)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;cd $dir &amp;&amp; svn st&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;return SvnPeer::runCmd($command);
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;static public function hasConflict($dir)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$output = SvnPeer::getStatus($dir);
&nbsp;&nbsp;&nbsp;&nbsp;foreach ($output as $line)&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (&#039;C&#039; == substr(trim($line), 0, 1) &#124;&#124; (&#039;!&#039; == substr(trim($line), 0, 1)))&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;return false;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;/**
&nbsp;&nbsp; * Show the log messages for a set of path with XML
&nbsp;&nbsp; *
&nbsp;&nbsp; * @param path string 
&nbsp;&nbsp; * @return log message string 
&nbsp;&nbsp; */
&nbsp;&nbsp;static public function getLog($path)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;svn log $path --xml&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;return implode(&#039;&#039;, $output);
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;static public function getPathRevision($path)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;svn info $path --xml&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;$string&nbsp;&nbsp;= implode(&#039;&#039;, $output);
&nbsp;&nbsp;&nbsp;&nbsp;$xml&nbsp;&nbsp;&nbsp;&nbsp; = new SimpleXMLElement($string);
&nbsp;&nbsp;&nbsp;&nbsp;foreach ($xml-&gt;entry[0]-&gt;attributes() as $key=&gt;$value)&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (&#039;revision&#039; == $key) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $value;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;static public function getHeadRevision($path)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$command = &quot;cd $path &amp;&amp; svn up&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= SvnPeer::runCmd($command);
&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;&nbsp;= implode(&#039;&lt;br&gt;&#039;, $output);

&nbsp;&nbsp;&nbsp;&nbsp;preg_match_all(&quot;/[0-9]+/&quot;, $output, $ret);
&nbsp;&nbsp;&nbsp;&nbsp;if (!$ret[0][0])&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return &quot;&lt;br&gt;&quot; . $command . &quot;&lt;br&gt;&quot; . $output;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;return $ret[0][0];
&nbsp;&nbsp;&#125;

 /**
&nbsp;&nbsp;* Run a cmd and return result
&nbsp;&nbsp;*
&nbsp;&nbsp;* @param string command line
&nbsp;&nbsp;* @param boolen true need add the svn authentication
&nbsp;&nbsp;* @return array the contents of the output that svn execute
&nbsp;&nbsp;*/
&nbsp;&nbsp;static protected function runCmd($command)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$authCommand = &#039; --username &#039; . SVN_USERNAME . &#039; --password &#039; . SVN_PASSWORD . &#039; --no-auth-cache --non-interactive --config-dir &#039;.SVN_CONFIG_DIR.&#039;.subversion&#039;;
&nbsp;&nbsp;&nbsp;&nbsp;exec($command . $authCommand . &quot; 2&gt;&amp;1&quot;, $output);

&nbsp;&nbsp;&nbsp;&nbsp;return $output;
&nbsp;&nbsp;&#125;
&#125;

</textarea><br/><br/>更多参考：http://linjin101.blog.51cto.com/2601349/466337
]]>
</description>
</item><item>
<link>http://jackxiang.com/post/4989/#blogcomment63436</link>
<title><![CDATA[[评论]  php操作SVN类]]></title> 
<author>hxngb8yf &lt;omtv00@mail114.net&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 15 Feb 2012 17:29:36 +0000</pubDate> 
<guid>http://jackxiang.com/post/4989/#blogcomment63436</guid> 
<description>
<![CDATA[ 
	楼主说得好，支持一下
]]>
</description>
</item><item>
<link>http://jackxiang.com/post/4989/#blogcomment63440</link>
<title><![CDATA[[评论]  php操作SVN类]]></title> 
<author>分进合击 &lt;zzzzaaaa1122@126.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 16 Feb 2012 16:40:24 +0000</pubDate> 
<guid>http://jackxiang.com/post/4989/#blogcomment63440</guid> 
<description>
<![CDATA[ 
	论坛是交流的地方，没有回帖跟帖，那么你如何跟人交流？不交流，又如何取得进步 <br/>？所以，看完帖子后，无论你感到好还是坏，都请你告诉作者。因为，无论你说什么，都 <br/>比冷漠要强！
]]>
</description>
</item><item>
<link>http://jackxiang.com/post/4989/#blogcomment63442</link>
<title><![CDATA[[评论]  php操作SVN类]]></title> 
<author>pengruncs196 &lt;chuangkhpwnknl21@tom.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 16 Feb 2012 17:55:00 +0000</pubDate> 
<guid>http://jackxiang.com/post/4989/#blogcomment63442</guid> 
<description>
<![CDATA[ 
	吃着糖在嘴里的感觉真好
]]>
</description>
</item><item>
<link>http://jackxiang.com/post/4989/#blogcomment63678</link>
<title><![CDATA[[评论]  php操作SVN类]]></title> 
<author>guoxinc1919 &lt;lavonapgtvim20@21cn.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 10 Mar 2012 19:45:51 +0000</pubDate> 
<guid>http://jackxiang.com/post/4989/#blogcomment63678</guid> 
<description>
<![CDATA[ 
	难倒这就是我还没有找到传说中的沙发吗呵呵确实厉定
]]>
</description>
</item><item>
<link>http://jackxiang.com/post/4989/#blogcomment63699</link>
<title><![CDATA[[评论]  php操作SVN类]]></title> 
<author>gfhtfhgghh &lt;6577657@qq.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 11 Apr 2012 17:38:26 +0000</pubDate> 
<guid>http://jackxiang.com/post/4989/#blogcomment63699</guid> 
<description>
<![CDATA[ 
	来到了才看到这么好的不然就白来了真是不错好句子啊
]]>
</description>
</item>
</channel>
</rss>