]> git.cworth.org Git - sup/commitdiff
Merge branch 'string-split-fixes' into next
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 13 May 2009 20:53:47 +0000 (13:53 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 13 May 2009 20:53:47 +0000 (13:53 -0700)
Conflicts:
lib/sup/index.rb

bin/sup-sync
bin/sup-sync-back
lib/sup/buffer.rb
lib/sup/index.rb
lib/sup/poll.rb
lib/sup/util.rb

index 01c0ebaac42d452760c1e20999f2e4c37a50f597..9c342d25693f908e26825c3d7c4348e0b5ba84ee 100644 (file)
@@ -102,7 +102,7 @@ restored_state =
     IO.foreach opts[:restore] do |l|
       l =~ /^(\S+) \((.*?)\)$/ or raise "Can't read dump line: #{l.inspect}"
       mid, labels = $1, $2
-      dump[mid] = labels.split(" ").map { |x| x.intern }
+      dump[mid] = labels.symbolistize
     end
     $stderr.puts "Read #{dump.size} entries from dump file."
     dump
@@ -156,7 +156,7 @@ begin
       next if target == :changed && entry && entry[:source_id].to_i == source.id && entry[:source_info].to_i == offset
 
       ## get the state currently in the index
-      index_state = entry[:label].split(/\s+/).map { |x| x.intern } if entry
+      index_state = entry[:label].symbolistize if entry
 
       ## skip if we're operating on restored messages, and this one
       ## ain't.
@@ -166,7 +166,7 @@ begin
       ## to default source state modification flags.
       m.labels -= [:inbox] if opts[:archive]
       m.labels -= [:unread] if opts[:read]
-      m.labels += opts[:extra_labels].split(/\s*,\s*/).map { |x| x.intern } if opts[:extra_labels]
+      m.labels += opts[:extra_labels].strip.split(/\s*,\s*/).map { |x| x.intern } if opts[:extra_labels]
 
       ## assign message labels based on the operation we're performing
       case op
index 4216cf9e46f5db3c595b72edb8462f15bb0fe966..4f1387e7f1e62d9ec13c03833d0670c9e87e4531 100644 (file)
@@ -109,7 +109,7 @@ EOS
       num_scanned += 1
 
       if entry
-        labels = entry[:label].split.map { |x| x.intern }.to_boolean_h
+        labels = entry[:label].symbolistize.to_boolean_h
 
         if labels.member? :deleted
           if opts[:drop_deleted]
index cb61e12ffd19df6a2ccc0a2df7c54ec80066938e..6f0acf9852ea51d4b45125d035476051ed42d2f4 100644 (file)
@@ -489,7 +489,7 @@ EOS
 
     return unless answer
 
-    user_labels = answer.split(/\s+/).map { |l| l.intern }
+    user_labels = answer.symbolistize
     user_labels.each do |l|
       if forbidden_labels.include?(l) || LabelManager::RESERVED_LABELS.include?(l)
         BufferManager.flash "'#{l}' is a reserved label!"
index c66a24eac428ab7256ea237db16c42e126189dd7..c7838eb43d534a7d03ddad7bda2a612812564b39 100644 (file)
@@ -226,7 +226,7 @@ EOS
     ## but merge in the labels.
     if entry[:source_id] && entry[:source_info] && entry[:label] &&
       ((entry[:source_id].to_i > source_id) || (entry[:source_info].to_i < m.source_info))
-      labels = (entry[:label].split(/\s+/).map { |l| l.intern } + m.labels).uniq
+      labels = (entry[:label].symbolistize + m.labels).uniq
       #Redwood::log "found updated version of message #{m.id}: #{m.subj}"
       #Redwood::log "previous version was at #{entry[:source_id].inspect}:#{entry[:source_info].inspect}, this version at #{source_id.inspect}:#{m.source_info.inspect}"
       #Redwood::log "merged labels are #{labels.inspect} (index #{entry[:label].inspect}, message #{m.labels.inspect})"
@@ -332,7 +332,7 @@ EOS
 
       q = Ferret::Search::BooleanQuery.new true
       sq = Ferret::Search::PhraseQuery.new(:subject)
-      wrap_subj(Message.normalize_subj(m.subj)).split(/\s+/).each do |t|
+      wrap_subj(Message.normalize_subj(m.subj)).split.each do |t|
         sq.add_term t
       end
       q.add_query sq, :must
@@ -377,7 +377,7 @@ EOS
           unless messages.member?(mid)
             #Redwood::log "got #{mid} as a child of #{id}"
             messages[mid] ||= lambda { build_message docid }
-            refs = @index[docid][:refs].split(" ")
+            refs = @index[docid][:refs].split
             pending += refs.select { |id| !searched[id] }
           end
         end
@@ -408,13 +408,13 @@ EOS
         "date" => Time.at(doc[:date].to_i),
         "subject" => unwrap_subj(doc[:subject]),
         "from" => doc[:from],
-        "to" => doc[:to].split(/\s+/).join(", "), # reformat
+        "to" => doc[:to].split.join(", "), # reformat
         "message-id" => doc[:message_id],
-        "references" => doc[:refs].split(/\s+/).map { |x| "<#{x}>" }.join(" "),
+        "references" => doc[:refs].split.map { |x| "<#{x}>" }.join(" "),
       }
 
       m = Message.new :source => source, :source_info => doc[:source_info].to_i,
-                  :labels => doc[:label].split(" ").map { |s| s.intern },
+                  :labels => doc[:label].symbolistize,
                   :snippet => doc[:snippet]
       m.parse_header fake_header
       m
index 9a10ca67ee63e72bf8fb5456366a4f14e814c437..fb4abb2526771422579020407bb0ba671391485a 100644 (file)
@@ -97,7 +97,7 @@ EOS
         numi = 0
         add_messages_from source do |m, offset, entry|
           ## always preserve the labels on disk.
-          m.labels = ((m.labels - [:unread, :inbox]) + entry[:label].split(/\s+/).map { |x| x.intern }).uniq if entry
+          m.labels = ((m.labels - [:unread, :inbox]) + entry[:label].symbolistize).uniq if entry
           yield "Found message at #{offset} with labels {#{m.labels * ', '}}"
           unless entry
             num += 1
index 8b92fd2e079761965d3684ab051aee1b72cf6840..c54a2c0db2b47efdc547000cc0ed9f8974536960 100644 (file)
@@ -271,6 +271,11 @@ class String
   def normalize_whitespace
     gsub(/\t/, "    ").gsub(/\r/, "")
   end
+
+  ## takes a space-separated list of words, and returns an array of symbols.
+  ## typically used in Sup for translating Ferret's representation of a list
+  ## of labels (a string) to an array of label symbols.
+  def symbolistize; split.map { |x| x.intern } end
 end
 
 class Numeric