Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 16 additions & 6 deletions Source/Source.API.php
Original file line number Diff line number Diff line change
Expand Up @@ -1039,14 +1039,24 @@ function save_bugs( $p_user_id=null ) {
$t_params = array();

foreach( $t_bugs_added as $t_bug_id ) {
$t_query .= ( $t_count == 0 ? '' : ', ' ) .
'(' . db_param() . ', ' . db_param() . ')';
$t_params[] = $this->id;
$t_params[] = $t_bug_id;
$t_count++;
$t_params_2 = array();
$t_query_2 = "SELECT COUNT(*) AS b FROM $t_bug_table WHERE change_id=" . db_param() . " AND bug_id=" . db_param();
$t_params_2[] = $this->id;
$t_params_2[] = $t_bug_id;
$t_result = db_query( $t_query_2, $t_params_2 );
$t_row = db_fetch_array( $t_result );
if ($t_row['b'] < 1) {
$t_query .= ( $t_count == 0 ? '' : ', ' ) .
'(' . db_param() . ', ' . db_param() . ')';
$t_params[] = $this->id;
$t_params[] = $t_bug_id;
$t_count++;
}
}

db_query( $t_query, $t_params );
if ( substr( $t_query, -1 ) == ")" ) {
db_query( $t_query, $t_params );
}

foreach( $t_bugs_added as $t_bug_id ) {
plugin_history_log( $t_bug_id, 'changeset_attached', '',
Expand Down
5 changes: 4 additions & 1 deletion Source/pages/checkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
# Let plugins try to intepret POST data before we do
$t_predata = event_signal( 'EVENT_SOURCE_PRECOMMIT' );

# Try to gracefully detect revprop changes flag
$f_revprop = gpc_get_bool( 'revprop', false );

# Expect plugin data in form of array( repo_name, data )
if ( is_array( $t_predata ) && count( $t_predata ) == 2 ) {
$t_repo = $t_predata['repo'];
Expand All @@ -79,7 +82,7 @@
$t_vcs = SourceVCS::repo( $t_repo );

# Let the plugins handle commit data
$t_changesets = $t_vcs->commit( $t_repo, $f_data );
$t_changesets = $t_vcs->commit( $t_repo, $f_data, $f_revprop );

# Changesets couldn't be loaded apparently
if ( !is_array( $t_changesets ) ) {
Expand Down
29 changes: 22 additions & 7 deletions SourceSVN/SourceSVN.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,21 @@ public function update_config() {
}
}

public function commit( $p_repo, $p_data ) {
public function commit( $p_repo, $p_data, $p_revprop = false ) {
if ( preg_match( '/(\d+)/', $p_data, $p_matches ) ) {

$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 ( $p_revprop == false ) {
if ( SourceChangeset::exists( $p_repo->id, $t_revision ) ) {
echo "Revision $t_revision already committed!\n";
return null;
}
}

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

Expand Down Expand Up @@ -441,9 +443,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 +533,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 " REVPROP change detected.\n";
$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
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