Skip to content

Commit 3f320d7

Browse files
committed
Use constants for SourceFile actions
Previously, the action stored in the DB to indicate the type operation for each file in a Changeset (add, mod, rm, mv) was hardcoded in the VCS plugins' commit processing functions. These values are now defined as constants in the SourceFile class, and used wherever they were referenced. Fixes #400
1 parent 8f99e9b commit 3f320d7

File tree

13 files changed

+71
-45
lines changed

13 files changed

+71
-45
lines changed

Source/Source.API.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,18 @@ public function getLocalTimestamp( $p_format = null )
12971297
* Abstract source control file data.
12981298
*/
12991299
class SourceFile {
1300+
/**
1301+
* Action constants
1302+
*/
1303+
const ADDED = 'add';
1304+
const MODIFIED = 'mod';
1305+
const RENAMED = 'mv';
1306+
const DELETED = 'rm';
1307+
const UNKNOWN = '??';
1308+
# These are used by SourceHgWeb - not sure what they actually mean
1309+
const BINARY = 'bin';
1310+
const NA = 'n/a';
1311+
13001312
var $id;
13011313
var $change_id;
13021314
var $revision;

SourceAzureDevOps/SourceAzureDevOps.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,19 @@ private function json_commit_changeset( $p_repo, $p_commit_ref, $p_branch='' )
392392
{
393393
case "add":
394394
case "undelete":
395-
$t_action='add';
395+
$t_action = SourceFile::ADDED;
396396
break;
397397
case "edit":
398398
case "merge":
399-
$t_action = 'mod';
399+
$t_action = SourceFile::MODIFIED;
400400
break;
401401
case 'rename':
402402
case 'sourceRename':
403403
case 'targetRename':
404-
$t_action = 'mv';
404+
$t_action = SourceFile::RENAMED;
405405
break;
406406
case 'delete':
407-
$t_action = 'rm';
407+
$t_action = SourceFile::DELETED;
408408
break;
409409
}
410410
$t_changeset->files[] = new SourceFile( 0, $t_change->item->commitId, $t_change->item->path, $t_action );

SourceBitBucket/SourceBitBucket.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,17 +421,22 @@ private function json_commit_changeset( $p_repo, $p_json, $p_branch = '' ) {
421421
$t_files = $this->api_json_url_values( $p_repo, $t_url );
422422
if( !empty($t_files) ) {
423423
foreach ( $t_files as $t_file ) {
424+
$t_filename = $t_file->new->path;
424425
switch( $t_file->status ) {
425426
case 'added':
426-
$t_changeset->files[] = new SourceFile(0, '', $t_file->new->path, 'add');
427+
$t_action = SourceFile::ADDED;
427428
break;
428429
case 'modified':
429-
$t_changeset->files[] = new SourceFile(0, '', $t_file->new->path, 'mod');
430+
$t_action = SourceFile::MODIFIED;
430431
break;
431432
case 'removed':
432-
$t_changeset->files[] = new SourceFile(0, '', $t_file->old->path, 'rm');
433+
$t_action = SourceFile::DELETED;
434+
$t_filename = $t_file->old->path;
433435
break;
436+
default:
437+
$t_action = SourceFile::UNKNOWN . ' ' . $t_file->status;
434438
}
439+
$t_changeset->files[] = new SourceFile(0, '', $t_filename, $t_action );
435440
}
436441
}
437442

SourceCgit/SourceCgit.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,16 @@ public function commit_files( $p_input ) {
328328
$t_file['filename'] = $t_file_matches[5];
329329
$t_file['revision'] = $t_file_matches[4];
330330

331-
if ( 'add' == $t_file_matches[2] ) {
332-
$t_file['action'] = 'add';
333-
} else if ( 'del' == $t_file_matches[2] ) {
334-
$t_file['action'] = 'rm';
335-
} else {
336-
$t_file['action'] = 'mod';
331+
switch( $t_file_matches[2] ) {
332+
case 'add':
333+
$t_file['action'] = SourceFile::ADDED;
334+
break;
335+
case 'del':
336+
$t_file['action'] = SourceFile::DELETED;
337+
break;
338+
default:
339+
$t_file['action'] = SourceFile::MODIFIED;
340+
break;
337341
}
338342
$t_files[] = $t_file;
339343
}

SourceGithub/SourceGithub.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,17 +783,21 @@ private function json_commit_changeset( $p_repo, $p_json, $p_branch='' ) {
783783

784784
if ( isset( $p_json->files ) ) {
785785
foreach ( $p_json->files as $t_file ) {
786+
$t_filename = $t_file->filename;
786787
switch ( $t_file->status ) {
787788
case 'added':
788-
$t_changeset->files[] = new SourceFile( 0, '', $t_file->filename, 'add' );
789+
$t_action = SourceFile::ADDED;
789790
break;
790791
case 'modified':
791-
$t_changeset->files[] = new SourceFile( 0, '', $t_file->filename, 'mod' );
792+
$t_action = SourceFile::MODIFIED;
792793
break;
793794
case 'removed':
794-
$t_changeset->files[] = new SourceFile( 0, '', $t_file->filename, 'rm' );
795+
$t_action = SourceFile::DELETED;
795796
break;
797+
default:
798+
$t_action = SourceFile::UNKNOWN . ' ' . $t_file->status;
796799
}
800+
$t_changeset->files[] = new SourceFile( 0, '', $t_filename, $t_action );
797801
}
798802
}
799803

SourceGitphp/SourceGitphp.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,15 @@ private function commit_changeset( $p_repo, $p_input, $p_branch='' ) {
326326
$t_file['revision'] = $t_file_matches[1];
327327

328328
if ( isset( $t_file_matches[3] ) ) {
329-
if ( $t_file_matches[3] == 'new' or $t_file_matches[3] == 'moved' ) {
330-
$t_file['action'] = 'add';
331-
} else if ( $t_file_matches[3] == 'deleted' or $t_file_matches[3] == 'similarity' ) {
332-
$t_file['action'] = 'rm';
329+
if ( $t_file_matches[3] == 'new' || $t_file_matches[3] == 'moved' ) {
330+
$t_file['action'] = SourceFile::ADDED;
331+
} else if ( $t_file_matches[3] == 'deleted' || $t_file_matches[3] == 'similarity' ) {
332+
$t_file['action'] = SourceFile::DELETED;
333333
} else {
334-
$t_file['action'] = 'mod';
334+
$t_file['action'] = SourceFile::MODIFIED;
335335
}
336336
} else {
337-
$t_file['action'] = 'mod';
337+
$t_file['action'] = SourceFile::MODIFIED;
338338
}
339339

340340
$t_commit['files'][] = $t_file;

SourceGitweb/SourceGitweb.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,15 @@ private function commit_changeset( $p_repo, $p_input, $p_branch='' ) {
380380
$t_file['revision'] = $t_file_matches[1];
381381

382382
if ( isset( $t_file_matches[3] ) ) {
383-
if ( $t_file_matches[3] == 'new' or $t_file_matches[3] == 'moved' ) {
384-
$t_file['action'] = 'add';
385-
} else if ( $t_file_matches[3] == 'deleted' or $t_file_matches[3] == 'similarity' ) {
386-
$t_file['action'] = 'rm';
383+
if ( $t_file_matches[3] == 'new' || $t_file_matches[3] == 'moved' ) {
384+
$t_file['action'] = SourceFile::ADDED;
385+
} else if ( $t_file_matches[3] == 'deleted' || $t_file_matches[3] == 'similarity' ) {
386+
$t_file['action'] = SourceFile::DELETED;
387387
} else {
388-
$t_file['action'] = 'mod';
388+
$t_file['action'] = SourceFile::MODIFIED;
389389
}
390390
} else {
391-
$t_file['action'] = 'mod';
391+
$t_file['action'] = SourceFile::MODIFIED;
392392
}
393393

394394
$t_commit['files'][] = $t_file;

SourceHgWeb/SourceHgWeb.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,21 +327,22 @@ private function commit_changeset( $p_repo, $p_input, $p_branch='' ) {
327327
$t_file['filename'] = $t_file_matches[3];
328328
$t_file['revision'] = $t_commit['revision'];
329329

330+
$t_file['action'] = SourceFile::UNKNOWN;
330331
if(!empty($t_file_matches[3])) {
331332
if (empty($t_file_matches[5]) && empty($t_file_matches[6]) && empty($t_file_matches[7])) {
332-
$t_file['action'] = 'mod';
333+
$t_file['action'] = SourceFile::MODIFIED;
333334
}
334335
else if(!empty($t_file_matches[5])) {
335-
$t_file['action'] = 'bin';
336+
$t_file['action'] = SourceFile::BINARY;
336337
}
337338
else if ("/dev/null" == $t_file_matches[6]) {
338-
$t_file['action'] = 'add';
339+
$t_file['action'] = SourceFile::ADDED;
339340
}
340341
else if ("/dev/null" == $t_file_matches[7]) {
341-
$t_file['action'] = 'rm';
342+
$t_file['action'] = SourceFile::DELETED;
342343
}
343344
else if ("/dev/null" == $t_file_matches[7] && "/dev/null" == $t_file_matches[6]) {
344-
$t_file['action'] = 'n/a';
345+
$t_file['action'] = SourceFile::NA;
345346
}
346347
}
347348
$t_commit['files'][] = $t_file;

SourceSFSVN/SourceSFSVN.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public function url_changeset( $p_repo, $p_changeset ) {
4545
public function url_file( $p_repo, $p_changeset, $p_file ) {
4646
# if the file has been removed, it doesn't exist in current revision
4747
# so we generate a link to (current revision - 1)
48-
$t_revision = ($p_file->action == 'rm')
48+
$t_revision = ($p_file->action == SourceFile::DELETED)
4949
? $p_changeset->revision - 1
5050
: $p_changeset->revision;
5151
return $this->sf_url( $p_repo ) . urlencode( $p_file->filename ) .
5252
'?view=markup&pathrev=' . urlencode( $t_revision );
5353
}
5454

5555
public function url_diff( $p_repo, $p_changeset, $p_file ) {
56-
if ( $p_file->action == 'rm' || $p_file->action == 'add' ) {
56+
if ( $p_file->action == SourceFile::DELETED || $p_file->action == SourceFile::ADDED ) {
5757
return '';
5858
}
5959
$t_diff = '?r1=' . urlencode( $p_changeset->revision ) . '&r2=' . urlencode( $p_changeset->revision - 1 );

SourceSVN/SourceSVN.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,10 @@ private function process_svn_log_xml( $p_repo, $p_svnlog_xml, $p_revprop = false
521521
if(isset($t_entry->paths->path)){
522522
foreach( $t_entry->paths->path as $t_path ) {
523523
switch( (string)$t_path['action'] ) {
524-
case 'A': $t_action = 'add'; break;
525-
case 'D': $t_action = 'rm'; break;
526-
case 'M': $t_action = 'mod'; break;
527-
case 'R': $t_action = 'mv'; break;
524+
case 'A': $t_action = SourceFile::ADDED; break;
525+
case 'D': $t_action = SourceFile::DELETED; break;
526+
case 'M': $t_action = SourceFile::MODIFIED; break;
527+
case 'R': $t_action = SourceFile::RENAMED; break;
528528
default: $t_action = (string)$t_path['action'];
529529
}
530530

0 commit comments

Comments
 (0)