[PATCH 02/10] search: Support --use-schema

Austin Clements amdragon at MIT.EDU
Sat Dec 1 18:39:54 PST 2012


---
 man/man1/notmuch-search.1 |   20 ++++++++++++++++++++
 notmuch-client.h          |    2 ++
 notmuch-search.c          |    3 +++
 3 files changed, 25 insertions(+)

diff --git a/man/man1/notmuch-search.1 b/man/man1/notmuch-search.1
index 6ccd3b8..79dc1fe 100644
--- a/man/man1/notmuch-search.1
+++ b/man/man1/notmuch-search.1
@@ -32,6 +32,15 @@ Presents the results in either JSON or plain-text (default).
 
 .RS 4
 .TP 4
+.BR \-\-use-schema=N
+
+Use the specified structured output schema version.  This is intended
+for programs that invoke \fBnotmuch\fR(1) internally.  If omitted, the
+latest supported version will be used.
+.RE
+
+.RS 4
+.TP 4
 .B \-\-output=(summary|threads|messages|files|tags)
 
 .RS 4
@@ -125,6 +134,17 @@ In this case all matching threads are returned but the "match count"
 is the number of matching non-excluded messages in the thread.
 .RE
 
+.SH EXIT STATUS
+
+This command supports the following special exit status codes
+
+.TP
+.B 20
+The requested schema version is too old.
+.TP
+.B 21
+The requested schema version is too new.
+
 .SH SEE ALSO
 
 \fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
diff --git a/notmuch-client.h b/notmuch-client.h
index 14e7363..95c4dd7 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -140,6 +140,8 @@ chomp_newline (char *str)
  * "current" version is consistent across all parts of the schema.
  */
 #define NOTMUCH_SCHEMA_CUR 1
+/* The minimum schema version supported by the "search" command. */
+#define NOTMUCH_SCHEMA_SEARCH 1
 
 /* The schema version requested by the caller on the command line.  If
  * no schema version is requested, this should be set to
diff --git a/notmuch-search.c b/notmuch-search.c
index 830c4e4..477f9eb 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -317,6 +317,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 	  (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
 				  { "text", NOTMUCH_FORMAT_TEXT },
 				  { 0, 0 } } },
+	{ NOTMUCH_OPT_INT, &notmuch_schema_version, "use-schema", 0, 0 },
 	{ NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
 	  (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
 				  { "threads", OUTPUT_THREADS },
@@ -352,6 +353,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 	INTERNAL_ERROR("no output format selected");
     }
 
+    notmuch_exit_if_unsupported_schema ("search", NOTMUCH_SCHEMA_SEARCH);
+
     config = notmuch_config_open (ctx, NULL, NULL);
     if (config == NULL)
 	return 1;
-- 
1.7.10.4



More information about the notmuch mailing list