-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
54 lines (45 loc) · 1.48 KB
/
index.coffee
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
git = require 'gitteh-promisified'
{commitTreeEntry} = require 'gitteh-tree-entry'
{all} = require 'kew'
{SKIP, asSeq, produced, reduced, join, series, map, empty, window} = require 'reduced'
# m a, (a -> m bool) -> m a
filterM = (seq, f) ->
seq = asSeq seq
next: (done) ->
seq.next (s, v) ->
return done(s) if s?
reduced(asSeq f v)
.then (allowed) ->
if allowed then done(null, v) else done(SKIP)
.end()
changedBetween = (path, commit, prevCommit) ->
if prevCommit?
all(commitTreeEntry(commit, path), commitTreeEntry(prevCommit, path))
.then ([entry, prevEntry]) ->
created = entry and not prevEntry
changed = entry?.id != prevEntry?.id
changed or created
else
commitTreeEntry(commit, path)
previousCommitsSeq = (commit) ->
getCommit = (id) ->
commit.then (commit) ->
commit.repository.commit(id)
getPreviousCommit = (commit) ->
if commit.parents.length > 0
parents = map(commit.parents, getCommit)
join map(parents, previousCommitsSeq)
else
empty()
join series(getPreviousCommit, commit)
logSeq = (ref, file) ->
commits = previousCommitsSeq ref.repository.commit(ref.target)
if file?
commits = filterM (window commits, 2), ([commit, prevCommit]) ->
changedBetween(file, commit, prevCommit)
map commits, ([commit, prevCommit]) -> commit
else
commits
log = (ref, file) ->
produced logSeq(ref, file)
module.exports = {log, logSeq, previousCommitsSeq}