Skip to content

Commit 10652d0

Browse files
author
root
committed
Bypass Cache if git_cache_id is nil
1 parent 2325ba7 commit 10652d0

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

Diff for: lib/redmine_git_hosting/patches/git_adapter_patch.rb

+15-7
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,23 @@ def git_cmd_with_git_hosting(args, options = {}, &block)
4747

4848
cmd_str = full_args.map { |e| shell_quote e.to_s }.join(' ')
4949

50-
RedmineGitolite::GitHosting.logger.debug { "Send GitCommand : #{cmd_str}" }
51-
5250
# Compute string from repo_path that should be same as: repo.git_cache_id
5351
# If only we had access to the repo (we don't).
54-
repo_id = Repository::Git.repo_path_to_git_cache_id(repo_path)
55-
56-
# Insert cache between shell execution and caller
57-
# repo_path argument used to identify cache entries
58-
RedmineGitolite::Cache.execute(cmd_str, repo_id, options, &block)
52+
RedmineGitolite::GitHosting.logger.debug { "Lookup for git_cache_id with repository path '#{repo_path}' ... " }
53+
54+
git_cache_id = Repository::Git.repo_path_to_git_cache_id(repo_path)
55+
56+
if !git_cache_id.nil?
57+
# Insert cache between shell execution and caller
58+
# repo_path argument used to identify cache entries
59+
RedmineGitolite::GitHosting.logger.debug { "Found git_cache_id ('#{git_cache_id}'), call cache... " }
60+
RedmineGitolite::GitHosting.logger.debug { "Send GitCommand : #{cmd_str}" }
61+
RedmineGitolite::Cache.execute(cmd_str, git_cache_id, options, &block)
62+
else
63+
RedmineGitolite::GitHosting.logger.debug { "Unable to find git_cache_id, bypass cache... " }
64+
RedmineGitolite::GitHosting.logger.debug { "Send GitCommand : #{cmd_str}" }
65+
Redmine::Scm::Adapters::AbstractAdapter.shellout(cmd_str, options, &block)
66+
end
5967
end
6068

6169
end

Diff for: lib/redmine_git_hosting/patches/repository_git_patch.rb

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def repo_path_to_git_cache_id(repo_path)
4949
return @@cached_id if @@cached_path == repo_path
5050

5151
repo = Repository::Git.find_by_path(repo_path, :loose => true)
52+
5253
if repo
5354
# Cache translated id path, return id
5455
@@cached_path = repo_path

Diff for: lib/redmine_gitolite/cache.rb

+5-9
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,17 @@ def self.logger
3232
# Primary interface: execute given command and send IO to block
3333
# options[:write_stdin] will derive caching key from data that block writes to io stream
3434
def self.execute(cmd_str, repo_id, options = {}, &block)
35-
if repo_id.nil?
36-
logger.error { "repo_id is nil, exit!" }
37-
return false
38-
end
39-
4035
if max_cache_time == 0 || options[:uncached]
4136
# Disabled cache, simply launch shell, don't redirect
4237
logger.warn { "Cache is disabled : '#{repo_id}'" }
4338
options.delete(:uncached)
44-
retio = options.empty? ? Redmine::Scm::Adapters::AbstractAdapter.shellout(cmd_str, &block) : Redmine::Scm::Adapters::AbstractAdapter.shellout(cmd_str, options, &block)
39+
retio = Redmine::Scm::Adapters::AbstractAdapter.shellout(cmd_str, options, &block)
4540
status = $?
4641
elsif !options[:write_stdin] && out = self.check_cache(cmd_str)
4742
# Simple case -- have cached result that depends only on cmd_str
4843
block.call(out)
49-
status = nil
5044
retio = out
45+
status = nil
5146
else
5247
# Create redirector stream and call block
5348
redirector = self.new(cmd_str, repo_id, options)
@@ -56,9 +51,10 @@ def self.execute(cmd_str, repo_id, options = {}, &block)
5651
end
5752

5853
if status && status.exitstatus.to_i != 0
59-
logger.error { "Git exited with non-zero status : #{$?.exitstatus}" }
60-
raise Redmine::Scm::Adapters::GitAdapter::ScmCommandAborted, "Git exited with non-zero status : #{$?.exitstatus}"
54+
logger.error { "Git exited with non-zero status : #{status.exitstatus}" }
55+
raise Redmine::Scm::Adapters::GitAdapter::ScmCommandAborted, "Git exited with non-zero status : #{status.exitstatus}"
6156
end
57+
6258
return retio
6359
end
6460

0 commit comments

Comments
 (0)