Permalink
Browse files

Remove ridiculous newbie shit

  • Loading branch information...
1 parent 465921a commit 3f1d70e473785b093a63b77b07d387acbc45c3d1 @wilson wilson committed Aug 24, 2008
View
@@ -1,20 +0,0 @@
-Copyright (c) 2008 Chad Fowler, Evan Phoenix, Rich Kilmer
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,25 +1,8 @@
-bin/gitjour
History.txt
-License.txt
Manifest.txt
README.txt
Rakefile
-config/hoe.rb
-config/requirements.rb
+bin/gitjour
lib/gitjour.rb
-lib/gitjour/application.rb
-lib/gitjour/version.rb
-script/destroy
-script/generate
-script/txt2html
-setup.rb
-tasks/deployment.rake
-tasks/environment.rake
-tasks/website.rake
test/test_gitjour.rb
test/test_helper.rb
-website/index.html
-website/index.txt
-website/javascripts/rounded_corners_lite.inc.js
-website/stylesheets/screen.css
-website/template.rhtml
View
@@ -1,8 +1,49 @@
-README
+= gitjour
-DEVELOPMENT
+* http://github.com/chad/gitjour
-How to test from the console:
+== DESCRIPTION:
-irb -r 'lib/gitjour/application'
-> Gitjour::Application.run "list"
+Automates DNSSD-powered serving and cloning of git repositories.
+
+== FEATURES/PROBLEMS:
+
+* As needed
+
+== SYNOPSIS:
+
+ % gitjour serve project_dir [name_to_advertise_as]
+ % gitjour list
+
+== REQUIREMENTS:
+
+* dnssd
+
+== INSTALL:
+
+* sudo gem install gitjour
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2008 Chad Fowler, Evan Phoenix, and Rich Kilmer
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,4 +1,14 @@
-require 'config/requirements'
-require 'config/hoe' # setup Hoe + all gem configuration
-
-Dir['tasks/**/*.rake'].each { |rake| load rake }
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+require './lib/gitjour.rb'
+
+Hoe.new('gitjour', Gitjour::VERSION) do |p|
+ p.extra_deps = ['dnssd']
+ p.developer('Chad Fowler', 'chad@chadfowler.com')
+ p.developer('Evan Phoenix', 'evan@fallingsnow.net')
+ p.developer('Rich Kilmer', 'rich@example.com')
+end
+
+# vim: syntax=Ruby
View
@@ -1,71 +0,0 @@
-require 'gitjour/version'
-
-AUTHOR = ['Chad Fowler', 'Rich Kilmer', 'Evan Phoenix'] # can also be an array of Authors
-EMAIL = "chad@chadfowler.com"
-DESCRIPTION = "Automates DNSSD-powered serving and cloning of git repositories."
-GEM_NAME = 'gitjour' # what ppl will type to install your gem
-RUBYFORGE_PROJECT = 'gitjour' # The unix name for your project
-HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
-DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
-
-@config_file = "~/.rubyforge/user-config.yml"
-@config = nil
-RUBYFORGE_USERNAME = "chadfowler"
-def rubyforge_username
- unless @config
- begin
- @config = YAML.load(File.read(File.expand_path(@config_file)))
- rescue
- puts <<-EOS
-ERROR: No rubyforge config file found: #{@config_file}
-Run 'rubyforge setup' to prepare your env for access to Rubyforge
- - See http://newgem.rubyforge.org/rubyforge.html for more details
- EOS
- exit
- end
- end
- RUBYFORGE_USERNAME.replace @config["username"]
-end
-
-
-REV = nil
-# UNCOMMENT IF REQUIRED:
-# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
-VERS = Gitjour::VERSION::STRING + (REV ? ".#{REV}" : "")
-RDOC_OPTS = ['--quiet', '--title', 'gitjour documentation',
- "--opname", "index.html",
- "--line-numbers",
- "--main", "README",
- "--inline-source"]
-
-class Hoe
- def extra_deps
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
- @extra_deps
- end
-end
-
-# Generate all the Rake tasks
-# Run 'rake -T' to see list of generated tasks (from gem root directory)
-hoe = Hoe.new(GEM_NAME, VERS) do |p|
- p.author = AUTHOR
- p.description = DESCRIPTION
- p.email = EMAIL
- p.summary = DESCRIPTION
- p.url = HOMEPATH
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
- p.test_globs = ["test/**/test_*.rb"]
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
- p.extra_deps = ['dnssd']
- # == Optional
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
- #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
-
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
-
-end
-
-CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
-PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
-hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
-hoe.rsync_args = '-av --delete --ignore-errors'
View
@@ -1,17 +0,0 @@
-require 'fileutils'
-include FileUtils
-
-require 'rubygems'
-%w[rake hoe newgem rubigen].each do |req_gem|
- begin
- require req_gem
- rescue LoadError
- puts "This Rakefile requires the '#{req_gem}' RubyGem."
- puts "Installation: gem install #{req_gem} -y"
- exit
- end
-end
-
-$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
-
-require 'gitjour'
View
@@ -1 +1,183 @@
-require 'gitjour/application'
+require 'rubygems'
+require 'dnssd'
+require 'set'
+
+Thread.abort_on_exception = true
+
+module Gitjour
+ VERSION = "6.3.0"
+ GitService = Struct.new(:name, :host, :port, :description)
+
+ class Application
+
+ class << self
+ def run(*args)
+ case args.shift
+ when "list"
+ list
+ when "clone"
+ clone(*args)
+ when "serve"
+ serve(*args)
+ when "remote"
+ remote(*args)
+ else
+ help
+ end
+ end
+
+ private
+ def list
+ service_list.each do |service|
+ puts "=== #{service.name} on #{service.host}:#{service.port} ==="
+ puts " gitjour clone #{service.name}"
+ if service.description != '' && service.description !~ /^Unnamed repository/
+ puts " #{service.description}"
+ end
+ puts
+ end
+ end
+
+ def clone(repository_name, *rest)
+ dir = rest.shift || repository_name
+ if File.exists?(dir)
+ exit_with! "ERROR: Clone directory '#{dir}' already exists."
+ end
+
+ puts "Cloning '#{repository_name}' into directory '#{dir}'..."
+
+ unless service = locate_repo(repository_name)
+ exit_with! "ERROR: Unable to find project named '#{repository_name}'"
+ end
+
+ puts "Connecting to #{service.host}:#{service.port}"
+
+ system "git clone git://#{service.host}:#{service.port}/ #{dir}/"
+ end
+
+ def remote(repository_name, *rest)
+ dir = rest.shift || repository_name
+ service = locate_repo repository_name
+ system "git remote add #{dir} git://#{service.host}:#{service.port}/"
+ end
+
+ def serve(path=Dir.pwd, *rest)
+ path = File.expand_path(path)
+ name = rest.shift || File.basename(path)
+ port = rest.shift || 9418
+
+ # If the name starts with ^, then don't apply the prefix
+ if name[0] == ?^
+ name = name[1..-1]
+ else
+ prefix = `git config --get gitjour.prefix`.chomp
+ prefix = ENV["USER"] if prefix.empty?
+ name = [prefix, name].compact.join("-")
+ end
+
+ if File.exists?("#{path}/.git")
+ announce_repo(path, name, port.to_i)
+ else
+ Dir["#{path}/*"].each do |dir|
+ if File.directory?(dir)
+ name = File.basename(dir)
+ announce_repo(dir, name, 9418)
+ end
+ end
+ end
+
+ `git-daemon --verbose --export-all --port=#{port} --base-path=#{path} --base-path-relaxed`
+ end
+
+ def help
+ puts "Gitjour #{Gitjour::VERSION::STRING}"
+ puts "Serve up and use git repositories via Bonjour/DNSSD."
+ puts "\nUsage: gitjour <command> [args]"
+ puts
+ puts " list"
+ puts " Lists available repositories."
+ puts
+ puts " clone <project> [<directory>]"
+ puts " Clone a gitjour served repository."
+ puts
+ puts " serve <path_to_project> [<name_of_project>] [<port>] or"
+ puts " <path_to_projects>"
+ puts " Serve up the current directory or projects via gitjour."
+ puts
+ puts " The name of your project is automatically prefixed with"
+ puts " `git config --get gitjour.prefix` or your username (preference"
+ puts " in that order). If you don't want a prefix, put a ^ on the front"
+ puts " of the name_of_project (the ^ is removed before announcing)."
+ puts
+ puts " remote <project> [<name>]"
+ puts " Add a Bonjour remote into your current repository."
+ puts " Optionally pass name to not use pwd."
+ puts
+ end
+
+ def exit_with!(message)
+ STDERR.puts message
+ exit!
+ end
+
+ class Done < RuntimeError; end
+
+ def discover(timeout=5)
+ waiting_thread = Thread.current
+
+ dns = DNSSD.browse "_git._tcp" do |reply|
+ DNSSD.resolve reply.name, reply.type, reply.domain do |resolve_reply|
+ service = GitService.new(reply.name,
+ resolve_reply.target,
+ resolve_reply.port,
+ resolve_reply.text_record['description'].to_s)
+ begin
+ yield service
+ rescue Done
+ waiting_thread.run
+ end
+ end
+ end
+
+ puts "Gathering for up to #{timeout} seconds..."
+ sleep timeout
+ dns.stop
+ end
+
+ def locate_repo(name)
+ found = nil
+
+ discover do |obj|
+ if obj.name == name
+ found = obj
+ raise Done
+ end
+ end
+
+ return found
+ end
+
+ def service_list
+ list = Set.new
+ discover { |obj| list << obj }
+
+ return list
+ end
+
+ def announce_repo(path, name, port)
+ return unless File.exists?("#{path}/.git")
+
+ tr = DNSSD::TextRecord.new
+ tr['description'] = File.read("#{path}/.git/description") rescue "a git project"
+
+ DNSSD.register(name, "_git._tcp", 'local', port, tr.encode) do |rr|
+ puts "Registered #{name} on port #{port}. Starting service."
+ end
+ end
+
+ end
+ end
+end
+
+
+
Oops, something went wrong.

1 comment on commit 3f1d70e

It would be nice if the README added the pull step as a reference, as at first I was not sure how to use the bonjour shared repo from another machine.

Please sign in to comment.