Skip to content

Commit 74a0578

Browse files
committed
Plugin Directory: SVN: Add SVN::copy().
See #343. See #407. git-svn-id: https://meta.svn.wordpress.org/sites/trunk@14314 74240141-8908-4e6f-9713-ba540dce6ec7
1 parent a25e1d9 commit 74a0578

File tree

1 file changed

+44
-2
lines changed
  • wordpress.org/public_html/wp-content/plugins/plugin-directory/tools

1 file changed

+44
-2
lines changed

wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-svn.php

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,54 @@ public static function log( $url, $revision = 'HEAD', $options = array() ) {
445445
* }
446446
*/
447447
public static function rename( $from, $to, $options = array() ) {
448+
return SVN::_copy_rename_helper( 'mv', $from, $to, $options );
449+
}
450+
451+
/**
452+
* Copy a file or folder in a SVN checkout.
453+
*
454+
* @static
455+
*
456+
* @param string $source The path of the file to copy. May be a URL.
457+
* @param string $destination The path to copy the file to. May be a URL.
458+
* @param array $options Optional. A list of options to pass to SVN. Default: empty array.
459+
* @return array {
460+
* @type bool $result The result of the operation.
461+
* @type int $revision The revision.
462+
* @type false|array $errors Whether any errors or warnings were encountered.
463+
* }
464+
*/
465+
public static function copy( $from, $to, $options = array() ) {
466+
return SVN::_copy_rename_helper( 'cp', $from, $to, $options = array() );
467+
}
468+
469+
/**
470+
* Helper function for copy and rename operations.
471+
*
472+
* @static
473+
* @param string $svn_op The SVN operation to perform. 'cp' or 'mv'.
474+
* @param string $from The path of the SVN folder to rename. May be a URL.
475+
* @param string $to The new path of the SVN folder. May be a URL.
476+
* @param array $options Optional. A list of options to pass to SVN. Default: empty array.
477+
* @return array {
478+
* @type bool $result The result of the operation.
479+
* @type int $revision The revision.
480+
* @type false|array $errors Whether any errors or warnings were encountered.
481+
* }
482+
*/
483+
public static function _copy_rename_helper( $svn_op, $from, $to, $options = array() ) {
448484
$options[] = 'non-interactive';
449485
$is_url = ( preg_match( '#https?://#i', $from ) && preg_match( '#https?://#i', $to ) );
450486

451487
if ( $is_url ) {
452488
// Set the message if not provided.
453489
if ( ! isset( $options['message'] ) && ! isset( $options['m'] ) ) {
454-
$options['message'] = sprintf( "Rename %s to %s.", basename( $from ), basename( $to ) );
490+
$options['message'] = sprintf(
491+
"%s %s to %s.",
492+
'mv' === $svn_op ? 'Rename' : 'Copy',
493+
basename( $from ),
494+
basename( $to )
495+
);
455496
}
456497

457498
if ( empty( $options['username'] ) ) {
@@ -462,10 +503,11 @@ public static function rename( $from, $to, $options = array() ) {
462503

463504
$esc_options = self::parse_esc_parameters( $options );
464505

506+
$esc_op = escapeshellarg( $svn_op );
465507
$esc_from = escapeshellarg( $from );
466508
$esc_to = escapeshellarg( $to );
467509

468-
$output = self::shell_exec( "svn mv $esc_from $esc_to $esc_options 2>&1" );
510+
$output = self::shell_exec( "svn $esc_op $esc_from $esc_to $esc_options 2>&1" );
469511
if ( $is_url && preg_match( '/Committed revision (?P<revision>\d+)[.]/i', $output, $m ) ) {
470512
$revision = (int) $m['revision'];
471513
$result = true;

0 commit comments

Comments
 (0)