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

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

Date: Fri, 31 Mar 2023 14:53:36 -0600

To: notmuch@notmuchmail.org

Cc:

From: Felipe Contreras


Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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, &notmuch_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, &uuid);
+    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-leave@notmuchmail.org

Thread: