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 65F4E429E4E for ; Wed, 14 Dec 2011 13:54:26 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 xW-r4LAB+r9a for ; Wed, 14 Dec 2011 13:54:25 -0800 (PST) Received: from VA3EHSOBE003.bigfish.com (va3ehsobe003.messaging.microsoft.com [216.32.180.13]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 63AE3429E4D for ; Wed, 14 Dec 2011 13:54:25 -0800 (PST) Received: from mail70-va3-R.bigfish.com (10.7.14.235) by VA3EHSOBE003.bigfish.com (10.7.40.23) with Microsoft SMTP Server id 14.1.225.23; Wed, 14 Dec 2011 21:54:26 +0000 Received: from mail70-va3 (localhost [127.0.0.1]) by mail70-va3-R.bigfish.com (Postfix) with ESMTP id 878B122037F; Wed, 14 Dec 2011 21:54:28 +0000 (UTC) X-SpamScore: -9 X-BigFish: VPS-9(zz1432N98dKzz1202hzz8275ch8275dhz2dh668h839h944h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: CIP:163.181.249.108; KIP:(null); UIP:(null); IPV:NLI; H:ausb3twp01.amd.com; RD:none; EFVD:NLI Received: from mail70-va3 (localhost.localdomain [127.0.0.1]) by mail70-va3 (MessageSwitch) id 1323899668177659_15395; Wed, 14 Dec 2011 21:54:28 +0000 (UTC) Received: from VA3EHSMHS023.bigfish.com (unknown [10.7.14.235]) by mail70-va3.bigfish.com (Postfix) with ESMTP id 25059C0045; Wed, 14 Dec 2011 21:54:28 +0000 (UTC) Received: from ausb3twp01.amd.com (163.181.249.108) by VA3EHSMHS023.bigfish.com (10.7.99.33) with Microsoft SMTP Server id 14.1.225.23; Wed, 14 Dec 2011 21:54:20 +0000 X-WSS-ID: 0LW7RIE-01-9C7-02 X-M-MSG: Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com [163.181.249.73]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Axway MailGate 3.8.1) with ESMTP id 2F6141028051; Wed, 14 Dec 2011 15:54:14 -0600 (CST) Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep02.amd.com (163.181.36.59) with Microsoft SMTP Server (TLS) id 8.3.192.1; Wed, 14 Dec 2011 15:54:29 -0600 Received: from adcvmail01.amd.com (163.181.21.78) by sausexhtp02.amd.com (163.181.3.152) with Microsoft SMTP Server (TLS) id 8.3.213.0; Wed, 14 Dec 2011 15:54:16 -0600 Received: from mhdc-ns01.amd.com (mhdc-ns01.amd.com [165.204.35.147]) by adcvmail01.amd.com (8.13.8/8.13.8) with ESMTP id pBELsF31022473; Wed, 14 Dec 2011 15:54:16 -0600 Received: from testarossa.amd.com (testarossa.amd.com [165.204.147.44]) by mhdc-ns01.amd.com (8.13.8+Sun/8.13.8) with ESMTP id pBELsFgi024368; Wed, 14 Dec 2011 14:54:15 -0700 (MST) Received: (from manderso@localhost) by testarossa.amd.com (8.13.8/8.13.8/Submit) id pBELsABF030781; Wed, 14 Dec 2011 14:54:10 -0700 X-Authentication-Warning: testarossa.amd.com: manderso set sender to MarkR.Anderson@amd.com using -f From: Mark Anderson To: Thomas Jost , "notmuch@notmuchmail.org" Subject: Re: [PATCH 2/5] lib: Add a MTIME value to every mail document In-Reply-To: <1323796305-28789-3-git-send-email-schnouki@schnouki.net> References: <1323796305-28789-1-git-send-email-schnouki@schnouki.net> <1323796305-28789-3-git-send-email-schnouki@schnouki.net> User-Agent: Notmuch/0.10.2+101~g11c52d7 (http://notmuchmail.org) Emacs/23.1.1 (i686-pc-linux-gnu) Date: Wed, 14 Dec 2011 14:54:10 -0700 Message-ID: <3wdvcpi6cql.fsf@testarossa.amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-OriginatorOrg: amd.com 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: Wed, 14 Dec 2011 21:54:26 -0000 On Tue, 13 Dec 2011 11:11:42 -0600, Thomas Jost wrote: > This is a time_t value, similar to the message date (TIMESTAMP). It is first set > when the message is added to the database, and is then updated every time a tag > is added or removed. It can thus be used for doing incremental dumps of the > database or for synchronizing it between several computers. > > This value can be read freely (with notmuch_message_get_mtime()) but for now it > can't be set to an arbitrary value: it can only be set to "now" when updated. > There's no specific reason for this except that I don't really see a real use > case for setting it to an arbitrary value. I think it would be easier to write some testcases if the last modified time could be touched directly. Perhaps they aren't in the set of "must have", but it's what comes to mind. -Mark > --- > lib/database.cc | 7 ++++++- > lib/message.cc | 32 ++++++++++++++++++++++++++++++++ > lib/notmuch-private.h | 6 +++++- > lib/notmuch.h | 4 ++++ > 4 files changed, 47 insertions(+), 2 deletions(-) > > diff --git a/lib/database.cc b/lib/database.cc > index 2025189..6dc6f73 100644 > --- a/lib/database.cc > +++ b/lib/database.cc > @@ -81,7 +81,7 @@ typedef struct { > * STRING is the name of a file within that > * directory for this mail message. > * > - * A mail document also has four values: > + * A mail document also has five values: > * > * TIMESTAMP: The time_t value corresponding to the message's > * Date header. > @@ -92,6 +92,9 @@ typedef struct { > * > * SUBJECT: The value of the "Subject" header > * > + * MTIME: The time_t value corresponding to the last time > + * a tag was added or removed on the message. > + * > * In addition, terms from the content of the message are added with > * "from", "to", "attachment", and "subject" prefixes for use by the > * user in searching. Similarly, terms from the path of the mail > @@ -1735,6 +1738,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch, > date = notmuch_message_file_get_header (message_file, "date"); > _notmuch_message_set_header_values (message, date, from, subject); > > + _notmuch_message_update_mtime (message); > + > _notmuch_message_index_file (message, filename); > } else { > ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID; > diff --git a/lib/message.cc b/lib/message.cc > index 0075425..0c98589 100644 > --- a/lib/message.cc > +++ b/lib/message.cc > @@ -830,6 +830,34 @@ _notmuch_message_set_header_values (notmuch_message_t *message, > message->doc.add_value (NOTMUCH_VALUE_SUBJECT, subject); > } > > +/* Get the message mtime, i.e. when it was added or the last time a tag was > + * added/removed. */ > +time_t > +notmuch_message_get_mtime (notmuch_message_t *message) > +{ > + std::string value; > + > + try { > + value = message->doc.get_value (NOTMUCH_VALUE_MTIME); > + } catch (Xapian::Error &error) { > + INTERNAL_ERROR ("Failed to read mtime value from document."); > + return 0; > + } > + > + return Xapian::sortable_unserialise (value); > +} > + > +/* Set the message mtime to "now". */ > +void > +_notmuch_message_update_mtime (notmuch_message_t *message) > +{ > + time_t time_value; > + > + time_value = time (NULL); > + message->doc.add_value (NOTMUCH_VALUE_MTIME, > + Xapian::sortable_serialise (time_value)); > +} > + > /* Synchronize changes made to message->doc out into the database. */ > void > _notmuch_message_sync (notmuch_message_t *message) > @@ -994,6 +1022,8 @@ notmuch_message_add_tag (notmuch_message_t *message, const char *tag) > private_status); > } > > + _notmuch_message_update_mtime (message); > + > if (! message->frozen) > _notmuch_message_sync (message); > > @@ -1022,6 +1052,8 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag) > private_status); > } > > + _notmuch_message_update_mtime (message); > + > if (! message->frozen) > _notmuch_message_sync (message); > > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h > index 60a932f..9859872 100644 > --- a/lib/notmuch-private.h > +++ b/lib/notmuch-private.h > @@ -95,7 +95,8 @@ typedef enum { > NOTMUCH_VALUE_TIMESTAMP = 0, > NOTMUCH_VALUE_MESSAGE_ID, > NOTMUCH_VALUE_FROM, > - NOTMUCH_VALUE_SUBJECT > + NOTMUCH_VALUE_SUBJECT, > + NOTMUCH_VALUE_MTIME > } notmuch_value_t; > > /* Xapian (with flint backend) complains if we provide a term longer > @@ -276,6 +277,9 @@ _notmuch_message_set_header_values (notmuch_message_t *message, > const char *from, > const char *subject); > void > +_notmuch_message_update_mtime (notmuch_message_t *message); > + > +void > _notmuch_message_sync (notmuch_message_t *message); > > notmuch_status_t > diff --git a/lib/notmuch.h b/lib/notmuch.h > index 9f23a10..643ebce 100644 > --- a/lib/notmuch.h > +++ b/lib/notmuch.h > @@ -910,6 +910,10 @@ notmuch_message_set_flag (notmuch_message_t *message, > time_t > notmuch_message_get_date (notmuch_message_t *message); > > +/* Get the mtime of 'message' as a time_t value. */ > +time_t > +notmuch_message_get_mtime (notmuch_message_t *message); > + > /* Get the value of the specified header from 'message'. > * > * The value will be read from the actual message file, not from the > -- > 1.7.8 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch >