-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (52 loc) · 1.1 KB
/
index.js
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
module.exports = parse
var lines = require('line-stream')
, through = require('through')
function parse() {
var stream = through(write, end)
, line_number = 0
, internal = lines()
, last
stream.on('pipe', function(source) {
source.setEncoding('utf8')
})
internal.on('data', parse_line)
internal.on('end', function() {
if(last) {
stream.queue(last)
}
stream.queue(null)
})
return stream
function write(data) {
internal.write(data)
}
function end() {
internal.end()
}
function parse_line(data) {
++line_number
data = data.replace(/^\s+/, '').replace(/\s+$/, '')
if(data.charAt(0) === '#') {
return
}
if(data.charAt(0) === '^') {
if(!last) {
return stream.emit(
'error'
, new Error('unexpected tag commit ref on line '+line_number)
)
}
last.commit = data.slice(1, 41)
stream.queue(last)
return
}
if(last) {
stream.queue(last)
}
last = {
hash: data.slice(0, 40)
, name: data.slice(41)
, commit: null
}
}
}