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
92
|
# File 'lib/fugit/graph_renderer.rb', line 5
def graphify(commits)
graph = []
branch_parents = [commits.first[0]]
commits.each do |sha, parents, |
parents = parents.split(" ")
branches = []
parent_found = false
children = branch_parents.select {|b| b == sha}
branch_parents.each do |parent|
indicator = "│"
indicator = " " if parent.empty?
indicator = "┼" if parent_found && children.size > 1 && !parent.empty?
indicator = "●" if sha == parent && !parent_found
indicator = "┘" if sha == parent && parent_found
children.shift if sha == parent && parent_found
parent_found = true if sha == parent
branches << indicator
end
sha_found = false
branch_parents.map! do |b|
match = sha_found && sha == b
sha_found = sha == b if !sha_found
match ? "" : b
end
if parents.empty?
branch_parents.delete(sha)
else
sha_index = branch_parents.index(sha)
branch_parents[sha_index] = parents.shift if sha_index
parents.each do |p|
branch_parents << p
branches << "┐" if sha_index
end
branches << "●" unless sha_index
if parents.empty?
found = false
branchoffs = branches.select{|b| b == "┘"}
branches.map! do |b|
val = !found ? b : case b
when "┘"
branchoffs.shift
"┴"
when " "
branchoffs.empty? ? " " : "─"
else
b
end
found ||= b == "●"
val
end
branches.reverse!
found = false
branches.map! do |b|
was_found = !found && b == "┴"
found = was_found if !found
was_found ? "┘" : b
end
branches.reverse!
else
found = false
branches.map! do |b|
val = !found ? b : case b
when "│"
"┼"
when "┘"
"┴"
when " "
"─"
else
b
end
found = b == "●" if !found
val
end
end
end
branch_parents.reverse!
matched = false
branch_parents.reject! do |parent|
match = !matched && parent == ""
matched = parent != "" if !matched
match
end
branch_parents.reverse!
graph << [branches.join, , sha]
end
graph
end
|