Skip to content

SVN: support svn:log revprop changes #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Source/Source.API.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ static public function init() {
foreach ( $t_callbacks as $t_callback => $t_object ) {
if ( is_subclass_of( $t_object, 'MantisSourcePlugin' ) &&
is_string( $t_object->type ) && !is_blank( $t_object->type ) ) {
$t_type = strtolower($t_object->type);
self::$cache[ $t_type ] = new SourceVCSWrapper( $t_object );
$t_type = strtolower($t_object->type);
self::$cache[ $t_type ] = new SourceVCSWrapper( $t_object );
}
}
}
Expand Down Expand Up @@ -914,7 +914,7 @@ class SourceChangeset {
* @param string $p_author_email
*/
function __construct( $p_repo_id, $p_revision, $p_branch='', $p_timestamp='',
$p_author='', $p_message='', $p_user_id=0, $p_parent='', $p_ported='', $p_author_email='' ) {
$p_author='', $p_message='', $p_user_id=0, $p_parent='', $p_ported='', $p_author_email='' ) {

$this->id = 0;
$this->user_id = $p_user_id;
Expand Down Expand Up @@ -1614,7 +1614,7 @@ function save() {
$this->new = false;
}

# handle loaded objects
# handle loaded objects
} else {
if ( is_blank( $this->username ) ) { # delete existing entry
$t_query = "DELETE FROM $t_user_table WHERE user_id=" . db_param();
Expand All @@ -1627,4 +1627,4 @@ function save() {
}
}
}
}
}
3 changes: 1 addition & 2 deletions Source/pages/checkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Always allow the same machine to check-in
if ( '127.0.0.1' == $t_address || '127.0.1.1' == $t_address
|| 'localhost' == $t_address || '::1' == $t_address ) {
|| 'localhost' == $t_address || '::1' == $t_address ) {
$t_valid = true;
}

Expand Down Expand Up @@ -92,4 +92,3 @@
}

Source_Process_Changesets( $t_changesets );

28 changes: 23 additions & 5 deletions SourceSVN/SourceSVN.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,21 @@ public function update_config() {
public function commit( $p_repo, $p_data ) {
if ( preg_match( '/(\d+)/', $p_data, $p_matches ) ) {

// Detect if there is a svn:log revprop change, assume not
$t_revprop = gpc_get_bool( 'revprop', false );

$t_url = $p_repo->url;
$t_revision = $p_matches[1];
$t_svnlog_xml = $this->svn_run( "log -v $t_url -r$t_revision --xml", $p_repo );

if ( SourceChangeset::exists( $p_repo->id, $t_revision ) ) {
echo "Revision $t_revision already committed!\n";
return null;
if ( !$t_revprop ) {
if ( SourceChangeset::exists( $p_repo->id, $t_revision ) ) {
echo sprintf( plugin_lang_get( 'revision_already_committed' ), $t_revision );
return null;
}
}

return $this->process_svn_log_xml( $p_repo, $t_svnlog_xml );
return $this->process_svn_log_xml( $p_repo, $t_svnlog_xml, $t_revprop );
}
}

Expand Down Expand Up @@ -441,9 +446,10 @@ public static function svn_binary( $p_path=null, $p_reset=false ) {
* Parse the svn log output (with --xml option)
* @param SourceRepo SVN repository object
* @param string SVN log (XML formated)
* @param boolean REVPROP change flag
* @return SourceChangeset[] Changesets for the provided input (empty on error)
*/
private function process_svn_log_xml( $p_repo, $p_svnlog_xml ) {
private function process_svn_log_xml( $p_repo, $p_svnlog_xml, $p_revprop = false ) {
$t_changesets = array();
$t_changeset = null;
$t_comments = '';
Expand Down Expand Up @@ -530,6 +536,18 @@ private function process_svn_log_xml( $p_repo, $p_svnlog_xml ) {
// Save changeset and append to array
if( !is_null( $t_changeset) ) {
if( !is_blank( $t_changeset->branch ) ) {
if( $p_revprop ) {
echo plugin_lang_get( 'revprop_detected' );
$t_existing_changeset = SourceChangeset::load_by_revision( $p_repo, $t_changeset->revision );
$t_changeset->id = $t_existing_changeset->id;
$t_changeset->user_id = $t_existing_changeset->user_id;
$t_changeset->files = $t_existing_changeset->files;
$t_old_bugs = array_unique( Source_Parse_Buglinks( $t_existing_changeset->message ));
$t_new_bugs = array_unique( Source_Parse_Buglinks( $t_changeset->message ));
if( count( $t_old_bugs ) >= count( $t_new_bugs )) {
$t_changeset->__bugs = array_diff( $t_old_bugs, $t_new_bugs );
}
}
$t_changeset->save();
$t_changesets[] = $t_changeset;
}
Expand Down
3 changes: 3 additions & 0 deletions SourceSVN/lang/strings_english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ $s_plugin_SourceSVN_winstart = 'SVN: Use Windows `start`<br/><span class="small"
$s_plugin_SourceSVN_error_path_invalid = 'Path to Subversion binary is invalid, inaccessible or not a directory.';
$s_plugin_SourceSVN_error_svn_run = 'Failed to execute Subversion.';
$s_plugin_SourceSVN_error_svn_cmd = 'Subversion execution returned an error: "%1$s".';

$s_plugin_SourceSVN_revision_already_committed = 'Revision %s already committed!';
$s_plugin_SourceSVN_revprop_detected = ' SVN:LOG revision property change detected.';
20 changes: 20 additions & 0 deletions SourceSVN/post-revprop-change.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Copyright (c) 2014 GGP Systems Limited
# Licensed under the BSD (3-clause) license

REPOS="$1"
REV="$2"
PROP="$4"

if [ "$PROP" = 'svn:log' ]; then
URL="http://localhost/mantisbt/plugin.php?page=Source/checkin"
PROJECT="Repository Name"
API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxx"

LOG_FILE=`mktemp /tmp/svn_${PROJECT}_${REV}_log.XXX`

CURL=/usr/bin/curl

${CURL} -d "repo_name=${PROJECT}" -d "data=${REV}" -d "revprop=TRUE" -d "api_key=${API_KEY}" ${URL} >> ${LOG_FILE}
fi