|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the GitElephant package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Matteo Giachino <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @package GitElephant\Command |
|
12
|
|
|
* |
|
13
|
|
|
* Just for fun... |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace GitElephant\Command; |
|
17
|
|
|
|
|
18
|
|
|
use GitElephant\Objects\TreeishInterface; |
|
19
|
|
|
use GitElephant\Repository; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Log Range command generator |
|
23
|
|
|
* |
|
24
|
|
|
* @author Matteo Giachino <[email protected]> |
|
25
|
|
|
* @author John Cartwright <[email protected]> |
|
26
|
|
|
* @author Dhaval Patel <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class LogRangeCommand extends BaseCommand |
|
29
|
|
|
{ |
|
30
|
|
|
public const GIT_LOG = 'log'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* constructor |
|
34
|
|
|
* |
|
35
|
|
|
* @param \GitElephant\Repository $repo The repository object this command |
|
36
|
|
|
* will interact with |
|
37
|
|
|
*/ |
|
38
|
6 |
|
public function __construct(Repository $repo = null) |
|
39
|
|
|
{ |
|
40
|
6 |
|
parent::__construct($repo); |
|
41
|
6 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Build a generic log command |
|
45
|
|
|
* |
|
46
|
|
|
* @param \GitElephant\Objects\TreeishInterface|string $refStart the reference range start to build the log for |
|
47
|
|
|
* @param \GitElephant\Objects\TreeishInterface|string $refEnd the reference range end to build the log for |
|
48
|
|
|
* @param string|null $path the physical path to the tree relative |
|
49
|
|
|
* to the repository root |
|
50
|
|
|
* @param int|null $limit limit to n entries |
|
51
|
|
|
* @param int|null $offset skip n entries |
|
52
|
|
|
* @param boolean|false $firstParent skip commits brought in to branch by a merge |
|
53
|
|
|
* |
|
54
|
|
|
* @throws \RuntimeException |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
6 |
|
public function showLog( |
|
58
|
|
|
$refStart, |
|
59
|
|
|
$refEnd, |
|
60
|
|
|
$path = null, |
|
61
|
|
|
$limit = null, |
|
62
|
|
|
$offset = null, |
|
63
|
|
|
bool $firstParent = false |
|
64
|
|
|
): string { |
|
65
|
6 |
|
$this->clearAll(); |
|
66
|
|
|
|
|
67
|
6 |
|
$this->addCommandName(self::GIT_LOG); |
|
68
|
6 |
|
$this->addCommandArgument('-s'); |
|
69
|
6 |
|
$this->addCommandArgument('--pretty=raw'); |
|
70
|
6 |
|
$this->addCommandArgument('--no-color'); |
|
71
|
|
|
|
|
72
|
6 |
|
if (null !== $limit) { |
|
73
|
6 |
|
$limit = (int) $limit; |
|
74
|
6 |
|
$this->addCommandArgument('--max-count=' . $limit); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
6 |
|
if (null !== $offset) { |
|
78
|
6 |
|
$offset = (int) $offset; |
|
79
|
6 |
|
$this->addCommandArgument('--skip=' . $offset); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
6 |
|
if ($firstParent) { |
|
83
|
|
|
$this->addCommandArgument('--first-parent'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
6 |
|
if ($refStart instanceof TreeishInterface) { |
|
87
|
6 |
|
$refStart = $refStart->getSha(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
6 |
|
if ($refEnd instanceof TreeishInterface) { |
|
91
|
6 |
|
$refEnd = $refEnd->getSha(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
6 |
|
if (null !== $path && !empty($path)) { |
|
95
|
|
|
$this->addPath($path); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
6 |
|
$this->addCommandSubject($refStart . '..' . $refEnd); |
|
99
|
|
|
|
|
100
|
6 |
|
return $this->getCommand(); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|