]> git.cworth.org Git - sup/commitdiff
Merge branch 'logging' into next
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 17 Aug 2009 19:24:26 +0000 (15:24 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 17 Aug 2009 19:25:05 +0000 (15:25 -0400)
Conflicts:
bin/sup
bin/sup-sync-back
bin/sup-tweak-labels
lib/sup.rb
lib/sup/buffer.rb
lib/sup/message-chunks.rb
lib/sup/suicide.rb

13 files changed:
1  2 
bin/sup
bin/sup-add
bin/sup-sync
bin/sup-sync-back
bin/sup-tweak-labels
lib/sup.rb
lib/sup/buffer.rb
lib/sup/ferret_index.rb
lib/sup/hook.rb
lib/sup/index.rb
lib/sup/message-chunks.rb
lib/sup/message.rb
lib/sup/util.rb

diff --cc bin/sup
index a9f0b95686d567067e7ce0f873d0b372779da91c,155bb65b49193d73cbf2123baae2a5ec54f6ebc1..5d651be5ce83175192a333f19aa9551e64e28a7e
+++ b/bin/sup
@@@ -129,8 -129,32 +129,8 @@@ def stop_cursin
  end
  module_function :start_cursing, :stop_cursing
  
- Index.new
+ Index.init
 -begin
 -  Index.lock
 -rescue Index::LockError => e
 -  require 'highline'
 -
 -  h = HighLine.new
 -  h.wrap_at = :auto
 -  h.say Index.fancy_lock_error_message_for(e)
 -
 -  case h.ask("Should I ask that process to kill itself? ")
 -  when /^\s*y(es)?\s*$/i
 -    h.say "Ok, suggesting seppuku..."
 -    FileUtils.touch Redwood::SUICIDE_FN
 -    sleep SuicideManager::DELAY * 2
 -    FileUtils.rm_f Redwood::SUICIDE_FN
 -    h.say "Let's try that again."
 -    retry
 -  else
 -    h.say <<EOS
 -Ok, giving up. If the process crashed and left a stale lockfile, you
 -can fix this by manually deleting #{Index.lockfile}.
 -EOS
 -    exit
 -  end
 -end
 +Index.lock_interactively or exit
  
  begin
    Redwood::start
@@@ -309,10 -326,12 +315,12 @@@ ensur
  
    Redwood::finish
    stop_cursing
-   Redwood::log "stopped cursing"
+   Redwood::Logger.remove_all_sinks!
+   Redwood::Logger.add_sink $stderr, false
+   debug "stopped cursing"
  
 -  if SuicideManager.instantiated? && SuicideManager.die?
 +  if $die
-     Redwood::log "I've been ordered to commit seppuku. I obey!"
+     info "I've been ordered to commit seppuku. I obey!"
    end
  
    if Redwood::exceptions.empty?
diff --cc bin/sup-add
index 64d2890596cd4d5465d57bbc7e8aafdeb2c0c2a5,8f7010ee3f4dc06aa9051006ab08a4f45a42bec9..e27a0ebf6ff446a9347d4fd8937653ab45b97db8
@@@ -77,9 -77,9 +77,9 @@@ en
  
  $terminal.wrap_at = :auto
  Redwood::start
- index = Redwood::Index.new
+ index = Redwood::Index.init
  
 -index.lock_or_die
 +index.lock_interactively or exit
  
  begin
    Redwood::SourceManager.load_sources
diff --cc bin/sup-sync
index 6ac2429f45c633660c054c2165cc51c0994b39dd,b743c1c13e3cdf9f73d6d24a5c88882985c30681..2aa00c3720bcd0dbbce60499e5d14a70e01ae418
@@@ -93,25 -95,24 +95,24 @@@ target = [:new, :changed, :all, :restor
  op = [:asis, :restore, :discard].find { |x| opts[x] } || :asis
  
  Redwood::start
- index = Redwood::Index.new
- restored_state =
-   if opts[:restore]
-     dump = {}
-     $stderr.puts "Loading state dump from #{opts[:restore]}..."
-     IO.foreach opts[:restore] do |l|
-       l =~ /^(\S+) \((.*?)\)$/ or raise "Can't read dump line: #{l.inspect}"
-       mid, labels = $1, $2
-       dump[mid] = labels.symbolistize
-     end
-     $stderr.puts "Read #{dump.size} entries from dump file."
-     dump
-   else
-     {}
+ index = Redwood::Index.init
+ restored_state = if opts[:restore]
+   dump = {}
+   $stderr.puts "Loading state dump from #{opts[:restore]}..."
+   IO.foreach opts[:restore] do |l|
+     l =~ /^(\S+) \((.*?)\)$/ or raise "Can't read dump line: #{l.inspect}"
+     mid, labels = $1, $2
+     dump[mid] = labels.to_set_of_symbols
    end
+   $stderr.puts "Read #{dump.size} entries from dump file."
+   dump
+ else
+   {}
+ end
  
  seen = {}
 -index.lock_or_die
 +index.lock_interactively or exit
  begin
    index.load
  
index 6e66c6b646519afb1b5865a40e336520768ce64d,4d76f17f587fb75e4294b4a39c4bf52f0d5280c8..6298c97c3e6190e8704ff2cd1333843f09511fea
@@@ -65,8 -65,8 +65,8 @@@ EO
  end
  
  Redwood::start
- index = Redwood::Index.new
+ index = Redwood::Index.init
 -index.lock_or_die
 +index.lock_interactively or exit
  
  deleted_fp, spam_fp = nil
  unless opts[:dry_run]
index eac300ebf866e90ef1f7ac1328713e87126331d6,138f7e1738c7c6029ceb40003716d71763be53ab..90f6a57ddb0cbebd037f4a74dd1692a191de522e
@@@ -54,25 -54,22 +54,24 @@@ EO
  end
  opts[:verbose] = true if opts[:very_verbose]
  
- add_labels = (opts[:add] || "").split(",").map { |l| l.intern }.uniq
- remove_labels = (opts[:remove] || "").split(",").map { |l| l.intern }.uniq
+ add_labels = opts[:add].to_set_of_symbols ","
+ remove_labels = opts[:remove].to_set_of_symbols ","
  
  Trollop::die "nothing to do: no labels to add or remove" if add_labels.empty? && remove_labels.empty?
 +Trollop::die "no sources specified" if ARGV.empty?
  
  Redwood::start
- index = Redwood::Index.new
++index = Redwood::Index.init
 +index.lock_interactively or exit
  begin
 -  index = Redwood::Index.init
    index.load
  
-   source_ids = 
-     if opts[:all_sources]
-       Redwood::SourceManager.sources
-     else
-       ARGV.map do |uri|
-         Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
-       end
+   source_ids = if opts[:all_sources]
+     Redwood::SourceManager.sources
+   else
+     ARGV.map do |uri|
+       Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
+     end
    end.map { |s| s.id }
    Trollop::die "nothing to do: no sources" if source_ids.empty?
  
diff --cc lib/sup.rb
index cfa93fc6608c13c6c0dd508c0c99267f6bdcb1f6,ed144589a705abd854573e9b9f6eddf247ec458a..a6e5aef86d09cebd22cd313837d2206620be9191
@@@ -107,16 -107,17 +107,16 @@@ module Redwoo
    end
  
    def start
-     Redwood::SentManager.new $config[:sent_source] || 'sup://sent'
-     Redwood::ContactManager.new Redwood::CONTACT_FN
-     Redwood::LabelManager.new Redwood::LABEL_FN
-     Redwood::AccountManager.new $config[:accounts]
-     Redwood::DraftManager.new Redwood::DRAFT_DIR
-     Redwood::UpdateManager.new
-     Redwood::PollManager.new
-     Redwood::CryptoManager.new
-     Redwood::UndoManager.new
-     Redwood::SourceManager.new
+     Redwood::SentManager.init $config[:sent_source] || 'sup://sent'
+     Redwood::ContactManager.init Redwood::CONTACT_FN
+     Redwood::LabelManager.init Redwood::LABEL_FN
+     Redwood::AccountManager.init $config[:accounts]
+     Redwood::DraftManager.init Redwood::DRAFT_DIR
+     Redwood::UpdateManager.init
+     Redwood::PollManager.init
 -    Redwood::SuicideManager.init Redwood::SUICIDE_FN
+     Redwood::CryptoManager.init
+     Redwood::UndoManager.init
+     Redwood::SourceManager.init
    end
  
    def finish
@@@ -253,8 -246,14 +245,13 @@@ include Redwood::LogsStuf
      $encoding = "UTF-8"
    end
  
- ## now everything else (which can feel free to call Redwood::log at load time)
+ require "sup/buffer"
+ require "sup/keymap"
+ require "sup/mode"
+ require "sup/modes/scroll-mode"
+ require "sup/modes/text-mode"
+ require "sup/modes/log-mode"
  require "sup/update"
 -require "sup/suicide"
  require "sup/message-chunks"
  require "sup/message"
  require "sup/source"
index 09281e9f5823bf99f609a103a949a5cf98c2c7b7,53479199ce6e06670bbb56cf577937cd5e2b59e8..e1d1bc6f0e374d986402880cecb47a4a6ff00b95
@@@ -198,15 -196,8 +198,13 @@@ EO
      @flash = nil
      @shelled = @asking = false
      @in_x = ENV["TERM"] =~ /(xterm|rxvt|screen)/
-     self.class.i_am_the_instance self
 +    @sigwinch_happened = false
 +    @sigwinch_mutex = Mutex.new
    end
  
 +  def sigwinch_happened!; @sigwinch_mutex.synchronize { @sigwinch_happened = true } end
 +  def sigwinch_happened?; @sigwinch_mutex.synchronize { @sigwinch_happened } end
 +
    def buffers; @name_map.to_a; end
  
    def focus_on buf
Simple merge
diff --cc lib/sup/hook.rb
Simple merge
index 54ec84325224bce3a0ff75dbd695daf42c3e2b98,dfaeee819c1db70f410de829f001ccf21c19280c..ff03f195f6bca74aefdb23eedecc01c2172ee39c
@@@ -56,9 -53,45 +55,9 @@@ class BaseInde
      @lock_update_thread = nil
    end
  
 -  def possibly_pluralize number_of, kind
 -    "#{number_of} #{kind}" +
 -        if number_of == 1 then "" else "s" end
 -  end
 -
 -  def fancy_lock_error_message_for e
 -    secs = (Time.now - e.mtime).to_i
 -    mins = secs / 60
 -    time =
 -      if mins == 0
 -        possibly_pluralize secs , "second"
 -      else
 -        possibly_pluralize mins, "minute"
 -      end
 -
 -    <<EOS
 -Error: the sup index is locked by another process! User '#{e.user}' on
 -host '#{e.host}' is running #{e.pname} with pid #{e.pid}. The process was alive
 -as of #{time} ago.
 -EOS
 -  end
 -
 -  def lock_or_die
 -    begin
 -      lock
 -    rescue LockError => e
 -      $stderr.puts fancy_lock_error_message_for(e)
 -      $stderr.puts <<EOS
 -
 -You can wait for the process to finish, or, if it crashed and left a
 -stale lock file behind, you can manually delete #{@lock.path}.
 -EOS
 -      exit
 -    end
 -  end
 -
    def unlock
      if @lock && @lock.locked?
-       Redwood::log "unlocking #{lockfile}..."
+       debug "unlocking #{lockfile}..."
        @lock.unlock
      end
    end
index 705f15eb4b0ccd152811a65e8d1dbe4761962cf4,1eda17438df45e08eaa6f5269fca073e1714bb19..ce7d1ee4f5fde1e1df37d1ed5c6223e6ba5b3481
@@@ -131,9 -131,9 +131,9 @@@ EO
      def initial_state; :open end
      def viewable?; @lines.nil? end
      def view_default! path
 -      cmd = "/usr/bin/run-mailcap --action=view '#{@content_type}:#{path}' 2>/dev/null"
 +      cmd = "/usr/bin/run-mailcap --action=view '#{@content_type}:#{path}'"
-       Redwood::log "running: #{cmd.inspect}"
+       debug "running: #{cmd.inspect}"
 -      system cmd
 +      BufferManager.shell_out(cmd)
        $? == 0
      end
  
Simple merge
diff --cc lib/sup/util.rb
Simple merge