From: Austin Clements Date: Fri, 3 Oct 2014 14:19:08 +0000 (+2000) Subject: [PATCH 01/11] lib: Move message ID compression to _notmuch_message_create_for_message_id X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a1312b5b366eb70f6364fb578bd05261b3edb8a3;p=notmuch-archives.git [PATCH 01/11] lib: Move message ID compression to _notmuch_message_create_for_message_id --- diff --git a/ac/d69f2167dda81857af6ae4cf4d08ae6a74c255 b/ac/d69f2167dda81857af6ae4cf4d08ae6a74c255 new file mode 100644 index 000000000..11fddfb67 --- /dev/null +++ b/ac/d69f2167dda81857af6ae4cf4d08ae6a74c255 @@ -0,0 +1,170 @@ +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 1E51C431FCF + for ; Fri, 3 Oct 2014 07:20:19 -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 BZSI2emUxEFO for ; + Fri, 3 Oct 2014 07:20:11 -0700 (PDT) +Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu + [18.7.68.37]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 8B405431FDE + for ; Fri, 3 Oct 2014 07:19:36 -0700 (PDT) +X-AuditID: 12074425-f79e46d000002583-44-542eb0751d50 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP + id 91.28.09603.570BE245; Fri, 3 Oct 2014 10:19:33 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s93EJNje020194; + Fri, 3 Oct 2014 10:19:23 -0400 +Received: from drake.dyndns.org + (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [216.15.114.40]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s93EJLwW023306 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Fri, 3 Oct 2014 10:19:22 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1Xa3hY-0002JY-VT; Fri, 03 Oct 2014 10:19:20 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 01/11] lib: Move message ID compression to + _notmuch_message_create_for_message_id +Date: Fri, 3 Oct 2014 10:19:08 -0400 +Message-Id: <1412345958-8278-2-git-send-email-aclements@csail.mit.edu> +X-Mailer: git-send-email 2.1.0 +In-Reply-To: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu> +References: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFlrPIsWRmVeSWpSXmKPExsUixG6nrlu6QS/EoLXBwuL6zZnMDowez1bd + Yg5gjOKySUnNySxLLdK3S+DKWPlXr2CbVMWT+RtYGxiPi3YxcnJICJhIPD98nw3CFpO4cG89 + mC0kMJtJYt+9ui5GLiB7A6NE+83jzBCJ20wSC9/KQiSWMEq83NjPCJJgE9CXWLF2EiuILSIg + LbHz7mwgm4ODWUBN4k+XCogpLJAoMXlSDUgFi4CqxJE9rWDVvAJuEld3TmSBuEFOYsPu/2AT + OQXcJS7cfQp1j5vEqmPdbBMY+RcwMqxilE3JrdLNTczMKU5N1i1OTszLSy3StdDLzSzRS00p + 3cQIDhcX1R2MEw4pHWIU4GBU4uH9eEM3RIg1say4MvcQoyQHk5Iob+VivRAhvqT8lMqMxOKM + +KLSnNTiQ4wSHMxKIrwLVgLleFMSK6tSi/JhUtIcLErivJt+8IUICaQnlqRmp6YWpBbBZGU4 + OJQkeLmAcSEkWJSanlqRlplTgpBm4uAEGc4DNLx9Pcjw4oLE3OLMdIj8KUZFKXFeUZBmAZBE + RmkeXC8snl8xigO9IszLBFLFA0wFcN2vgAYzAQ1+Z68LMrgkESEl1cB4YbMg++NiDzuVf8Gc + daJ1y5js9wtbTsyIPVS9wvJPro346ndnPRmeaDzneHauzfP9+4/H5EKeCm75N+2/o7RvVs8R + DafEdtajFUHpjT96pjtNMi1av3CZqO9Spr3zD9d++hza8iCiJoHPWGu36+qzviuu+QieWjZX + 6+Oq2yFVzc+X6U9qbPinxFKckWioxVxUnAgAtz0vOsICAAA= +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: Fri, 03 Oct 2014 14:20:19 -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 +