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\BugsPlugin; |
20
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\MergesPlugin; |
21
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\PathsPlugin; |
22
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\ProjectsPlugin; |
23
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RefsPlugin; |
24
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\SummaryPlugin; |
25
|
|
|
|
26
|
|
|
class RevisionLogFactory |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Repository connector. |
31
|
|
|
* |
32
|
|
|
* @var Connector |
33
|
|
|
*/ |
34
|
|
|
private $_repositoryConnector; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Database manager. |
38
|
|
|
* |
39
|
|
|
* @var DatabaseManager |
40
|
|
|
*/ |
41
|
|
|
private $_databaseManager; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Log message parser factory |
45
|
|
|
* |
46
|
|
|
* @var LogMessageParserFactory |
47
|
|
|
*/ |
48
|
|
|
private $_logMessageParserFactory; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Revision logs by url |
52
|
|
|
* |
53
|
|
|
* @var RevisionLog[] |
54
|
|
|
*/ |
55
|
|
|
private $_cache = array(); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Create revision log. |
59
|
|
|
* |
60
|
|
|
* @param Connector $repository_connector Repository connector. |
61
|
|
|
* @param DatabaseManager $database_manager Database manager. |
62
|
|
|
* @param LogMessageParserFactory $log_message_parser_factory Log message parser factory. |
63
|
|
|
*/ |
64
|
3 |
|
public function __construct( |
65
|
|
|
Connector $repository_connector, |
66
|
|
|
DatabaseManager $database_manager, |
67
|
|
|
LogMessageParserFactory $log_message_parser_factory |
68
|
|
|
) { |
69
|
3 |
|
$this->_repositoryConnector = $repository_connector; |
70
|
3 |
|
$this->_databaseManager = $database_manager; |
71
|
3 |
|
$this->_logMessageParserFactory = $log_message_parser_factory; |
72
|
3 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Returns revision log for url. |
76
|
|
|
* |
77
|
|
|
* @param string $repository_url Repository url. |
78
|
|
|
* @param ConsoleIO $io Console IO. |
79
|
|
|
* |
80
|
|
|
* @return RevisionLog |
81
|
|
|
*/ |
82
|
1 |
|
public function getRevisionLog($repository_url, ConsoleIO $io = null) |
83
|
|
|
{ |
84
|
1 |
|
$repository_url = $this->_repositoryConnector->removeCredentials($repository_url); |
85
|
|
|
|
86
|
1 |
|
if ( !isset($this->_cache[$repository_url]) ) { |
87
|
1 |
|
$this->_cache[$repository_url] = $this->createRevisionLog($repository_url, $io); |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
return $this->_cache[$repository_url]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns revision log for url. |
95
|
|
|
* |
96
|
|
|
* @param string $repository_url Repository url. |
97
|
|
|
* @param ConsoleIO $io Console IO. |
98
|
|
|
* |
99
|
|
|
* @return RevisionLog |
100
|
|
|
*/ |
101
|
1 |
|
protected function createRevisionLog($repository_url, ConsoleIO $io = null) |
102
|
|
|
{ |
103
|
|
|
// Gets database for given repository url. |
104
|
1 |
|
$root_url = $this->_repositoryConnector->getRootUrl($repository_url); |
105
|
1 |
|
$database = $this->_databaseManager->getDatabase($root_url, $io); |
106
|
|
|
|
107
|
|
|
// Create dependencies. |
108
|
1 |
|
$database_cache = new DatabaseCache($database); |
109
|
1 |
|
$repository_filler = new RepositoryFiller($database, $database_cache); |
110
|
|
|
|
111
|
|
|
// Create blank revision log. |
112
|
1 |
|
$revision_log = new RevisionLog($repository_url, $this->_repositoryConnector, $io); |
113
|
|
|
|
114
|
|
|
// Add plugins to revision log. |
115
|
1 |
|
$revision_log->registerPlugin(new SummaryPlugin($database, $repository_filler)); |
116
|
1 |
|
$revision_log->registerPlugin(new PathsPlugin( |
117
|
1 |
|
$database, |
118
|
1 |
|
$repository_filler, |
119
|
1 |
|
$database_cache, |
120
|
1 |
|
$this->_repositoryConnector, |
121
|
1 |
|
new PathCollisionDetector() |
122
|
|
|
)); |
123
|
1 |
|
$revision_log->registerPlugin(new ProjectsPlugin($database, $repository_filler)); |
124
|
1 |
|
$revision_log->registerPlugin(new BugsPlugin( |
125
|
1 |
|
$database, |
126
|
1 |
|
$repository_filler, |
127
|
1 |
|
$root_url, |
128
|
1 |
|
$this->_repositoryConnector, |
129
|
1 |
|
$this->_logMessageParserFactory |
130
|
|
|
)); |
131
|
1 |
|
$revision_log->registerPlugin(new MergesPlugin($database, $repository_filler)); |
132
|
1 |
|
$revision_log->registerPlugin(new RefsPlugin($database, $repository_filler)); |
133
|
|
|
|
134
|
|
|
// Run migrations (includes initial schema creation). |
135
|
1 |
|
$context = new MigrationContext($database, clone $revision_log); |
136
|
1 |
|
$this->_databaseManager->runMigrations($context); |
137
|
|
|
|
138
|
1 |
|
$profiler = $database->getProfiler(); |
139
|
|
|
|
140
|
1 |
|
if ( $profiler instanceof StatementProfiler ) { |
141
|
|
|
$profiler->trackDuplicates(true); |
142
|
|
|
} |
143
|
|
|
|
144
|
1 |
|
$revision_log->refresh(false); |
145
|
|
|
|
146
|
1 |
|
if ( $profiler instanceof StatementProfiler ) { |
147
|
|
|
$profiler->trackDuplicates(false); |
148
|
|
|
} |
149
|
|
|
|
150
|
1 |
|
return $revision_log; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
} |
154
|
|
|
|