unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Clements <aclements@csail.mit.edu>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 01/12] lib: Move message ID compression to _notmuch_message_create_for_message_id
Date: Mon,  6 Oct 2014 17:17:07 -0600	[thread overview]
Message-ID: <1412637438-4821-2-git-send-email-aclements@csail.mit.edu> (raw)
In-Reply-To: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu>

From: Austin Clements <amdragon@mit.edu>

Previously, this was performed by notmuch_database_add_message.  This
happens to be the only caller currently (which is why this was safe),
but we're about to introduce more callers, and it makes more sense to
put responsibility for ID compression in the lower-level function
rather than requiring each caller to handle it.
---
 lib/database.cc       | 16 ++++------------
 lib/message.cc        |  4 ++++
 lib/notmuch-private.h |  3 +++
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index a47a71d..4e68706 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -390,8 +390,8 @@ find_document_for_doc_id (notmuch_database_t *notmuch, unsigned doc_id)
  *
  *	notmuch-sha1-<sha1_sum_of_message_id>
  */
-static char *
-_message_id_compressed (void *ctx, const char *message_id)
+char *
+_notmuch_message_id_compressed (void *ctx, const char *message_id)
 {
     char *sha1, *compressed;
 
@@ -415,7 +415,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch,
 	return NOTMUCH_STATUS_NULL_POINTER;
 
     if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
-	message_id = _message_id_compressed (notmuch, message_id);
+	message_id = _notmuch_message_id_compressed (notmuch, message_id);
 
     try {
 	status = _notmuch_database_find_unique_doc_id (notmuch, "id",
@@ -1728,7 +1728,7 @@ static char *
 _get_metadata_thread_id_key (void *ctx, const char *message_id)
 {
     if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
-	message_id = _message_id_compressed (ctx, message_id);
+	message_id = _notmuch_message_id_compressed (ctx, message_id);
 
     return talloc_asprintf (ctx, NOTMUCH_METADATA_THREAD_ID_PREFIX "%s",
 			    message_id);
@@ -2100,14 +2100,6 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 	     * better than no message-id at all. */
 	    if (message_id == NULL)
 		message_id = talloc_strdup (message_file, header);
-
-	    /* If a message ID is too long, substitute its sha1 instead. */
-	    if (message_id && strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX) {
-		char *compressed = _message_id_compressed (message_file,
-							   message_id);
-		talloc_free (message_id);
-		message_id = compressed;
-	    }
 	}
 
 	if (message_id == NULL ) {
diff --git a/lib/message.cc b/lib/message.cc
index 7e82548..bbfc250 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -226,6 +226,10 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,
     else if (*status_ret)
 	return NULL;
 
+    /* If the message ID is too long, substitute its sha1 instead. */
+    if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
+	message_id = _notmuch_message_id_compressed (message, message_id);
+
     term = talloc_asprintf (NULL, "%s%s",
 			    _find_prefix ("id"), message_id);
     if (term == NULL) {
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 17f3061..36cc12b 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -174,6 +174,9 @@ typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;
 const char *
 _find_prefix (const char *name);
 
+char *
+_notmuch_message_id_compressed (void *ctx, const char *message_id);
+
 notmuch_status_t
 _notmuch_database_ensure_writable (notmuch_database_t *notmuch);
 
-- 
2.1.0

  reply	other threads:[~2014-10-06 23:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-06 23:17 [PATCH 00/12] Add ghost messages and fix thread linking Austin Clements
2014-10-06 23:17 ` Austin Clements [this message]
2014-10-06 23:17 ` [PATCH v2 02/12] lib: Refactor _notmuch_database_link_message Austin Clements
2014-10-06 23:17 ` [PATCH v2 03/12] lib: Handle empty date value Austin Clements
2014-10-11  5:12   ` David Bremner
2014-10-06 23:17 ` [PATCH v2 04/12] lib: Add a ghost messages database feature Austin Clements
2014-10-06 23:17 ` [PATCH v2 05/12] lib: Update database schema doc for ghost messages Austin Clements
2014-10-06 23:17 ` [PATCH v2 06/12] lib: Introduce macros for bit operations Austin Clements
2014-10-06 23:17 ` [PATCH v2 07/12] lib: Internal support for querying and creating ghost messages Austin Clements
2014-10-21 23:05   ` Mark Walters
2014-10-22  1:33     ` Austin Clements
2014-10-06 23:17 ` [PATCH v2 08/12] lib: Implement ghost-based thread linking Austin Clements
2014-10-21 23:10   ` Mark Walters
2014-10-22  1:49     ` Austin Clements
2014-10-06 23:17 ` [PATCH v2 09/12] lib: Implement upgrade to ghost messages feature Austin Clements
2014-10-06 23:17 ` [PATCH v2 10/12] lib: Enable " Austin Clements
2014-10-06 23:17 ` [PATCH v2 11/12] test: Test upgrade to " Austin Clements
2014-10-06 23:17 ` [PATCH v2 12/12] lib: Remove unnecessary thread linking steps when using ghost messages Austin Clements
2014-10-21 23:17   ` Mark Walters
2014-10-22  1:51     ` Austin Clements
2014-10-21 23:32 ` [PATCH 00/12] Add ghost messages and fix thread linking Mark Walters

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1412637438-4821-2-git-send-email-aclements@csail.mit.edu \
    --to=aclements@csail.mit.edu \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).