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
|
|
|
'with-details', |
145
|
|
|
'd', |
146
|
|
|
InputOption::VALUE_NONE, |
147
|
|
|
'Shows detailed revision information, e.g. paths affected' |
148
|
|
|
) |
149
|
|
|
->addOption( |
150
|
|
|
'with-summary', |
151
|
|
|
's', |
152
|
|
|
InputOption::VALUE_NONE, |
153
|
|
|
'Shows number of added/changed/removed paths in the revision' |
154
|
|
|
) |
155
|
|
|
->addOption( |
156
|
|
|
'with-refs', |
157
|
|
|
null, |
158
|
|
|
InputOption::VALUE_NONE, |
159
|
|
|
'Shows revision refs' |
160
|
|
|
) |
161
|
|
|
->addOption( |
162
|
|
|
'with-merge-oracle', |
163
|
|
|
null, |
164
|
|
|
InputOption::VALUE_NONE, |
165
|
|
|
'Shows number of paths in the revision, that can cause conflict upon merging' |
166
|
|
|
) |
167
|
|
|
->addOption( |
168
|
|
|
'with-merge-status', |
169
|
|
|
null, |
170
|
|
|
InputOption::VALUE_NONE, |
171
|
|
|
'Shows merge revisions affecting this revision' |
172
|
|
|
) |
173
|
|
|
->addOption( |
174
|
|
|
'max-count', |
175
|
|
|
null, |
176
|
|
|
InputOption::VALUE_REQUIRED, |
177
|
|
|
'Limit the number of revisions to output' |
178
|
|
|
); |
179
|
|
|
|
180
|
|
|
parent::configure(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Return possible values for the named option |
185
|
|
|
* |
186
|
|
|
* @param string $optionName Option name. |
187
|
|
|
* @param CompletionContext $context Completion context. |
188
|
|
|
* |
189
|
|
|
* @return array |
190
|
|
|
*/ |
191
|
|
|
public function completeOptionValues($optionName, CompletionContext $context) |
192
|
|
|
{ |
193
|
|
|
$ret = parent::completeOptionValues($optionName, $context); |
194
|
|
|
|
195
|
|
|
if ( $optionName === 'refs' ) { |
196
|
|
|
return $this->getAllRefs(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
return $ret; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
|
|
|
|
203
|
|
|
* {@inheritdoc} |
204
|
|
|
*/ |
205
|
|
|
public function initialize(InputInterface $input, OutputInterface $output) |
206
|
|
|
{ |
207
|
|
|
parent::initialize($input, $output); |
208
|
|
|
|
209
|
|
|
$this->_revisionLog = $this->getRevisionLog($this->getWorkingCopyUrl()); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* {@inheritdoc} |
|
|
|
|
214
|
|
|
*/ |
|
|
|
|
215
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
216
|
|
|
{ |
217
|
|
|
$bugs = $this->getList($this->io->getOption('bugs')); |
218
|
|
|
$revisions = $this->getList($this->io->getOption('revisions')); |
219
|
|
|
|
220
|
|
|
if ( $bugs && $revisions ) { |
221
|
|
|
throw new \RuntimeException('The "--bugs" and "--revisions" options are mutually exclusive.'); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
$missing_revisions = array(); |
225
|
|
|
$revisions_by_path = $this->getRevisionsByPath(); |
226
|
|
|
|
227
|
|
|
if ( $revisions ) { |
228
|
|
|
$revisions = $this->_revisionListParser->expandRanges($revisions); |
229
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $revisions); |
230
|
|
|
$missing_revisions = array_diff($revisions, $revisions_by_path); |
231
|
|
|
} |
232
|
|
|
elseif ( $bugs ) { |
233
|
|
|
// Only show bug-related revisions on given path. The $missing_revisions is always empty. |
234
|
|
|
$revisions_from_bugs = $this->_revisionLog->find('bugs', $bugs); |
235
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $revisions_from_bugs); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
$merged_by = $this->getList($this->io->getOption('merged-by')); |
239
|
|
|
|
240
|
|
|
if ( $merged_by ) { |
241
|
|
|
// Exclude revisions, that were merged outside of project root folder in repository. |
242
|
|
|
$merged_by = $this->_revisionListParser->expandRanges($merged_by); |
243
|
|
|
$revisions_by_path = $this->_revisionLog->find( |
244
|
|
|
'paths', |
245
|
|
|
$this->repositoryConnector->getProjectUrl( |
246
|
|
|
$this->repositoryConnector->getRelativePath($this->getWorkingCopyPath()) |
247
|
|
|
) |
248
|
|
|
); |
249
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', $merged_by)); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
if ( $this->io->getOption('merges') ) { |
253
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges')); |
254
|
|
|
} |
255
|
|
|
elseif ( $this->io->getOption('no-merges') ) { |
256
|
|
|
$revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges')); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
if ( $this->io->getOption('merged') ) { |
260
|
|
|
$revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged')); |
261
|
|
|
} |
262
|
|
|
elseif ( $this->io->getOption('not-merged') ) { |
263
|
|
|
$revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged')); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
if ( $missing_revisions ) { |
267
|
|
|
throw new CommandException($this->getMissingRevisionsErrorMessage($missing_revisions)); |
268
|
|
|
} |
269
|
|
|
elseif ( !$revisions_by_path ) { |
270
|
|
|
throw new CommandException('No matching revisions found.'); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
rsort($revisions_by_path, SORT_NUMERIC); |
274
|
|
|
|
275
|
|
|
if ( $bugs || $revisions ) { |
276
|
|
|
// Don't limit revisions, when provided explicitly by user. |
277
|
|
|
$revisions_by_path_with_limit = $revisions_by_path; |
278
|
|
|
} |
279
|
|
|
else { |
280
|
|
|
// Apply limit only, when no explicit bugs/revisions are set. |
281
|
|
|
$revisions_by_path_with_limit = array_slice($revisions_by_path, 0, $this->getMaxCount()); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
$revisions_by_path_count = count($revisions_by_path); |
285
|
|
|
$revisions_by_path_with_limit_count = count($revisions_by_path_with_limit); |
286
|
|
|
|
287
|
|
|
if ( $revisions_by_path_with_limit_count === $revisions_by_path_count ) { |
288
|
|
|
$this->io->writeln(sprintf( |
289
|
|
|
' * Showing <info>%d</info> revision(-s):', |
290
|
|
|
$revisions_by_path_with_limit_count |
291
|
|
|
)); |
292
|
|
|
} |
293
|
|
|
else { |
294
|
|
|
$this->io->writeln(sprintf( |
295
|
|
|
' * Showing <info>%d</info> of <info>%d</info> revision(-s):', |
296
|
|
|
$revisions_by_path_with_limit_count, |
297
|
|
|
$revisions_by_path_count |
298
|
|
|
)); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
$this->printRevisions($revisions_by_path_with_limit, (boolean)$this->io->getOption('with-details')); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Shows error about missing revisions. |
306
|
|
|
* |
307
|
|
|
* @param array $missing_revisions Missing revisions. |
308
|
|
|
* |
309
|
|
|
* @return string |
310
|
|
|
*/ |
311
|
|
|
protected function getMissingRevisionsErrorMessage(array $missing_revisions) |
312
|
|
|
{ |
313
|
|
|
$refs = $this->io->getOption('refs'); |
314
|
|
|
$missing_revisions = implode(', ', $missing_revisions); |
315
|
|
|
|
316
|
|
|
if ( $refs ) { |
317
|
|
|
$revision_source = 'in "' . $refs . '" ref(-s)'; |
318
|
|
|
} |
319
|
|
|
else { |
320
|
|
|
$revision_source = 'at "' . $this->getWorkingCopyUrl() . '" url'; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
return 'The ' . $missing_revisions . ' revision(-s) not found ' . $revision_source . '.'; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Returns list of revisions by path. |
328
|
|
|
* |
329
|
|
|
* @return array |
330
|
|
|
* @throws CommandException When given refs doesn't exist. |
331
|
|
|
*/ |
332
|
|
|
protected function getRevisionsByPath() |
333
|
|
|
{ |
334
|
|
|
$refs = $this->getList($this->io->getOption('refs')); |
335
|
|
|
$relative_path = $this->repositoryConnector->getRelativePath($this->getWorkingCopyPath()); |
336
|
|
|
|
337
|
|
|
if ( !$refs ) { |
338
|
|
|
$ref = $this->repositoryConnector->getRefByPath($relative_path); |
339
|
|
|
|
340
|
|
|
// Use search by ref, when working copy represents ref root folder. |
341
|
|
|
if ( $ref !== false && preg_match('/' . preg_quote($ref, '/') . '$/', $relative_path) ) { |
342
|
|
|
return $this->_revisionLog->find('refs', $ref); |
343
|
|
|
} |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
if ( $refs ) { |
347
|
|
|
$incorrect_refs = array_diff($refs, $this->getAllRefs()); |
348
|
|
|
|
349
|
|
|
if ( $incorrect_refs ) { |
350
|
|
|
throw new CommandException( |
351
|
|
|
'The following refs are unknown: "' . implode('", "', $incorrect_refs) . '".' |
352
|
|
|
); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
return $this->_revisionLog->find('refs', $refs); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
return $this->_revisionLog->find('paths', $relative_path); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* Returns displayed revision limit. |
363
|
|
|
* |
364
|
|
|
* @return integer |
365
|
|
|
*/ |
366
|
|
|
protected function getMaxCount() |
367
|
|
|
{ |
368
|
|
|
$max_count = $this->io->getOption('max-count'); |
369
|
|
|
|
370
|
|
|
if ( $max_count !== null ) { |
371
|
|
|
return $max_count; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
return $this->getSetting(self::SETTING_LOG_LIMIT); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* Prints revisions. |
379
|
|
|
* |
380
|
|
|
* @param array $revisions Revisions. |
381
|
|
|
* @param boolean $with_details Print extended revision details (e.g. paths changed). |
382
|
|
|
* |
383
|
|
|
* @return void |
384
|
|
|
*/ |
385
|
|
|
protected function printRevisions(array $revisions, $with_details = false) |
386
|
|
|
{ |
387
|
|
|
$table = new Table($this->io->getOutput()); |
388
|
|
|
$headers = array('Revision', 'Author', 'Date', 'Bug-ID', 'Log Message'); |
389
|
|
|
|
390
|
|
|
// Add "Summary" header. |
391
|
|
|
$with_summary = $this->io->getOption('with-summary'); |
392
|
|
|
|
393
|
|
|
if ( $with_summary ) { |
394
|
|
|
$headers[] = 'Summary'; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
// Add "Refs" header. |
398
|
|
|
$with_refs = $this->io->getOption('with-refs'); |
399
|
|
|
|
400
|
|
|
if ( $with_refs ) { |
401
|
|
|
$headers[] = 'Refs'; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
$with_merge_oracle = $this->io->getOption('with-merge-oracle'); |
405
|
|
|
|
406
|
|
|
// Add "M.O." header. |
407
|
|
|
if ( $with_merge_oracle ) { |
408
|
|
|
$headers[] = 'M.O.'; |
409
|
|
|
$merge_conflict_regexps = $this->getMergeConflictRegExps(); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
// Add "Merged Via" header. |
413
|
|
|
$with_merge_status = $this->io->getOption('with-merge-status'); |
414
|
|
|
|
415
|
|
|
if ( $with_merge_status ) { |
416
|
|
|
$headers[] = 'Merged Via'; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
$table->setHeaders($headers); |
420
|
|
|
|
421
|
|
|
/** @var DateHelper $date_helper */ |
422
|
|
|
$date_helper = $this->getHelper('date'); |
423
|
|
|
|
424
|
|
|
$prev_bugs = null; |
425
|
|
|
$last_color = 'yellow'; |
426
|
|
|
$last_revision = end($revisions); |
427
|
|
|
|
428
|
|
|
$repository_path = $this->repositoryConnector->getRelativePath( |
429
|
|
|
$this->getWorkingCopyPath() |
430
|
|
|
) . '/'; |
431
|
|
|
|
432
|
|
|
$log_message_limit = $this->getSetting(self::SETTING_LOG_MESSAGE_LIMIT); |
433
|
|
|
$bugs_per_row = $with_details ? 1 : 3; |
434
|
|
|
|
435
|
|
|
foreach ( $revisions as $revision ) { |
436
|
|
|
$revision_data = $this->_revisionLog->getRevisionData('summary', $revision); |
437
|
|
|
|
438
|
|
|
if ( $with_details ) { |
439
|
|
|
// When details requested don't transform commit message except for word wrapping. |
440
|
|
|
$log_message = wordwrap($revision_data['msg'], $log_message_limit); // FIXME: Not UTF-8 safe solution. |
441
|
|
|
} |
442
|
|
|
else { |
443
|
|
|
// When details not requested only operate on first line of commit message. |
444
|
|
|
list($log_message,) = explode(PHP_EOL, $revision_data['msg']); |
445
|
|
|
$log_message = preg_replace('/^\[fixes:.*?\]/s', "\xE2\x9C\x94", $log_message); |
446
|
|
|
|
447
|
|
|
if ( strpos($revision_data['msg'], PHP_EOL) !== false |
448
|
|
|
|| mb_strlen($log_message) > $log_message_limit |
449
|
|
|
) { |
450
|
|
|
$log_message = mb_substr($log_message, 0, $log_message_limit - 3) . '...'; |
451
|
|
|
} |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
$new_bugs = $this->_revisionLog->getRevisionData('bugs', $revision); |
455
|
|
|
|
456
|
|
|
if ( isset($prev_bugs) && $new_bugs !== $prev_bugs ) { |
457
|
|
|
$last_color = $last_color == 'yellow' ? 'magenta' : 'yellow'; |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
$row = array( |
461
|
|
|
$revision, |
462
|
|
|
$revision_data['author'], |
463
|
|
|
$date_helper->getAgoTime($revision_data['date']), |
464
|
|
|
$this->formatArray($new_bugs, $bugs_per_row, $last_color), |
465
|
|
|
$log_message, |
466
|
|
|
); |
467
|
|
|
|
468
|
|
|
$revision_paths = $this->_revisionLog->getRevisionData('paths', $revision); |
469
|
|
|
|
470
|
|
|
// Add "Summary" column. |
471
|
|
|
if ( $with_summary ) { |
472
|
|
|
$row[] = $this->generateChangeSummary($revision_paths); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
// Add "Refs" column. |
476
|
|
|
if ( $with_refs ) { |
477
|
|
|
$row[] = $this->formatArray( |
478
|
|
|
$this->_revisionLog->getRevisionData('refs', $revision), |
479
|
|
|
1 |
480
|
|
|
); |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
// Add "M.O." column. |
484
|
|
|
if ( $with_merge_oracle ) { |
485
|
|
|
$merge_conflict_predication = $this->getMergeConflictPrediction( |
486
|
|
|
$revision_paths, |
487
|
|
|
$merge_conflict_regexps |
|
|
|
|
488
|
|
|
); |
489
|
|
|
$row[] = $merge_conflict_predication ? '<error>' . count($merge_conflict_predication) . '</error>' : ''; |
490
|
|
|
} |
491
|
|
|
else { |
492
|
|
|
$merge_conflict_predication = array(); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
// Add "Merged Via" column. |
496
|
|
|
if ( $with_merge_status ) { |
497
|
|
|
$merged_via = $this->_revisionLog->getRevisionData('merges', $revision); |
498
|
|
|
$row[] = $merged_via ? implode(', ', $merged_via) : ''; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
$table->addRow($row); |
502
|
|
|
|
503
|
|
|
if ( $with_details ) { |
504
|
|
|
$details = '<fg=white;options=bold>Changed Paths:</>'; |
505
|
|
|
|
506
|
|
|
foreach ( $revision_paths as $path_data ) { |
507
|
|
|
$path_action = $path_data['action']; |
508
|
|
|
$relative_path = $this->_getRelativeLogPath($path_data, 'path', $repository_path); |
509
|
|
|
|
510
|
|
|
$details .= PHP_EOL . ' * '; |
511
|
|
|
|
512
|
|
|
if ( $path_action == 'A' ) { |
513
|
|
|
$color_format = 'fg=green'; |
514
|
|
|
} |
515
|
|
|
elseif ( $path_action == 'D' ) { |
516
|
|
|
$color_format = 'fg=red'; |
517
|
|
|
} |
518
|
|
|
else { |
519
|
|
|
$color_format = in_array($path_data['path'], $merge_conflict_predication) ? 'error' : ''; |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
$to_colorize = array($path_action . ' ' . $relative_path); |
523
|
|
|
|
524
|
|
|
if ( isset($path_data['copyfrom-path']) ) { |
525
|
|
|
// TODO: When copy happened from different ref/project, then relative path = absolute path. |
526
|
|
|
$copy_from_rev = $path_data['copyfrom-rev']; |
527
|
|
|
$copy_from_path = $this->_getRelativeLogPath($path_data, 'copyfrom-path', $repository_path); |
528
|
|
|
$to_colorize[] = ' (from ' . $copy_from_path . ':' . $copy_from_rev . ')'; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
if ( $color_format ) { |
532
|
|
|
$details .= '<' . $color_format . '>'; |
533
|
|
|
$details .= implode('</>' . PHP_EOL . '<' . $color_format . '>', $to_colorize); |
534
|
|
|
$details .= '</>'; |
535
|
|
|
} |
536
|
|
|
else { |
537
|
|
|
$details .= implode(PHP_EOL, $to_colorize); |
538
|
|
|
} |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
$table->addRow(new TableSeparator()); |
542
|
|
|
$table->addRow(array(new TableCell($details, array('colspan' => 5)))); |
543
|
|
|
|
544
|
|
|
if ( $revision != $last_revision ) { |
545
|
|
|
$table->addRow(new TableSeparator()); |
546
|
|
|
} |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
$prev_bugs = $new_bugs; |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
$table->render(); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
/** |
556
|
|
|
* Returns formatted list of records. |
557
|
|
|
* |
558
|
|
|
* @param array $items List of items. |
559
|
|
|
* @param integer $items_per_row Number of bugs displayed per row. |
560
|
|
|
* @param string|null $color Color. |
561
|
|
|
* |
562
|
|
|
* @return string |
563
|
|
|
*/ |
564
|
|
|
protected function formatArray(array $items, $items_per_row, $color = null) |
565
|
|
|
{ |
566
|
|
|
$bug_chunks = array_chunk($items, $items_per_row); |
567
|
|
|
|
568
|
|
|
$ret = array(); |
569
|
|
|
|
570
|
|
|
if ( isset($color) ) { |
571
|
|
|
foreach ( $bug_chunks as $bug_chunk ) { |
572
|
|
|
$ret[] = '<fg=' . $color . '>' . implode('</>, <fg=' . $color . '>', $bug_chunk) . '</>'; |
573
|
|
|
} |
574
|
|
|
} |
575
|
|
|
else { |
576
|
|
|
foreach ( $bug_chunks as $bug_chunk ) { |
577
|
|
|
$ret[] = implode(', ', $bug_chunk); |
578
|
|
|
} |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
return implode(',' . PHP_EOL, $ret); |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* Generates change summary for a revision. |
586
|
|
|
* |
587
|
|
|
* @param array $revision_paths Revision paths. |
588
|
|
|
* |
589
|
|
|
* @return string |
590
|
|
|
*/ |
591
|
|
|
protected function generateChangeSummary(array $revision_paths) |
592
|
|
|
{ |
593
|
|
|
$summary = array('added' => 0, 'changed' => 0, 'removed' => 0); |
594
|
|
|
|
595
|
|
|
foreach ( $revision_paths as $path_data ) { |
596
|
|
|
$path_action = $path_data['action']; |
597
|
|
|
|
598
|
|
|
if ( $path_action == 'A' ) { |
599
|
|
|
$summary['added']++; |
600
|
|
|
} |
601
|
|
|
elseif ( $path_action == 'D' ) { |
602
|
|
|
$summary['removed']++; |
603
|
|
|
} |
604
|
|
|
else { |
605
|
|
|
$summary['changed']++; |
606
|
|
|
} |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
if ( $summary['added'] ) { |
610
|
|
|
$summary['added'] = '<fg=green>+' . $summary['added'] . '</>'; |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
if ( $summary['removed'] ) { |
614
|
|
|
$summary['removed'] = '<fg=red>-' . $summary['removed'] . '</>'; |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
return implode(' ', array_filter($summary)); |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
/** |
621
|
|
|
* Returns merge conflict path predictions. |
622
|
|
|
* |
623
|
|
|
* @param array $revision_paths Revision paths. |
624
|
|
|
* @param array $merge_conflict_regexps Merge conflict paths. |
625
|
|
|
* |
626
|
|
|
* @return array |
627
|
|
|
*/ |
628
|
|
|
protected function getMergeConflictPrediction(array $revision_paths, array $merge_conflict_regexps) |
629
|
|
|
{ |
630
|
|
|
if ( !$merge_conflict_regexps ) { |
631
|
|
|
return array(); |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
$conflict_paths = array(); |
635
|
|
|
|
636
|
|
|
foreach ( $revision_paths as $revision_path ) { |
637
|
|
|
foreach ( $merge_conflict_regexps as $merge_conflict_regexp ) { |
638
|
|
|
if ( preg_match($merge_conflict_regexp, $revision_path['path']) ) { |
639
|
|
|
$conflict_paths[] = $revision_path['path']; |
640
|
|
|
} |
641
|
|
|
} |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
return $conflict_paths; |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
/** |
648
|
|
|
* Returns merge conflict regexps. |
649
|
|
|
* |
650
|
|
|
* @return array |
651
|
|
|
*/ |
652
|
|
|
protected function getMergeConflictRegExps() |
653
|
|
|
{ |
654
|
|
|
return $this->getSetting(self::SETTING_LOG_MERGE_CONFLICT_REGEXPS); |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
/** |
658
|
|
|
* Returns relative path to "svn log" returned path. |
659
|
|
|
* |
660
|
|
|
* @param array $path_data Path data. |
661
|
|
|
* @param string $path_key Path key. |
662
|
|
|
* @param string $repository_path Repository path. |
663
|
|
|
* |
664
|
|
|
* @return string |
665
|
|
|
*/ |
666
|
|
|
private function _getRelativeLogPath(array $path_data, $path_key, $repository_path) |
667
|
|
|
{ |
668
|
|
|
$ret = $path_data[$path_key]; |
669
|
|
|
|
670
|
|
|
if ( $path_data['kind'] == 'dir' ) { |
671
|
|
|
$ret .= '/'; |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
$ret = preg_replace('/^' . preg_quote($repository_path, '/') . '/', '', $ret, 1); |
675
|
|
|
|
676
|
|
|
if ( $ret === '' ) { |
677
|
|
|
$ret = '.'; |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
return $ret; |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* Returns URL to the working copy. |
685
|
|
|
* |
686
|
|
|
* @return string |
687
|
|
|
*/ |
688
|
|
|
protected function getWorkingCopyUrl() |
689
|
|
|
{ |
690
|
|
|
$wc_path = $this->getWorkingCopyPath(); |
691
|
|
|
|
692
|
|
|
if ( !$this->repositoryConnector->isUrl($wc_path) ) { |
693
|
|
|
return $this->repositoryConnector->getWorkingCopyUrl($wc_path); |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
return $wc_path; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
/** |
700
|
|
|
* Returns list of config settings. |
701
|
|
|
* |
702
|
|
|
* @return AbstractConfigSetting[] |
703
|
|
|
*/ |
704
|
|
|
public function getConfigSettings() |
705
|
|
|
{ |
706
|
|
|
return array( |
707
|
|
|
new IntegerConfigSetting(self::SETTING_LOG_LIMIT, 10), |
708
|
|
|
new IntegerConfigSetting(self::SETTING_LOG_MESSAGE_LIMIT, 68), |
709
|
|
|
new RegExpsConfigSetting(self::SETTING_LOG_MERGE_CONFLICT_REGEXPS, '#/composer\.lock$#'), |
710
|
|
|
); |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
} |
714
|
|
|
|