forked from gitonomy/gitlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogParser.php
More file actions
91 lines (73 loc) · 2.74 KB
/
LogParser.php
File metadata and controls
91 lines (73 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* This file is part of Gitonomy.
*
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
* (c) Julien DIDIER <genzo.wm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Parser;
class LogParser extends CommitParser
{
public $log = [];
protected function doParse()
{
$this->log = [];
while (!$this->isFinished()) {
$commit = [];
$this->consume('commit ');
$commit['id'] = $this->consumeHash();
$this->consumeNewLine();
$this->consume('tree ');
$commit['treeHash'] = $this->consumeHash();
$this->consumeNewLine();
$commit['parentHashes'] = [];
while ($this->expects('parent ')) {
$commit['parentHashes'][] = $this->consumeHash();
$this->consumeNewLine();
}
$this->consume('author ');
list($commit['authorName'], $commit['authorEmail'], $authorDate) = $this->consumeNameEmailDate();
$commit['authorDate'] = $this->parseDate($authorDate);
$this->consumeNewLine();
$this->consume('committer ');
list($commit['committerName'], $commit['committerEmail'], $committerDate) = $this->consumeNameEmailDate();
$commit['committerDate'] = $this->parseDate($committerDate);
$this->consumeMergeTag();
// will consume an GPG signed commit if there is one
$this->consumeGPGSignature();
$this->consumeNewLine();
$this->consumeUnsupportedLinesToNewLine();
if ($this->cursor < strlen($this->content)) {
$this->consumeNewLine();
}
$message = '';
if ($this->expects(' ')) {
$this->cursor -= strlen(' ');
while ($this->expects(' ')) {
$message .= $this->consumeTo("\n")."\n";
$this->consumeNewLine();
}
} else {
$this->cursor--;
}
if (!$this->isFinished()) {
$this->consumeNewLine();
}
$commit['message'] = $message;
$this->log[] = $commit;
}
}
protected function consumeUnsupportedLinesToNewLine()
{
// Consume any unsupported lines that may appear in the log output. For
// example, gitbutler headers or other custom metadata but this should
// work regardless of the content.
while (!$this->isFinished() && substr($this->content, $this->cursor, 1) !== "\n") {
$this->consumeTo("\n");
$this->consumeNewLine();
}
}
}