summaryrefslogtreecommitdiff
path: root/app/models/graph/commit.rb
diff options
context:
space:
mode:
authorSato Hiroyuki <sathiroyuki@gmail.com>2013-02-26 13:28:11 +0900
committerSato Hiroyuki <sathiroyuki@gmail.com>2013-02-26 20:31:39 +0900
commitd8a40d8c933da8e89013e989940f8b60d0f2e247 (patch)
tree8ccafedef6f21a99c318615164209e7d5cbce9ea /app/models/graph/commit.rb
parentc9b1df1201dccded5fdfb4835209af9c0f258c55 (diff)
downloadgitlab-ce-d8a40d8c933da8e89013e989940f8b60d0f2e247.tar.gz
Move graph module from lib or vendor directory to app directory.
Because not autoloading lib directory at development mode.
Diffstat (limited to 'app/models/graph/commit.rb')
-rw-r--r--app/models/graph/commit.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/app/models/graph/commit.rb b/app/models/graph/commit.rb
new file mode 100644
index 00000000000..2b09d53902a
--- /dev/null
+++ b/app/models/graph/commit.rb
@@ -0,0 +1,50 @@
+require "grit"
+
+module Graph
+ class Commit
+ include ActionView::Helpers::TagHelper
+
+ attr_accessor :time, :space, :refs, :parent_spaces
+
+ def initialize(commit)
+ @_commit = commit
+ @time = -1
+ @space = 0
+ @parent_spaces = []
+ 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] = {
+ name: author.name,
+ email: author.email
+ }
+ h[:time] = time
+ h[:space] = space
+ h[:parent_spaces] = parent_spaces
+ h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
+ h[:id] = sha
+ h[:date] = date
+ h[:message] = message
+ 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
+end