From e53d56b71e35fa1a929a4b375279c55486e016a4 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 7 Oct 2014 17:17:07 +1800 Subject: [PATCH] [PATCH v2 01/12] lib: Move message ID compression to _notmuch_message_create_for_message_id --- 40/3e4c6bb64368f138cfc667c98c4d3aa1aa3f6d | 168 ++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 40/3e4c6bb64368f138cfc667c98c4d3aa1aa3f6d diff --git a/40/3e4c6bb64368f138cfc667c98c4d3aa1aa3f6d b/40/3e4c6bb64368f138cfc667c98c4d3aa1aa3f6d new file mode 100644 index 000000000..de1da80b5 --- /dev/null +++ b/40/3e4c6bb64368f138cfc667c98c4d3aa1aa3f6d @@ -0,0 +1,168 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 17CAB431FB6 + for ; Mon, 6 Oct 2014 16:18:08 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 2EsvOc-w5aPh for ; + Mon, 6 Oct 2014 16:18:04 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 6CEA5431FAE + for ; Mon, 6 Oct 2014 16:17:40 -0700 (PDT) +X-AuditID: 1209190e-f79d46d000003643-68-543323132dd7 +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id CD.5D.13891.31323345; Mon, 6 Oct 2014 19:17:39 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s96NHT81030746; + Mon, 6 Oct 2014 19:17:29 -0400 +Received: from drake.dyndns.org ([12.185.136.2]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s96NHRec014546 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Mon, 6 Oct 2014 19:17:28 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1XbHWr-0001JI-GX; Mon, 06 Oct 2014 17:17:21 -0600 +From: Austin Clements +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 +Message-Id: <1412637438-4821-2-git-send-email-aclements@csail.mit.edu> +X-Mailer: git-send-email 2.1.0 +In-Reply-To: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu> +References: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixCmqrSusbBxiMOmGscWN1m5Gi+s3ZzI7 + MHk8W3WL2WPLoffMAUxRXDYpqTmZZalF+nYJXBkr/+oVbJOqeDJ/A2sD43HRLkZODgkBE4lP + sw6wQ9hiEhfurWfrYuTiEBKYzSRx4e55ZghnA6PEklkLoZylTBKP+/rYIZwljBLTpq5gAeln + E9CXWLF2EiuILSIgLbHz7mwwm1nAUuLq13YmEFtYIEXixv5VYPUsAqoSl5t72EBsXgE3iTn7 + PrNA3CEnsWH3f0YQm1PAXWLNlclgc4SAap7/fMoygZF/ASPDKkbZlNwq3dzEzJzi1GTd4uTE + vLzUIl1jvdzMEr3UlNJNjOBQkuTbwfj1oNIhRgEORiUe3ogdhiFCrIllxZW5hxglOZiURHnn + sBuHCPEl5adUZiQWZ8QXleakFh9ilOBgVhLh5fptFCLEm5JYWZValA+TkuZgURLn3fSDL0RI + ID2xJDU7NbUgtQgmK8PBoSTB+1sRaKhgUWp6akVaZk4JQpqJgxNkOA/Q8H8gNbzFBYm5xZnp + EPlTjIpS4rzJSkAJAZBERmkeXC8s1l8xigO9IswrDlLFA0wTcN2vgAYzAQ02naMPMrgkESEl + 1cC42oe5aRlPmk3DjBU5uasPrHz5Y/UymaTk+bLfDpv2GtuXr2IqNnWdvWrjbqHABiXJ5zZr + 2+ecT7k7abV1cOpsEanjjPvS+z+1W/eeFr/2YqaNb96s49G7Oz1tDzJO/q7hETTNbs2cbGdl + s/VvjOf0LvN9fHjnDYlsoe87r5UEbM/XubqJl/u3EktxRqKhFnNRcSIAnhRx09ACAAA= +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 06 Oct 2014 23:18:08 -0000 + +From: Austin Clements + +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- + */ +-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 + -- 2.26.2