php操作SVN版本服务器类代码_php技巧
SvnPeer.php
/**
*
* This class for execute the external program of svn
*
* @auth Seven Yang
*
*/
class SvnPeer
{
/**
* List directory entries in the repository
*
* @param string a specific project repository path
* @return bool true, if validated successfully, otherwise false
*/
static public function ls($repository)
{
$command = "svn ls " . $repository;
$output = SvnPeer::runCmd($command);
$output = implode("
", $output);
if (strpos($output, 'non-existent in that revision')) {
return false;
}
return "
" . $command . "
" . $output;
}
/**
* Duplicate something in working copy or repository, remembering history
*
* @param $src
* @param $dst
* @param $comment string specify log message
* @return bool true, if copy successfully, otherwise return the error message
*
* @todo comment need addslashes for svn commit
*/
static public function copy($src, $dst, $comment)
{
$command = "svn cp $src $dst -m '$comment'";
$output = SvnPeer::runCmd($command);
$output = implode("
", $output);
if (strpos($output, 'Committed revision')) {
return true;
}
return "
" . $command . "
" . $output;
}
/**
* Remove files and directories from version control
*
* @param $url
* @return bool true, if delete successfully, otherwise return the error message
*
* @todo comment need addslashes for svn commit
*/
static public function delete($url, $comment)
{
$command = "svn del $url -m '$comment'";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);
if (strpos($output, 'Committed revision')) {
return true;
}
return "
" . $command . "
" . $output;
}
/**
* Move and/or rename something in working copy or repository
*
* @param $src string trunk path
* @param $dst string new branch path
* @param $comment string specify log message
* @return bool true, if move successfully, otherwise return the error message
*
* @todo comment need addslashes for svn commit
*/
static public function move($src, $dst, $comment)
{
$command = "svn mv $src $dst -m '$comment'";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);
if (strpos($output, 'Committed revision')) {
return true;
}
return "
" . $command . "
" . $output;
}
/**
* Create a new directory under version control
*
* @param $url string
* @param $comment string the svn message
* @return bool true, if create successfully, otherwise return the error message
*
* @todo comment need addslashes for svn commit
*/
static public function mkdir($url, $comment)
{
$command = "svn mkdir $url -m '$comment'";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);
if (strpos($output, 'Committed revision')) {
return true;
}
return "
" . $command . "
" . $output;
}
static public function diff($pathA, $pathB)
{
$output = SvnPeer::runCmd("svn diff $pathA $pathB");
return implode('
', $output);
}
static public function checkout($url, $dir)
{
$command = "cd $dir && svn co $url";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);
if (strstr($output, 'Checked out revision')) {
return true;
}
return "
" . $command . "
" . $output;
}
static public function update($path)
{
$command = "cd $path && svn up";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);
preg_match_all("/[0-9]+/", $output, $ret);
if (!$ret[0][0]){
return "
" . $command . "
" . $output;
}
return $ret[0][0];
}
static public function merge($revision, $url, $dir)
{
$command = "cd $dir && svn merge -r1:$revision $url";
$output = implode('
', SvnPeer::runCmd($command));
if (strstr($output, 'Text conflicts')) {
return 'Command: ' . $command .'
'. $output;
}
return true;
}
static public function commit($dir, $comment)
{
$command = "cd $dir && svn commit -m'$comment'";
$output = implode('
', SvnPeer::runCmd($command));
if (strpos($output, 'Committed revision') || empty($output)) {
return true;
}
return $output;
}
static public function getStatus($dir)
{
$command = "cd $dir && svn st";
return SvnPeer::runCmd($command);
}
static public function hasConflict($dir)
{
$output = SvnPeer::getStatus($dir);
foreach ($output as $line){
if ('C' == substr(trim($line), 0, 1) || ('!' == substr(trim($line), 0, 1))){
return true;
}
}
return false;
}
/**
* Show the log messages for a set of path with XML
*
* @param path string
* @return log message string
*/
static public function getLog($path)
{
$command = "svn log $path --xml";
$output = SvnPeer::runCmd($command);
return implode('', $output);
}
static public function getPathRevision($path)
{
$command = "svn info $path --xml";
$output = SvnPeer::runCmd($command);
$string = implode('', $output);
$xml = new SimpleXMLElement($string);
foreach ($xml->entry[0]->attributes() as $key=>$value){
if ('revision' == $key) {
return $value;
}
}
}
static public function getHeadRevision($path)
{
$command = "cd $path && svn up";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);
preg_match_all("/[0-9]+/", $output, $ret);
if (!$ret[0][0]){
return "
" . $command . "
" . $output;
}
return $ret[0][0];
}
/**
* Run a cmd and return result
*
* @param string command line
* @param boolen true need add the svn authentication
* @return array the contents of the output that svn execute
*/
static protected function runCmd($command)
{
$authCommand = ' --username ' . SVN_USERNAME . ' --password ' . SVN_PASSWORD . ' --no-auth-cache --non-interactive --config-dir '.SVN_CONFIG_DIR.'.subversion';
exec($command . $authCommand . " 2>&1", $output);
return $output;
}
}

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











バージョン管理は PHP 開発において非常に一般的な操作であり、最も一般的に使用されるツールは SVN (Subversion) です。共同開発中のコードの履歴バージョンとコードの更新を簡単に管理できます。 PHP開発におけるバージョン管理にSVNを使用する方法を紹介します。 1. SVN クライアントとサーバーをインストールする まず、SVN クライアントとサーバーをインストールする必要があります。 SVN クライアントは SVN 公式 Web サイトから対応するバージョンをダウンロードしてインストールできますが、サーバーは自分で構築する必要があります。

SVN の概要 SVN (Subversion) は、コード ベースの管理と保守に使用される集中バージョン管理システムです。これにより、複数の開発者が同時にコード開発に協力できるようになり、コードの変更履歴の完全な記録が提供されます。 SVN を使用することで、開発者は次のことが可能になります。 コードの安定性を確保し、コードの損失や損傷を回避します。コードの変更履歴を追跡し、以前のバージョンに簡単にロールバックできます。共同開発。複数の開発者が競合することなく同時にコードを変更します。 SVN の基本操作 SVN を使用するには、TortoiseSVN や SublimeMerge などの SVN クライアントをインストールする必要があります。その後、次の手順に従って基本的な操作を実行できます。 1. コード ベース svnmkdirHttp://exampl を作成します。

EclipseSVN プラグインのインストールと設定方法の詳細な説明 Eclipse は、機能を拡張するためにさまざまなプラグインをサポートする、広く使用されている統合開発環境 (IDE) です。その 1 つは EclipseSVN プラグインで、開発者が Subversion バージョン管理システムと対話できるようにします。この記事では、EclipseSVN プラグインのインストールおよび設定方法を詳しく説明し、具体的なコード例を示します。ステップ 1: EclipseSVN プラグインをインストールし、Eclipse を開く

Linux では、svndiff コマンドを直接使用してコードの変更を表示するのは非常に難しいため、インターネット上でより良い解決策を探しました。それは、特に使用に慣れている人向けに、svndiff のコード表示ツールとして vimdiff を使用することです。 vim. とても便利です。 svndiff コマンドを使用して特定のファイルの変更を比較する場合、たとえばコマンド $svndiff-r4420ngx_http_limit_req_module.c を実行すると、実際にはコマンド -u-Lngx_http_limit_req_module.c がデフォルトの差分プログラムに送信されます。 (改訂 4420)-Lngx_

CentOS に SVN をインストールすることは、非常に一般的な操作です。これは、ソフトウェア開発中の変更の管理と追跡に使用できる強力なバージョン管理システムです。この記事では、CentOS に SVN をインストールする方法と、一般的に使用されるツールをいくつか紹介します。ラインの設置方法。 CentOS に SVN をインストールするにはさまざまな方法がありますが、ここでは一般的な 2 つのインストール方法を紹介します。 1. ターミナルを開き、root ユーザーとしてログインします。 2. 次のコマンドを実行してシステム パッケージ リストを更新します: ```yumupdate3。次のコマンドを実行して SVN をインストールします: yuminstallsubversion4。インストールが完了したら、次のコマンドを実行して SVN が正常にインストールされたかどうかを確認できます: svn - -v

違い: 1. vss は Microsoft によって開発され有料ですが、svn はオープンソースで無料です; 2. vss にはクライアントが必要ですが、svn はクライアント、コマンド ライン モード、または Web ページ Access で読み取り専用を使用できます。 3. vss は Windows システムのみをサポートしますが、svn は Windows と Linux システムをサポートします; 4. vss は「ロック-編集-ロック解除」モードであり、svn のデフォルトは「変更-競合-マージ」モードです; 5. のバージョン番号vss は単一のファイルに対応し、svn のバージョン番号はバージョン ライブラリ全体に対応します。

Linux 開発者は、多くの場合、SVN を使用してプロジェクトのバージョンを制御する必要があります。優秀な開発者にとって、SVN のバージョンを確認する方法を知ることは、間違いなく必須のスキルの 1 つです。今日は、この実践的なスキルをよりよく習得するのに役立つことを願って、この機会を利用して私の経験を共有したいと思います。 1. SVN コマンド ライン ツールをインストールするには、まず Linux 環境に SVN コマンド ライン ツールをインストールしてください。ターミナルにダイヤルし、次のコマンドを安全に入力してインストールを完了してください: 「ユーザーの皆様、sudoapt-getinstallsubversion を実行して Subversion をインストールしてください。」 2. SVN サーバーに接続する インストールが完了したら、SVN サーバーに接続する必要があります。次のコマンドを入力します。

一般的に使用されるサーバー側スクリプト言語として、PHP は、オープン ソースとクロスプラットフォームの利点により、Web 開発の分野で広く使用されています。複数人での共同作業の開発では、バージョン管理は不可欠なツールであり、ソース コードの変更と更新を効果的に管理し、チーム メンバー間のコードの同期のずれによる競合を回避できます。 SVN は、人気のあるバージョン管理ツールとして、PHP 開発でも広く使用されています。この記事では、SVNのインストールなど、PHP開発におけるSVNバージョン管理の基礎知識を紹介します。
