This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

wide-ranging minor refactorings

  • Loading branch information...
technomancy committed Jul 26, 2008
1 parent 808b2a4 commit 0580318a6f499678d44561f4912131fc70aa4c82
Showing with 36 additions and 33 deletions.
  1. +5 −3 History.txt
  2. +1 −0 Manifest.txt
  3. +2 −0 bin/conspire
  4. +7 −11 lib/conspire.rb
  5. +12 −14 lib/conspire/conspirator.rb
  6. +5 −2 lib/conspire/gitjour_exts.rb
  7. +1 −0 lib/conspire/support/conspire.el
  8. +3 −3 test/test_conspire.rb
View
@@ -1,6 +1,8 @@
-=== 0.0.1 / 2008-07-22
+=== 0.1.0 / 2008-07-24
-* 1 major enhancement
+* Nearly usable! Sorta-works!
- * Birthday!
+=== 0.0.1 / 2008-07-23
+
+* Birthday!
View
@@ -4,6 +4,7 @@ Manifest.txt
README.rdoc
Rakefile
bin/conspire
+conspire.gemspec
lib/conspire.rb
lib/conspire/conspirator.rb
lib/conspire/gitjour_exts.rb
View
@@ -11,6 +11,8 @@ options = Clip do |c|
:default => Conspire::DEFAULTS[:name])
end
+abort options.to_s if !options.valid?
+
Conspire.start ARGV.first, options
Thread.new { Conspire.discover_loop }
Conspire.sync_loop
View
@@ -1,12 +1,11 @@
-$LOAD_PATH << File.dirname(__FILE__)
require 'set'
require 'fileutils'
require 'rubygems'
require 'gitjour' # TODO: can we get rid of the avahi compatibility warning?
-require 'conspire/gitjour_exts'
-require 'conspire/conspirator'
+require File.dirname(__FILE__) + '/conspire/gitjour_exts'
+require File.dirname(__FILE__) + '/conspire/conspirator'
module Conspire
VERSION = '0.1.0'
@@ -20,11 +19,10 @@ module Conspire
# Begin a conspiracy session
def start(path, options)
- @options = options
- @path = path
+ @path, @options = path, options
+
Gitjour::Application.init @path
- FileUtils.touch(@path + '/.conspire')
- `cd #{@path}; git add .conspire; git commit -m "initial"`
+
@thread = Thread.new do
Gitjour::Application.serve(@path, @options.name, @options.port)
end
@@ -42,6 +40,7 @@ def discover(wait = 5)
end
end
+ # Sync with all conspirators, dropping the problematic ones
def sync_all
@conspirators.map do |c|
begin
@@ -58,9 +57,6 @@ def sync_loop
end
def discover_loop
- loop do
- Conspire.discover
- puts Conspire.conspirators.map{ |c| c.to_s } if ENV['DEBUG']
- end
+ loop { discover and (p @conspirators if ENV['DEBUG']) }
end
end
@@ -1,27 +1,25 @@
module Conspire
class Conspirator
- attr_accessor :last_synced, :host, :port, :name
+ attr_accessor :host, :port, :name
- def initialize(host, port, name = DEFAULTS[:name])
- @host, @port, @name = host[0 .. -2], port || DEFAULTS[:port], name
+ def initialize(host, port, name)
+ # host has a trailing dot; remove it
+ @host, @port, @name = host[0 .. -2], port, name
end
def sync(path)
- # TODO: figure out conflictless rebasing... evan?
- success = if ENV['DEBUG']
- puts "cd #{path} && git pull --rebase #{url}"
- system "cd #{path} && git pull --rebase #{url}"
- else
- system "cd #{path} && git pull --rebase #{url} &> /dev/null"
- end
-
- raise "could not rebase from #{url}" if ! success
- # @last_synced = Time.now # is this useful?
+ # TODO: figure out conflictless rebasing; new content always wins. evan?
+ if ENV['DEBUG']
+ puts "cd #{path} && git pull --rebase #{url}"
+ system "cd #{path} && git pull --rebase #{url}"
+ else
+ system "cd #{path} && git pull --rebase #{url} &> /dev/null"
+ end or raise "could not rebase from #{url}" if ! success
end
def url; "git://#{@host}:#{@port}/" end
-
alias_method :to_s, :url
+ alias_method :inspect, :url
# For set equality
def eql?(other); self.url == other.url end
@@ -5,9 +5,12 @@ class << self
def init(path)
abort "Repository already exists: #{path}" if File.exist? path + '/.git'
- at_exit { FileUtils.rm_rf [path + '/.git', path + '/.conspire'] } unless ENV['KEEP']
+
`mkdir -p #{path} && cd #{path} && git init`
- `touch #{path}/.git/git-daemon-export-ok`
+ FileUtils.touch ["#{path}/.git/git-daemon-export-ok", "#{path}/.conspire"]
+ `cd #{path}; git add .conspire; git commit -m "initial"`
+
+ at_exit { FileUtils.rm_rf [path + '/.git', path + '/.conspire'] } unless ENV['KEEP']
end
def puts(*args); end unless ENV['DEBUG']
@@ -40,6 +40,7 @@
;;; TODO:
;; For some reason conspire-sync-buffer only runs on cursor movement
+;; Gracefully kill shell process so it can clean up
;; Don't bother with *Async Shell Command* output buffer
;; Color lines based on which conspirator wrote them?
View
@@ -30,7 +30,7 @@ def setup
@remote_thread = Thread.new do
Gitjour::Application.serve(REMOTE_SPACE, 'conspiracy-remote-test', 7458)
end
- @remote = Conspire::Conspirator.new('localhost.', '7458')
+ @remote = Conspire::Conspirator.new('localhost.', '7458', 'conspiracy')
Conspire.start(LOCAL_SPACE, OpenStruct.new(:port => 7457,
:name => 'conspiracy',
:sync_interval => 0.5))
@@ -61,8 +61,8 @@ def test_sync
end
def test_conspirator_set
- Conspire.conspirators << Conspire::Conspirator.new('dynabook.', '7458')
- Conspire.conspirators << Conspire::Conspirator.new('dynabook.', '7458')
+ Conspire.conspirators << Conspire::Conspirator.new('dynabook.', '7458', 'conspiracy')
+ Conspire.conspirators << Conspire::Conspirator.new('dynabook.', '7458', 'conspiracy')
assert_equal 1, Conspire.conspirators.size
end

0 comments on commit 0580318

Please sign in to comment.