summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/refs_controller.rb2
-rw-r--r--app/models/merge_request.rb30
-rw-r--r--app/models/tree.rb32
-rw-r--r--app/services/git_push_service.rb2
-rw-r--r--app/views/commits/_diffs.html.haml2
5 files changed, 23 insertions, 45 deletions
diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb
index eb8d1e19616..c67912b97a6 100644
--- a/app/controllers/refs_controller.rb
+++ b/app/controllers/refs_controller.rb
@@ -48,7 +48,7 @@ class RefsController < ProjectResourceController
@repo = project.repository
@commit = @repo.commit(@ref)
- @tree = Tree.new(@commit.tree, @ref, params[:path])
+ @tree = Tree.new(@repo, @commit.id, @ref, params[:path])
@hex_path = Digest::SHA1.hexdigest(params[:path] || "")
if params[:path]
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 6ce944173cd..0bab88313c1 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -152,17 +152,7 @@ class MergeRequest < ActiveRecord::Base
end
def commits
- if st_commits.present?
- # check if merge request commits are valid
- if st_commits.first.respond_to?(:short_id)
- st_commits
- else
- # if commits are invalid - simply reload it from repo
- reloaded_commits
- end
- else
- []
- end
+ load_commits(st_commits) || []
end
def probably_merged?
@@ -172,13 +162,7 @@ class MergeRequest < ActiveRecord::Base
def reloaded_commits
if opened? && unmerged_commits.any?
- # we need to reset st_commits field first
- # in order to prevent internal rails comparison
- self.st_commits = []
- save
-
- # Then we can safely write unmerged commits
- self.st_commits = unmerged_commits
+ self.st_commits = dump_commits(unmerged_commits)
save
end
commits
@@ -228,4 +212,14 @@ class MergeRequest < ActiveRecord::Base
def last_commit_short_sha
@last_commit_short_sha ||= last_commit.sha[0..10]
end
+
+ private
+
+ def dump_commits(commits)
+ commits.map(&:to_hash)
+ end
+
+ def load_commits(array)
+ array.map { |hash| Commit.new(Gitlab::Git::Commit.new(hash)) }
+ end
end
diff --git a/app/models/tree.rb b/app/models/tree.rb
index 4b6c5b133e9..e726c596f7e 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -1,37 +1,21 @@
class Tree
- include Linguist::BlobHelper
-
attr_accessor :path, :tree, :ref
- delegate :contents, :basename, :name, :data, :mime_type,
- :mode, :size, :text?, :colorize, to: :tree
-
- def initialize(raw_tree, ref = nil, path = nil)
- @ref, @path = ref, path
- @tree = if path.present?
- raw_tree / path
- else
- raw_tree
- end
- end
-
- def is_blob?
- tree.is_a?(Grit::Blob)
+ def initialize(repository, sha, ref = nil, path = nil)
+ @raw = Gitlab::Git::Tree.new(repository, sha, ref, path)
end
def invalid?
- tree.nil?
+ @raw.nil?
end
- def empty?
- data.blank?
+ def method_missing(m, *args, &block)
+ @raw.send(m, *args, &block)
end
- def up_dir?
- path.present?
- end
+ def respond_to?(method)
+ return true if @raw.respond_to?(method)
- def readme
- @readme ||= contents.find { |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i }
+ super
end
end
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb
index 383e6398b74..e8b32f52ce1 100644
--- a/app/services/git_push_service.rb
+++ b/app/services/git_push_service.rb
@@ -104,7 +104,7 @@ class GitPushService
data[:commits] << {
id: commit.id,
message: commit.safe_message,
- timestamp: commit.date.xmlschema,
+ timestamp: commit.committed_date.xmlschema,
url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/commit/#{commit.id}",
author: {
name: commit.author_name,
diff --git a/app/views/commits/_diffs.html.haml b/app/views/commits/_diffs.html.haml
index b2da4796db6..9d57edb1d97 100644
--- a/app/views/commits/_diffs.html.haml
+++ b/app/views/commits/_diffs.html.haml
@@ -16,7 +16,7 @@
- unless @suppress_diff
- diffs.each_with_index do |diff, i|
- next if diff.diff.empty?
- - file = (@commit.tree / diff.new_path)
+ - file = Tree.new(@repository, @commit.id, @ref, diff.new_path)
- file = (@commit.prev_commit.tree / diff.old_path) unless file
- next unless file
.file{id: "diff-#{i}"}