Commit 3a1c6ccc authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'bug/500_tag_name' into 'master'

Fix 500 on tags page

Fix bug when grit parse tags wrong and raise exception on tags page.
Fixes #993
parents 07157799 97a4d8ae
No related merge requests found
...@@ -29,7 +29,7 @@ gem 'omniauth-github' ...@@ -29,7 +29,7 @@ gem 'omniauth-github'
# Extracting information from a git repository # Extracting information from a git repository
# Provide access to Gitlab::Git library # Provide access to Gitlab::Git library
gem "gitlab_git", "~> 5.0.0" gem "gitlab_git", git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: '39bc4f043414f1e49f802ed633fa20e6400bfa49'
# Ruby/Rack Git Smart-HTTP Server Handler # Ruby/Rack Git Smart-HTTP Server Handler
gem 'gitlab-grack', '~> 2.0.0.pre', require: 'grack' gem 'gitlab-grack', '~> 2.0.0.pre', require: 'grack'
......
...@@ -5,6 +5,17 @@ GIT ...@@ -5,6 +5,17 @@ GIT
specs: specs:
github-markup (0.7.6) github-markup (0.7.6)
GIT
remote: https://gitlab.com/gitlab-org/gitlab_git.git
revision: 39bc4f043414f1e49f802ed633fa20e6400bfa49
ref: 39bc4f043414f1e49f802ed633fa20e6400bfa49
specs:
gitlab_git (5.1.0.pre)
activesupport (~> 4.0.0)
gitlab-grit (~> 2.6.1)
gitlab-linguist (~> 3.0.0)
rugged (~> 0.19.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
...@@ -176,10 +187,6 @@ GEM ...@@ -176,10 +187,6 @@ GEM
charlock_holmes (~> 0.6.6) charlock_holmes (~> 0.6.6)
escape_utils (~> 0.2.4) escape_utils (~> 0.2.4)
mime-types (~> 1.19) mime-types (~> 1.19)
gitlab_git (5.0.0)
activesupport (~> 4.0.0)
gitlab-grit (~> 2.6.1)
gitlab-linguist (~> 3.0.0)
gitlab_meta (6.0) gitlab_meta (6.0)
gitlab_omniauth-ldap (1.0.4) gitlab_omniauth-ldap (1.0.4)
net-ldap (~> 0.3.1) net-ldap (~> 0.3.1)
...@@ -417,6 +424,7 @@ GEM ...@@ -417,6 +424,7 @@ GEM
ruby-hmac (0.4.0) ruby-hmac (0.4.0)
ruby-progressbar (1.2.0) ruby-progressbar (1.2.0)
rubyntlm (0.1.1) rubyntlm (0.1.1)
rugged (0.19.0)
safe_yaml (0.9.7) safe_yaml (0.9.7)
sanitize (2.0.6) sanitize (2.0.6)
nokogiri (>= 1.4.4) nokogiri (>= 1.4.4)
...@@ -574,7 +582,7 @@ DEPENDENCIES ...@@ -574,7 +582,7 @@ DEPENDENCIES
gitlab-gollum-lib (~> 1.1.0) gitlab-gollum-lib (~> 1.1.0)
gitlab-grack (~> 2.0.0.pre) gitlab-grack (~> 2.0.0.pre)
gitlab-linguist (~> 3.0.0) gitlab-linguist (~> 3.0.0)
gitlab_git (~> 5.0.0) gitlab_git!
gitlab_meta (= 6.0) gitlab_meta (= 6.0)
gitlab_omniauth-ldap (= 1.0.4) gitlab_omniauth-ldap (= 1.0.4)
gon (~> 5.0.0) gon (~> 5.0.0)
......
...@@ -8,7 +8,7 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -8,7 +8,7 @@ class Projects::TagsController < Projects::ApplicationController
before_filter :authorize_admin_project!, only: [:destroy] before_filter :authorize_admin_project!, only: [:destroy]
def index def index
@tags = Kaminari.paginate_array(@repository.tags).page(params[:page]).per(30) @tags = Kaminari.paginate_array(@repository.tags.reverse).page(params[:page]).per(30)
end end
def create def create
......
...@@ -166,13 +166,13 @@ module GitlabMarkdownHelper ...@@ -166,13 +166,13 @@ module GitlabMarkdownHelper
def file_exists?(path) def file_exists?(path)
return false if path.nil? || path.empty? return false if path.nil? || path.empty?
return @repository.blob_at(current_ref, path).present? || Tree.new(@repository, current_ref, path).entries.any? return @repository.blob_at(current_ref, path).present? || @repository.tree(:head, path).entries.any?
end end
# Check if the path is pointing to a directory(tree) or a file(blob) # Check if the path is pointing to a directory(tree) or a file(blob)
# eg. doc/api is directory and doc/README.md is file # eg. doc/api is directory and doc/README.md is file
def local_path(path) def local_path(path)
return "tree" if Tree.new(@repository, current_ref, path).entries.any? return "tree" if @repository.tree(:head, path).entries.any?
return "raw" if @repository.blob_at(current_ref, path).image? return "raw" if @repository.blob_at(current_ref, path).image?
return "blob" return "blob"
end end
......
...@@ -16,16 +16,17 @@ class Commit ...@@ -16,16 +16,17 @@ class Commit
DIFF_HARD_LIMIT_FILES = 500 DIFF_HARD_LIMIT_FILES = 500
DIFF_HARD_LIMIT_LINES = 10000 DIFF_HARD_LIMIT_LINES = 10000
def self.decorate(commits) class << self
def decorate(commits)
commits.map { |c| self.new(c) } commits.map { |c| self.new(c) }
end end
# Calculate number of lines to render for diffs # Calculate number of lines to render for diffs
def self.diff_line_count(diffs) def diff_line_count(diffs)
diffs.reduce(0){|sum, d| sum + d.diff.lines.count} diffs.reduce(0){|sum, d| sum + d.diff.lines.count}
end end
def self.diff_suppress?(diffs, line_count = nil) def diff_suppress?(diffs, line_count = nil)
# optimize - check file count first # optimize - check file count first
return true if diffs.size > DIFF_SAFE_FILES return true if diffs.size > DIFF_SAFE_FILES
...@@ -33,13 +34,14 @@ class Commit ...@@ -33,13 +34,14 @@ class Commit
line_count > DIFF_SAFE_LINES line_count > DIFF_SAFE_LINES
end end
def self.diff_force_suppress?(diffs, line_count = nil) def diff_force_suppress?(diffs, line_count = nil)
# optimize - check file count first # optimize - check file count first
return true if diffs.size > DIFF_HARD_LIMIT_FILES return true if diffs.size > DIFF_HARD_LIMIT_FILES
line_count ||= Commit::diff_line_count(diffs) line_count ||= Commit::diff_line_count(diffs)
line_count > DIFF_HARD_LIMIT_LINES line_count > DIFF_HARD_LIMIT_LINES
end end
end
attr_accessor :raw attr_accessor :raw
......
...@@ -57,7 +57,7 @@ class Repository ...@@ -57,7 +57,7 @@ class Repository
def recent_branches(limit = 20) def recent_branches(limit = 20)
branches.sort do |a, b| branches.sort do |a, b|
b.commit.committed_date <=> a.commit.committed_date commit(b.target).committed_date <=> commit(a.target).committed_date
end[0..limit] end[0..limit]
end end
...@@ -163,7 +163,19 @@ class Repository ...@@ -163,7 +163,19 @@ class Repository
def readme def readme
Rails.cache.fetch(cache_key(:readme)) do Rails.cache.fetch(cache_key(:readme)) do
Tree.new(self, self.root_ref).readme tree(:head).readme
end end
end end
def head_commit
commit(self.root_ref)
end
def tree(sha = :head, path = nil)
if sha == :head
sha = head_commit.sha
end
Tree.new(self, sha, path)
end
end end
...@@ -23,4 +23,8 @@ class Tree ...@@ -23,4 +23,8 @@ class Tree
def submodules def submodules
@entries.select(&:submodule?) @entries.select(&:submodule?)
end end
def sorted_entries
trees + blobs + submodules
end
end end
- commit = Commit.new(Gitlab::Git::Commit.new(branch.commit)) - commit = @repository.commit(branch.target)
%li %li
%h4 %h4
= link_to project_commits_path(@project, branch.name) do = link_to project_commits_path(@project, branch.name) do
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
= link_to project_branch_path(@project, branch.name), class: 'btn grouped btn-small remove-row', method: :delete, data: { confirm: 'Removed branch cannot be restored. Are you sure?'}, remote: true do = link_to project_branch_path(@project, branch.name), class: 'btn grouped btn-small remove-row', method: :delete, data: { confirm: 'Removed branch cannot be restored. Are you sure?'}, remote: true do
%i.icon-trash %i.icon-trash
- if commit
%p %p
= link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do = link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do
= commit.short_id = commit.short_id
...@@ -26,3 +27,6 @@ ...@@ -26,3 +27,6 @@
%span.light %span.light
= gfm escape_once(truncate(commit.title, length: 40)) = gfm escape_once(truncate(commit.title, length: 40))
#{time_ago_with_tooltip(commit.committed_date)} #{time_ago_with_tooltip(commit.committed_date)}
- else
%p
Cant find HEAD commit for this branch
- commit = @repository.commit(tag.target)
%li
%h4
= link_to project_commits_path(@project, tag.name), class: "" do
%i.icon-tag
= tag.name
.pull-right
%small.cdark
%i.icon-calendar
#{time_ago_with_tooltip(commit.committed_date)}
%p.prepend-left-20
= link_to commit.short_id(8), project_commit_path(@project, commit), class: "monospace"
&ndash;
= link_to_gfm truncate(commit.title, length: 70), project_commit_path(@project, commit.id), class: "cdark"
%span.pull-right
- if can? current_user, :download_code, @project
= render 'projects/repositories/download_archive', ref: tag.name, btn_class: 'grouped btn-group-small'
- if can?(current_user, :admin_project, @project)
= link_to project_tag_path(@project, tag.name), class: 'btn btn-small remove-row grouped', method: :delete, data: { confirm: 'Removed tag cannot be restored. Are you sure?'}, remote: true do
%i.icon-trash
...@@ -13,29 +13,7 @@ ...@@ -13,29 +13,7 @@
- unless @tags.empty? - unless @tags.empty?
%ul.bordered-list %ul.bordered-list
- @tags.each do |tag| - @tags.each do |tag|
- commit = Commit.new(Gitlab::Git::Commit.new(tag.commit)) = render 'tag', tag: tag
%li
%h4
= link_to project_commits_path(@project, tag.name), class: "" do
%i.icon-tag
= tag.name
%small
= truncate(tag.message || '', length: 70)
.pull-right
%small.cdark
%i.icon-calendar
#{time_ago_with_tooltip(commit.committed_date)}
%p.prepend-left-20
= link_to commit.short_id(8), project_commit_path(@project, commit), class: "monospace"
&ndash;
= link_to_gfm truncate(commit.title, length: 70), project_commit_path(@project, commit.id), class: "cdark"
%span.pull-right
- if can? current_user, :download_code, @project
= render 'projects/repositories/download_archive', ref: tag.name, btn_class: 'grouped btn-group-small'
- if can?(current_user, :admin_project, @project)
= link_to project_tag_path(@project, tag.name), class: 'btn btn-small remove-row grouped', method: :delete, data: { confirm: 'Removed tag cannot be restored. Are you sure?'}, remote: true do
%i.icon-trash
= paginate @tags, theme: 'gitlab' = paginate @tags, theme: 'gitlab'
......
...@@ -79,7 +79,16 @@ module API ...@@ -79,7 +79,16 @@ module API
end end
class RepoObject < Grape::Entity class RepoObject < Grape::Entity
expose :name, :commit expose :name
expose :commit do |repo_obj, options|
if repo_obj.respond_to?(:commit)
repo_obj.commit
elsif options[:project]
options[:project].repository.commit(repo_obj.target)
end
end
expose :protected do |repo, options| expose :protected do |repo, options|
if options[:project] if options[:project]
options[:project].protected_branch? repo.name options[:project].protected_branch? repo.name
...@@ -87,6 +96,16 @@ module API ...@@ -87,6 +96,16 @@ module API
end end
end end
class RepoTreeObject < Grape::Entity
expose :id, :name, :type
expose :mode do |obj, options|
filemode = obj.mode.to_s(8)
filemode = "0" + filemode if filemode.length < 6
filemode
end
end
class RepoCommit < Grape::Entity class RepoCommit < Grape::Entity
expose :id, :short_id, :title, :author_name, :author_email, :created_at expose :id, :short_id, :title, :author_name, :author_email, :created_at
end end
......
...@@ -82,7 +82,7 @@ module API ...@@ -82,7 +82,7 @@ module API
# Example Request: # Example Request:
# GET /projects/:id/repository/tags # GET /projects/:id/repository/tags
get ":id/repository/tags" do get ":id/repository/tags" do
present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject, project: user_project
end end
# Get a project repository commits # Get a project repository commits
...@@ -141,15 +141,9 @@ module API ...@@ -141,15 +141,9 @@ module API
path = params[:path] || nil path = params[:path] || nil
commit = user_project.repository.commit(ref) commit = user_project.repository.commit(ref)
tree = Tree.new(user_project.repository, commit.id, path) tree = user_project.repository.tree(commit.id, path)
trees = [] present tree.sorted_entries, with: Entities::RepoTreeObject
%w(trees blobs submodules).each do |type|
trees += tree.send(type).map { |t| {name: t.name, type: type.singularize, mode: t.mode, id: t.id} }
end
trees
end end
# Get a raw file contents # Get a raw file contents
...@@ -233,4 +227,3 @@ module API ...@@ -233,4 +227,3 @@ module API
end end
end end
end end
...@@ -117,7 +117,7 @@ module ExtractsPath ...@@ -117,7 +117,7 @@ module ExtractsPath
end end
def tree def tree
@tree ||= Tree.new(@repo, @commit.id, @path) @tree ||= @repo.tree(@commit.id, @path)
end end
private private
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment