From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/ag:master commit in: /, lib/
Date: Tue, 24 Feb 2015 02:17:02 +0000 (UTC) [thread overview]
Message-ID: <1424744215.ef43e934de266b49dec9373cb6c281c0ee7c67dc.robbat2@gentoo> (raw)
commit: ef43e934de266b49dec9373cb6c281c0ee7c67dc
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 24 02:16:55 2015 +0000
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Tue Feb 24 02:16:55 2015 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=ef43e934
Improve delete code paths.
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
---
ag | 37 +++++++++++++++++++++++--------------
lib/storage.rb | 4 ++++
lib/utils.rb | 6 ++++++
3 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/ag b/ag
index 57dc0a4..ffe714b 100755
--- a/ag
+++ b/ag
@@ -26,41 +26,46 @@ $options.debug = false
$options.readonly = false
$options.jobs = false
$options.progress = true
+$options.need_argument = true
+$options.argmode = nil
op = OptionParser.new do |opts|
opts.banner = "Usage: ag <<--index-full|--index-new|--delete-msg|--delete-index|--reindex|--info> <--list listname>> <[--file|--msgid|--hash] <maildir/file/hash/messageid>> [options]"
- opts.on('--index-full', 'Read the full past archive from the .cur Maildir') do
+ opts.on('--index-full', 'Read the full past archive from Maildir/cur. Needs --list and a Maildir') do
abort 'Can only select one action' if $options.action != nil
$options.action = :do_full
+ $options.argmode = :dir
end
- opts.on('--index-new', 'Read new messages from .new and move them to .cur') do
+ opts.on('--index-new', 'Read new messages from Maildir/new and move them to Maildir/cur. Needs --list and a Maildir') do
abort 'Can only select one action' if $options.action != nil
$options.action = :do_incremental
+ $options.argmode = :dir
end
- opts.on('--delete-msg', 'Delete message. Needs --file, --msgid, or --hash') do
+ opts.on('--delete-msg', 'Delete message. Needs --list and one of --file, --msgid, or --hash') do
abort 'Can only select one action' if $options.action != nil
$options.action = :do_delete_msg
end
-
- opts.on('--delete-Index', 'Delete index. Needs --list') do
+
+ opts.on('--delete-index', 'Delete index. Needs --list') do
abort 'Can only select one action' if $options.action != nil
$options.action = :do_index
+ $options.need_argument = false
end
- opts.on('--info', 'Display message details. Needs --file, --msgid, or --hash') do
+ opts.on('--info', 'Display message details. Needs --list and one of --file, --msgid, or --hash') do
abort 'Can only select one action' if $options.action != nil
$options.action = :do_info
end
- opts.on('--reindex', 'Reindex message. Needs --file') do
+ opts.on('--reindex', 'Reindex message. Needs --list and --file') do
abort 'Can only select one action' if $options.action != nil
$options.action = :do_reindex
@@ -105,7 +110,7 @@ op = OptionParser.new do |opts|
opts.on('--jobs JOBS', 'Number of parallel jobs to run (defaults to 75% of core count)') do |jobs|
$options.jobs = jobs.to_i
end
-
+
opts.on('--progress', 'Display the progress bar') do
$options.progress = true
end
@@ -117,11 +122,13 @@ op.parse!
abort op.help unless $options.action
abort 'List name required' unless $options.name
-$options.dir = ARGV[0] or abort 'Need a Maildir/File/Hash/Message-Id to work with'
+$options.dir = ARGV[0] or abort 'Need a Maildir/File/Hash/Message-Id to work with' if $options.need_argument
-# Open maildir and set serializer
-$maildir = Maildir.new(File.join($options.dir), false)
-$maildir.serializer = Maildir::Serializer::Mail.new
+if($options.argmode == :dir)
+ # Open maildir and set serializer
+ $maildir = Maildir.new(File.join($options.dir), false)
+ $maildir.serializer = Maildir::Serializer::Mail.new
+end
# Connect to Elasticsearch
$es = Elasticsearch::Client.new(log: false)
@@ -132,12 +139,13 @@ Ag::Utils.proc_count = $options.jobs
###############################################################################
def do_full
+ abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir
Ag::Storage.create_index($options.name)
messages = $maildir.list(:cur)
opts = {
- :in_processes => Ag::Utils.proc_count,
+ :in_processes => Ag::Utils.proc_count,
}
opts[:progress] = "Importing #{$options.name}" if $options.progress
Parallel.each(messages, opts) do |maildir_message|
@@ -155,10 +163,11 @@ def do_full
end
def do_incremental
+ abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir
messages = $maildir.list(:cur)
opts = {
- :in_processes => Ag::Utils.proc_count,
+ :in_processes => Ag::Utils.proc_count,
}
opts[:progress] = "Importing #{$options.name}" if $options.progress
Parallel.each(messages, opts) do |maildir_message|
diff --git a/lib/storage.rb b/lib/storage.rb
index 8ab2d4e..68de268 100644
--- a/lib/storage.rb
+++ b/lib/storage.rb
@@ -141,6 +141,10 @@ module Ag::Storage
resolve_by_field(list, :raw_filename, filename)
end
+ def resolve_hash(list, hash = nil)
+ resolve_by_field(list, :_id, hash)
+ end
+
def store(list, message, filename)
content = get_content(message, filename)
diff --git a/lib/utils.rb b/lib/utils.rb
index 38349e0..b9156cd 100644
--- a/lib/utils.rb
+++ b/lib/utils.rb
@@ -33,6 +33,12 @@ module Ag
id = Ag::Storage.resolve_message_id($options.name, $options.dir)
when :file
id = Ag::Storage.resolve_filename($options.name, $options.dir)
+ when :hash
+ id = Ag::Storage.resolve_hash($options.name, $options.dir)
+ when :dir
+ abort 'Cannot perform resolve a directory to a message id'
+ when nil
+ abort 'Cannot resolve a nil id'
end
id
next reply other threads:[~2015-02-24 2:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-24 2:17 Robin H. Johnson [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-02-24 2:00 [gentoo-commits] proj/ag:master commit in: /, lib/ Robin H. Johnson
2015-02-23 22:44 Robin H. Johnson
2015-02-23 20:59 Alex Legler
2015-02-23 0:05 Alex Legler
2015-02-23 0:05 Alex Legler
2015-02-21 21:45 Robin H. Johnson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1424744215.ef43e934de266b49dec9373cb6c281c0ee7c67dc.robbat2@gentoo \
--to=robbat2@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox