Skip to content

Commit 753b70b

Browse files
author
root
committed
Refactor a little, add rake task to check repositories identifier uniqueness
1 parent c33d7ce commit 753b70b

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ def repo_ident_unique?
3838
end
3939

4040

41+
def have_duplicated_identifier?
42+
if ((self.all.map(&:identifier).inject(Hash.new(0)) do |h, x|
43+
h[x] += 1 unless x.blank?
44+
h
45+
end.values.max) || 0) > 1
46+
# Oops -- have duplication
47+
return true
48+
else
49+
return false
50+
end
51+
end
52+
53+
4154
# Translate repository path into a unique ID for use in caching of git commands.
4255
#
4356
# We perform caching here to speed this up, since this function gets called

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

+5-11
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,18 @@ def save_git_hosting_values
177177

178178
# Check to see if we are trying to claim all repository identifiers are unique
179179
if valuehash[:unique_repo_identifier] == 'true'
180-
if ((Repository.all.map(&:identifier).inject(Hash.new(0)) do |h,x|
181-
h[x]+=1 unless x.blank?
182-
h
183-
end.values.max) || 0) > 1
180+
if Repository::Git.have_duplicated_identifier?
184181
# Oops -- have duplication. Force to false.
185-
RedmineGitolite::GitHosting.logger.error { "Detected non-unique repository identifiers. Setting unique_repo_identifier => 'false'" }
182+
RedmineGitolite::GitHosting.logger.error { "Detected non-unique repository identifiers. Cannot switch to unique_repo_identifier, setting unique_repo_identifier => 'false'" }
186183
valuehash[:unique_repo_identifier] = 'false'
187184
end
188185
end
189186

190187

191188
if @@old_valuehash[:hierarchical_organisation] == 'true' && valuehash[:hierarchical_organisation] == 'false'
192-
if ((Repository.all.map(&:identifier).inject(Hash.new(0)) do |h,x|
193-
h[x]+=1 unless x.blank?
194-
h
195-
end.values.max) || 0) > 1
196-
# Oops -- have duplication. Force to false.
197-
RedmineGitolite::GitHosting.logger.error { "Detected non-unique repository identifiers. Setting hierarchical_organisation => 'false'" }
189+
if Repository::Git.have_duplicated_identifier?
190+
# Oops -- have duplication. Force to true.
191+
RedmineGitolite::GitHosting.logger.error { "Detected non-unique repository identifiers. Cannot switch to flat mode, setting hierarchical_organisation => 'true'" }
198192
valuehash[:hierarchical_organisation] = 'true'
199193
end
200194
end

Diff for: lib/tasks/redmine_git_hosting.rake

+18
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ namespace :redmine_git_hosting do
6666
puts "Done!"
6767
end
6868

69+
6970
desc "Update/repair Gitolite configuration"
7071
task :update_repositories => [:environment] do
7172
puts "Performing manual update_repositories operation..."
@@ -80,6 +81,7 @@ namespace :redmine_git_hosting do
8081
puts "Done!"
8182
end
8283

84+
8385
desc "Fetch commits from gitolite repositories/update gitolite configuration"
8486
task :fetch_changesets => [:environment] do
8587
puts "Performing manual fetch_changesets operation..."
@@ -88,6 +90,21 @@ namespace :redmine_git_hosting do
8890
puts "Done!"
8991
end
9092

93+
94+
desc "Check repositories identifier uniqueness"
95+
task :check_repository_uniqueness => [:environment] do
96+
puts "Checking repositories identifier uniqueness..."
97+
if Repository::Git.have_duplicated_identifier?
98+
# Oops -- have duplication.
99+
RedmineGitolite::GitHosting.logger.error { "Detected non-unique repository identifiers!" }
100+
puts "Detected non-unique repository identifiers!"
101+
else
102+
puts "pass!"
103+
end
104+
puts "Done!"
105+
end
106+
107+
91108
desc "Install redmine_git_hosting scripts"
92109
task :install_scripts do |t,args|
93110
if !ENV["READ_ONLY"]
@@ -96,6 +113,7 @@ namespace :redmine_git_hosting do
96113
Rake::Task["selinux:redmine_git_hosting:install_scripts"].invoke
97114
end
98115

116+
99117
desc "Remove redmine_git_hosting scripts"
100118
task :remove_scripts do
101119
Rake::Task["selinux:redmine_git_hosting:remove_scripts"].invoke

0 commit comments

Comments
 (0)