Commit dd4d124832c387ddfc694fdcdae694dc5289cb6c
1 parent
f082c8ae
Exists in
master
and in
4 other branches
remove accidently created file
Showing
1 changed file
with
0 additions
and
165 deletions
Show diff stats
lib/gitlab/graph/'
... | ... | @@ -1,165 +0,0 @@ |
1 | -require "grit" | |
2 | - | |
3 | -module Gitlab | |
4 | - module Graph | |
5 | - class JsonBuilder | |
6 | - attr_accessor :max_count, :days, :commits | |
7 | - | |
8 | - def initialize project | |
9 | - @project = project | |
10 | - @repo = project.repo | |
11 | - @commits = collect_commits(@repo).dup | |
12 | - @ref_cache = {} | |
13 | - | |
14 | - @commits.map! { |commit| Graph::Commit.new(Commit.new(commit))} | |
15 | - @commits.each { |commit| commit.add_refs(ref_cache, @repo) } | |
16 | - | |
17 | - days = Graph::Commit.index_commits(@commits) | |
18 | - | |
19 | - return @days_json, @commits_json | |
20 | - end | |
21 | - | |
22 | - def collect_commits | |
23 | - end | |
24 | - | |
25 | - def days_json | |
26 | - @days_json = @days.compact.map { |d| [d.day, d.strftime("%b")] }.to_json | |
27 | - end | |
28 | - | |
29 | - def commits_json | |
30 | - @commits_json = @commits.map(&:to_graph_hash).to_json | |
31 | - end | |
32 | - | |
33 | - # Get commits from repository | |
34 | - # | |
35 | - def collect_commits repo | |
36 | - Grit::Commit.find_all(repo, nil, {max_count: self.max_count}) | |
37 | - end | |
38 | - | |
39 | - def max_count | |
40 | - @max_count ||= 650 | |
41 | - end | |
42 | - | |
43 | - # Method is adding time and space on the | |
44 | - # list of commits. As well as returns date list | |
45 | - # corelated with time set on commits. | |
46 | - # | |
47 | - # @param [Array<Graph::Commit>] comits to index | |
48 | - # | |
49 | - # @return [Array<TimeDate>] list of commit dates corelated with time on commits | |
50 | - def index_commits(commits) | |
51 | - days, heads = [], [] | |
52 | - map = {} | |
53 | - | |
54 | - commits.reverse.each_with_index do |c,i| | |
55 | - c.time = i | |
56 | - days[i] = c.committed_date | |
57 | - map[c.id] = c | |
58 | - heads += c.refs unless c.refs.nil? | |
59 | - end | |
60 | - | |
61 | - heads.select!{|h| h.is_a? Grit::Head or h.is_a? Grit::Remote} | |
62 | - # sort heads so the master is top and current branches are closer | |
63 | - heads.sort! do |a,b| | |
64 | - if a.name == "master" | |
65 | - -1 | |
66 | - elsif b.name == "master" | |
67 | - 1 | |
68 | - else | |
69 | - b.commit.committed_date <=> a.commit.committed_date | |
70 | - end | |
71 | - end | |
72 | - | |
73 | - @_reserved = {} | |
74 | - days.each_index do |i| | |
75 | - @_reserved[i] = [] | |
76 | - end | |
77 | - | |
78 | - heads.each do |h| | |
79 | - if map.include? h.commit.id then | |
80 | - place_chain(map[h.commit.id], map) | |
81 | - end | |
82 | - end | |
83 | - days | |
84 | - end | |
85 | - | |
86 | - # Add space mark on commit and its parents | |
87 | - # | |
88 | - # @param [Graph::Commit] the commit object. | |
89 | - # @param [Hash<String,Graph::Commit>] map of commits | |
90 | - def place_chain(commit, map, parent_time = nil) | |
91 | - leaves = take_left_leaves(commit, map) | |
92 | - if leaves.empty? then | |
93 | - return | |
94 | - end | |
95 | - space = find_free_space(leaves.last.time..leaves.first.time) | |
96 | - leaves.each{|l| l.space = space} | |
97 | - # and mark it as reserved | |
98 | - min_time = leaves.last.time | |
99 | - parents = leaves.last.parents.collect | |
100 | - parents.each do |p| | |
101 | - if map.include? p.id then | |
102 | - parent = map[p.id] | |
103 | - if parent.time < min_time then | |
104 | - min_time = parent.time | |
105 | - end | |
106 | - end | |
107 | - end | |
108 | - if parent_time.nil? then | |
109 | - max_time = leaves.first.time | |
110 | - else | |
111 | - max_time = parent_time - 1 | |
112 | - end | |
113 | - mark_reserved(min_time..max_time, space) | |
114 | - # Visit branching chains | |
115 | - leaves.each do |l| | |
116 | - parents = l.parents.collect | |
117 | - .select{|p| map.include? p.id and map[p.id].space == 0} | |
118 | - for p in parents | |
119 | - place_chain(map[p.id], map, l.time) | |
120 | - end | |
121 | - end | |
122 | - end | |
123 | - | |
124 | - def mark_reserved(time_range, space) | |
125 | - for day in time_range | |
126 | - @_reserved[day].push(space) | |
127 | - end | |
128 | - end | |
129 | - | |
130 | - def find_free_space(time_range) | |
131 | - reserved = [] | |
132 | - for day in time_range | |
133 | - reserved += @_reserved[day] | |
134 | - end | |
135 | - space = 1 | |
136 | - while reserved.include? space do | |
137 | - space += 1 | |
138 | - end | |
139 | - space | |
140 | - end | |
141 | - | |
142 | - # Takes most left subtree branch of commits | |
143 | - # which don't have space mark yet. | |
144 | - # | |
145 | - # @param [Graph::Commit] the commit object. | |
146 | - # @param [Hash<String,Graph::Commit>] map of commits | |
147 | - # | |
148 | - # @return [Array<Graph::Commit>] list of branch commits | |
149 | - def take_left_leaves(commit, map) | |
150 | - leaves = [] | |
151 | - leaves.push(commit) if commit.space == 0 | |
152 | - while true | |
153 | - parent = commit.parents.collect | |
154 | - self.select{|p| map.include? p.id and map[p.id].space == 0} | |
155 | - if parent.count == 0 then | |
156 | - return leaves | |
157 | - else | |
158 | - commit = map[parent.first.id] | |
159 | - leaves.push(commit) | |
160 | - end | |
161 | - end | |
162 | - end | |
163 | - end | |
164 | - end | |
165 | -end |