diff --git a/SourceSFSVN/SourceSFSVN.php b/SourceSFSVN/SourceSFSVN.php index 87ba5d7..dd08fab 100644 --- a/SourceSFSVN/SourceSFSVN.php +++ b/SourceSFSVN/SourceSFSVN.php @@ -217,19 +217,9 @@ private function svn_call( $p_repo=null ) { static $s_call; - # Generate, validate, and cache the SVN binary path + # Get a full binary call, including configured parameters if ( is_null( $s_call ) ) { - $t_path = plugin_config_get( 'svnpath' ); - if ( !is_blank( $t_path ) && is_dir( $t_path ) ) { - $s_call = $t_path . DIRECTORY_SEPARATOR . 'svn'; - - if ( !is_file( $s_call ) || !is_executable( $s_call ) ) { - $s_call = 'svn'; - } - - } else { - $s_call = 'svn'; - } + $s_call = self::svn_binary(); } # If not given a repo, just return the base SVN binary @@ -253,6 +243,46 @@ return $t_call; } + /** + * Generate, validate, and cache the SVN binary path. + * @param string Path to SVN + * @param boolean Reset cached value + * @return string SVN binary + */ + public static function svn_binary( $p_path=null, $p_reset=false ) { + static $s_binary; + + if ( is_null( $s_binary ) || $p_reset ) { + if ( is_null( $p_path ) ) { + $t_path = plugin_config_get( 'svnpath' ); + } else { + $t_path = $p_path; + } + + if ( !is_blank( $t_path ) && is_dir( $t_path ) ) { + + # Linux / UNIX paths + $t_binary = $t_path . DIRECTORY_SEPARATOR . 'svn'; + if ( is_file( $t_binary ) && is_executable( $t_binary ) ) { + return $s_binary = $t_binary; + } + + # Windows paths + $t_binary = $t_path . DIRECTORY_SEPARATOR . 'svn.exe'; + if ( is_file( $t_binary ) && is_executable( $t_binary ) ) { + return $s_binary = $t_binary; + } + + } else { + # Generic pathless call + return $s_binary = 'svn'; + } + } + + return $s_binary; + } + + private function process_svn_log( $p_repo, $p_svnlog ) { $t_state = 0; $t_svnline = str_pad( '', 72, '-' ); diff --git a/SourceSFSVN/pages/config_update.php b/SourceSFSVN/pages/config_update.php index e603698..834f90a 100644 --- a/SourceSFSVN/pages/config_update.php +++ b/SourceSFSVN/pages/config_update.php @@ -27,10 +27,7 @@ } else { # be sure that the path is valid - if ( is_dir( $f_svnpath ) && - is_file( $f_svnpath . DIRECTORY_SEPARATOR . 'svn' ) && - is_executable( $f_svnpath . DIRECTORY_SEPARATOR . 'svn' ) ) { - + if ( SourceWebSVN::svn_binary( $f_svnpath, true ) != 'svn' ) { plugin_config_set( 'svnpath', $f_svnpath ); } else { plugin_error( 'SVNPathInvalid' ); diff --git a/SourceWebSVN/SourceWebSVN.php b/SourceWebSVN/SourceWebSVN.php index 4e650a5..01ce0a6 100644 --- a/SourceWebSVN/SourceWebSVN.php +++ b/SourceWebSVN/SourceWebSVN.php @@ -228,19 +228,9 @@ private function svn_call( $p_repo=null ) { static $s_call; - # Generate, validate, and cache the SVN binary path + # Get a full binary call, including configured parameters if ( is_null( $s_call ) ) { - $t_path = plugin_config_get( 'svnpath' ); - if ( !is_blank( $t_path ) && is_dir( $t_path ) ) { - $s_call = $t_path . DIRECTORY_SEPARATOR . 'svn'; - - if ( !is_file( $s_call ) || !is_executable( $s_call ) ) { - $s_call = 'svn'; - } - - } else { - $s_call = 'svn'; - } + $s_call = self::svn_binary(); } # If not given a repo, just return the base SVN binary @@ -264,6 +254,45 @@ return $t_call; } + /** + * Generate, validate, and cache the SVN binary path. + * @param string Path to SVN + * @param boolean Reset cached value + * @return string SVN binary + */ + public static function svn_binary( $p_path=null, $p_reset=false ) { + static $s_binary; + + if ( is_null( $s_binary ) || $p_reset ) { + if ( is_null( $p_path ) ) { + $t_path = plugin_config_get( 'svnpath' ); + } else { + $t_path = $p_path; + } + + if ( !is_blank( $t_path ) && is_dir( $t_path ) ) { + + # Linux / UNIX paths + $t_binary = $t_path . DIRECTORY_SEPARATOR . 'svn'; + if ( is_file( $t_binary ) && is_executable( $t_binary ) ) { + return $s_binary = $t_binary; + } + + # Windows paths + $t_binary = $t_path . DIRECTORY_SEPARATOR . 'svn.exe'; + if ( is_file( $t_binary ) && is_executable( $t_binary ) ) { + return $s_binary = $t_binary; + } + + } else { + # Generic pathless call + return $s_binary = 'svn'; + } + } + + return $s_binary; + } + private function process_svn_log( $p_repo, $p_svnlog ) { $t_state = 0; $t_svnline = str_pad( '', 72, '-' ); diff --git a/SourceWebSVN/pages/config_update.php b/SourceWebSVN/pages/config_update.php index ccf6012..9e98ac9 100644 --- a/SourceWebSVN/pages/config_update.php +++ b/SourceWebSVN/pages/config_update.php @@ -27,10 +27,7 @@ } else { # be sure that the path is valid - if ( is_dir( $f_svnpath ) && - is_file( $f_svnpath . DIRECTORY_SEPARATOR . 'svn' ) && - is_executable( $f_svnpath . DIRECTORY_SEPARATOR . 'svn' ) ) { - + if ( SourceWebSVN::svn_binary( $f_svnpath, true ) != 'svn' ) { plugin_config_set( 'svnpath', $f_svnpath ); } else { plugin_error( 'SVNPathInvalid' );