Failed Conditions
Push — master ( 598f4b...15edf4 )
by Alexander
04:31
created

LogCommand::printRevisions()   F

Complexity

Conditions 27
Paths > 20000

Size

Total Lines 183
Code Lines 102

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 756

Importance

Changes 16
Bugs 1 Features 5
Metric Value
c 16
b 1
f 5
dl 0
loc 183
ccs 0
cts 121
cp 0
rs 2
cc 27
eloc 102
nc 41536
nop 2
crap 756

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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}
0 ignored issues
show
introduced by
Doc comment short description must start with a capital letter
Loading history...
69
	 */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
70
	protected function configure()
71
	{
72
		$this->pathAcceptsUrl = true;
73
74
		$this
75
			->setName('log')
76
			->setDescription(
77
				'Show the log messages for a set of revisions, bugs, paths, refs, etc.'
78
			)
79
			->addArgument(
80
				'path',
81
				InputArgument::OPTIONAL,
82
				'Working copy path or URL',
83
				'.'
84
			)
85
			->addOption(
86
				'revisions',
87
				'r',
88
				InputOption::VALUE_REQUIRED,
89
				'List of revision(-s) and/or revision range(-s), e.g. <comment>53324</comment>, <comment>1224-4433</comment>'
90
			)
91
			->addOption(
92
				'bugs',
93
				'b',
94
				InputOption::VALUE_REQUIRED,
95
				'List of bug(-s), e.g. <comment>JRA-1234</comment>, <comment>43644</comment>'
96
			)
97
			->addOption(
98
				'refs',
99
				null,
100
				InputOption::VALUE_REQUIRED,
101
				'List of refs, e.g. <comment>trunk</comment>, <comment>branches/branch-name</comment>, <comment>tags/tag-name</comment>'
102
			)
103
			->addOption(
104
				'merges',
105
				null,
106
				InputOption::VALUE_NONE,
107
				'Show merge revisions only'
108
			)
109
			->addOption(
110
				'no-merges',
111
				null,
112
				InputOption::VALUE_NONE,
113
				'Hide merge revisions'
114
			)
115
			->addOption(
116
				'merged',
117
				null,
118
				InputOption::VALUE_NONE,
119
				'Shows only revisions, that were merged at least once'
120
			)
121
			->addOption(
122
				'not-merged',
123
				null,
124
				InputOption::VALUE_NONE,
125
				'Shows only revisions, that were not merged'
126
			)
127
			->addOption(
128
				'merged-by',
129
				null,
130
				InputOption::VALUE_REQUIRED,
131
				'Show revisions merged by list of revision(-s) and/or revision range(-s)'
132
			)
133
			->addOption(
134
				'with-details',
135
				'd',
136
				InputOption::VALUE_NONE,
137
				'Shows detailed revision information, e.g. paths affected'
138
			)
139
			->addOption(
140
				'with-summary',
141
				's',
142
				InputOption::VALUE_NONE,
143
				'Shows number of added/changed/removed paths in the revision'
144
			)
145
			->addOption(
146
				'with-refs',
147
				null,
148
				InputOption::VALUE_NONE,
149
				'Shows revision refs'
150
			)
151
			->addOption(
152
				'with-merge-oracle',
153
				null,
154
				InputOption::VALUE_NONE,
155
				'Shows number of paths in the revision, that can cause conflict upon merging'
156
			)
157
			->addOption(
158
				'with-merge-status',
159
				null,
160
				InputOption::VALUE_NONE,
161
				'Shows merge revisions affecting this revision'
162
			)
163
			->addOption(
164
				'max-count',
165
				null,
166
				InputOption::VALUE_REQUIRED,
167
				'Limit the number of revisions to output'
168
			);
169
170
		parent::configure();
171
	}
172
173
	/**
174
	 * Return possible values for the named option
175
	 *
176
	 * @param string            $optionName Option name.
177
	 * @param CompletionContext $context    Completion context.
178
	 *
179
	 * @return array
180
	 */
181
	public function completeOptionValues($optionName, CompletionContext $context)
182
	{
183
		$ret = parent::completeOptionValues($optionName, $context);
184
185
		if ( $optionName === 'refs' ) {
186
			return $this->getAllRefs();
187
		}
188
189
		return $ret;
190
	}
191
192
	/**
193
	 * {@inheritdoc}
194
	 */
195
	public function initialize(InputInterface $input, OutputInterface $output)
196
	{
197
		parent::initialize($input, $output);
198
199
		$this->_revisionLog = $this->getRevisionLog($this->getWorkingCopyUrl());
200
	}
201
202
	/**
0 ignored issues
show
introduced by
Doc comment for parameter "$input" missing
Loading history...
introduced by
Doc comment for parameter "$output" missing
Loading history...
203
	 * {@inheritdoc}
204
	 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @throws tag in function comment
Loading history...
205
	protected function execute(InputInterface $input, OutputInterface $output)
206
	{
207
		$bugs = $this->getList($this->io->getOption('bugs'));
208
		$revisions = $this->getList($this->io->getOption('revisions'));
209
210
		if ( $bugs && $revisions ) {
211
			throw new \RuntimeException('The "--bugs" and "--revisions" options are mutually exclusive.');
212
		}
213
214
		$missing_revisions = array();
215
		$revisions_by_path = $this->getRevisionsByPath();
216
217
		if ( $revisions ) {
218
			$revisions = $this->_revisionListParser->expandRanges($revisions);
219
			$revisions_by_path = array_intersect($revisions_by_path, $revisions);
220
			$missing_revisions = array_diff($revisions, $revisions_by_path);
221
		}
222
		elseif ( $bugs ) {
223
			// Only show bug-related revisions on given path. The $missing_revisions is always empty.
224
			$revisions_from_bugs = $this->_revisionLog->find('bugs', $bugs);
225
			$revisions_by_path = array_intersect($revisions_by_path, $revisions_from_bugs);
226
		}
227
228
		$merged_by = $this->getList($this->io->getOption('merged-by'));
229
230
		if ( $merged_by ) {
231
			$merged_by = $this->_revisionListParser->expandRanges($merged_by);
232
			$revisions_by_path = $this->_revisionLog->find('merges', $merged_by);
233
		}
234
235
		if ( $this->io->getOption('merges') ) {
236
			$revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges'));
237
		}
238
		elseif ( $this->io->getOption('no-merges') ) {
239
			$revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merges'));
240
		}
241
242
		if ( $this->io->getOption('merged') ) {
243
			$revisions_by_path = array_intersect($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged'));
244
		}
245
		elseif ( $this->io->getOption('not-merged') ) {
246
			$revisions_by_path = array_diff($revisions_by_path, $this->_revisionLog->find('merges', 'all_merged'));
247
		}
248
249
		if ( $missing_revisions ) {
250
			throw new CommandException($this->getMissingRevisionsErrorMessage($missing_revisions));
251
		}
252
		elseif ( !$revisions_by_path ) {
253
			throw new CommandException('No matching revisions found.');
254
		}
255
256
		rsort($revisions_by_path, SORT_NUMERIC);
257
258
		if ( $bugs || $revisions ) {
259
			// Don't limit revisions, when provided explicitly by user.
260
			$revisions_by_path_with_limit = $revisions_by_path;
261
		}
262
		else {
263
			// Apply limit only, when no explicit bugs/revisions are set.
264
			$revisions_by_path_with_limit = array_slice($revisions_by_path, 0, $this->getMaxCount());
265
		}
266
267
		$revisions_by_path_count = count($revisions_by_path);
268
		$revisions_by_path_with_limit_count = count($revisions_by_path_with_limit);
269
270
		if ( $revisions_by_path_with_limit_count === $revisions_by_path_count ) {
271
			$this->io->writeln(sprintf(
272
				' * Showing <info>%d</info> revision(-s) in %s:',
273
				$revisions_by_path_with_limit_count,
274
				$this->getRevisionLogIdentifier()
275
			));
276
		}
277
		else {
278
			$this->io->writeln(sprintf(
279
				' * Showing <info>%d</info> of <info>%d</info> revision(-s) in %s:',
280
				$revisions_by_path_with_limit_count,
281
				$revisions_by_path_count,
282
				$this->getRevisionLogIdentifier()
283
			));
284
		}
285
286
		$this->printRevisions($revisions_by_path_with_limit, (boolean)$this->io->getOption('with-details'));
287
	}
288
289
	/**
290
	 * Returns revision log identifier.
291
	 *
292
	 * @return string
293
	 */
294
	protected function getRevisionLogIdentifier()
295
	{
296
		$ret = '<info>' . $this->_revisionLog->getProjectPath() . '</info> project';
297
298
		$ref_name = $this->_revisionLog->getRefName();
299
300
		if ( $ref_name ) {
301
			$ret .= ' (ref: <info>' . $ref_name . '</info>)';
302
		}
303
		else {
304
			$ret .= ' (all refs)';
305
		}
306
307
		return $ret;
308
	}
309
310
	/**
311
	 * Shows error about missing revisions.
312
	 *
313
	 * @param array $missing_revisions Missing revisions.
314
	 *
315
	 * @return string
316
	 */
317
	protected function getMissingRevisionsErrorMessage(array $missing_revisions)
318
	{
319
		$refs = $this->io->getOption('refs');
320
		$missing_revisions = implode(', ', $missing_revisions);
321
322
		if ( $refs ) {
323
			$revision_source = 'in "' . $refs . '" ref(-s)';
324
		}
325
		else {
326
			$revision_source = 'at "' . $this->getWorkingCopyUrl() . '" url';
327
		}
328
329
		return 'The ' . $missing_revisions . ' revision(-s) not found ' . $revision_source . '.';
330
	}
331
332
	/**
333
	 * Returns list of revisions by path.
334
	 *
335
	 * @return array
336
	 * @throws CommandException When given refs doesn't exist.
337
	 */
338
	protected function getRevisionsByPath()
339
	{
340
		$refs = $this->getList($this->io->getOption('refs'));
341
		$relative_path = $this->repositoryConnector->getRelativePath($this->getWorkingCopyPath()) . '/';
342
343
		if ( !$refs ) {
344
			$ref = $this->repositoryConnector->getRefByPath($relative_path);
345
346
			// Use search by ref, when working copy represents ref root folder.
347
			if ( $ref !== false && preg_match('#' . preg_quote($ref, '#') . '/$#', $relative_path) ) {
348
				return $this->_revisionLog->find('refs', $ref);
349
			}
350
		}
351
352
		if ( $refs ) {
353
			$incorrect_refs = array_diff($refs, $this->getAllRefs());
354
355
			if ( $incorrect_refs ) {
356
				throw new CommandException(
357
					'The following refs are unknown: "' . implode('", "', $incorrect_refs) . '".'
358
				);
359
			}
360
361
			return $this->_revisionLog->find('refs', $refs);
362
		}
363
364
		return $this->_revisionLog->find('paths', $relative_path);
365
	}
366
367
	/**
368
	 * Returns displayed revision limit.
369
	 *
370
	 * @return integer
371
	 */
372
	protected function getMaxCount()
373
	{
374
		$max_count = $this->io->getOption('max-count');
375
376
		if ( $max_count !== null ) {
377
			return $max_count;
378
		}
379
380
		return $this->getSetting(self::SETTING_LOG_LIMIT);
381
	}
382
383
	/**
384
	 * Prints revisions.
385
	 *
386
	 * @param array   $revisions    Revisions.
387
	 * @param boolean $with_details Print extended revision details (e.g. paths changed).
388
	 *
389
	 * @return void
390
	 */
391
	protected function printRevisions(array $revisions, $with_details = false)
392
	{
393
		$table = new Table($this->io->getOutput());
394
		$headers = array('Revision', 'Author', 'Date', 'Bug-ID', 'Log Message');
395
396
		// Add "Summary" header.
397
		$with_summary = $this->io->getOption('with-summary');
398
399
		if ( $with_summary ) {
400
			$headers[] = 'Summary';
401
		}
402
403
		// Add "Refs" header.
404
		$with_refs = $this->io->getOption('with-refs');
405
406
		if ( $with_refs ) {
407
			$headers[] = 'Refs';
408
		}
409
410
		$with_merge_oracle = $this->io->getOption('with-merge-oracle');
411
412
		// Add "M.O." header.
413
		if ( $with_merge_oracle ) {
414
			$headers[] = 'M.O.';
415
			$merge_conflict_regexps = $this->getMergeConflictRegExps();
416
		}
417
418
		// Add "Merged Via" header.
419
		$with_merge_status = $this->io->getOption('with-merge-status');
420
421
		if ( $with_merge_status ) {
422
			$headers[] = 'Merged Via';
423
		}
424
425
		$table->setHeaders($headers);
426
427
		/** @var DateHelper $date_helper */
428
		$date_helper = $this->getHelper('date');
429
430
		$prev_bugs = null;
431
		$last_color = 'yellow';
432
		$last_revision = end($revisions);
433
434
		$relative_wc_path = $this->repositoryConnector->getRelativePath(
435
			$this->getWorkingCopyPath()
436
		) . '/';
437
		$project_path = $this->repositoryConnector->getProjectUrl($relative_wc_path) . '/';
438
439
		$log_message_limit = $this->getSetting(self::SETTING_LOG_MESSAGE_LIMIT);
440
		$bugs_per_row = $with_details ? 1 : 3;
441
442
		$revisions_data = $this->_revisionLog->getRevisionsData('summary', $revisions);
443
		$revisions_paths = $this->_revisionLog->getRevisionsData('paths', $revisions);
444
		$revisions_bugs = $this->_revisionLog->getRevisionsData('bugs', $revisions);
445
		$revisions_refs = $this->_revisionLog->getRevisionsData('refs', $revisions);
446
447
		if ( $with_merge_status ) {
448
			$revisions_merged_via = $this->_revisionLog->getRevisionsData('merges', $revisions);
449
			$revisions_merged_via_refs = $this->_revisionLog->getRevisionsData(
450
				'refs',
451
				call_user_func_array('array_merge', $revisions_merged_via)
452
			);
453
		}
454
455
		foreach ( $revisions as $revision ) {
456
			$revision_data = $revisions_data[$revision];
457
458
			if ( $with_details ) {
459
				// When details requested don't transform commit message except for word wrapping.
460
				$log_message = wordwrap($revision_data['msg'], $log_message_limit); // FIXME: Not UTF-8 safe solution.
461
			}
462
			else {
463
				// When details not requested only operate on first line of commit message.
464
				list($log_message,) = explode(PHP_EOL, $revision_data['msg']);
465
				$log_message = preg_replace('/^\[fixes:.*?\]/s', "\xE2\x9C\x94", $log_message);
466
467
				if ( strpos($revision_data['msg'], PHP_EOL) !== false
468
					|| mb_strlen($log_message) > $log_message_limit
469
				) {
470
					$log_message = mb_substr($log_message, 0, $log_message_limit - 3) . '...';
471
				}
472
			}
473
474
			$new_bugs = $revisions_bugs[$revision];
475
476
			if ( isset($prev_bugs) && $new_bugs !== $prev_bugs ) {
477
				$last_color = $last_color == 'yellow' ? 'magenta' : 'yellow';
478
			}
479
480
			$row = array(
481
				$revision,
482
				$revision_data['author'],
483
				$date_helper->getAgoTime($revision_data['date']),
484
				$this->formatArray($new_bugs, $bugs_per_row, $last_color),
485
				$log_message,
486
			);
487
488
			$revision_paths = $revisions_paths[$revision];
489
490
			// Add "Summary" column.
491
			if ( $with_summary ) {
492
				$row[] = $this->generateChangeSummary($revision_paths);
493
			}
494
495
			// Add "Refs" column.
496
			if ( $with_refs ) {
497
				$row[] = $this->formatArray(
498
					$revisions_refs[$revision],
499
					1
500
				);
501
			}
502
503
			// Add "M.O." column.
504
			if ( $with_merge_oracle ) {
505
				$merge_conflict_predication = $this->getMergeConflictPrediction(
506
					$revision_paths,
507
					$merge_conflict_regexps
0 ignored issues
show
Bug introduced by
The variable $merge_conflict_regexps does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
508
				);
509
				$row[] = $merge_conflict_predication ? '<error>' . count($merge_conflict_predication) . '</error>' : '';
510
			}
511
			else {
512
				$merge_conflict_predication = array();
513
			}
514
515
			// Add "Merged Via" column.
516
			if ( $with_merge_status ) {
517
				$row[] = $this->generateMergedVia($revisions_merged_via[$revision], $revisions_merged_via_refs);
518
			}
519
520
			$table->addRow($row);
521
522
			if ( $with_details ) {
523
				$details = '<fg=white;options=bold>Changed Paths:</>';
524
				$path_cut_off_regexp = $this->getPathCutOffRegExp($project_path, $revisions_refs[$revision]);
525
526
				foreach ( $revision_paths as $path_data ) {
527
					$path_action = $path_data['action'];
528
					$relative_path = $this->_getRelativeLogPath($path_data, 'path', $path_cut_off_regexp);
529
530
					$details .= PHP_EOL . ' * ';
531
532
					if ( $path_action == 'A' ) {
533
						$color_format = 'fg=green';
534
					}
535
					elseif ( $path_action == 'D' ) {
536
						$color_format = 'fg=red';
537
					}
538
					else {
539
						$color_format = in_array($path_data['path'], $merge_conflict_predication) ? 'error' : '';
540
					}
541
542
					$to_colorize = array($path_action . '    ' . $relative_path);
543
544
					if ( isset($path_data['copyfrom-path']) ) {
545
						// TODO: When copy happened from different ref/project, then relative path = absolute path.
546
						$copy_from_rev = $path_data['copyfrom-rev'];
547
						$copy_from_path = $this->_getRelativeLogPath($path_data, 'copyfrom-path', $path_cut_off_regexp);
548
						$to_colorize[] = '        (from ' . $copy_from_path . ':' . $copy_from_rev . ')';
549
					}
550
551
					if ( $color_format ) {
552
						$details .= '<' . $color_format . '>';
553
						$details .= implode('</>' . PHP_EOL . '<' . $color_format . '>', $to_colorize);
554
						$details .= '</>';
555
					}
556
					else {
557
						$details .= implode(PHP_EOL, $to_colorize);
558
					}
559
				}
560
561
				$table->addRow(new TableSeparator());
562
				$table->addRow(array(new TableCell($details, array('colspan' => 5))));
563
564
				if ( $revision != $last_revision ) {
565
					$table->addRow(new TableSeparator());
566
				}
567
			}
568
569
			$prev_bugs = $new_bugs;
570
		}
571
572
		$table->render();
573
	}
574
575
	/**
576
	 * Generates change summary for a revision.
577
	 *
578
	 * @param array $revision_paths Revision paths.
579
	 *
580
	 * @return string
581
	 */
582
	protected function generateChangeSummary(array $revision_paths)
583
	{
584
		$summary = array('added' => 0, 'changed' => 0, 'removed' => 0);
585
586
		foreach ( $revision_paths as $path_data ) {
587
			$path_action = $path_data['action'];
588
589
			if ( $path_action == 'A' ) {
590
				$summary['added']++;
591
			}
592
			elseif ( $path_action == 'D' ) {
593
				$summary['removed']++;
594
			}
595
			else {
596
				$summary['changed']++;
597
			}
598
		}
599
600
		if ( $summary['added'] ) {
601
			$summary['added'] = '<fg=green>+' . $summary['added'] . '</>';
602
		}
603
604
		if ( $summary['removed'] ) {
605
			$summary['removed'] = '<fg=red>-' . $summary['removed'] . '</>';
606
		}
607
608
		return implode(' ', array_filter($summary));
609
	}
610
611
	/**
612
	 * Generates content for "Merged Via" cell content.
613
	 *
614
	 * @param array $merged_via                Merged Via.
615
	 * @param array $revisions_merged_via_refs Merged Via Refs.
616
	 *
617
	 * @return string
618
	 */
619
	protected function generateMergedVia(array $merged_via, array $revisions_merged_via_refs)
620
	{
621
		if ( !$merged_via ) {
622
			return '';
623
		}
624
625
		$merged_via_enhanced = array();
626
627
		foreach ( $merged_via as $merged_via_revision ) {
628
			$merged_via_revision_refs = $revisions_merged_via_refs[$merged_via_revision];
629
630
			if ( $merged_via_revision_refs ) {
631
				$merged_via_enhanced[] = $merged_via_revision . ' (' . implode(',', $merged_via_revision_refs) . ')';
632
			}
633
			else {
634
				$merged_via_enhanced[] = $merged_via_revision;
635
			}
636
		}
637
638
		return $this->formatArray($merged_via_enhanced, 1);
639
	}
640
641
	/**
642
	 * Returns merge conflict path predictions.
643
	 *
644
	 * @param array $revision_paths         Revision paths.
645
	 * @param array $merge_conflict_regexps Merge conflict paths.
646
	 *
647
	 * @return array
648
	 */
649
	protected function getMergeConflictPrediction(array $revision_paths, array $merge_conflict_regexps)
650
	{
651
		if ( !$merge_conflict_regexps ) {
652
			return array();
653
		}
654
655
		$conflict_paths = array();
656
657
		foreach ( $revision_paths as $revision_path ) {
658
			foreach ( $merge_conflict_regexps as $merge_conflict_regexp ) {
659
				if ( preg_match($merge_conflict_regexp, $revision_path['path']) ) {
660
					$conflict_paths[] = $revision_path['path'];
661
				}
662
			}
663
		}
664
665
		return $conflict_paths;
666
	}
667
668
	/**
669
	 * Returns merge conflict regexps.
670
	 *
671
	 * @return array
672
	 */
673
	protected function getMergeConflictRegExps()
674
	{
675
		return $this->getSetting(self::SETTING_LOG_MERGE_CONFLICT_REGEXPS);
676
	}
677
678
	/**
679
	 * Returns relative path to "svn log" returned path.
680
	 *
681
	 * @param array  $path_data           Path data.
682
	 * @param string $path_key            Path key.
683
	 * @param string $path_cut_off_regexp Path cut off regexp.
684
	 *
685
	 * @return string
686
	 */
687
	private function _getRelativeLogPath(array $path_data, $path_key, $path_cut_off_regexp)
688
	{
689
		$ret = preg_replace($path_cut_off_regexp, '', $path_data[$path_key], 1);
690
691
		if ( $ret === '' ) {
692
			$ret = '.';
693
		}
694
695
		return $ret;
696
	}
697
698
	/**
699
	 * Returns path cut off regexp.
700
	 *
701
	 * @param string $project_path Project path.
702
	 * @param array  $refs         Refs.
703
	 *
704
	 * @return string
705
	 */
706
	protected function getPathCutOffRegExp($project_path, array $refs)
707
	{
708
		$ret = array();
709
710
		// Remove ref from path only for single-ref revision.
711
		if ( count($refs) === 1 ) {
712
			$ret[] = $project_path . reset($refs) . '/';
713
		}
714
715
		// Always remove project path.
716
		$ret[] = $project_path;
717
718
		return '#^(' . implode('|', array_map('preg_quote', $ret)) . ')#';
719
	}
720
721
	/**
722
	 * Returns list of config settings.
723
	 *
724
	 * @return AbstractConfigSetting[]
725
	 */
726
	public function getConfigSettings()
727
	{
728
		return array(
729
			new IntegerConfigSetting(self::SETTING_LOG_LIMIT, 10),
730
			new IntegerConfigSetting(self::SETTING_LOG_MESSAGE_LIMIT, 68),
731
			new RegExpsConfigSetting(self::SETTING_LOG_MERGE_CONFLICT_REGEXPS, '#/composer\.lock$#'),
732
		);
733
	}
734
735
}
736