1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the SVN-Buddy library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy\Repository\RevisionLog; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\ConsoleKit\ConsoleIO; |
15
|
|
|
use ConsoleHelpers\SVNBuddy\Database\DatabaseCache; |
16
|
|
|
use ConsoleHelpers\SVNBuddy\Database\StatementProfiler; |
17
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; |
18
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory; |
19
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\DatabaseCollectorPlugin\BugsPlugin; |
20
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\DatabaseCollectorPlugin\ProjectsPlugin; |
21
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\DatabaseCollectorPlugin\RefsPlugin; |
22
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RepositoryCollectorPlugin\MergesPlugin; |
23
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RepositoryCollectorPlugin\PathsPlugin; |
24
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RepositoryCollectorPlugin\SummaryPlugin; |
25
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionUrlBuilder; |
26
|
|
|
|
27
|
|
|
class RevisionLogFactory |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Repository connector. |
32
|
|
|
* |
33
|
|
|
* @var Connector |
34
|
|
|
*/ |
35
|
|
|
private $_repositoryConnector; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Database manager. |
39
|
|
|
* |
40
|
|
|
* @var DatabaseManager |
41
|
|
|
*/ |
42
|
|
|
private $_databaseManager; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Log message parser factory |
46
|
|
|
* |
47
|
|
|
* @var LogMessageParserFactory |
48
|
|
|
*/ |
49
|
|
|
private $_logMessageParserFactory; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Working directory. |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
private $_workingDirectory; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Revision logs by url |
60
|
|
|
* |
61
|
|
|
* @var RevisionLog[] |
62
|
|
|
*/ |
63
|
|
|
private $_cache = array(); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Create revision log. |
67
|
|
|
* |
68
|
|
|
* @param Connector $repository_connector Repository connector. |
69
|
|
|
* @param DatabaseManager $database_manager Database manager. |
70
|
|
|
* @param LogMessageParserFactory $log_message_parser_factory Log message parser factory. |
71
|
|
|
* @param string $working_directory Working directory. |
72
|
|
|
*/ |
73
|
3 |
|
public function __construct( |
74
|
|
|
Connector $repository_connector, |
75
|
|
|
DatabaseManager $database_manager, |
76
|
|
|
LogMessageParserFactory $log_message_parser_factory, |
77
|
|
|
$working_directory |
78
|
|
|
) { |
79
|
3 |
|
$this->_repositoryConnector = $repository_connector; |
80
|
3 |
|
$this->_databaseManager = $database_manager; |
81
|
3 |
|
$this->_logMessageParserFactory = $log_message_parser_factory; |
82
|
3 |
|
$this->_workingDirectory = $working_directory; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns revision log for url. |
87
|
|
|
* |
88
|
|
|
* @param string $repository_url Repository url. |
89
|
|
|
* @param ConsoleIO $io Console IO. |
90
|
|
|
* |
91
|
|
|
* @return RevisionLog |
92
|
|
|
*/ |
93
|
1 |
|
public function getRevisionLog($repository_url, ConsoleIO $io = null) |
94
|
|
|
{ |
95
|
1 |
|
$repository_url = $this->_repositoryConnector->removeCredentials($repository_url); |
96
|
|
|
|
97
|
1 |
|
if ( !isset($this->_cache[$repository_url]) ) { |
98
|
1 |
|
$this->_cache[$repository_url] = $this->createRevisionLog($repository_url, $io); |
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
return $this->_cache[$repository_url]; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns revision log for url. |
106
|
|
|
* |
107
|
|
|
* @param string $repository_url Repository url. |
108
|
|
|
* @param ConsoleIO $io Console IO. |
109
|
|
|
* |
110
|
|
|
* @return RevisionLog |
111
|
|
|
*/ |
112
|
1 |
|
protected function createRevisionLog($repository_url, ConsoleIO $io = null) |
113
|
|
|
{ |
114
|
|
|
// Gets database for given repository url. |
115
|
1 |
|
$root_url = $this->_repositoryConnector->getRootUrl($repository_url); |
116
|
1 |
|
$database = $this->_databaseManager->getDatabase($root_url, $io); |
117
|
|
|
|
118
|
|
|
// Create dependencies. |
119
|
1 |
|
$database_cache = new DatabaseCache($database); |
120
|
1 |
|
$repository_filler = new RepositoryFiller($database, $database_cache); |
121
|
|
|
|
122
|
1 |
|
$revision_url_builder = new RevisionUrlBuilder($this->_repositoryConnector, $repository_url); |
123
|
|
|
|
124
|
|
|
// Create blank revision log. |
125
|
1 |
|
$revision_log = new RevisionLog( |
126
|
1 |
|
$repository_url, |
127
|
1 |
|
$revision_url_builder, |
128
|
1 |
|
$this->_repositoryConnector, |
129
|
1 |
|
$this->_workingDirectory, |
130
|
1 |
|
$io |
131
|
1 |
|
); |
132
|
|
|
|
133
|
|
|
// Add plugins to revision log. |
134
|
1 |
|
$revision_log->registerPlugin(new SummaryPlugin($database, $repository_filler)); |
135
|
1 |
|
$revision_log->registerPlugin(new PathsPlugin( |
136
|
1 |
|
$database, |
137
|
1 |
|
$repository_filler, |
138
|
1 |
|
$database_cache, |
139
|
1 |
|
$this->_repositoryConnector, |
140
|
1 |
|
new PathCollisionDetector() |
141
|
1 |
|
)); |
142
|
1 |
|
$revision_log->registerPlugin(new ProjectsPlugin($database, $repository_filler)); |
143
|
1 |
|
$revision_log->registerPlugin(new BugsPlugin( |
144
|
1 |
|
$database, |
145
|
1 |
|
$repository_filler, |
146
|
1 |
|
$root_url, |
147
|
1 |
|
$this->_repositoryConnector, |
148
|
1 |
|
$this->_logMessageParserFactory |
149
|
1 |
|
)); |
150
|
1 |
|
$revision_log->registerPlugin(new MergesPlugin($database, $repository_filler)); |
151
|
1 |
|
$revision_log->registerPlugin(new RefsPlugin($database, $repository_filler)); |
152
|
|
|
|
153
|
|
|
// Run migrations (includes initial schema creation). |
154
|
1 |
|
$context = new MigrationContext($database, clone $revision_log); |
155
|
1 |
|
$this->_databaseManager->runMigrations($context); |
156
|
|
|
|
157
|
1 |
|
$profiler = $database->getProfiler(); |
158
|
|
|
|
159
|
1 |
|
if ( $profiler instanceof StatementProfiler ) { |
160
|
|
|
$profiler->trackDuplicates(true); |
161
|
|
|
} |
162
|
|
|
|
163
|
1 |
|
$revision_log->refresh(false); |
164
|
|
|
|
165
|
1 |
|
if ( $profiler instanceof StatementProfiler ) { |
166
|
|
|
$profiler->trackDuplicates(false); |
167
|
|
|
} |
168
|
|
|
|
169
|
1 |
|
return $revision_log; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
} |
173
|
|
|
|