Merge branch 'master' of dev.gitlabhq.com:gitlabhq
This commit is contained in:
commit
c0a30b3a0c
5 changed files with 132 additions and 88 deletions
|
@ -64,7 +64,7 @@ class ApplicationController < ActionController::Base
|
||||||
else
|
else
|
||||||
@branch = params[:branch].blank? ? nil : params[:branch]
|
@branch = params[:branch].blank? ? nil : params[:branch]
|
||||||
@tag = params[:tag].blank? ? nil : params[:tag]
|
@tag = params[:tag].blank? ? nil : params[:tag]
|
||||||
@ref = @branch || @tag || "master"
|
@ref = @branch || @tag || Repository.default_ref
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,18 +8,18 @@ class CommitsController < ApplicationController
|
||||||
before_filter :add_project_abilities
|
before_filter :add_project_abilities
|
||||||
before_filter :authorize_read_project!
|
before_filter :authorize_read_project!
|
||||||
before_filter :require_non_empty_project
|
before_filter :require_non_empty_project
|
||||||
|
before_filter :load_refs, :only => :index # load @branch, @tag & @ref
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
load_refs # load @branch, @tag & @ref
|
|
||||||
|
|
||||||
@repo = project.repo
|
@repo = project.repo
|
||||||
limit, offset = (params[:limit] || 20), (params[:offset] || 0)
|
limit, offset = (params[:limit] || 20), (params[:offset] || 0)
|
||||||
|
|
||||||
if params[:path]
|
@commits = if params[:path]
|
||||||
@commits = @repo.log(@ref, params[:path], :max_count => limit, :skip => offset)
|
@repo.log(@ref, params[:path], :max_count => limit, :skip => offset)
|
||||||
else
|
else
|
||||||
@commits = @repo.commits(@ref, limit, offset)
|
@repo.commits(@ref, limit, offset)
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
|
@ -29,8 +29,8 @@ class CommitsController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@commit = project.repo.commits(params[:id]).first
|
@commit = project.repo.commits(params[:id]).first
|
||||||
@notes = project.notes.where(:noteable_id => @commit.id, :noteable_type => "Commit").order("created_at DESC").limit(20)
|
@notes = project.commit_notes(@commit).fresh.limit(20)
|
||||||
@note = @project.notes.new(:noteable_id => @commit.id, :noteable_type => "Commit")
|
@note = @project.build_commit_note(@commit)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
|
|
@ -6,8 +6,8 @@ class ProjectsController < ApplicationController
|
||||||
before_filter :add_project_abilities
|
before_filter :add_project_abilities
|
||||||
before_filter :authorize_read_project!, :except => [:index, :new, :create]
|
before_filter :authorize_read_project!, :except => [:index, :new, :create]
|
||||||
before_filter :authorize_admin_project!, :only => [:edit, :update, :destroy]
|
before_filter :authorize_admin_project!, :only => [:edit, :update, :destroy]
|
||||||
|
|
||||||
before_filter :require_non_empty_project, :only => [:blob, :tree]
|
before_filter :require_non_empty_project, :only => [:blob, :tree]
|
||||||
|
before_filter :load_refs, :only => :tree # load @branch, @tag & @ref
|
||||||
|
|
||||||
def index
|
def index
|
||||||
source = current_user.projects
|
source = current_user.projects
|
||||||
|
@ -101,15 +101,13 @@ class ProjectsController < ApplicationController
|
||||||
#
|
#
|
||||||
|
|
||||||
def tree
|
def tree
|
||||||
load_refs # load @branch, @tag & @ref
|
|
||||||
|
|
||||||
@repo = project.repo
|
@repo = project.repo
|
||||||
|
|
||||||
if params[:commit_id]
|
@commit = if params[:commit_id]
|
||||||
@commit = @repo.commits(params[:commit_id]).first
|
@repo.commits(params[:commit_id]).first
|
||||||
else
|
else
|
||||||
@commit = @repo.commits(@ref || "master").first
|
@repo.commits(@ref).first
|
||||||
end
|
end
|
||||||
|
|
||||||
@tree = @commit.tree
|
@tree = @commit.tree
|
||||||
@tree = @tree / params[:path] if params[:path]
|
@tree = @tree / params[:path] if params[:path]
|
||||||
|
|
|
@ -46,6 +46,25 @@ class Project < ActiveRecord::Base
|
||||||
|
|
||||||
scope :public_only, where(:private_flag => false)
|
scope :public_only, where(:private_flag => false)
|
||||||
|
|
||||||
|
def repository
|
||||||
|
@repository ||= Repository.new(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
delegate :repo,
|
||||||
|
:url_to_repo,
|
||||||
|
:path_to_repo,
|
||||||
|
:update_gitosis_project,
|
||||||
|
:destroy_gitosis_project,
|
||||||
|
:tags,
|
||||||
|
:repo_exists?,
|
||||||
|
:commit,
|
||||||
|
:commits,
|
||||||
|
:tree,
|
||||||
|
:heads,
|
||||||
|
:commits_since,
|
||||||
|
:fresh_commits,
|
||||||
|
:to => :repository, :prefix => nil
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
code
|
code
|
||||||
end
|
end
|
||||||
|
@ -59,16 +78,12 @@ class Project < ActiveRecord::Base
|
||||||
notes.where(:noteable_type => ["", nil])
|
notes.where(:noteable_type => ["", nil])
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_gitosis_project
|
def build_commit_note(commit)
|
||||||
Gitosis.new.configure do |c|
|
notes.new(:noteable_id => commit.id, :noteable_type => "Commit")
|
||||||
c.update_project(path, gitosis_writers)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_gitosis_project
|
def commit_notes(commit)
|
||||||
Gitosis.new.configure do |c|
|
notes.where(:noteable_id => commit.id, :noteable_type => "Commit")
|
||||||
c.destroy_project(self)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_access(user, *access)
|
def add_access(user, *access)
|
||||||
|
@ -106,26 +121,6 @@ class Project < ActiveRecord::Base
|
||||||
private_flag
|
private_flag
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_to_repo
|
|
||||||
"#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git"
|
|
||||||
end
|
|
||||||
|
|
||||||
def path_to_repo
|
|
||||||
GITOSIS["base_path"] + path + ".git"
|
|
||||||
end
|
|
||||||
|
|
||||||
def repo
|
|
||||||
@repo ||= Grit::Repo.new(path_to_repo)
|
|
||||||
end
|
|
||||||
|
|
||||||
def tags
|
|
||||||
repo.tags.map(&:name).sort.reverse
|
|
||||||
end
|
|
||||||
|
|
||||||
def repo_exists?
|
|
||||||
repo rescue false
|
|
||||||
end
|
|
||||||
|
|
||||||
def last_activity
|
def last_activity
|
||||||
updates(1).first
|
updates(1).first
|
||||||
rescue
|
rescue
|
||||||
|
@ -146,48 +141,6 @@ class Project < ActiveRecord::Base
|
||||||
end[0...n]
|
end[0...n]
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit(commit_id = nil)
|
|
||||||
if commit_id
|
|
||||||
repo.commits(commit_id).first
|
|
||||||
else
|
|
||||||
repo.commits.first
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def heads
|
|
||||||
@heads ||= repo.heads
|
|
||||||
end
|
|
||||||
|
|
||||||
def fresh_commits(n = 10)
|
|
||||||
commits = heads.map do |h|
|
|
||||||
repo.commits(h.name, n)
|
|
||||||
end.flatten.uniq { |c| c.id }
|
|
||||||
|
|
||||||
commits.sort! do |x, y|
|
|
||||||
y.committed_date <=> x.committed_date
|
|
||||||
end
|
|
||||||
|
|
||||||
commits[0...n]
|
|
||||||
end
|
|
||||||
|
|
||||||
def commits_since(date)
|
|
||||||
commits = heads.map do |h|
|
|
||||||
repo.log(h.name, nil, :since => date)
|
|
||||||
end.flatten.uniq { |c| c.id }
|
|
||||||
|
|
||||||
commits.sort! do |x, y|
|
|
||||||
y.committed_date <=> x.committed_date
|
|
||||||
end
|
|
||||||
|
|
||||||
commits
|
|
||||||
end
|
|
||||||
|
|
||||||
def tree(fcommit, path = nil)
|
|
||||||
fcommit = commit if fcommit == :head
|
|
||||||
tree = fcommit.tree
|
|
||||||
path ? (tree / path) : tree
|
|
||||||
end
|
|
||||||
|
|
||||||
def check_limit
|
def check_limit
|
||||||
unless owner.can_create_project?
|
unless owner.can_create_project?
|
||||||
errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it")
|
errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it")
|
||||||
|
|
93
app/models/repository.rb
Normal file
93
app/models/repository.rb
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
class Repository
|
||||||
|
attr_accessor :project
|
||||||
|
|
||||||
|
def self.default_ref
|
||||||
|
"master"
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(project)
|
||||||
|
@project = project
|
||||||
|
end
|
||||||
|
|
||||||
|
def path
|
||||||
|
@path ||= project.path
|
||||||
|
end
|
||||||
|
|
||||||
|
def project_id
|
||||||
|
project.id
|
||||||
|
end
|
||||||
|
|
||||||
|
def repo
|
||||||
|
@repo ||= Grit::Repo.new(project.path_to_repo)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url_to_repo
|
||||||
|
"#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git"
|
||||||
|
end
|
||||||
|
|
||||||
|
def path_to_repo
|
||||||
|
GITOSIS["base_path"] + path + ".git"
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_gitosis_project
|
||||||
|
Gitosis.new.configure do |c|
|
||||||
|
c.update_project(path, project.gitosis_writers)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy_gitosis_project
|
||||||
|
Gitosis.new.configure do |c|
|
||||||
|
c.destroy_project(@project)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def repo_exists?
|
||||||
|
repo rescue false
|
||||||
|
end
|
||||||
|
|
||||||
|
def tags
|
||||||
|
repo.tags.map(&:name).sort.reverse
|
||||||
|
end
|
||||||
|
|
||||||
|
def heads
|
||||||
|
@heads ||= repo.heads
|
||||||
|
end
|
||||||
|
|
||||||
|
def tree(fcommit, path = nil)
|
||||||
|
fcommit = commit if fcommit == :head
|
||||||
|
tree = fcommit.tree
|
||||||
|
path ? (tree / path) : tree
|
||||||
|
end
|
||||||
|
|
||||||
|
def commit(commit_id = nil)
|
||||||
|
if commit_id
|
||||||
|
repo.commits(commit_id).first
|
||||||
|
else
|
||||||
|
repo.commits.first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def fresh_commits(n = 10)
|
||||||
|
commits = heads.map do |h|
|
||||||
|
repo.commits(h.name, n)
|
||||||
|
end.flatten.uniq { |c| c.id }
|
||||||
|
|
||||||
|
commits.sort! do |x, y|
|
||||||
|
y.committed_date <=> x.committed_date
|
||||||
|
end
|
||||||
|
|
||||||
|
commits[0...n]
|
||||||
|
end
|
||||||
|
|
||||||
|
def commits_since(date)
|
||||||
|
commits = heads.map do |h|
|
||||||
|
repo.log(h.name, nil, :since => date)
|
||||||
|
end.flatten.uniq { |c| c.id }
|
||||||
|
|
||||||
|
commits.sort! do |x, y|
|
||||||
|
y.committed_date <=> x.committed_date
|
||||||
|
end
|
||||||
|
|
||||||
|
commits
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue