diff options
author | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2011-11-27 19:35:49 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2011-11-27 19:35:49 +0400 |
commit | a031813887a203b80006e7fdc3204355fd8d02b7 (patch) | |
tree | 880220df6e58e81503bd5c299164cb5b3582dd7f /lib | |
parent | 1b2fba08fe83c7075d58cb34ba6ce79dfd527b41 (diff) |
Commit, network graph refactoring
Diffstat (limited to 'lib')
-rw-r--r-- | lib/commit_ext.rb | 20 | ||||
-rw-r--r-- | lib/graph_commit.rb | 59 |
2 files changed, 52 insertions, 27 deletions
diff --git a/lib/commit_ext.rb b/lib/commit_ext.rb deleted file mode 100644 index 0e045911843..00000000000 --- a/lib/commit_ext.rb +++ /dev/null @@ -1,20 +0,0 @@ -module CommitExt - attr_accessor :head - attr_accessor :refs - - def safe_message - message.force_encoding(Encoding::UTF_8) - end - - def created_at - committed_date - end - - def author_email - author.email.force_encoding(Encoding::UTF_8) - end - - def author_name - author.name.force_encoding(Encoding::UTF_8) - end -end diff --git a/lib/graph_commit.rb b/lib/graph_commit.rb index 69368f7abe3..18b1702250c 100644 --- a/lib/graph_commit.rb +++ b/lib/graph_commit.rb @@ -2,14 +2,22 @@ require "grit" class GraphCommit attr_accessor :time, :space - def initialize(commit) - @_commit = commit - @time = -1 - @space = 0 - end + attr_accessor :refs - def method_missing(m, *args, &block) - @_commit.send(m, *args, &block) + def self.to_graph(project) + @repo = project.repo + commits = Grit::Commit.find_all(@repo, nil, {:max_count => 650}) + + ref_cache = {} + + commits.map! {|c| GraphCommit.new(Commit.new(c))} + commits.each { |commit| commit.add_refs(ref_cache, @repo) } + + days = GraphCommit.index_commits(commits) + @days_json = days.compact.collect{|d| [d.day, d.strftime("%b")] }.to_json + @commits_json = commits.map(&:to_graph_hash).to_json + + return @days_json, @commits_json end # Method is adding time and space on the @@ -72,4 +80,41 @@ class GraphCommit marks.compact.max end + + def initialize(commit) + @_commit = commit + @time = -1 + @space = 0 + end + + def method_missing(m, *args, &block) + @_commit.send(m, *args, &block) + end + + def to_graph_hash + h = {} + h[:parents] = self.parents.collect do |p| + [p.id,0,0] + end + h[:author] = author.name.force_encoding("UTF-8") + h[:time] = time + h[:space] = space + h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? + h[:id] = sha + h[:date] = date + h[:message] = message.force_encoding("UTF-8") + h[:login] = author.email + h + end + + def add_refs(ref_cache, repo) + if ref_cache.empty? + repo.refs.each do |ref| + ref_cache[ref.commit.id] ||= [] + ref_cache[ref.commit.id] << ref + end + end + @refs = ref_cache[@_commit.id] if ref_cache.include?(@_commit.id) + @refs ||= [] + end end |