GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of chad/gitjour
Description: Serve git and advertise with bonjour
Homepage: http://rubyforge.org/projects/gitjour
Clone URL: git://github.com/wilson/gitjour.git
Remove ridiculous newbie shit
wilson (author)
Sat Aug 23 18:37:16 -0700 2008
commit  3f1d70e473785b093a63b77b07d387acbc45c3d1
tree    78a486cc725ffd15c99d2ff12f0a711373978456
parent  465921a6518d34b3d34d3ae0b3dd30493b054bf5
  • License.txt
  • Manifest.txt
  • README.txt
  • Rakefile
  • config/hoe.rb
  • config/requirements.rb
  • lib/gitjour.rb
  • lib/gitjour/application.rb
  • lib/gitjour/version.rb
  • log/debug.log
  • script/destroy
  • script/generate
  • script/txt2html
  • setup.rb
  • tasks/deployment.rake
  • tasks/environment.rake
  • tasks/website.rake
  • website/index.html
  • website/index.txt
  • website/javascripts/rounded_corners_lite.inc.js
  • website/stylesheets/screen.css
  • website/template.rhtml
...
1
2
3
4
5
6
7
8
 
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
 
1
 
2
3
4
 
 
5
6
 
 
 
 
 
 
 
 
 
7
8
 
 
 
 
 
0
@@ -1,25 +1,8 @@
0
-bin/gitjour
0
 History.txt
0
-License.txt
0
 Manifest.txt
0
 README.txt
0
 Rakefile
0
-config/hoe.rb
0
-config/requirements.rb
0
+bin/gitjour
0
 lib/gitjour.rb
0
-lib/gitjour/application.rb
0
-lib/gitjour/version.rb
0
-script/destroy
0
-script/generate
0
-script/txt2html
0
-setup.rb
0
-tasks/deployment.rake
0
-tasks/environment.rake
0
-tasks/website.rake
0
 test/test_gitjour.rb
0
 test/test_helper.rb
0
-website/index.html
0
-website/index.txt
0
-website/javascripts/rounded_corners_lite.inc.js
0
-website/stylesheets/screen.css
0
-website/template.rhtml
...
1
 
2
3
 
4
5
 
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
 
1
2
 
3
4
 
5
6
 
 
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
0
@@ -1,8 +1,49 @@
0
-README
0
+= gitjour
0
 
0
-DEVELOPMENT
0
+* http://github.com/chad/gitjour
0
 
0
-How to test from the console:
0
+== DESCRIPTION:
0
 
0
-irb -r 'lib/gitjour/application'
0
-> Gitjour::Application.run "list"
0
+Automates DNSSD-powered serving and cloning of git repositories.
0
+
0
+== FEATURES/PROBLEMS:
0
+
0
+* As needed
0
+
0
+== SYNOPSIS:
0
+
0
+ % gitjour serve project_dir [name_to_advertise_as]
0
+ % gitjour list
0
+
0
+== REQUIREMENTS:
0
+
0
+* dnssd
0
+
0
+== INSTALL:
0
+
0
+* sudo gem install gitjour
0
+
0
+== LICENSE:
0
+
0
+(The MIT License)
0
+
0
+Copyright (c) 2008 Chad Fowler, Evan Phoenix, and Rich Kilmer
0
+
0
+Permission is hereby granted, free of charge, to any person obtaining
0
+a copy of this software and associated documentation files (the
0
+'Software'), to deal in the Software without restriction, including
0
+without limitation the rights to use, copy, modify, merge, publish,
0
+distribute, sublicense, and/or sell copies of the Software, and to
0
+permit persons to whom the Software is furnished to do so, subject to
0
+the following conditions:
0
+
0
+The above copyright notice and this permission notice shall be
0
+included in all copies or substantial portions of the Software.
0
+
0
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
0
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
0
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
0
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
0
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
...
1
2
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1,4 +1,14 @@
0
-require 'config/requirements'
0
-require 'config/hoe' # setup Hoe + all gem configuration
0
-
0
-Dir['tasks/**/*.rake'].each { |rake| load rake }
0
\ No newline at end of file
0
+# -*- ruby -*-
0
+
0
+require 'rubygems'
0
+require 'hoe'
0
+require './lib/gitjour.rb'
0
+
0
+Hoe.new('gitjour', Gitjour::VERSION) do |p|
0
+ p.extra_deps = ['dnssd']
0
+ p.developer('Chad Fowler', 'chad@chadfowler.com')
0
+ p.developer('Evan Phoenix', 'evan@fallingsnow.net')
0
+ p.developer('Rich Kilmer', 'rich@example.com')
0
+end
0
+
0
+# vim: syntax=Ruby
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
0
@@ -1 +1,183 @@
0
-require 'gitjour/application'
0
+require 'rubygems'
0
+require 'dnssd'
0
+require 'set'
0
+
0
+Thread.abort_on_exception = true
0
+
0
+module Gitjour
0
+ VERSION = "6.3.0"
0
+ GitService = Struct.new(:name, :host, :port, :description)
0
+
0
+ class Application
0
+
0
+ class << self
0
+ def run(*args)
0
+ case args.shift
0
+ when "list"
0
+ list
0
+ when "clone"
0
+ clone(*args)
0
+ when "serve"
0
+ serve(*args)
0
+ when "remote"
0
+ remote(*args)
0
+ else
0
+ help
0
+ end
0
+ end
0
+
0
+ private
0
+ def list
0
+ service_list.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
+ puts " #{service.description}"
0
+ end
0
+ puts
0
+ end
0
+ end
0
+
0
+ def clone(repository_name, *rest)
0
+ dir = rest.shift || repository_name
0
+ if File.exists?(dir)
0
+ exit_with! "ERROR: Clone directory '#{dir}' already exists."
0
+ end
0
+
0
+ puts "Cloning '#{repository_name}' into directory '#{dir}'..."
0
+
0
+ unless service = locate_repo(repository_name)
0
+ exit_with! "ERROR: Unable to find project named '#{repository_name}'"
0
+ end
0
+
0
+ puts "Connecting to #{service.host}:#{service.port}"
0
+
0
+ system "git clone git://#{service.host}:#{service.port}/ #{dir}/"
0
+ end
0
+
0
+ def remote(repository_name, *rest)
0
+ dir = rest.shift || repository_name
0
+ service = locate_repo repository_name
0
+ system "git remote add #{dir} git://#{service.host}:#{service.port}/"
0
+ end
0
+
0
+ def serve(path=Dir.pwd, *rest)
0
+ path = File.expand_path(path)
0
+ name = rest.shift || File.basename(path)
0
+ port = rest.shift || 9418
0
+
0
+ # If the name starts with ^, then don't apply the prefix
0
+ if name[0] == ?^
0
+ name = name[1..-1]
0
+ else
0
+ prefix = `git config --get gitjour.prefix`.chomp
0
+ prefix = ENV["USER"] if prefix.empty?
0
+ name = [prefix, name].compact.join("-")
0
+ end
0
+
0
+ if File.exists?("#{path}/.git")
0
+ announce_repo(path, name, port.to_i)
0
+ else
0
+ Dir["#{path}/*"].each do |dir|
0
+ if File.directory?(dir)
0
+ name = File.basename(dir)
0
+ announce_repo(dir, name, 9418)
0
+ end
0
+ end
0
+ end
0
+
0
+ `git-daemon --verbose --export-all --port=#{port} --base-path=#{path} --base-path-relaxed`
0
+ end
0
+
0
+ def help
0
+ puts "Gitjour #{Gitjour::VERSION::STRING}"
0
+ puts "Serve up and use git repositories via Bonjour/DNSSD."
0
+ puts "\nUsage: gitjour <command> [args]"
0
+ puts
0
+ puts " list"
0
+ puts " Lists available repositories."
0
+ puts
0
+ puts " clone <project> [<directory>]"
0
+ puts " Clone a gitjour served repository."
0
+ puts
0
+ puts " serve <path_to_project> [<name_of_project>] [<port>] or"
0
+ puts " <path_to_projects>"
0
+ puts " Serve up the current directory or projects via gitjour."
0
+ puts
0
+ puts " The name of your project is automatically prefixed with"
0
+ puts " `git config --get gitjour.prefix` or your username (preference"
0
+ puts " in that order). If you don't want a prefix, put a ^ on the front"
0
+ puts " of the name_of_project (the ^ is removed before announcing)."
0
+ puts
0
+ puts " remote <project> [<name>]"
0
+ puts " Add a Bonjour remote into your current repository."
0
+ puts " Optionally pass name to not use pwd."
0
+ puts
0
+ end
0
+
0
+ def exit_with!(message)
0
+ STDERR.puts message
0
+ exit!
0
+ end
0
+
0
+ class Done < RuntimeError; end
0
+
0
+ def discover(timeout=5)
0
+ waiting_thread = Thread.current
0
+
0
+ dns = DNSSD.browse "_git._tcp" 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
+ resolve_reply.port,
0
+ resolve_reply.text_record['description'].to_s)
0
+ begin
0
+ yield service
0
+ rescue Done
0
+ waiting_thread.run
0
+ end
0
+ end
0
+ end
0
+
0
+ puts "Gathering for up to #{timeout} seconds..."
0
+ sleep timeout
0
+ dns.stop
0
+ end
0
+
0
+ def locate_repo(name)
0
+ found = nil
0
+
0
+ discover do |obj|
0
+ if obj.name == name
0
+ found = obj
0
+ raise Done
0
+ end
0
+ end
0
+
0
+ return found
0
+ end
0
+
0
+ def service_list
0
+ list = Set.new
0
+ discover { |obj| list << obj }
0
+
0
+ return list
0
+ end
0
+
0
+ def announce_repo(path, name, port)
0
+ return unless File.exists?("#{path}/.git")
0
+
0
+ tr = DNSSD::TextRecord.new
0
+ tr['description'] = File.read("#{path}/.git/description") rescue "a git project"
0
+
0
+ DNSSD.register(name, "_git._tcp", 'local', port, tr.encode) do |rr|
0
+ puts "Registered #{name} on port #{port}. Starting service."
0
+ end
0
+ end
0
+
0
+ end
0
+ end
0
+end
0
+
0
+
0
+

Comments

    No one has commented yet.