Commit, network graph refactoring
This commit is contained in:
parent
1b2fba08fe
commit
a031813887
14 changed files with 125 additions and 97 deletions
|
@ -11,7 +11,7 @@
|
|||
.cm { color: #888888 } /* Comment.Multiline */
|
||||
.cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
|
||||
.c1 { color: #888888 } /* Comment.Single */
|
||||
.cs { color: #cc0000; font-weight: bold; background-color: auto } /* Comment.Special */
|
||||
.cs { color: #cc0000; font-weight: bold; background-color: transparent } /* Comment.Special */
|
||||
.gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
|
||||
.ge { font-style: italic } /* Generic.Emph */
|
||||
.gr { color: #aa0000 } /* Generic.Error */
|
||||
|
@ -30,7 +30,7 @@
|
|||
.highlight .kt{color:#458;font-weight:bold;} /* Keyword.Type */
|
||||
.m { color: #0000DD; font-weight: bold } /* Literal.Number */
|
||||
.p { color: #eee; }
|
||||
.s { color: #dd2200; background-color: auto } /* Literal.String */
|
||||
.s { color: #dd2200; background-color: transparent } /* Literal.String */
|
||||
.highlight .na{color:#008080;} /* Name.Attribute */
|
||||
.highlight .nb{color:#0086B3;} /* Name.Builtin */
|
||||
.highlight .nc{color:#4d3;font-weight:bold;} /* Name.Class */
|
||||
|
@ -48,9 +48,9 @@
|
|||
.mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
|
||||
.highlight .mi {color:#099;} /* Literal.Number.Integer */
|
||||
.mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
|
||||
.sb { color: #dd2200; background-color: auto } /* Literal.String.Backtick */
|
||||
.sb { color: #dd2200; background-color: transparent; } /* Literal.String.Backtick */
|
||||
.highlight .sc{color:#d14;} /* Literal.String.Char */
|
||||
.sd { color: #dd2200; background-color: auto } /* Literal.String.Doc */
|
||||
.sd { color: #dd2200; background-color: transparent; } /* Literal.String.Doc */
|
||||
.highlight .s2{color:orange;} /* Literal.String.Double */
|
||||
.highlight .se{color:orange;} /* Literal.String.Escape */
|
||||
.highlight .sh{color:orange;} /* Literal.String.Heredoc */
|
||||
|
|
|
@ -13,12 +13,7 @@ class CommitsController < ApplicationController
|
|||
def index
|
||||
@repo = project.repo
|
||||
@limit, @offset = (params[:limit] || 20), (params[:offset] || 0)
|
||||
|
||||
@commits = if params[:path]
|
||||
@repo.log(@ref, params[:path], :max_count => @limit, :skip => @offset)
|
||||
else
|
||||
@repo.commits(@ref, @limit, @offset)
|
||||
end
|
||||
@commits = @project.commits(@ref, params[:path], @limit, @offset)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
@ -28,7 +23,7 @@ class CommitsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@commit = project.repo.commits(params[:id]).first
|
||||
@commit = project.commit(params[:id])
|
||||
@notes = project.commit_notes(@commit).fresh.limit(20)
|
||||
@note = @project.build_commit_note(@commit)
|
||||
|
||||
|
|
|
@ -86,31 +86,7 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def graph
|
||||
@repo = project.repo
|
||||
commits = Grit::Commit.find_all(@repo, nil, {:max_count => 650})
|
||||
ref_cache = {}
|
||||
commits.collect! do |commit|
|
||||
add_refs(commit, ref_cache)
|
||||
GraphCommit.new(commit)
|
||||
end
|
||||
|
||||
days = GraphCommit.index_commits(commits)
|
||||
@days_json = days.compact.collect{|d| [d.day, d.strftime("%b")] }.to_json
|
||||
@commits_json = commits.collect do |c|
|
||||
h = {}
|
||||
h[:parents] = c.parents.collect do |p|
|
||||
[p.id,0,0]
|
||||
end
|
||||
h[:author] = c.author.name.force_encoding("UTF-8")
|
||||
h[:time] = c.time
|
||||
h[:space] = c.space
|
||||
h[:refs] = c.refs.collect{|r|r.name}.join(" ") unless c.refs.nil?
|
||||
h[:id] = c.sha
|
||||
h[:date] = c.date
|
||||
h[:message] = c.message.force_encoding("UTF-8")
|
||||
h[:login] = c.author.email
|
||||
h
|
||||
end.to_json
|
||||
@days_json, @commits_json = GraphCommit.to_graph(project)
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -123,17 +99,6 @@ class ProjectsController < ApplicationController
|
|||
|
||||
protected
|
||||
|
||||
def add_refs(commit, ref_cache)
|
||||
if ref_cache.empty?
|
||||
@repo.refs.each do |ref|
|
||||
ref_cache[ref.commit.id] ||= []
|
||||
ref_cache[ref.commit.id] << ref
|
||||
end
|
||||
end
|
||||
commit.refs = ref_cache[commit.id] if ref_cache.include? commit.id
|
||||
commit.refs ||= []
|
||||
end
|
||||
|
||||
def project
|
||||
@project ||= Project.find_by_code(params[:id])
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ module DashboardHelper
|
|||
def dashboard_feed_path(project, object)
|
||||
case object.class.name.to_s
|
||||
when "Issue" then project_issue_path(project, project.issues.find(object.id))
|
||||
when "Grit::Commit" then project_commit_path(project, project.repo.commits(object.id).first)
|
||||
when "Commit" then project_commit_path(project, project.repo.commits(object.id).first)
|
||||
when "Note"
|
||||
then
|
||||
note = object
|
||||
|
|
|
@ -1,2 +1,37 @@
|
|||
class Commit
|
||||
attr_accessor :commit
|
||||
attr_accessor :head
|
||||
|
||||
delegate :message,
|
||||
:committed_date,
|
||||
:parents,
|
||||
:sha,
|
||||
:date,
|
||||
:author,
|
||||
:message,
|
||||
:diffs,
|
||||
:tree,
|
||||
:id,
|
||||
:to => :commit
|
||||
|
||||
def initialize(raw_commit, head = nil)
|
||||
@commit = raw_commit
|
||||
@head = head
|
||||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -64,16 +64,17 @@ class Repository
|
|||
end
|
||||
|
||||
def commit(commit_id = nil)
|
||||
if commit_id
|
||||
repo.commits(commit_id).first
|
||||
else
|
||||
repo.commits.first
|
||||
end
|
||||
commit = if commit_id
|
||||
repo.commits(commit_id).first
|
||||
else
|
||||
repo.commits.first
|
||||
end
|
||||
Commit.new(commit) if commit
|
||||
end
|
||||
|
||||
def fresh_commits(n = 10)
|
||||
commits = heads.map do |h|
|
||||
repo.commits(h.name, n).each { |c| c.head = h }
|
||||
repo.commits(h.name, n).map { |c| Commit.new(c, h) }
|
||||
end.flatten.uniq { |c| c.id }
|
||||
|
||||
commits.sort! do |x, y|
|
||||
|
@ -85,7 +86,7 @@ class Repository
|
|||
|
||||
def commits_since(date)
|
||||
commits = heads.map do |h|
|
||||
repo.log(h.name, nil, :since => date).each { |c| c.head = h }
|
||||
repo.log(h.name, nil, :since => date).each { |c| Commit.new(c, h) }
|
||||
end.flatten.uniq { |c| c.id }
|
||||
|
||||
commits.sort! do |x, y|
|
||||
|
@ -94,4 +95,14 @@ class Repository
|
|||
|
||||
commits
|
||||
end
|
||||
|
||||
def commits(ref, path = nil, limit = nil, offset = nil)
|
||||
if path
|
||||
repo.log(ref, path, :max_count => limit, :skip => offset)
|
||||
elsif limit && offset
|
||||
repo.commits(ref, limit, offset)
|
||||
else
|
||||
repo.commits(ref)
|
||||
end.map{ |c| Commit.new(c) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
.right
|
||||
- klass = update.class.to_s.split("::").last.downcase
|
||||
%span.tag{ :class => klass }= klass
|
||||
- if update.kind_of?(Grit::Commit)
|
||||
- if update.kind_of?(Commit)
|
||||
%span.tag.commit= update.head.name
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- file = params[:path] ? File.join(params[:path], content.name) : content.name
|
||||
- content_commit = @project.repo.log(@commit.id, file, :max_count => 1).last
|
||||
- content_commit = @project.commits(@commit.id, file, 1).last
|
||||
- return unless content_commit
|
||||
%tr{ :class => "tree-item", :url => tree_file_project_ref_path(@project, @ref, file) }
|
||||
%td.tree-item-file-name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue