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