[PATCH 3/3] ruby: add db.{set,get}_config

2023-03-31 Thread Felipe Contreras
Signed-off-by: Felipe Contreras 
---
 bindings/ruby/database.c | 45 
 bindings/ruby/defs.h |  6 ++
 bindings/ruby/init.c |  2 ++
 3 files changed, 53 insertions(+)

diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index 4372afa1..10bdab4e 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -497,3 +497,48 @@ notmuch_rb_database_revision (VALUE self)
 rev = notmuch_database_get_revision (db, );
 return rb_ary_new3(2, INT2FIX (rev), rb_str_new2 (uuid));
 }
+
+/*
+ * call-seq: DB.set_config(key, value) => nil
+ *
+ * Sets configuration key to value.
+ */
+VALUE
+notmuch_rb_database_set_config (VALUE self, VALUE key, VALUE value)
+{
+notmuch_database_t *db;
+notmuch_status_t ret;
+const char *cvalue;
+
+Data_Get_Notmuch_Database (self, db);
+
+cvalue = value != Qnil ? RSTRING_PTR (value) : "";
+ret = notmuch_database_set_config (db, RSTRING_PTR (key), cvalue);
+notmuch_rb_status_raise (ret);
+
+return Qnil;
+}
+
+/*
+ * call-seq: DB.get_config(key) => String
+ *
+ * Retrieves a configuration key.
+ */
+VALUE
+notmuch_rb_database_get_config (VALUE self, VALUE key)
+{
+notmuch_database_t *db;
+notmuch_status_t ret;
+char *value;
+VALUE rvalue;
+
+Data_Get_Notmuch_Database (self, db);
+
+ret = notmuch_database_get_config (db, RSTRING_PTR (key), );
+notmuch_rb_status_raise (ret);
+
+rvalue = rb_str_new2 (value);
+free (value);
+
+return rvalue;
+}
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 3ef228b7..352458c8 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -211,6 +211,12 @@ notmuch_rb_database_query_create (int argc, VALUE *argv, 
VALUE self);
 VALUE
 notmuch_rb_database_revision (VALUE self);
 
+VALUE
+notmuch_rb_database_set_config (VALUE self, VALUE key, VALUE value);
+
+VALUE
+notmuch_rb_database_get_config (VALUE self, VALUE key);
+
 /* directory.c */
 VALUE
 notmuch_rb_directory_destroy (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 625c6c4d..95dc237f 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -284,6 +284,8 @@ Init_notmuch (void)
 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, "revision", 
notmuch_rb_database_revision, 0); /* in database.c */
+rb_define_method (notmuch_rb_cDatabase, "set_config", 
notmuch_rb_database_set_config, 2); /* in database.c */
+rb_define_method (notmuch_rb_cDatabase, "get_config", 
notmuch_rb_database_get_config, 1); /* in database.c */
 
 /*
  * Document-class: Notmuch::Directory
-- 
2.40.0

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH 2/3] ruby: add directory.delete

2023-03-31 Thread Felipe Contreras
Signed-off-by: Felipe Contreras 
---
 bindings/ruby/defs.h  |  3 +++
 bindings/ruby/directory.c | 19 +++
 bindings/ruby/init.c  |  1 +
 3 files changed, 23 insertions(+)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index c4943681..3ef228b7 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -227,6 +227,9 @@ notmuch_rb_directory_get_child_files (VALUE self);
 VALUE
 notmuch_rb_directory_get_child_directories (VALUE self);
 
+VALUE
+notmuch_rb_directory_delete (VALUE self);
+
 /* filenames.c */
 VALUE
 notmuch_rb_filenames_destroy (VALUE self);
diff --git a/bindings/ruby/directory.c b/bindings/ruby/directory.c
index 910f0a99..2fb22c70 100644
--- a/bindings/ruby/directory.c
+++ b/bindings/ruby/directory.c
@@ -108,3 +108,22 @@ notmuch_rb_directory_get_child_directories (VALUE self)
 
 return Data_Wrap_Notmuch_Object (notmuch_rb_cFileNames, 
_rb_filenames_type, fnames);
 }
+
+/*
+ * call-seq: DIR.delete => nil
+ *
+ * Delete directory from the database.
+ */
+VALUE
+notmuch_rb_directory_delete (VALUE self)
+{
+notmuch_directory_t *dir;
+notmuch_status_t ret;
+
+Data_Get_Notmuch_Directory (self, dir);
+
+ret = notmuch_directory_delete (dir);
+notmuch_rb_status_raise (ret);
+
+return Qnil;
+}
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index c78242a0..625c6c4d 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -297,6 +297,7 @@ Init_notmuch (void)
 rb_define_method (notmuch_rb_cDirectory, "mtime=", 
notmuch_rb_directory_set_mtime, 1); /* in directory.c */
 rb_define_method (notmuch_rb_cDirectory, "child_files", 
notmuch_rb_directory_get_child_files, 0); /* in directory.c */
 rb_define_method (notmuch_rb_cDirectory, "child_directories", 
notmuch_rb_directory_get_child_directories, 0); /* in directory.c */
+rb_define_method (notmuch_rb_cDirectory, "delete", 
notmuch_rb_directory_delete, 0); /* in directory.c */
 
 /*
  * Document-class: Notmuch::FileNames
-- 
2.40.0

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH 0/3] ruby: api updates

2023-03-31 Thread Felipe Contreras
These are some API updates I did years ago but didn't send for fear of
distracting from more important patches.

However, I was already butten by db.revision not being available.

So here they are.

If you want I can incrementally check all the API updates and implement them
all in the ruby bindings.

Felipe Contreras (3):
  ruby: add database.revision
  ruby: add directory.delete
  ruby: add db.{set,get}_config

 bindings/ruby/database.c  | 63 +++
 bindings/ruby/defs.h  | 12 
 bindings/ruby/directory.c | 19 
 bindings/ruby/init.c  |  4 +++
 4 files changed, 98 insertions(+)

-- 
2.40.0

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH 1/3] ruby: add database.revision

2023-03-31 Thread Felipe Contreras
Signed-off-by: Felipe Contreras 
---
 bindings/ruby/database.c | 18 ++
 bindings/ruby/defs.h |  3 +++
 bindings/ruby/init.c |  1 +
 3 files changed, 22 insertions(+)

diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index b6de1254..4372afa1 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -479,3 +479,21 @@ notmuch_rb_database_query_create (int argc, VALUE *argv, 
VALUE self)
 
 return Data_Wrap_Notmuch_Object (notmuch_rb_cQuery, 
_rb_query_type, query);
 }
+
+/*
+ * call-seq: DB.revision => Array
+ *
+ * Returns the commutted database revision and UUID.
+ */
+VALUE
+notmuch_rb_database_revision (VALUE self)
+{
+notmuch_database_t *db;
+unsigned long rev;
+const char *uuid;
+
+Data_Get_Notmuch_Database (self, db);
+
+rev = notmuch_database_get_revision (db, );
+return rb_ary_new3(2, INT2FIX (rev), rb_str_new2 (uuid));
+}
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index e2541e8f..c4943681 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -208,6 +208,9 @@ notmuch_rb_database_get_all_tags (VALUE self);
 VALUE
 notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self);
 
+VALUE
+notmuch_rb_database_revision (VALUE self);
+
 /* directory.c */
 VALUE
 notmuch_rb_directory_destroy (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index cd9f04cd..c78242a0 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -283,6 +283,7 @@ Init_notmuch (void)
  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, "revision", 
notmuch_rb_database_revision, 0); /* in database.c */
 
 /*
  * Document-class: Notmuch::Directory
-- 
2.40.0

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH 0/2] ruby: database open improvements

2023-03-31 Thread Felipe Contreras
On Fri, Mar 31, 2023 at 5:07 AM David Bremner  wrote:
>
> Felipe Contreras  writes:
>
> > Essentially we want to do notmuch_database_open_with_config() and load the
> > default database.
> >
>
> Applied to master. Thanks for this change, both are things I'd wanted to
> fix.

Good. Since you chose to pick this series, I just sent another patch I
have lying around to reorganize this initializer code.

Cheers.

-- 
Felipe Contreras
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH] ruby: db: reorganize initializer

2023-03-31 Thread Felipe Contreras
In order to make it more extensible.

No functional changes.

Signed-off-by: Felipe Contreras 
---
 bindings/ruby/database.c | 52 
 bindings/ruby/defs.h |  2 --
 bindings/ruby/init.c |  4 
 3 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index b6de1254..67be3b23 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -58,37 +58,49 @@ notmuch_rb_database_initialize (int argc, VALUE *argv, 
VALUE self)
 notmuch_database_t *database;
 notmuch_status_t ret;
 
+path = NULL;
+create = 0;
+mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
+
 /* Check arguments */
 rb_scan_args (argc, argv, "02", , );
 
 if (!NIL_P (pathv)) {
SafeStringValue (pathv);
path = RSTRING_PTR (pathv);
-} else {
-   path = NULL;
 }
 
 if (!NIL_P (hashv)) {
-   Check_Type (hashv, T_HASH);
-   create = RTEST (rb_hash_aref (hashv, ID2SYM (ID_db_create)));
-   modev = rb_hash_aref (hashv, ID2SYM (ID_db_mode));
-   if (NIL_P (modev))
-   mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
-   else if (!FIXNUM_P (modev))
-   rb_raise (rb_eTypeError, ":mode isn't a Fixnum");
-   else {
-   mode = FIX2INT (modev);
-   switch (mode) {
-   case NOTMUCH_DATABASE_MODE_READ_ONLY:
-   case NOTMUCH_DATABASE_MODE_READ_WRITE:
-   break;
-   default:
-   rb_raise ( rb_eTypeError, "Invalid mode");
+   VALUE rmode, rcreate;
+   VALUE kwargs[2];
+   static ID keyword_ids[2];
+
+   if (!keyword_ids[0]) {
+   keyword_ids[0] = rb_intern_const ("mode");
+   keyword_ids[1] = rb_intern_const ("create");
+   }
+
+   rb_get_kwargs (hashv, keyword_ids, 0, 2, kwargs);
+
+   rmode = kwargs[0];
+   rcreate = kwargs[1];
+
+   if (rmode != Qundef) {
+   if (!FIXNUM_P (rmode))
+   rb_raise (rb_eTypeError, ":mode isn't a Fixnum");
+   else {
+   mode = FIX2INT (rmode);
+   switch (mode) {
+   case NOTMUCH_DATABASE_MODE_READ_ONLY:
+   case NOTMUCH_DATABASE_MODE_READ_WRITE:
+   break;
+   default:
+   rb_raise ( rb_eTypeError, "Invalid mode");
+   }
}
}
-} else {
-   create = 0;
-   mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
+   if (rcreate != Qundef)
+   create = RTEST (rcreate);
 }
 
 rb_check_typeddata (self, _rb_database_type);
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index e2541e8f..042e0a89 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -48,8 +48,6 @@ extern VALUE notmuch_rb_eUnbalancedFreezeThawError;
 extern VALUE notmuch_rb_eUnbalancedAtomicError;
 
 extern ID ID_call;
-extern ID ID_db_create;
-extern ID ID_db_mode;
 
 /* RSTRING_PTR() is new in ruby-1.9 */
 #if !defined(RSTRING_PTR)
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index cd9f04cd..691e1475 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -43,8 +43,6 @@ VALUE notmuch_rb_eUnbalancedFreezeThawError;
 VALUE notmuch_rb_eUnbalancedAtomicError;
 
 ID ID_call;
-ID ID_db_create;
-ID ID_db_mode;
 
 const rb_data_type_t notmuch_rb_object_type = {
 .wrap_struct_name = "notmuch_object",
@@ -101,8 +99,6 @@ Init_notmuch (void)
 VALUE mod;
 
 ID_call = rb_intern ("call");
-ID_db_create = rb_intern ("create");
-ID_db_mode = rb_intern ("mode");
 
 mod = rb_define_module ("Notmuch");
 
-- 
2.40.0

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH 1/1] lib: replace some uses of Query::MatchAll with a thread-safe alternative

2023-03-31 Thread David Bremner
Kevin Boulain  writes:

> This replaces two instances of Xapian::Query::MatchAll with the
> equivalent but thread-safe alternative Xapian::Query(std::string()).
> Xapian::Query::MatchAll maintains an internal pointer to a refcounted
> Xapian::Internal::QueryTerm.
>

Applied to master, thanks, and sorry for the delay.

By the way I see sfsexp has merged your related PR last week.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH 0/2] ruby: database open improvements

2023-03-31 Thread David Bremner
Felipe Contreras  writes:

> Essentially we want to do notmuch_database_open_with_config() and load the
> default database.
>

Applied to master. Thanks for this change, both are things I'd wanted to
fix.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org