From c21ae07e331ca14605410555d0582f14cb661bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Tue, 25 Jul 2017 16:48:17 -0400 Subject: Refactor Gitlab::Git::Commit to include a repository --- app/models/commit.rb | 3 ++- app/models/merge_request_diff.rb | 4 +--- app/models/repository.rb | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/commit.rb b/app/models/commit.rb index 7940733f557..96605c9168b 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -55,7 +55,8 @@ class Commit end def from_hash(hash, project) - new(Gitlab::Git::Commit.new(hash), project) + raw_commit = Gitlab::Git::Commit.new(project.repository.raw, hash) + new(raw_commit, project) end def valid_hash?(key) diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index d9d746ccf41..58050e1f438 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -282,9 +282,7 @@ class MergeRequestDiff < ActiveRecord::Base def load_commits commits = st_commits.presence || merge_request_diff_commits - commits.map do |commit| - Commit.new(Gitlab::Git::Commit.new(commit.to_hash), merge_request.source_project) - end + commits.map { |commit| Commit.from_hash(commit.to_hash, project) } end def save_diffs diff --git a/app/models/repository.rb b/app/models/repository.rb index f86a0869b01..3045db06af1 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -64,6 +64,8 @@ class Repository @raw_repository ||= initialize_raw_repository end + alias_method :raw, :raw_repository + # Return absolute path to repository def path_to_repo @path_to_repo ||= File.expand_path( -- cgit v1.2.1 From e363fbf71a7874de2352740b3f33350e5ec4cf54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Tue, 25 Jul 2017 17:26:52 -0400 Subject: Move `deltas` and `diff_from_parents` logic to Gitlab::Git::Commit This helps keep the abstraction layers simpler, and also keep the interface of those methods consistent, in case of implementation changes. --- app/models/commit.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'app/models') diff --git a/app/models/commit.rb b/app/models/commit.rb index 96605c9168b..638fddc5d3d 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -321,21 +321,11 @@ class Commit end def raw_diffs(*args) - if Gitlab::GitalyClient.feature_enabled?(:commit_raw_diffs) - Gitlab::GitalyClient::CommitService.new(project.repository).diff_from_parent(self, *args) - else - raw.diffs(*args) - end + raw.diffs(*args) end def raw_deltas - @deltas ||= Gitlab::GitalyClient.migrate(:commit_deltas) do |is_enabled| - if is_enabled - Gitlab::GitalyClient::CommitService.new(project.repository).commit_deltas(self) - else - raw.deltas - end - end + @deltas ||= raw.deltas end def diffs(diff_options = nil) -- cgit v1.2.1 From 3ce6f03f1437633c9328dc30aa5272a49368655b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Tue, 25 Jul 2017 17:33:06 -0400 Subject: Incorporate Gitaly's CommitService.FindCommit RPC --- app/models/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/repository.rb b/app/models/repository.rb index 3045db06af1..bd9adeaf613 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -769,7 +769,7 @@ class Repository index = Gitlab::Git::Index.new(raw_repository) if start_commit - index.read_tree(start_commit.raw_commit.tree) + index.read_tree(start_commit.rugged_commit.tree) parents = [start_commit.sha] else parents = [] -- cgit v1.2.1