public
Fork of chad/gitjour
Description: Serve git and advertise with bonjour
Homepage: http://rubyforge.org/projects/gitjour
Clone URL: git://github.com/alexvollmer/gitjour.git
First pass at browsing for instaweb repositories.
alexvollmer (author)
Wed Jun 04 21:45:47 -0700 2008
commit  38c1327ef70294b65b8269deb9bbe9e208e7e590
tree    c1eb43eb713292ac87905063f28cea3ffb84b568
parent  63b554e23ade90b8960b7499456644e932524d79
...
1
2
3
 
4
5
6
...
23
24
25
 
 
26
27
28
...
30
31
32
33
 
34
35
36
...
154
155
156
157
 
158
159
160
 
161
162
163
...
179
180
181
182
 
183
184
185
...
189
190
191
192
 
193
194
 
195
196
197
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
200
201
...
1
2
3
4
5
6
7
...
24
25
26
27
28
29
30
31
...
33
34
35
 
36
37
38
39
...
157
158
159
 
160
161
162
 
163
164
165
166
...
182
183
184
 
185
186
187
188
...
192
193
194
 
195
196
 
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
0
@@ -1,6 +1,7 @@
0
 require 'rubygems'
0
 require 'dnssd'
0
 require 'set'
0
+require 'webrick'
0
 require 'gitjour/version'
0
 
0
 Thread.abort_on_exception = true
0
@@ -23,6 +24,8 @@ module Gitjour
0
             remote(*args);
0
           when "web"
0
             web(*args)
0
+ when "browse"
0
+ browse(*args)
0
           else
0
             help
0
         end
0
@@ -30,7 +33,7 @@ module Gitjour
0
 
0
       private
0
       def list
0
- service_list.each do |service|
0
+ service_list("_git._tcp").each do |service|
0
           puts "=== #{service.name} on #{service.host}:#{service.port} ==="
0
           puts " gitjour clone #{service.name}"
0
           if service.description != '' && service.description !~ /^Unnamed repository/
0
@@ -154,10 +157,10 @@ module Gitjour
0
 
0
       class Done < RuntimeError; end
0
 
0
- def discover(timeout=5)
0
+ def discover(type, timeout=5)
0
         waiting_thread = Thread.current
0
 
0
- dns = DNSSD.browse "_git._tcp" do |reply|
0
+ dns = DNSSD.browse type do |reply|
0
           DNSSD.resolve reply.name, reply.type, reply.domain do |resolve_reply|
0
             service = GitService.new(reply.name,
0
                                      resolve_reply.target,
0
@@ -179,7 +182,7 @@ module Gitjour
0
       def locate_repo(name)
0
         found = nil
0
 
0
- discover do |obj|
0
+ discover("_git._tcp") do |obj|
0
           if obj.name == name
0
             found = obj
0
             raise Done
0
@@ -189,13 +192,38 @@ module Gitjour
0
         return found
0
       end
0
 
0
- def service_list
0
+ def service_list(type)
0
         list = Set.new
0
- discover { |obj| list << obj }
0
+ discover(type) { |obj| list << obj }
0
 
0
         return list
0
       end
0
 
0
+ def browse(*args)
0
+ http = WEBrick::HTTPServer.new(:Port => 9850)
0
+ http.mount_proc("/") do |req, res|
0
+ res['Content-Type'] = 'text/html'
0
+ res.body = <<-HTML
0
+<html>
0
+ <body>
0
+ <h1>Browseable Git Repositories</h1>
0
+ <ul>
0
+ #{http_services.map do |s|
0
+ "<li><a href='http://#{s.host}:#{s.port}'>#{s.name}</a></li>"
0
+ end}
0
+ </ul>
0
+ </body>
0
+</html>
0
+HTML
0
+ end
0
+ trap("INT") { http.shutdown }
0
+ http.start
0
+ end
0
+
0
+ def http_services
0
+ service_list("_http._tcp").select { |s| s.name =~ /-gitjour$/ }
0
+ end
0
+
0
       def announce_git(path, name, port)
0
         announce_repo(path, name, port, "_git._tcp")
0
       end

Comments

    No one has commented yet.