Mac Pro uses PHP to export SVN new or modified file examples

Source: Internet
Author: User
Tags diff php file svn tortoisesvn

Previously in the Windows operating system, accustomed to using TORTOISESVN to export new or modified files ("fairly practical" how to get TortoiseSVN to export new or modified files), recently replaced the Mac Pro notebook computer, for a while did not find a similar tortoisesvn Easy to use client tools. Well, use PHP to write an export gadget:

1, tool file name: svn.php, its contents are as follows:

The code is as follows Copy Code

<?php
/**
* Export the difference files between the specified versions, such as the difference between 100 and 200, to export all modifications of 100 (excluding)-200 (including)
* "SVN command line"
* 1, view the differences between versions
* SVN diff-r 2359:2360--summarize--username Simon--password Simonfit
* 2, export a version of the file to the local
* SVN export-r 2360 svn://112.73.80.56/sjf/source/common/controller/wechatbasecontroller.class.php/root/2/files_ 2359_2360/common/controller/wechatbasecontroller.class.php--username Wenjianbao--password wjb888
*
* */

root directory
Define (' Site_path ', DirName (__file__));


SVN account Information
$SVN _url = ' Svn://112.73.80.56/sjf/source ';
$svn _username = ' Wenjianbao ';
$svn _password = ' 5c95e61387c478c85ccf45e6a8ae6de3 ';


$error _msg = ' You must useage like '. $_server[' argv '][0]. ' Old_version (excluding) new_version (including) ';
if ($_server[' argc ']!= 3)
{
echo $error _msg;
Exit (1);
}

if ($_server[' argv '][1] > $_server[' argv '][2])
{
echo $error _msg;
Exit (1);
}

$old _version = $_server[' argv '][1];
$new _version = $_server[' argv '][2];

$work _path = Site_path. "/file_${old_version}_${new_version}";

echo "starts analyzing version differences ... \ n";
$diff _cmd = "svn diff-r ${old_version}:${new_version}--summarize--username ${svn_username}--password ${svn_password}" ${svn_url} ";
EXEC ($diff _cmd, $diff _list, $return);
$diff _list = (array) $diff _list;
foreach ($diff _list as $diff _info)
{
Echo $diff _info. "\ n";
}

# Empty old data
@system (' Rm-rf '. Site_path. '/file_* ');
@system (' Rm-rf '. Site_path. '/diff_* ');

# New Folder
Dir_mkdir ($work _path);

$diff _count = count ($diff _list);
if ($diff _count < 1)
{
echo "There is no difference between versions";
Exit (1);
}

$diff _count = 0;
$diff _file_path = Site_path. "/diff_${old_version}_${new_version}.txt";

# Export Version File
echo "Start exporting ... \ n";
foreach ($diff _list as $diff _info)
{
if (Preg_match ([\w]+) \s+ (svn:.+)/', $diff _info, $matches))
{
$SVN _file_mode = $matches [1];
$SVN _file_name = $matches [2];

A, M, D, AM is added and modified
File is deleted
if ($svn _file_mode = = ' D ')
{
Continue
}
$diff _count++;

Write log
File_write ($diff _file_path, $matches [0]. "\ n", ' a ');

Download to Local
$local _file_path = $work _path. Str_replace ($svn _url, ", $svn _file_name);
$local _file_dir = dirname ($local _file_path);
Dir_mkdir ($local _file_dir);

$export _cmd = "svn export-r ${new_version} ${svn_file_name ${local_file_path}--username ${svn_username}--password ${s Vn_password} ";
System ($export _cmd);
}
}

echo "Altogether exports ${diff_count} difference file";
Exit (0);


/**
* Create Folder
*
* @param string $path folder path
* @param int $mode access rights
* @param bool $recursive is created recursively
* @return BOOL
*/
function Dir_mkdir ($path = ', $mode = 0777, $recursive = True)
{
Clearstatcache ();
if (!is_dir ($path))
{
mkdir ($path, $mode, $recursive);
return chmod ($path, $mode);
}

return true;
}

/**
* Write file
*
* @param string $filename filename
* @param string $text The text string to write
* @param string $openmod text Write mode (' W ': Overwrite rewrite, ' A ': text append)
* @return BOOL
*/
function File_write ($filename = ', $text = ', $openmod = ' W ')
{
if (@ $fp = fopen ($filename, $openmod))
{
Flock ($FP, 2);
Fwrite ($fp, $text);
Fclose ($FP);
return true;
}
Else
{
return false;
}
}

2, the use of methods

Modify the address and account number of your SVN server in the svn.php file and run it in command-line mode, such as exporting the difference file from version 100 to 200.


PHP svn.php 100 200

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.