From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0r.migadu.com with LMTPS id AABrA/dDjWAVZgEALuJCtg (envelope-from ) for ; Sat, 01 May 2021 14:05:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id mFC+OvZDjWCwOgAAB5/wlQ (envelope-from ) for ; Sat, 01 May 2021 12:05:10 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A1818110CE for ; Sat, 1 May 2021 14:05:10 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 4FA39271EE; Sat, 1 May 2021 08:05:04 -0400 (EDT) Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by mail.notmuchmail.org (Postfix) with ESMTPS id 77345271F2 for ; Sat, 1 May 2021 08:05:00 -0400 (EDT) Received: by mail-oi1-x235.google.com with SMTP id k25so836756oic.4 for ; Sat, 01 May 2021 05:05:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=71Wty/rFu+qrePhfFK37WZBa9HLq6bnHUxpWDyJb5Jk=; b=D/ciuBJwAAXAva0q/IJ7y9vwxbkhrhidgRh+AnVLpJubEbkY5Vw7jW4ocXmph4Q1fu zFYaFR7SaSA2Hzl9jLHcka4RLjOlbdo/ETxDqVaiFbHT3CP+NJk/5Ai2xBq4D+chYfGZ 17TTGGV/XBwbNUUP/pvLarclV989iFyEMj8TDkgQZq6yATe1Rq0iAtwmQlTrVADDGq/C tuIETrGEdN8NK7Sl4HzRphsqOocBLW38ESrYj7TjQqT7EFkxyerKN56AIwKCXikBnEL5 PkOEqezYnZhxbWVt0Rg0y3ZyQz3tdxAC2EXXg9KoRvIxqDCS9QjD7MjCao81lCAwmbJO C/wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=71Wty/rFu+qrePhfFK37WZBa9HLq6bnHUxpWDyJb5Jk=; b=c3SedDgGpP/UXcbySamV1ZrmcfA6ti294+wYmk3ehIcrigUE5LvIsumoZ+sfbhwcyM r31/WvkIa0AH7vwbJdt2nGF87qxpKrG4RYbWbCzgCBupbrv1rK2z7U5QfNJSuFyKKzF/ ocemMs/9TkfDXAU1OnbTyhjmIAWX4jF7UbZVmEHjHIS6/Fs4y2WqTwezwtlIAwX+1Iy3 +O67eymI/mIWpChusovWxmDyxncCBsMtUiFei16jL6fVMotQvKpCf+SwmRGtAZhk6lMs YaKW3jWYfUZcRcSyJDjByrWGOlKszKEY6FwBqwLD403P7lE5OmhWfJFVrUtCKyj0Tuwj GS5g== X-Gm-Message-State: AOAM530SLg1KGhO1oxpYVZ7k0KJYuA/R1r0wXFbJDSNA3Zd4Sr/tWQuT n/VknU+/7zrqebzRlPvdHemZr3rzF8AY9g== X-Google-Smtp-Source: ABdhPJzXo2sTMS4iKqeMAQUIwnQphVZ6tVuXSAhHnkZSA6w+IW2AOZuBFWYsMZFy60TEMF+HhlOm1g== X-Received: by 2002:aca:428b:: with SMTP id p133mr6349102oia.22.1619870693088; Sat, 01 May 2021 05:04:53 -0700 (PDT) Received: from localhost ([2806:2f0:4060:638f:a2c5:89ff:fe0c:1151]) by smtp.gmail.com with ESMTPSA id p1sm339507otk.58.2021.05.01.05.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 May 2021 05:04:52 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Subject: [PATCH 2/3] ruby: add keyword arguments to db.query Date: Sat, 1 May 2021 07:04:47 -0500 Message-Id: <20210501120448.484082-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210501120448.484082-1-felipe.contreras@gmail.com> References: <20210501120448.484082-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Message-ID-Hash: BH7ZBDIZIKOE2AIOQZM3A4MHNU5U3ION X-Message-ID-Hash: BH7ZBDIZIKOE2AIOQZM3A4MHNU5U3ION X-MailFrom: felipe.contreras@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Ludovic LANGE , Stefano Zacchiroli X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619870710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=6geaUr+773s7Skqybpr92L0ASltvc8wUusnzcnZ+FP4=; b=ivXCQTNsxjhnII2Klq+hH6GALIeTvgEVfvQfn5VB9dJul9ZGuo25F1xHKmPMjw0GstMrjE wJ7WC8o8bSHOsEVgv3Jg96n5sLVew6ThM+q/kL5JjoRjxAfBRfafrystLoo1286LLI2iZp ccGc61KE1OgIW1xfE7HI4DBZcrKOmSVKWA6byleZ1ptHSjyfb6GGNh/N6c5NUo9A20skW6 +aXvfnm++5QkFtCjsu0/PMWeOx257jhZ4uSQxNR1WsGFCUH+99xB5JoFE2NoSCJoDqQwSq +tIOiYdkiUUoXMrMVTol0dPg0wR9PmTcQilPA/ADIscp5ZYWZpwmz0AWRakobQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619870710; a=rsa-sha256; cv=none; b=WOZIv1hXTa2QwUP9VyjhsqgGTJ1FU9D6PoRveLyWs7Z7CsJ0lKPA+pHm4MI2u8utC4CQ+v DVk/J/34ql8g+GLMiS9YSRqMaWXbBWualupdk2Luh3zykABcu4FDhIyjGQvJ/QER++9j3a ekNywqry98U7MA4YSJaN2Bkj/mew477XLTPPh3u+lojYVd65fdf27PHyMA2GjM3gvgPL26 uz9WSiGjwGcyBoJwHitYAgZ4RWSeh64fZiPL3AjVO3pvU3cwCimpavA50LNMn7oLlv7QLs RmGGosZQ55AmLgUheoijRK/+cbLZowbHN0TNrALFUE9JH0B/5Cb0LZrrMDg/Jg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b="D/ciuBJw"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.00 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b="D/ciuBJw"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A1818110CE X-Spam-Score: -1.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: N/V9+wLqrpB2 That way we don't need pass them to the query object ourselves. Signed-off-by: Felipe Contreras --- bindings/ruby/database.c | 47 +++++++++++++++++++++++++++++++++++++--- bindings/ruby/defs.h | 2 +- bindings/ruby/init.c | 2 +- test/T395-ruby.sh | 18 +++++++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c index 416eb709..313a4338 100644 --- a/bindings/ruby/database.c +++ b/bindings/ruby/database.c @@ -399,17 +399,24 @@ notmuch_rb_database_get_all_tags (VALUE self) } /* - * call-seq: DB.query(query) => QUERY + * call-seq: + * DB.query(query) => QUERY + * DB.query(query, sort:, excluded_tags:, omit_excluded:) => QUERY * - * Retrieve a query object for the query string 'query' + * Retrieve a query object for the query string 'query'. When using keyword + * arguments they are passwed to the query object. */ VALUE -notmuch_rb_database_query_create (VALUE self, VALUE qstrv) +notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self) { + VALUE qstrv; + VALUE opts; const char *qstr; notmuch_query_t *query; notmuch_database_t *db; + rb_scan_args (argc, argv, "1:", &qstrv, &opts); + Data_Get_Notmuch_Database (self, db); SafeStringValue (qstrv); @@ -419,5 +426,39 @@ notmuch_rb_database_query_create (VALUE self, VALUE qstrv) if (!query) rb_raise (notmuch_rb_eMemoryError, "Out of memory"); + if (!NIL_P (opts)) { + VALUE sort, exclude_tags, omit_excluded; + VALUE kwargs[3]; + static ID keyword_ids[3]; + + if (!keyword_ids[0]) { + keyword_ids[0] = rb_intern_const ("sort"); + keyword_ids[1] = rb_intern_const ("exclude_tags"); + keyword_ids[2] = rb_intern_const ("omit_excluded"); + } + + rb_get_kwargs (opts, keyword_ids, 0, 3, kwargs); + + sort = kwargs[0]; + exclude_tags = kwargs[1]; + omit_excluded = kwargs[2]; + + if (sort != Qundef) + notmuch_query_set_sort (query, FIX2UINT (sort)); + + if (exclude_tags != Qundef) { + for (int i = 0; i < RARRAY_LEN (exclude_tags); i++) { + VALUE e = RARRAY_AREF (exclude_tags, i); + notmuch_query_add_tag_exclude (query, RSTRING_PTR (e)); + } + } + + if (omit_excluded != Qundef) { + notmuch_exclude_t omit; + omit = FIXNUM_P (omit_excluded) ? FIX2UINT (omit_excluded) : RTEST(omit_excluded); + notmuch_query_set_omit_excluded (query, omit); + } + } + return Data_Wrap_Struct (notmuch_rb_cQuery, NULL, NULL, query); } diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index 48544ca2..1ceaadb5 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -181,7 +181,7 @@ VALUE notmuch_rb_database_get_all_tags (VALUE self); VALUE -notmuch_rb_database_query_create (VALUE self, VALUE qstrv); +notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self); /* directory.c */ VALUE diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c index fd73ed8f..f509edbd 100644 --- a/bindings/ruby/init.c +++ b/bindings/ruby/init.c @@ -254,7 +254,7 @@ Init_notmuch (void) rb_define_method (notmuch_rb_cDatabase, "find_message_by_filename", notmuch_rb_database_find_message_by_filename, 1); /* in database.c */ rb_define_method (notmuch_rb_cDatabase, "all_tags", notmuch_rb_database_get_all_tags, 0); /* in database.c */ - rb_define_method (notmuch_rb_cDatabase, "query", notmuch_rb_database_query_create, 1); /* in database.c */ + rb_define_method (notmuch_rb_cDatabase, "query", notmuch_rb_database_query_create, -1); /* in database.c */ /* * Document-class: Notmuch::Directory diff --git a/test/T395-ruby.sh b/test/T395-ruby.sh index d36d4aff..e828efed 100755 --- a/test/T395-ruby.sh +++ b/test/T395-ruby.sh @@ -82,4 +82,22 @@ q.search_threads.each do |t| end EOF +test_begin_subtest "check sort argument" +notmuch search --sort=oldest-first --output=threads tag:inbox > EXPECTED +test_ruby <<"EOF" +q = db.query('tag:inbox', sort: Notmuch::SORT_OLDEST_FIRST) +q.search_threads.each do |t| + puts 'thread:%s' % t.thread_id +end +EOF + +test_begin_subtest "check exclude_tags argument" +notmuch search --output=threads --exclude=all tag:inbox > EXPECTED +test_ruby <<"EOF" +q = db.query('tag:inbox', exclude_tags: %w[deleted], omit_excluded: Notmuch::EXCLUDE_ALL) +q.search_threads.each do |t| + puts 'thread:%s' % t.thread_id +end +EOF + test_done -- 2.31.0