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\Command; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\SVNBuddy\Config\AbstractConfigSetting; |
15
|
|
|
use ConsoleHelpers\SVNBuddy\Config\IntegerConfigSetting; |
16
|
|
|
use ConsoleHelpers\SVNBuddy\Config\RegExpsConfigSetting; |
17
|
|
|
use ConsoleHelpers\ConsoleKit\Exception\CommandException; |
18
|
|
|
use ConsoleHelpers\SVNBuddy\Helper\DateHelper; |
19
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser; |
20
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLog; |
21
|
|
|
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
22
|
|
|
use Symfony\Component\Console\Helper\Table; |
23
|
|
|
use Symfony\Component\Console\Helper\TableCell; |
24
|
|
|
use Symfony\Component\Console\Helper\TableSeparator; |
25
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
26
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
27
|
|
|
use Symfony\Component\Console\Input\InputOption; |
28
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
29
|
|
|
|
30
|
|
|
class LogCommand extends AbstractCommand implements IAggregatorAwareCommand, IConfigAwareCommand |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
const SETTING_LOG_LIMIT = 'log.limit'; |
34
|
|
|
|
35
|
|
|
const SETTING_LOG_MESSAGE_LIMIT = 'log.message-limit'; |
36
|
|
|
|
37
|
|
|
const SETTING_LOG_MERGE_CONFLICT_REGEXPS = 'log.merge-conflict-regexps'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Revision list parser. |
41
|
|
|
* |
42
|
|
|
* @var RevisionListParser |
43
|
|
|
*/ |
44
|
|
|
private $_revisionListParser; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Revision log |
48
|
|
|
* |
49
|
|
|
* @var RevisionLog |
50
|
|
|
*/ |
51
|
|
|
private $_revisionLog; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Prepare dependencies. |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
protected function prepareDependencies() |
59
|
|
|
{ |
60
|
|
|
parent::prepareDependencies(); |
61
|
|
|
|
62
|
|
|
$container = $this->getContainer(); |
63
|
|
|
|
64
|
|
|
$this->_revisionListParser = $container['revision_list_parser']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
|
|
|
|
69
|
|
|
*/ |
|
|
|
|
70
|
|
|
protected function configure() |
71
|
|
|
{ |
72
|
|
|
$this->pathAcceptsUrl = true; |
73
|
|
|
|
74
|
|
|
$description = <<<TEXT |
75
|
|
|
<info>NOTE:</info> |
76
|
|
|
|
77
|
|
|
The revision is considered merged only, when associated merge revision |
78
|
|
|
can be found. Unfortunately Subversion doesn't create merge revisions |
79
|
|
|
on direct path operations (e.g. replacing <comment>tags/stable</comment> with <comment>trunk</comment>) and |
80
|
|
|
therefore affected revisions won't be considered as merged by SVN-Buddy. |
81
|
|
|
TEXT; |
82
|
|
|
|
83
|
|
|
$this |
84
|
|
|
->setName('log') |
85
|
|
|
->setDescription( |
86
|
|
|
'Show the log messages for a set of revisions, bugs, paths, refs, etc.' |
87
|
|
|
) |
88
|
|
|
->setHelp($description) |
89
|
|
|
->addArgument( |
90
|
|
|
'path', |
91
|
|
|
InputArgument::OPTIONAL, |
92
|
|
|
'Working copy path or URL', |
93
|
|
|
'.' |
94
|
|
|
) |
95
|
|
|
->addOption( |
96
|
|
|
'revisions', |
97
|
|
|
'r', |
98
|
|
|
InputOption::VALUE_REQUIRED, |
99
|
|
|
'List of revision(-s) and/or revision range(-s), e.g. <comment>53324</comment>, <comment>1224-4433</comment>' |
100
|
|
|
) |
101
|
|
|
->addOption( |
102
|
|
|
'bugs', |
103
|
|
|
'b', |
104
|
|
|
InputOption::VALUE_REQUIRED, |
105
|
|
|
'List of bug(-s), e.g. <comment>JRA-1234</comment>, <comment>43644</comment>' |
106
|
|
|
) |
107
|
|
|
->addOption( |
108
|
|
|
'refs', |
109
|
|
|
null, |
110
|
|
|
InputOption::VALUE_REQUIRED, |
111
|
|
|
'List of refs, e.g. <comment>trunk</comment>, <comment>branches/branch-name</comment>, <comment>tags/tag-name</comment>' |
112
|
|
|
) |
113
|
|
|
->addOption( |
114
|
|
|
'merges', |
115
|
|
|
null, |
116
|
|
|
InputOption::VALUE_NONE, |
117
|
|
|
'Show merge revisions only' |
118
|
|
|
) |
119
|
|
|
->addOption( |
120
|
|
|
'no-merges', |
121
|
|
|
null, |
122
|
|
|
InputOption::VALUE_NONE, |
123
|
|
|
'Hide merge revisions' |
124
|
|
|
) |
125
|
|
|
->addOption( |
126
|
|
|
'merged', |
127
|
|
|
null, |
128
|
|
|
InputOption::VALUE_NONE, |
129
|
|
|
'Shows only revisions, that were merged at least once' |
130
|
|
|
) |
131
|
|
|
->addOption( |
132
|
|
|
'not-merged', |
133
|
|
|
null, |
134
|
|
|
InputOption::VALUE_NONE, |
135
|
|
|
'Shows only revisions, that were not merged' |
136
|
|
|
) |
137
|
|
|
->addOption( |
138
|
|
|
'merged-by', |
139
|
|
|
null, |
140
|
|
|
InputOption::VALUE_REQUIRED, |
141
|
|
|
'Show revisions merged by list of revision(-s) and/or revision range(-s)' |
142
|
|
|
) |
143
|
|
|
->addOption( |
144
|
|
|
'details', |
145
|
|
|
'd', |
146
|
|
|
InputOption::VALUE_NONE, |
147
|
|
|
'Shows detailed revision information, e.g. paths affected' |
148
|
|
|
) |
149
|
|
|
->addOption( |
150
|
|
|
'summary', |
151
|
|
|
's', |
152
|
|
|
InputOption::VALUE_NONE, |
153
|
|
|
'Shows number of added/changed/removed paths in the revision' |
154
|
|
|
) |
155
|
|
|
->addOption( |
156
|
|
|
'merge-oracle', |
157
|
|
|
null, |
158
|
|
|
InputOption::VALUE_NONE, |
159
|
|
|
'Shows number of paths in the revision, that can cause conflict upon merging' |
160
|
|
|
) |
161
|
|
|
->addOption( |
162
|
|
|
'merge-status', |
163
|
|
|
null, |
164
|
|
|
InputOption::VALUE_NONE, |
165
|
|
|
'Shows merge revisions affecting this revision' |
166
|
|
|
) |
167
|
|
|
->addOption( |
168
|
|
|
'max-count', |
169
|
|
|
null, |
170
|
|
|
InputOption::VALUE_REQUIRED, |
171
|
|
|
'Limit the number of revisions to output' |
172
|
|
|
); |
173
|
|
|
|
174
|
|
|
parent::configure(); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Return possible values for the named option |
179
|
|
|
* |
180
|
|
|
* @param string $optionName Option name. |
181
|
|
|
* @param CompletionContext $context Completion context. |
182
|
|
|
* |
183
|
|
|
* @return array |
184
|
|
|
*/ |
185
|
|
|
public function completeOptionValues($optionName, CompletionContext $context) |
186
|
|
|
{ |
187
|
|
|
$ret = parent::completeOptionValues($optionName, $context); |
188
|
|
|
|
189
|
|
|
if ( $optionName === 'refs' ) { |
190
|
|
|
return $this->getAllRefs(); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return $ret; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
|
|
|
|
197
|
|
|
* {@inheritdoc} |
198
|
|
|
*/ |
199
|
|
|
public function initialize(InputInterface $input, OutputInterface $output) |
200
|
|
|
{ |
201
|
|
|
parent::initialize($input, $output); |
202
|
|
|
|
203
|
|
|
$this->_revisionLog = $this->getRevisionLog($this->getWorkingCopyUrl()); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* {@inheritdoc} |
|
|
|
|
208
|
|
|
*/ |
|
|
|
|
209
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
210
|
|
|
{ |
211
|
|
|
$bugs = $this->getList($this->io->getOption('bugs')); |
212
|
|
|
$revisions = $this->getList($this->io->getOption('revisions')); |
213
|
|
|
|
214
|
|
|
if ( $bugs && $revisions ) { |
215
|
|
|
throw new \RuntimeException('The "--bugs" and "--revisions" options are mutually exclusive.'); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
$missing_revisions = array(); |
219
|
|
|
$revisions_by_path = $this->getRevisionsByPath(); |
220
|
|
|
|
221
|
|
|
if ( $revisions ) { |
222
|
|
|
$revisions = $this->_revisionListParser->expandRanges($revisions); |
223
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $revisions); |
224
|
|
|
$missing_revisions = array_diff($revisions, $revisions_by_path); |
225
|
|
|
} |
226
|
|
|
elseif ( $bugs ) { |
227
|
|
|
// Only show bug-related revisions on given path. The $missing_revisions is always empty. |
228
|
|
|
$revisions_from_bugs = $this->_revisionLog->find('bugs', $bugs); |
229
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $revisions_from_bugs); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
$merged_by = $this->getList($this->io->getOption('merged-by')); |
233
|
|
|
|
234
|
|
|
if ( $merged_by ) { |
235
|
|
|
// Exclude revisions, that were merged outside of project root folder in repository. |
236
|
|
|
$merged_by = $this->_revisionListParser->expandRanges($merged_by); |
237
|
|
|
$revisions_by_path = $this->_revisionLog->find( |
238
|
|
|
'paths', |
239
|
|
|
$this->repositoryConnector->getProjectUrl( |
240
|
|
|
$this->repositoryConnector->getRelativePath($this->getWorkingCopyPath()) |
241
|
|
|
) |
242
|
|
|
); |
243
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', $merged_by)); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
if ( $this->io->getOption('merges') ) { |
247
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges')); |
248
|
|
|
} |
249
|
|
|
elseif ( $this->io->getOption('no-merges') ) { |
250
|
|
|
$revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges')); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
if ( $this->io->getOption('merged') ) { |
254
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged')); |
255
|
|
|
} |
256
|
|
|
elseif ( $this->io->getOption('not-merged') ) { |
257
|
|
|
$revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged')); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
if ( $missing_revisions ) { |
261
|
|
|
throw new CommandException($this->getMissingRevisionsErrorMessage($missing_revisions)); |
262
|
|
|
} |
263
|
|
|
elseif ( !$revisions_by_path ) { |
264
|
|
|
throw new CommandException('No matching revisions found.'); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
rsort($revisions_by_path, SORT_NUMERIC); |
268
|
|
|
|
269
|
|
|
if ( $bugs || $revisions ) { |
270
|
|
|
// Don't limit revisions, when provided explicitly by user. |
271
|
|
|
$revisions_by_path_with_limit = $revisions_by_path; |
272
|
|
|
} |
273
|
|
|
else { |
274
|
|
|
// Apply limit only, when no explicit bugs/revisions are set. |
275
|
|
|
$revisions_by_path_with_limit = array_slice($revisions_by_path, 0, $this->getMaxCount()); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
$revisions_by_path_count = count($revisions_by_path); |
279
|
|
|
$revisions_by_path_with_limit_count = count($revisions_by_path_with_limit); |
280
|
|
|
|
281
|
|
|
$this->io->writeln(sprintf( |
282
|
|
|
' * Showing <info>%d</info> of <info>%d</info> revision(-s):', |
283
|
|
|
$revisions_by_path_with_limit_count, |
284
|
|
|
$revisions_by_path_count |
285
|
|
|
)); |
286
|
|
|
|
287
|
|
|
$this->printRevisions($revisions_by_path_with_limit, (boolean)$this->io->getOption('details')); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Shows error about missing revisions. |
292
|
|
|
* |
293
|
|
|
* @param array $missing_revisions Missing revisions. |
294
|
|
|
* |
295
|
|
|
* @return string |
296
|
|
|
*/ |
297
|
|
|
protected function getMissingRevisionsErrorMessage(array $missing_revisions) |
298
|
|
|
{ |
299
|
|
|
$refs = $this->io->getOption('refs'); |
300
|
|
|
$missing_revisions = implode(', ', $missing_revisions); |
301
|
|
|
|
302
|
|
|
if ( $refs ) { |
303
|
|
|
$revision_source = 'in "' . $refs . '" ref(-s)'; |
304
|
|
|
} |
305
|
|
|
else { |
306
|
|
|
$revision_source = 'at "' . $this->getWorkingCopyUrl() . '" url'; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
return 'The ' . $missing_revisions . ' revision(-s) not found ' . $revision_source . '.'; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Returns list of revisions by path. |
314
|
|
|
* |
315
|
|
|
* @return array |
316
|
|
|
* @throws CommandException When given refs doesn't exist. |
317
|
|
|
*/ |
318
|
|
|
protected function getRevisionsByPath() |
319
|
|
|
{ |
320
|
|
|
$refs = $this->getList($this->io->getOption('refs')); |
321
|
|
|
$relative_path = $this->repositoryConnector->getRelativePath($this->getWorkingCopyPath()); |
322
|
|
|
|
323
|
|
|
if ( !$refs ) { |
324
|
|
|
$ref = $this->repositoryConnector->getRefByPath($relative_path); |
325
|
|
|
|
326
|
|
|
// Use search by ref, when working copy represents ref root folder. |
327
|
|
|
if ( $ref !== false && preg_match('/' . preg_quote($ref, '/') . '$/', $relative_path) ) { |
328
|
|
|
return $this->_revisionLog->find('refs', $ref); |
329
|
|
|
} |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
if ( $refs ) { |
333
|
|
|
$incorrect_refs = array_diff($refs, $this->getAllRefs()); |
334
|
|
|
|
335
|
|
|
if ( $incorrect_refs ) { |
336
|
|
|
throw new CommandException( |
337
|
|
|
'The following refs are unknown: "' . implode('", "', $incorrect_refs) . '".' |
338
|
|
|
); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
return $this->_revisionLog->find('refs', $refs); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
return $this->_revisionLog->find('paths', $relative_path); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Returns displayed revision limit. |
349
|
|
|
* |
350
|
|
|
* @return integer |
351
|
|
|
*/ |
352
|
|
|
protected function getMaxCount() |
353
|
|
|
{ |
354
|
|
|
$max_count = $this->io->getOption('max-count'); |
355
|
|
|
|
356
|
|
|
if ( $max_count !== null ) { |
357
|
|
|
return $max_count; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
return $this->getSetting(self::SETTING_LOG_LIMIT); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Prints revisions. |
365
|
|
|
* |
366
|
|
|
* @param array $revisions Revisions. |
367
|
|
|
* @param boolean $with_details Print extended revision details (e.g. paths changed). |
368
|
|
|
* |
369
|
|
|
* @return void |
370
|
|
|
*/ |
371
|
|
|
protected function printRevisions(array $revisions, $with_details = false) |
372
|
|
|
{ |
373
|
|
|
$table = new Table($this->io->getOutput()); |
374
|
|
|
$headers = array('Revision', 'Author', 'Date', 'Bug-ID', 'Log Message'); |
375
|
|
|
|
376
|
|
|
// Add "Summary" header. |
377
|
|
|
if ( $this->io->getOption('summary') ) { |
378
|
|
|
$headers[] = 'Summary'; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
$merge_oracle = $this->io->getOption('merge-oracle'); |
382
|
|
|
|
383
|
|
|
// Add "M.O." header. |
384
|
|
|
if ( $merge_oracle ) { |
385
|
|
|
$headers[] = 'M.O.'; |
386
|
|
|
$merge_conflict_regexps = $this->getMergeConflictRegExps(); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
// Add "Merged Via" header. |
390
|
|
|
$merge_status = $this->io->getOption('merge-status'); |
391
|
|
|
|
392
|
|
|
if ( $merge_status ) { |
393
|
|
|
$headers[] = 'Merged Via'; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
$table->setHeaders($headers); |
397
|
|
|
|
398
|
|
|
/** @var DateHelper $date_helper */ |
399
|
|
|
$date_helper = $this->getHelper('date'); |
400
|
|
|
|
401
|
|
|
$prev_bugs = null; |
402
|
|
|
$last_color = 'yellow'; |
403
|
|
|
$last_revision = end($revisions); |
404
|
|
|
|
405
|
|
|
$repository_path = $this->repositoryConnector->getRelativePath( |
406
|
|
|
$this->getWorkingCopyPath() |
407
|
|
|
) . '/'; |
408
|
|
|
|
409
|
|
|
$log_message_limit = $this->getSetting(self::SETTING_LOG_MESSAGE_LIMIT); |
410
|
|
|
|
411
|
|
|
foreach ( $revisions as $revision ) { |
412
|
|
|
$revision_data = $this->_revisionLog->getRevisionData('summary', $revision); |
413
|
|
|
|
414
|
|
|
if ( $with_details ) { |
415
|
|
|
// When details requested don't transform commit message except for word wrapping. |
416
|
|
|
$log_message = wordwrap($revision_data['msg'], $log_message_limit); // FIXME: Not UTF-8 safe solution. |
417
|
|
|
} |
418
|
|
|
else { |
419
|
|
|
// When details not requested only operate on first line of commit message. |
420
|
|
|
list($log_message,) = explode(PHP_EOL, $revision_data['msg']); |
421
|
|
|
$log_message = preg_replace('/^\[fixes:.*?\]/s', "\xE2\x9C\x94", $log_message); |
422
|
|
|
|
423
|
|
|
if ( strpos($revision_data['msg'], PHP_EOL) !== false |
424
|
|
|
|| mb_strlen($log_message) > $log_message_limit |
425
|
|
|
) { |
426
|
|
|
$log_message = mb_substr($log_message, 0, $log_message_limit - 3) . '...'; |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
$new_bugs = $this->_revisionLog->getRevisionData('bugs', $revision); |
431
|
|
|
|
432
|
|
|
if ( isset($prev_bugs) && $new_bugs !== $prev_bugs ) { |
433
|
|
|
$last_color = $last_color == 'yellow' ? 'magenta' : 'yellow'; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
$row = array( |
437
|
|
|
$revision, |
438
|
|
|
$revision_data['author'], |
439
|
|
|
$date_helper->getAgoTime($revision_data['date']), |
440
|
|
|
$this->formatBugs($new_bugs, $last_color), |
441
|
|
|
$log_message, |
442
|
|
|
); |
443
|
|
|
|
444
|
|
|
$revision_paths = $this->_revisionLog->getRevisionData('paths', $revision); |
445
|
|
|
|
446
|
|
|
// Add "Summary" column. |
447
|
|
|
if ( $this->io->getOption('summary') ) { |
448
|
|
|
$row[] = $this->generateChangeSummary($revision_paths); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
// Add "M.O." column. |
452
|
|
|
if ( $merge_oracle ) { |
453
|
|
|
$merge_conflict_predication = $this->getMergeConflictPrediction( |
454
|
|
|
$revision_paths, |
455
|
|
|
$merge_conflict_regexps |
|
|
|
|
456
|
|
|
); |
457
|
|
|
$row[] = $merge_conflict_predication ? '<error>' . count($merge_conflict_predication) . '</error>' : ''; |
458
|
|
|
} |
459
|
|
|
else { |
460
|
|
|
$merge_conflict_predication = array(); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
// Add "Merged Via" column. |
464
|
|
|
if ( $merge_status ) { |
465
|
|
|
$merged_via = $this->_revisionLog->getRevisionData('merges', $revision); |
466
|
|
|
$row[] = $merged_via ? implode(', ', $merged_via) : ''; |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
$table->addRow($row); |
470
|
|
|
|
471
|
|
|
if ( $with_details ) { |
472
|
|
|
$details = '<fg=white;options=bold>Changed Paths:</>'; |
473
|
|
|
|
474
|
|
|
foreach ( $revision_paths as $path_data ) { |
475
|
|
|
$path_action = $path_data['action']; |
476
|
|
|
$relative_path = $this->_getRelativeLogPath($path_data, 'path', $repository_path); |
477
|
|
|
|
478
|
|
|
$details .= PHP_EOL . ' * '; |
479
|
|
|
|
480
|
|
|
if ( $path_action == 'A' ) { |
481
|
|
|
$color_format = 'fg=green'; |
482
|
|
|
} |
483
|
|
|
elseif ( $path_action == 'D' ) { |
484
|
|
|
$color_format = 'fg=red'; |
485
|
|
|
} |
486
|
|
|
else { |
487
|
|
|
$color_format = in_array($path_data['path'], $merge_conflict_predication) ? 'error' : ''; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
$to_colorize = $path_action . ' ' . $relative_path; |
491
|
|
|
|
492
|
|
|
if ( isset($path_data['copyfrom-path']) ) { |
493
|
|
|
$copy_from_rev = $path_data['copyfrom-rev']; |
494
|
|
|
$copy_from_path = $this->_getRelativeLogPath($path_data, 'copyfrom-path', $repository_path); |
495
|
|
|
$to_colorize .= PHP_EOL . ' (from ' . $copy_from_path . ':' . $copy_from_rev . ')'; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
if ( $color_format ) { |
499
|
|
|
$to_colorize = '<' . $color_format . '>' . $to_colorize . '</>'; |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
$details .= $to_colorize; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
$table->addRow(new TableSeparator()); |
506
|
|
|
$table->addRow(array(new TableCell($details, array('colspan' => 5)))); |
507
|
|
|
|
508
|
|
|
if ( $revision != $last_revision ) { |
509
|
|
|
$table->addRow(new TableSeparator()); |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
$prev_bugs = $new_bugs; |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
$table->render(); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Returns formatted list of bugs. |
521
|
|
|
* |
522
|
|
|
* @param array $bugs List of bugs. |
523
|
|
|
* @param string $color Color. |
524
|
|
|
* |
525
|
|
|
* @return string |
526
|
|
|
*/ |
527
|
|
|
protected function formatBugs(array $bugs, $color) |
528
|
|
|
{ |
529
|
|
|
$bug_chunks = array_chunk($bugs, 3); |
530
|
|
|
|
531
|
|
|
$ret = array(); |
532
|
|
|
|
533
|
|
|
foreach ( $bug_chunks as $bug_chunk ) { |
534
|
|
|
$ret[] = '<fg=' . $color . '>' . implode('</>, <fg=' . $color . '>', $bug_chunk) . '</>'; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
return implode(PHP_EOL, $ret); |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
/** |
541
|
|
|
* Generates change summary for a revision. |
542
|
|
|
* |
543
|
|
|
* @param array $revision_paths Revision paths. |
544
|
|
|
* |
545
|
|
|
* @return string |
546
|
|
|
*/ |
547
|
|
|
protected function generateChangeSummary(array $revision_paths) |
548
|
|
|
{ |
549
|
|
|
$summary = array('added' => 0, 'changed' => 0, 'removed' => 0); |
550
|
|
|
|
551
|
|
|
foreach ( $revision_paths as $path_data ) { |
552
|
|
|
$path_action = $path_data['action']; |
553
|
|
|
|
554
|
|
|
if ( $path_action == 'A' ) { |
555
|
|
|
$summary['added']++; |
556
|
|
|
} |
557
|
|
|
elseif ( $path_action == 'D' ) { |
558
|
|
|
$summary['removed']++; |
559
|
|
|
} |
560
|
|
|
else { |
561
|
|
|
$summary['changed']++; |
562
|
|
|
} |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
if ( $summary['added'] ) { |
566
|
|
|
$summary['added'] = '<fg=green>+' . $summary['added'] . '</>'; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
if ( $summary['removed'] ) { |
570
|
|
|
$summary['removed'] = '<fg=red>-' . $summary['removed'] . '</>'; |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
return implode(' ', array_filter($summary)); |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
/** |
577
|
|
|
* Returns merge conflict path predictions. |
578
|
|
|
* |
579
|
|
|
* @param array $revision_paths Revision paths. |
580
|
|
|
* @param array $merge_conflict_regexps Merge conflict paths. |
581
|
|
|
* |
582
|
|
|
* @return array |
583
|
|
|
*/ |
584
|
|
|
protected function getMergeConflictPrediction(array $revision_paths, array $merge_conflict_regexps) |
585
|
|
|
{ |
586
|
|
|
if ( !$merge_conflict_regexps ) { |
587
|
|
|
return array(); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
$conflict_paths = array(); |
591
|
|
|
|
592
|
|
|
foreach ( $revision_paths as $revision_path ) { |
593
|
|
|
foreach ( $merge_conflict_regexps as $merge_conflict_regexp ) { |
594
|
|
|
if ( preg_match($merge_conflict_regexp, $revision_path['path']) ) { |
595
|
|
|
$conflict_paths[] = $revision_path['path']; |
596
|
|
|
} |
597
|
|
|
} |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
return $conflict_paths; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* Returns merge conflict regexps. |
605
|
|
|
* |
606
|
|
|
* @return array |
607
|
|
|
*/ |
608
|
|
|
protected function getMergeConflictRegExps() |
609
|
|
|
{ |
610
|
|
|
return $this->getSetting(self::SETTING_LOG_MERGE_CONFLICT_REGEXPS); |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* Returns relative path to "svn log" returned path. |
615
|
|
|
* |
616
|
|
|
* @param array $path_data Path data. |
617
|
|
|
* @param string $path_key Path key. |
618
|
|
|
* @param string $repository_path Repository path. |
619
|
|
|
* |
620
|
|
|
* @return string |
621
|
|
|
*/ |
622
|
|
|
private function _getRelativeLogPath(array $path_data, $path_key, $repository_path) |
623
|
|
|
{ |
624
|
|
|
$ret = $path_data[$path_key]; |
625
|
|
|
|
626
|
|
|
if ( $path_data['kind'] == 'dir' ) { |
627
|
|
|
$ret .= '/'; |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
$ret = preg_replace('/^' . preg_quote($repository_path, '/') . '/', '', $ret, 1); |
631
|
|
|
|
632
|
|
|
if ( $ret === '' ) { |
633
|
|
|
$ret = '.'; |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
return $ret; |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* Returns URL to the working copy. |
641
|
|
|
* |
642
|
|
|
* @return string |
643
|
|
|
*/ |
644
|
|
|
protected function getWorkingCopyUrl() |
645
|
|
|
{ |
646
|
|
|
$wc_path = $this->getWorkingCopyPath(); |
647
|
|
|
|
648
|
|
|
if ( !$this->repositoryConnector->isUrl($wc_path) ) { |
649
|
|
|
return $this->repositoryConnector->getWorkingCopyUrl($wc_path); |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
return $wc_path; |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* Returns list of config settings. |
657
|
|
|
* |
658
|
|
|
* @return AbstractConfigSetting[] |
659
|
|
|
*/ |
660
|
|
|
public function getConfigSettings() |
661
|
|
|
{ |
662
|
|
|
return array( |
663
|
|
|
new IntegerConfigSetting(self::SETTING_LOG_LIMIT, 10), |
664
|
|
|
new IntegerConfigSetting(self::SETTING_LOG_MESSAGE_LIMIT, 68), |
665
|
|
|
new RegExpsConfigSetting(self::SETTING_LOG_MERGE_CONFLICT_REGEXPS, '#/composer\.lock$#'), |
666
|
|
|
); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
} |
670
|
|
|
|