Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
Accept REPO_URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Nov 8, 2012
1 parent 28d2974 commit dbaec81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/receiver
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
require "puma"
require "sokoban/receiver"

s = Puma::Server.new(Sokoban::Receiver.new)
s = Puma::Server.new(Sokoban::Receiver.new(ENV["REPO_URL"]))
s.add_tcp_listener("localhost", (ENV["PORT"] || 5000))
s.run.join
15 changes: 10 additions & 5 deletions lib/sokoban/receiver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ class Receiver
["GET", 'get_idx_file', /(.*?)\/objects\/pack\/pack-[0-9a-f]{40}\\.idx$/],
]

def initialize(repo_dir)
@git_dir = repo_dir
def initialize(repo_url)
bundle = File.join("/tmp", "repo.bundle")
@repo_dir = File.join("/tmp", "repo.git")

system("curl --retry 3 --max-time 90 #{repo_url} > #{bundle}")
system("git bundle verify #{bundle}") or raise "Corrupt repo."
system("git clone --bare #{bundle} #{@repo_dir}")
end

def call(env)
Expand All @@ -35,7 +40,7 @@ def call(env)
return render_method_not_allowed if cmd == :not_allowed
return render_not_found if !cmd

Dir.chdir(@git_dir) do
Dir.chdir(@repo_dir) do
self.send(cmd.to_sym)
end
end
Expand All @@ -52,7 +57,7 @@ def service_rpc
@res.status = 200
@res["Content-Type"] = "application/x-git-%s-result" % @rpc
@res.finish do
command = "git #{@rpc} --stateless-rpc #{@git_dir}"
command = "git #{@rpc} --stateless-rpc #{@repo_dir}"
IO.popen(command, File::RDWR) do |pipe|
pipe.write(input)
while !pipe.eof?
Expand Down Expand Up @@ -128,7 +133,7 @@ def get_text_file

# some of this borrowed from the Rack::File implementation
def send_file(reqfile, content_type)
reqfile = File.join(@git_dir, reqfile)
reqfile = File.join(@repo_dir, reqfile)
return render_not_found if !F.exists?(reqfile)

@res = Rack::Response.new
Expand Down

0 comments on commit dbaec81

Please sign in to comment.