|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* GitElephant - An abstraction layer for git written in PHP |
|
5
|
|
|
* Copyright (C) 2013 Matteo Giachino |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program. If not, see [http://www.gnu.org/licenses/]. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace GitElephant\Command; |
|
22
|
|
|
|
|
23
|
|
|
use GitElephant\Objects\Branch; |
|
24
|
|
|
use GitElephant\Objects\NodeObject; |
|
25
|
|
|
use GitElephant\Objects\TreeishInterface; |
|
26
|
|
|
use GitElephant\Repository; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Log command generator |
|
30
|
|
|
* |
|
31
|
|
|
* @author Matteo Giachino <[email protected]> |
|
32
|
|
|
* @author Dhaval Patel <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
|
|
class LogCommand extends BaseCommand |
|
35
|
|
|
{ |
|
36
|
|
|
public const GIT_LOG = 'log'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* constructor |
|
40
|
|
|
* |
|
41
|
|
|
* @param \GitElephant\Repository $repo The repository object this command |
|
42
|
|
|
* will interact with |
|
43
|
|
|
*/ |
|
44
|
20 |
|
public function __construct(Repository $repo = null) |
|
45
|
|
|
{ |
|
46
|
20 |
|
parent::__construct($repo); |
|
47
|
20 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Build an object log command |
|
51
|
|
|
* |
|
52
|
|
|
* @param \GitElephant\Objects\NodeObject $obj the Object to get the log for |
|
53
|
|
|
* @param \GitElephant\Objects\Branch|string|null $branch the branch to consider |
|
54
|
|
|
* @param int|null $limit limit to n entries |
|
55
|
|
|
* @param int|null $offset skip n entries |
|
56
|
|
|
* |
|
57
|
|
|
* @throws \RuntimeException |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
2 |
|
public function showObjectLog(NodeObject $obj, $branch = null, int $limit = null, int $offset = null): string |
|
61
|
|
|
{ |
|
62
|
2 |
|
$subject = null; |
|
63
|
2 |
|
if (null !== $branch) { |
|
64
|
1 |
|
if ($branch instanceof Branch) { |
|
65
|
1 |
|
$subject .= $branch->getName(); |
|
66
|
|
|
} else { |
|
67
|
|
|
$subject .= (string) $branch; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
2 |
|
return $this->showLog($subject, $obj->getFullPath(), $limit, $offset); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Build a generic log command |
|
76
|
|
|
* |
|
77
|
|
|
* @param \GitElephant\Objects\TreeishInterface|string $ref the reference to build the log for |
|
78
|
|
|
* @param string|null $path the physical path to the tree relative to the |
|
79
|
|
|
* repository root |
|
80
|
|
|
* @param int|null $limit limit to n entries |
|
81
|
|
|
* @param int|null $offset skip n entries |
|
82
|
|
|
* @param bool $firstParent skip commits brought in to branch by a merge |
|
83
|
|
|
* |
|
84
|
|
|
* @throws \RuntimeException |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
20 |
|
public function showLog($ref, $path = null, $limit = null, int $offset = null, bool $firstParent = false): string |
|
88
|
|
|
{ |
|
89
|
20 |
|
$this->clearAll(); |
|
90
|
|
|
|
|
91
|
20 |
|
$this->addCommandName(self::GIT_LOG); |
|
92
|
20 |
|
$this->addCommandArgument('-s'); |
|
93
|
20 |
|
$this->addCommandArgument('--pretty=raw'); |
|
94
|
20 |
|
$this->addCommandArgument('--no-color'); |
|
95
|
|
|
|
|
96
|
20 |
|
if (null !== $limit) { |
|
97
|
19 |
|
$limit = (int) $limit; |
|
98
|
19 |
|
$this->addCommandArgument('--max-count=' . $limit); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
20 |
|
if (null !== $offset) { |
|
102
|
1 |
|
$offset = (int) $offset; |
|
103
|
1 |
|
$this->addCommandArgument('--skip=' . $offset); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
20 |
|
if ($firstParent) { |
|
107
|
|
|
$this->addCommandArgument('--first-parent'); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
20 |
|
if ($ref instanceof TreeishInterface) { |
|
111
|
|
|
$ref = $ref->getSha(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
20 |
|
if (null !== $path && !empty($path)) { |
|
115
|
5 |
|
$this->addPath($path); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
20 |
|
$this->addCommandSubject($ref); |
|
119
|
|
|
|
|
120
|
20 |
|
return $this->getCommand(); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|