찾다
백엔드 개발PHP 튜토리얼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;
}
}
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
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

用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_

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

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的版本号对应的是整个版本库。

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

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

VSCode Windows 64비트 다운로드

VSCode Windows 64비트 다운로드

Microsoft에서 출시한 강력한 무료 IDE 편집기

SecList

SecList

SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.