Skip to content

Commit 1544183

Browse files
pantsmanukdregad
authored andcommitted
SVN: support svn:log revision property changes
Add rudimentary support for svn:log revprop changes to permit SCI to keep repositories current when you have developers that don't always get commit messages right first time. Doesn't deal with reopening "accidentally closed" issues. Fixes #305
1 parent c150407 commit 1544183

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

SourceSVN/SourceSVN.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,21 @@ public function update_config() {
253253
public function commit( $p_repo, $p_data ) {
254254
if ( preg_match( '/(\d+)/', $p_data, $p_matches ) ) {
255255

256+
# Detect if there is a svn:log revprop change, assume not
257+
$t_revprop = gpc_get_bool( 'revprop', false );
258+
256259
$t_url = $p_repo->url;
257260
$t_revision = $p_matches[1];
258261
$t_svnlog_xml = $this->svn_run( "log -v $t_url -r$t_revision --xml", $p_repo );
259262

260-
if ( SourceChangeset::exists( $p_repo->id, $t_revision ) ) {
261-
echo "Revision $t_revision already committed!\n";
262-
return null;
263+
if ( !$t_revprop ) {
264+
if ( SourceChangeset::exists( $p_repo->id, $t_revision ) ) {
265+
echo sprintf( plugin_lang_get( 'revision_already_committed' ), $t_revision );
266+
return null;
267+
}
263268
}
264269

265-
return $this->process_svn_log_xml( $p_repo, $t_svnlog_xml );
270+
return $this->process_svn_log_xml( $p_repo, $t_svnlog_xml, $t_revprop );
266271
}
267272
}
268273

@@ -441,9 +446,10 @@ public static function svn_binary( $p_path=null, $p_reset=false ) {
441446
* Parse the svn log output (with --xml option)
442447
* @param SourceRepo SVN repository object
443448
* @param string SVN log (XML formated)
449+
* @param boolean REVPROP change flag
444450
* @return SourceChangeset[] Changesets for the provided input (empty on error)
445451
*/
446-
private function process_svn_log_xml( $p_repo, $p_svnlog_xml ) {
452+
private function process_svn_log_xml( $p_repo, $p_svnlog_xml, $p_revprop = false ) {
447453
$t_changesets = array();
448454
$t_changeset = null;
449455
$t_comments = '';
@@ -530,6 +536,18 @@ private function process_svn_log_xml( $p_repo, $p_svnlog_xml ) {
530536
// Save changeset and append to array
531537
if( !is_null( $t_changeset) ) {
532538
if( !is_blank( $t_changeset->branch ) ) {
539+
if( $p_revprop ) {
540+
echo plugin_lang_get( 'revprop_detected' );
541+
$t_existing_changeset = SourceChangeset::load_by_revision( $p_repo, $t_changeset->revision );
542+
$t_changeset->id = $t_existing_changeset->id;
543+
$t_changeset->user_id = $t_existing_changeset->user_id;
544+
$t_changeset->files = $t_existing_changeset->files;
545+
$t_old_bugs = array_unique( Source_Parse_Buglinks( $t_existing_changeset->message ));
546+
$t_new_bugs = array_unique( Source_Parse_Buglinks( $t_changeset->message ));
547+
if( count( $t_old_bugs ) >= count( $t_new_bugs )) {
548+
$t_changeset->__bugs = array_diff( $t_old_bugs, $t_new_bugs );
549+
}
550+
}
533551
$t_changeset->save();
534552
$t_changesets[] = $t_changeset;
535553
}

SourceSVN/lang/strings_english.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ $s_plugin_SourceSVN_winstart = 'SVN: Use Windows `start`<br/><span class="small"
2626
$s_plugin_SourceSVN_error_path_invalid = 'Path to Subversion binary is invalid, inaccessible or not a directory.';
2727
$s_plugin_SourceSVN_error_svn_run = 'Failed to execute Subversion.';
2828
$s_plugin_SourceSVN_error_svn_cmd = 'Subversion execution returned an error: "%1$s".';
29+
30+
$s_plugin_SourceSVN_revision_already_committed = 'Revision %s already committed!';
31+
$s_plugin_SourceSVN_revprop_detected = ' SVN:LOG revision property change detected.';

SourceSVN/post-revprop-change.tmpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) 2014 GGP Systems Limited
4+
# Licensed under the BSD (3-clause) license
5+
6+
REPOS="$1"
7+
REV="$2"
8+
PROP="$4"
9+
10+
if [ "$PROP" = 'svn:log' ]; then
11+
URL="http://localhost/mantisbt/plugin.php?page=Source/checkin"
12+
PROJECT="Repository Name"
13+
API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxx"
14+
15+
LOG_FILE=`mktemp /tmp/svn_${PROJECT}_${REV}_log.XXX`
16+
17+
CURL=/usr/bin/curl
18+
19+
${CURL} -d "repo_name=${PROJECT}" -d "data=${REV}" -d "revprop=TRUE" -d "api_key=${API_KEY}" ${URL} >> ${LOG_FILE}
20+
fi

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Includes all changes and fixes from [1.6.0](#160---2019-01-31).
1818

1919
- GitHub: Use AJAX to automate Webhook creation
2020
[#302](https://github.com/mantisbt-plugins/source-integration/pull/302)
21+
- SVN: support SVN:Log revision property changes
2122

2223
### Changed
2324

0 commit comments

Comments
 (0)