unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* v2 of message properties patches
@ 2016-08-03  0:30 David Bremner
  2016-08-03  0:30 ` [PATCH 1/8] lib: read "property" terms from messages David Bremner
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: David Bremner @ 2016-08-03  0:30 UTC (permalink / raw)
  To: notmuch

This includes a bunch of whitespace cleanup (enough that the interdiff
is a bit boring/noisy) and
id:1468665174-11929-1-git-send-email-david@tethera.net, as well as
being rebased on master.

Here is said boring interdiff

diff --git a/lib/message-property.cc b/lib/message-property.cc
index 4fa6cac..0b13cac 100644
--- a/lib/message-property.cc
+++ b/lib/message-property.cc
@@ -86,16 +86,23 @@ notmuch_message_remove_property (notmuch_message_t *message, const char *key, co
 }
 
 notmuch_status_t
-notmuch_message_remove_all_properties (notmuch_message_t *message)
+notmuch_message_remove_all_properties (notmuch_message_t *message, const char *key)
 {
     notmuch_status_t status;
+    const char * term_prefix;
+
     status = _notmuch_database_ensure_writable (_notmuch_message_database (message));
     if (status)
 	return status;
 
     _notmuch_message_invalidate_metadata (message, "property");
+    if (key)
+	term_prefix = talloc_asprintf (message, "%s%s=", _find_prefix ("property"), key);
+    else
+	term_prefix = _find_prefix ("property");
+
     /* XXX better error reporting ? */
-    _notmuch_message_remove_terms (message, _find_prefix ("property"));
+    _notmuch_message_remove_terms (message, term_prefix);
 
     return NOTMUCH_STATUS_SUCCESS;
 }
diff --git a/lib/notmuch.h b/lib/notmuch.h
index f6bad67..e03a05d 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1711,6 +1711,9 @@ notmuch_message_remove_property (notmuch_message_t *message, const char *key, co
 /**
  * Remove all (key,value) pairs from the given message.
  *
+ * @param[in,out] message  message to operate on.
+ * @param[in]     key      key to delete properties for. If NULL, delete
+ *			   properties for all keys
  * @returns
  * - NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
  *   read-only mode so message cannot be modified.
@@ -1718,7 +1721,7 @@ notmuch_message_remove_property (notmuch_message_t *message, const char *key, co
  *
  */
 notmuch_status_t
-notmuch_message_remove_all_properties (notmuch_message_t *message);
+notmuch_message_remove_all_properties (notmuch_message_t *message, const char *key);
 
 /**
  * Opaque message property iterator
diff --git a/notmuch-dump.c b/notmuch-dump.c
index ec82660..e7965ce 100644
--- a/notmuch-dump.c
+++ b/notmuch-dump.c
@@ -80,11 +80,11 @@ print_dump_header (gzFile output, int output_format, int include)
 	sep = ",";
     }
     if (include & DUMP_INCLUDE_PROPERTIES) {
-	gzprintf (output, "%sproperties",sep);
+	gzprintf (output, "%sproperties", sep);
 	sep = ",";
     }
     if (include & DUMP_INCLUDE_TAGS) {
-	gzprintf (output, "%sproperties",sep);
+	gzprintf (output, "%sproperties", sep);
     }
     gzputs (output, "\n");
 }
@@ -106,38 +106,38 @@ dump_properties_message (void *ctx,
 	return 0;
     }
 
-   for (list = notmuch_message_get_properties (message, "", FALSE);
-	notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
-       const char *key, *val;
-
-       if (first) {
-	   if (hex_encode (ctx, message_id, buffer_p, size_p) != HEX_SUCCESS) {
-	       fprintf (stderr, "Error: failed to hex-encode message-id %s\n", message_id);
-	       return 1;
-	   }
-	   gzprintf (output, "#= %s", *buffer_p);
-	   first = FALSE;
-       }
-
-       key = notmuch_message_properties_key (list);
-       val = notmuch_message_properties_value (list);
-
-       if (hex_encode (ctx, key, buffer_p, size_p) != HEX_SUCCESS) {
-	   fprintf (stderr, "Error: failed to hex-encode key %s\n", key);
-	   return 1;
-       }
-       gzprintf (output, " %s", *buffer_p);
-
-       if (hex_encode (ctx, val, buffer_p, size_p) != HEX_SUCCESS) {
-	   fprintf (stderr, "Error: failed to hex-encode value %s\n", val);
-	   return 1;
-       }
-       gzprintf (output, "=%s", *buffer_p);
-}
-   notmuch_message_properties_destroy (list);
+    for (list = notmuch_message_get_properties (message, "", FALSE);
+	 notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
+	const char *key, *val;
+
+	if (first) {
+	    if (hex_encode (ctx, message_id, buffer_p, size_p) != HEX_SUCCESS) {
+		fprintf (stderr, "Error: failed to hex-encode message-id %s\n", message_id);
+		return 1;
+	    }
+	    gzprintf (output, "#= %s", *buffer_p);
+	    first = FALSE;
+	}
+
+	key = notmuch_message_properties_key (list);
+	val = notmuch_message_properties_value (list);
+
+	if (hex_encode (ctx, key, buffer_p, size_p) != HEX_SUCCESS) {
+	    fprintf (stderr, "Error: failed to hex-encode key %s\n", key);
+	    return 1;
+	}
+	gzprintf (output, " %s", *buffer_p);
+
+	if (hex_encode (ctx, val, buffer_p, size_p) != HEX_SUCCESS) {
+	    fprintf (stderr, "Error: failed to hex-encode value %s\n", val);
+	    return 1;
+	}
+	gzprintf (output, "=%s", *buffer_p);
+    }
+    notmuch_message_properties_destroy (list);
 
-   if (!first)
-       gzprintf (output, "\n", *buffer_p);
+    if (! first)
+	gzprintf (output, "\n", *buffer_p);
 
     return 0;
 }
diff --git a/notmuch-restore.c b/notmuch-restore.c
index d2ada61..4b3690f 100644
--- a/notmuch-restore.c
+++ b/notmuch-restore.c
@@ -69,7 +69,7 @@ process_properties_line (notmuch_database_t *notmuch, const char* line)
     const char *delim = " \t\n";
     int ret = EXIT_FAILURE;
 
-    void *local = talloc_new(NULL);
+    void *local = talloc_new (NULL);
 
     id_p = strtok_len_c (line, delim, &id_len);
     id = talloc_strndup (local, id_p, id_len);
@@ -97,7 +97,7 @@ process_properties_line (notmuch_database_t *notmuch, const char* line)
 	}
 
 	key = talloc_strndup (local, tok, off);
-	value = talloc_strndup (local, tok+off+1, tok_len - off - 1);
+	value = talloc_strndup (local, tok + off + 1, tok_len - off - 1);
 
 	if (hex_decode_inplace (key) != HEX_SUCCESS) {
 	    fprintf (stderr, "hex decoding failure on key %s\n", key);
@@ -111,13 +111,13 @@ process_properties_line (notmuch_database_t *notmuch, const char* line)
 
 	if (print_status_database ("notmuch restore", notmuch,
 				   notmuch_message_add_property (message, key, value)))
-	goto DONE;
+	    goto DONE;
 
     }
 
     ret = EXIT_SUCCESS;
 
- DONE:
+  DONE:
     talloc_free (local);
     return ret;
 }
@@ -341,7 +341,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
 		goto DONE;
 	}
 	if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] == '=') {
-	    ret = process_properties_line(notmuch, line+2);
+	    ret = process_properties_line (notmuch, line + 2);
 	    if (ret)
 		goto DONE;
 	}
@@ -380,7 +380,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
 	line_ctx = talloc_new (config);
 
 	if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] == '=') {
-	    ret = process_properties_line(notmuch, line+2);
+	    ret = process_properties_line (notmuch, line + 2);
 	    if (ret)
 		goto DONE;
 	}
@@ -423,7 +423,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
 	    break;
 
     }  while (! (ret = gz_getline (line_ctx, &line, &line_len, input)));
-    
+
 
     /* EOF is normal loop termination condition, UTIL_SUCCESS is
      * impossible here */
@@ -435,14 +435,14 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
 	ret = EXIT_FAILURE;
     }
 
-    /* currently this should not be after DONE: since we don't 
+    /* currently this should not be after DONE: since we don't
      * know if the xregcomp was reached
      */
 
     if (input_format == DUMP_FORMAT_SUP)
 	regfree (&regex);
 
- DONE:
+  DONE:
     if (line_ctx != NULL)
 	talloc_free (line_ctx);
 

^ permalink raw reply related	[flat|nested] 10+ messages in thread
* message properties patches, v1.0
@ 2016-06-13  1:05 David Bremner
  2016-06-13  1:05 ` [PATCH 4/8] lib: extend private string map API with iterators David Bremner
  0 siblings, 1 reply; 10+ messages in thread
From: David Bremner @ 2016-06-13  1:05 UTC (permalink / raw)
  To: notmuch

There have been two rounds of RFC/WIP

      id:1463927339-5441-1-git-send-email-david@tethera.net
      id:1464608999-14774-1-git-send-email-david@tethera.net

This is the first feature complete version, and (compared to the
previous one) includes docs, more tests, and dump/restore support.

There is one notable API change: I added a convenience function to
remove all tags. More importantly I adjusted the memory semantics of
the iterators so that the underlying map objects are kept alive. This
is the same issue alread present in the tag iterator code; when the
message metadata cache is invalidated, we don't want the iterator to
start segfaulting, otherwise the iterators are effectively read-only.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-08-03  4:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-03  0:30 v2 of message properties patches David Bremner
2016-08-03  0:30 ` [PATCH 1/8] lib: read "property" terms from messages David Bremner
2016-08-03  0:30 ` [PATCH 2/8] lib: private string map (associative array) API David Bremner
2016-08-03  0:30 ` [PATCH 3/8] lib: basic message-property API David Bremner
2016-08-03  0:30 ` [PATCH 4/8] lib: extend private string map API with iterators David Bremner
2016-08-03  0:30 ` [PATCH 5/8] lib: iterator API for message properties David Bremner
2016-08-03  0:30 ` [PATCH 6/8] CLI: refactor dumping of tags David Bremner
2016-08-03  0:30 ` [PATCH 7/8] CLI: add properties to dump output David Bremner
2016-08-03  0:30 ` [PATCH 8/8] cli: optionally restore message properties from dump file David Bremner
  -- strict thread matches above, loose matches on Subject: below --
2016-06-13  1:05 message properties patches, v1.0 David Bremner
2016-06-13  1:05 ` [PATCH 4/8] lib: extend private string map API with iterators David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).