diff --git a/SourceHgWeb/SourceHgWeb.php b/SourceHgWeb/SourceHgWeb.php
index a50ea94..9e6e6cb 100644
--- a/SourceHgWeb/SourceHgWeb.php
+++ b/SourceHgWeb/SourceHgWeb.php
@@ -1,5 +1,5 @@
name = plugin_lang_get( 'title' );
$this->description = plugin_lang_get( 'description' );
- $this->version = '0.14';
+ $this->version = '0.15';
$this->requires = array(
'MantisCore' => '1.2.0',
'Source' => '0.14',
@@ -90,20 +90,20 @@
if ( isset( $p_repo->info['master_branch'] ) ) {
$t_master_branch = $p_repo->info['master_branch'];
} else {
- $t_master_branch = 'master';
+ $t_master_branch = 'default';
}
?>
>
- |
- |
+ |
+ |
>
- |
- |
+ |
+ |
>
- |
- |
+ |
+ |
info['master_branch'] ) {
- return;
- }
return $this->import_commits($p_repo, null, $t_commit_id, $t_branch);
}
@@ -144,7 +141,7 @@
$t_branch = $p_repo->info['master_branch'];
if ( is_blank( $t_branch ) ) {
- $t_branch = 'master';
+ $t_branch = 'default';
}
$t_branches = map( 'trim', explode( ',', $t_branch ) );
@@ -162,7 +159,7 @@
if ( db_num_rows( $t_result ) > 0 ) {
$t_parent = db_result( $t_result );
- echo "Oldest '$t_branch' branch parent: '$t_parent'\n";
+ echo 'Oldest \'' . string_display_line( $t_branch ) . '\' branch parent: \'' . string_display_line( $t_parent ) . "'\n";
if ( !empty( $t_parent ) ) {
$t_commits[] = $t_parent;
@@ -196,7 +193,7 @@
while( count( $s_parents ) > 0 && $s_counter < 200 ) {
$t_commit_id = array_shift( $s_parents );
- echo "Retrieving $t_commit_id ... ";
+ echo 'Retrieving ' . string_display_line( $t_commit_id ) . '... ';
$t_commit_url = $this->uri_base( $p_repo ) . 'raw-rev/' . $t_commit_id;
$t_input = url_get( $t_commit_url );
@@ -228,40 +225,80 @@
if( strpos( $t_line, '#' ) === 0 ) {
if( !isset( $t_commit['revision'] ) && preg_match( '@^# Node ID +([a-f0-9]+)@', $t_line, $t_matches ) ) {
$t_commit['revision'] = $t_matches[1];
- echo "Processing $t_commit[revision] ... ";
+ echo 'Processing ' . string_display_line( $t_commit[revision] ) . '... ';
if ( SourceChangeset::exists( $p_repo->id, $t_commit['revision'] ) ) {
echo "already exists.\n";
return array( null, array() );
}
- } else if( !isset( $t_commit['author'] ) && preg_match( '@^# User +([^<>]*) <([^<>]*)>@', $t_line, $t_matches ) ) {
- $t_commit['author'] = $t_matches[1];
+ } else if( !isset( $t_commit['author'] ) && preg_match( '@^# User ([^<>]*)(?(?=(?=<))<([^<>]*)>|.*)@', $t_line, $t_matches ) ) {
+ $t_commit['author'] = trim($t_matches[1]);
$t_commit['author_email'] = $t_matches[2];
} else if( !isset( $t_commit['date'] ) && preg_match( '@^# Date +(\d+) (-?\d+)@', $t_line, $t_matches ) ) {
- $t_timestamp_gmt = $t_matches[1] + (int)$t_matches[2];
+ $t_timestamp_gmt = $t_matches[1] - (int)$t_matches[2];
$t_commit['date'] = gmdate( 'Y-m-d H:i:s', $t_timestamp_gmt );
} else if( !isset( $t_commit['parent'] ) && preg_match( '@^# Parent +([a-f0-9]+)@', $t_line, $t_matches ) ) {
$t_parents[] = $t_matches[1];
$t_commit['parent'] = $t_matches[1];
}
} else if( isset( $t_commit['revision'] ) ) {
- if ( preg_match( '@^--- @', $t_line, $t_matches ) ) {
+ if ( preg_match( '@^diff @', $t_line, $t_matches ) ) {
break;
}
$t_message[] = $t_line;
}
}
- $t_commit['message'] = implode( "\n", $t_message );
+ if ( !SourceChangeset::exists( $p_repo->id, $t_commit['revision'] ) ) {
+ $t_commit['message'] = implode( "\n", $t_message );
- $t_changeset = new SourceChangeset( $p_repo->id, $t_commit['revision'],
- $p_branch, $t_commit['date'], $t_commit['author'],
- $t_commit['message'], 0,
- isset( $t_commit['parent'] ) ? $t_commit['parent'] : ''
+ $t_changeset = new SourceChangeset( $p_repo->id, $t_commit['revision'],
+ $p_branch, $t_commit['date'], $t_commit['author'],
+ $t_commit['message'], 0,
+ (isset( $t_commit['parent'] ) ? $t_commit['parent'] : '')
);
- $t_changeset->author_email = $t_commit['author_email'];
- $t_changeset->save();
- echo "saved.\n";
- return array( $t_changeset, $t_parents );
+ $t_changeset->author_email = empty($t_commit['author_email'])? '': $t_commit['author_email'];
+
+ preg_match_all('#diff[\s]*-r[\s]([^\s]*)[\s]*-r[\s]([^\s]*)[\s]([^\n]*)\n(Binary file[\s]([^\s]*)[\s]has changed|\-{3}[\s](/dev/null)?[^\t]*[^\n]*\n\+{3}[\s](/dev/null)?[^\t]*\t[^\n]*)#', $p_input, $t_matches, PREG_SET_ORDER);
+
+ $t_commit['files'] = array();
+
+ foreach( $t_matches as $t_file_matches ) {
+ $t_file = array();
+ $t_file['filename'] = $t_file_matches[3];
+ $t_file['revision'] = $t_commit['revision'];
+
+ if(!empty($t_file_matches[3])) {
+ if(!empty($t_file_matches[5])) {
+ $t_file['action'] = 'bin';
+ }
+ else if ("/dev/null" == $t_file_matches[7]) {
+ $t_file['action'] = 'rm';
+ }
+ else if ("/dev/null" == $t_file_matches[6]) {
+ $t_file['action'] = 'add';
+ }
+ else if ("/dev/null" == $t_file_matches[7] && "/dev/null" == $t_file_matches[6]) {
+ $t_file['action'] = 'n/a';
+ }
+ else if (empty($t_file_matches[5]) && empty($t_file_matches[6]) && empty($t_file_matches[7])) {
+ $t_file['action'] = 'mod';
+ }
+ }
+ $t_commit['files'][] = $t_file;
+ }
+
+ foreach( $t_commit['files'] as $t_file ) {
+ $t_changeset->files[] = new SourceFile( 0, $t_file['revision'], $t_file['filename'], $t_file['action'] );
+ }
+
+ $t_changeset->save();
+
+ echo "saved.\n";
+ return array( $t_changeset, $t_parents );
+ } else {
+ echo "already exists.\n";
+ return array( null, array() );
+ }
}
}