1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of SebastianFeldmann\Git. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace SebastianFeldmann\Git\Command\Log; |
11
|
|
|
|
12
|
|
|
use SebastianFeldmann\Git\Command\Base; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Log |
16
|
|
|
* |
17
|
|
|
* @package SebastianFeldmann\Git |
18
|
|
|
*/ |
19
|
|
|
abstract class Log extends Base |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Pretty log format. |
23
|
|
|
* --pretty |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $format = '%h -%d %s (%ci) <%an>'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Include or hide merge commits. |
31
|
|
|
* --no-merges |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $merges = ' --no-merges'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Shorten commit hashes. |
39
|
|
|
* --abbrev-commit |
40
|
|
|
* |
41
|
|
|
* @var bool |
42
|
|
|
*/ |
43
|
|
|
protected $abbrev = ' --abbrev-commit'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Can be revision or date query. |
47
|
|
|
* 1.0.0.. |
48
|
|
|
* 0.9.0..1.2.0 |
49
|
|
|
* --after='2016-12-31' |
50
|
|
|
* --after='2016-12-31' --before='2017-01-31' |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $since; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Filter log by author. |
58
|
|
|
* --author |
59
|
|
|
* |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
protected $author; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Define the pretty log format. |
66
|
|
|
* |
67
|
|
|
* @param string $format |
68
|
|
|
* @return \SebastianFeldmann\Git\Command\Log\Log |
69
|
|
|
*/ |
70
|
2 |
|
public function prettyFormat(string $format) : Log |
71
|
|
|
{ |
72
|
2 |
|
$this->format = $format; |
73
|
2 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Define merge commit behaviour. |
78
|
|
|
* |
79
|
|
|
* @param bool $bool |
80
|
|
|
* @return \SebastianFeldmann\Git\Command\Log\Log |
81
|
|
|
*/ |
82
|
1 |
|
public function withMerges(bool $bool = true) : Log |
83
|
|
|
{ |
84
|
1 |
|
$this->merges = ($bool ? '' : ' --no-merges'); |
85
|
1 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Define commit hash behaviour. |
90
|
|
|
* |
91
|
|
|
* @param bool $bool |
92
|
|
|
* @return \SebastianFeldmann\Git\Command\Log\Log |
93
|
|
|
*/ |
94
|
1 |
|
public function abbrevCommit(bool $bool = true) : Log |
95
|
|
|
{ |
96
|
1 |
|
$this->abbrev = ($bool ? ' --abbrev--commit' : ''); |
|
|
|
|
97
|
1 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set revision range. |
102
|
|
|
* |
103
|
|
|
* @param string $from |
104
|
|
|
* @param string $to |
105
|
|
|
* @return \SebastianFeldmann\Git\Command\Log\Log |
106
|
|
|
*/ |
107
|
4 |
|
public function byRevision(string $from, string $to = '') : Log |
108
|
|
|
{ |
109
|
4 |
|
$this->since = ' ' . escapeshellarg($from) . '..' |
110
|
4 |
|
. (empty($to) ? '' : escapeshellarg($to)); |
111
|
4 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Set author filter. |
116
|
|
|
* |
117
|
|
|
* @param string $author |
118
|
|
|
* @return \SebastianFeldmann\Git\Command\Log\Log |
119
|
|
|
*/ |
120
|
1 |
|
public function authoredBy(string $author) : Log |
121
|
|
|
{ |
122
|
1 |
|
$this->author = ' --author=' . escapeshellarg($author); |
123
|
1 |
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Set date range. |
128
|
|
|
* |
129
|
|
|
* @param string $from |
130
|
|
|
* @param string $to |
131
|
|
|
* @return \SebastianFeldmann\Git\Command\Log\Log |
132
|
|
|
*/ |
133
|
2 |
|
public function byDate(string $from, string $to = '') : Log |
134
|
|
|
{ |
135
|
2 |
|
$this->since = ' --after=' . escapeshellarg($from) |
136
|
2 |
|
. (empty($to) ? '' : ' --before=' . escapeshellarg($to)); |
137
|
2 |
|
return $this; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.