Skip to content

Commit aebcff0

Browse files
start work on implementing new mirror push strategy
1 parent 2c8a246 commit aebcff0

File tree

3 files changed

+7
-41
lines changed

3 files changed

+7
-41
lines changed

app/controllers/repository_mirrors_controller.rb

+7-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def create
2525
@mirror.project = @project
2626

2727
if @mirror.save
28-
GitHosting.git_mirror_identity_file(@mirror)
2928
respond_to do |format|
3029
format.html {
3130
redirect_to(
@@ -53,7 +52,6 @@ def edit
5352
def update
5453
respond_to do |format|
5554
if @mirror.update_attributes(params[:repository_mirrors])
56-
GitHosting.git_mirror_identity_file(@mirror)
5755
format.html {
5856
redirect_to(
5957
url_for(
@@ -78,7 +76,6 @@ def destroy
7876
# display confirmation view
7977
else
8078
if params[:confirm]
81-
identify_file = GitHosting.git_mirror_identity_file(@mirror)
8279
%x[#{git_user_runner} rm #{identify_file}]
8380
redirect_url = url_for(
8481
:controller => 'projects',
@@ -100,13 +97,13 @@ def settings
10097
def push
10198
respond_to do |format|
10299
format.html {
103-
@shellout = %x{ export GIT_MIRROR_IDENTITY_FILE=#{GitHosting.git_mirror_identity_file(@mirror)}; export GIT_SSH='#{GitHosting.git_exec_mirror}'; #{GitHosting.git_exec} --git-dir='#{GitHosting.repository_path(@project)}.git' push --mirror '#{@mirror.url}' 2>&1 }
104-
@push_failed = ($?.to_i!=0) ? true : false
105-
if @push_failed
106-
ms = " #{@mirror.url} push error "
107-
nr = (70-ms.length)/2
108-
GitHosting.logger.debug "Failed:\n%{nrs} #{ms} %{nrs}\n#{@shellout}%{nre} #{ms} %{nre}\n" % {:nrs => ">"*nr, :nre => "<"*nr}
109-
end
100+
#@shellout = %x{ export GIT_MIRROR_IDENTITY_FILE=#{GitHosting.git_mirror_identity_file(@mirror)}; export GIT_SSH='#{GitHosting.git_exec_mirror}'; #{GitHosting.git_exec} --git-dir='#{GitHosting.repository_path(@project)}.git' push --mirror '#{@mirror.url}' 2>&1 }
101+
#@push_failed = ($?.to_i!=0) ? true : false
102+
#if @push_failed
103+
# ms = " #{@mirror.url} push error "
104+
# nr = (70-ms.length)/2
105+
# GitHosting.logger.debug "Failed:\n%{nrs} #{ms} %{nrs}\n#{@shellout}%{nre} #{ms} %{nre}\n" % {:nrs => ">"*nr, :nre => "<"*nr}
106+
#end
110107
}
111108
end
112109
end

app/views/repository_mirrors/_form.html.erb

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
<div class="box">
44
<!--[form:repository_mirrors]-->
55
<p><%= f.text_field :url, :required => true, :size => 65 %></p>
6-
<p>
7-
<%= f.text_area :private_key, :required => true, :rows => 10, :cols => 65 %><br/>
8-
<label>&nbsp;</label>
9-
<span style="color: red; font-weight: bold;"><%= l(:field_private_key_warning) %></span>
10-
</p>
116
<p><%= f.check_box :active %></p>
127
</div>
138
<!--[eoform:repository_mirrors]-->

lib/git_hosting.rb

-26
Original file line numberDiff line numberDiff line change
@@ -185,29 +185,6 @@ def self.git_exec_mirror
185185
return git_exec_mirror_path()
186186
end
187187

188-
def self.git_mirror_identity_file(mirror)
189-
identity_file_path = File.join(get_mirror_identities_dir(), mirror.to_s)
190-
if !File.exists?(identity_file_path)
191-
if git_user == web_user
192-
File.open(identity_file_path, "w") do |f|
193-
f.puts "#{mirror.private_key}"
194-
end
195-
%x[chmod 0600 #{identity_file_path}]
196-
else
197-
file = Tempfile.new('')
198-
begin
199-
file.write(mirror.private_key)
200-
file.close
201-
%x[#{git_user_runner} 'sudo -nu #{web_user} cat #{file.path} | cat - > #{identity_file_path}']
202-
%x[#{git_user_runner} 'chmod 0600 #{identity_file_path}']
203-
ensure
204-
file.unlink
205-
end
206-
end
207-
end
208-
return identity_file_path
209-
end
210-
211188
def self.update_git_exec
212189
logger.info "Setting up #{get_tmp_dir()}"
213190
gitolite_key=Setting.plugin_redmine_git_hosting['gitoliteAdminPrivateKey']
@@ -302,9 +279,6 @@ def self.update_git_exec
302279
%x[#{git_user_runner} 'sudo -u #{web_user} chown #{web_user}:#{git_user} #{git_exec_mirror_path()}']
303280
end
304281

305-
RepositoryMirror.find(:all, :order => 'active DESC, created_at ASC', :conditions => "active=1").each {|mirror|
306-
git_mirror_identity_file(mirror)
307-
}
308282
end
309283

310284
def self.clone_or_pull_gitolite_admin

0 commit comments

Comments
 (0)