首頁 後端開發 php教程 php操作SVN版本服务器类代码_php技巧

php操作SVN版本服务器类代码_php技巧

May 17, 2016 am 09:14 AM
svn

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;
}
}
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

PHP開發中如何使用SVN進行版本控制 PHP開發中如何使用SVN進行版本控制 Jun 27, 2023 pm 01:39 PM

在PHP開發中進行版本控制是很常見的操作,其中最常用的工具就是SVN(Subversion)。它可以方便地管理程式碼的歷史版本以及協同開發過程中的程式碼更新。以下將介紹如何在PHP開發中使用SVN進行版本控制。一、安裝SVN客戶端和服務端首先需要安裝SVN客戶端和服務端。 SVN客戶端可以在SVN官網上下載對應的版本,安裝即可,而服務端則需要自行搭建,具體方法可以

Java SVN:程式碼倉庫的守護者,確保程式碼穩定性 Java SVN:程式碼倉庫的守護者,確保程式碼穩定性 Mar 09, 2024 am 09:20 AM

SVN簡介SVN(Subversion)是一種集中式版本控制系統,用於管理和維護程式碼庫。它允許多個開發者同時協作開發程式碼,並提供對程式碼歷史修改的完整記錄。透過使用SVN,開發者可以:保障程式碼穩定性,避免程式碼遺失和損壞。追蹤程式碼修改歷史,輕鬆回滾到之前的版本。協同開發,多個開發者同時修改程式碼而不會衝突。 SVN基本操作要使用SVN,需要安裝SVN客戶端,例如TortoiseSVN或SublimeMerge。然後,您可以按照以下步驟執行基本操作:1.建立程式碼庫svnmkdirHttp://exampl

詳解如何安裝和設定EclipseSVN插件 詳解如何安裝和設定EclipseSVN插件 Jan 28, 2024 am 08:42 AM

EclipseSVN插件的安裝和設定方法詳解Eclipse是一個廣泛使用的整合開發環境(IDE),它支援許多不同的插件來擴展其功能。其中之一是EclipseSVN插件,它使開發人員能夠與Subversion版本控制系統進行互動。本文將詳細介紹如何安裝和設定EclipseSVN插件,並提供具體的程式碼範例。第一步:安裝EclipseSVN外掛程式開啟Eclipse

svn與vss的差別是什麼 svn與vss的差別是什麼 Jun 21, 2022 am 11:23 AM

差別:1、vss是微軟開發的,是收費的,而svn是開源免費的;2、vss必須有客戶端,而svn可以用客戶端,也可以用命令列模式,還可以用網頁方式只讀存取;3、vss只支援windows系統,而svn支援windows和linux系統;4、vss是「鎖定-編輯-解鎖」模式,svn預設是「修改-衝突-合併」模式;5、vss的版本號對應的是單一文件,svn的版本號碼對應的是整個版本庫。

SVN在CentOS上的安裝及命令列安裝 SVN在CentOS上的安裝及命令列安裝 Feb 13, 2024 am 11:24 AM

在CentOS上安裝SVN是非常常見的操作,它是一個功能強大的版本控制系統,可以用於管理和追蹤軟體開發過程中的變更,本文將詳細介紹如何在CentOS上安裝SVN,並提供一些常用的命令列安裝方法。在CentOS上安裝SVN有多種方法,以下將介紹兩種常用的安裝方式。 1.開啟終端,以root使用者身分登入。 2.執行以下命令更新系統軟體包清單:```yumupdate3.執行以下命令安裝SVN:yuminstallsubversion4.安裝完成後,可以透過執行以下命令驗證SVN是否成功安裝:svn--v

用vimdiff取代svn diff:比較程式碼的工具 用vimdiff取代svn diff:比較程式碼的工具 Jan 09, 2024 pm 07:54 PM

在linux下,直接使用svndiff指令查看程式碼的修改是很吃力的,於是在網路上搜尋了一個比較好的解決方案,就是讓vimdiff作為svndiff的檢視程式碼工具,尤其對於習慣用vim的人來說真的是很方便。當使用svndiff指令比較某個檔案的修改前後時,例如執行下列指令:$svndiff-r4420ngx_http_limit_req_module.c那麼實際上會向預設的diff程式傳送如下指令:-u-Lngx_http_limit_req_module.c(revision4420)-Lngx_

Linux開發者的必備技能:簡單掌握SVN版本控制 Linux開發者的必備技能:簡單掌握SVN版本控制 Jan 26, 2024 pm 09:54 PM

身為Linux開發人員,往往需要運用SVN控制專案版本。對於優秀開發者而言,熟知如何查閱SVN版本無疑是必備技能之一。今日,筆者想藉此機會和各位分享自己的心得,希望能助您更能掌握這項實用技巧。 1.安裝SVN命令列工具請先在Linux環境中安裝SVN命令列工具哦!請撥通終端,然後穩健地輸入下面這條指令來完成安裝吧:```尊敬的用戶,請執行sudoapt-getinstallsubversion以安裝Subversion。 2.連接到SVN伺服器安裝完畢後,我們需要連接到SVN伺服器。輸入以下命令:

PHP入門指南:SVN版本管理 PHP入門指南:SVN版本管理 May 20, 2023 am 08:29 AM

作為常用的伺服器端腳本語言,PHP憑藉其開源、跨平台的優勢,被廣泛應用於Web開發領域。而在多人協作的開發中,版本控制是一個不可或缺的工具,它可以有效地管理原始碼的修改與更新,避免因團隊成員之間程式碼不同步而造成的衝突。而SVN作為一款流行的版本控制工具,在PHP開發的應用也十分廣泛。本文將為大家介紹PHP開發中的SVN版本控制的基礎知識,包括SVN的安

See all articles