dovecot: Changed mail_transaction_begin() API to take flags para...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jul 19 02:56:46 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/a19931ec66db
changeset: 6089:a19931ec66db
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jul 19 02:36:04 2007 +0300
description:
Changed mail_transaction_begin() API to take flags parameter instead of two
booleans.

diffstat:

8 files changed, 32 insertions(+), 25 deletions(-)
src/imap/imap-thread.c                         |    2 +-
src/lib-index/mail-index-sync.c                |    6 ++++--
src/lib-index/mail-index-transaction-private.h |    3 +--
src/lib-index/mail-index-transaction.c         |    6 ++----
src/lib-index/mail-index.h                     |   19 +++++++++++--------
src/lib-index/mail-transaction-log-append.c    |    9 +++++----
src/lib-storage/index/index-transaction.c      |    9 ++++++---
src/lib-storage/list/index-mailbox-list-sync.c |    3 ++-

diffs (200 lines):

diff -r 7639a6df4acb -r a19931ec66db src/imap/imap-thread.c
--- a/src/imap/imap-thread.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/imap/imap-thread.c	Thu Jul 19 02:36:04 2007 +0300
@@ -2082,7 +2082,7 @@ imap_thread_expunge_handler(struct mail_
 		if (mail_hash_lock(tbox->msgid_hash) <= 0)
 			return 0;
 
-		t = mail_index_transaction_begin(sync_ctx->view, FALSE, FALSE);
+		t = mail_index_transaction_begin(sync_ctx->view, 0);
 		mt = MAIL_STORAGE_CONTEXT(t);
 
 		ctx->msgid_hash = tbox->msgid_hash;
diff -r 7639a6df4acb -r a19931ec66db src/lib-index/mail-index-sync.c
--- a/src/lib-index/mail-index-sync.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-index-sync.c	Thu Jul 19 02:36:04 2007 +0300
@@ -364,7 +364,8 @@ int mail_index_sync_begin(struct mail_in
 	ctx->view = mail_index_view_open(index);
 
 	sync_view = mail_index_dummy_view_open(index);
-	ctx->sync_trans = mail_index_transaction_begin(sync_view, FALSE, TRUE);
+	ctx->sync_trans = mail_index_transaction_begin(sync_view,
+					MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
 	mail_index_view_close(&sync_view);
 
 	/* we wish to see all the changes from last mailbox sync position to
@@ -394,7 +395,8 @@ int mail_index_sync_begin(struct mail_in
 
 	/* create the transaction after the view has been updated with
 	   external transactions and marked as sync view */
-	ctx->ext_trans = mail_index_transaction_begin(ctx->view, FALSE, TRUE);
+	ctx->ext_trans = mail_index_transaction_begin(ctx->view,
+					MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
 
 	*ctx_r = ctx;
 	*view_r = ctx->view;
diff -r 7639a6df4acb -r a19931ec66db src/lib-index/mail-index-transaction-private.h
--- a/src/lib-index/mail-index-transaction-private.h	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-index-transaction-private.h	Thu Jul 19 02:36:04 2007 +0300
@@ -29,6 +29,7 @@ struct mail_index_transaction {
 struct mail_index_transaction {
 	int refcount;
 
+	enum mail_index_transaction_flags flags;
 	struct mail_index_transaction_vfuncs v;
 	struct mail_index_view *view;
 
@@ -65,9 +66,7 @@ struct mail_index_transaction {
 
 	/* this transaction was created for index_sync_view view */
 	unsigned int sync_transaction:1;
-	unsigned int hide_transaction:1;
 	unsigned int no_appends:1;
-	unsigned int external:1;
 
 	unsigned int appends_nonsorted:1;
 	unsigned int pre_hdr_changed:1;
diff -r 7639a6df4acb -r a19931ec66db src/lib-index/mail-index-transaction.c
--- a/src/lib-index/mail-index-transaction.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-index-transaction.c	Thu Jul 19 02:36:04 2007 +0300
@@ -590,7 +590,6 @@ void mail_index_append_assign_uids(struc
 
 void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq)
 {
-	i_assert(!t->hide_transaction);
 	i_assert(seq > 0 && seq <= mail_index_view_get_messages_count(t->view));
 
 	t->log_updates = TRUE;
@@ -1196,7 +1195,7 @@ struct mail_index_transaction_vfuncs tra
 
 struct mail_index_transaction *
 mail_index_transaction_begin(struct mail_index_view *view,
-			     bool hide, bool external)
+			     enum mail_index_transaction_flags flags)
 {
 	struct mail_index_transaction *t;
 
@@ -1208,8 +1207,7 @@ mail_index_transaction_begin(struct mail
 	t->refcount = 1;
 	t->v = trans_vfuncs;
 	t->view = view;
-	t->hide_transaction = hide;
-	t->external = external;
+	t->flags = flags;
 	t->sync_transaction = view->index_sync_view;
 
 	if (view->syncing) {
diff -r 7639a6df4acb -r a19931ec66db src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-index.h	Thu Jul 19 02:36:04 2007 +0300
@@ -100,6 +100,15 @@ struct mail_keywords {
 	unsigned int idx[1];
 };
 
+enum mail_index_transaction_flags {
+	/* If transaction is marked as hidden, the changes won't be listed
+	   when the view is synchronized. */
+	MAIL_INDEX_TRANSACTION_FLAG_HIDE		= 0x01,
+	/* External transactions describe changes to mailbox that have already
+	   happened. */
+	MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL		= 0x02
+};
+
 enum mail_index_sync_type {
 	MAIL_INDEX_SYNC_TYPE_APPEND		= 0x01,
 	MAIL_INDEX_SYNC_TYPE_EXPUNGE		= 0x02,
@@ -187,16 +196,10 @@ bool mail_index_view_is_inconsistent(str
 /* Transaction has to be opened to be able to modify index. You can have
    multiple transactions open simultaneously. Committed transactions won't
    show up until you've synchronized the view. Expunges won't show up until
-   you've synchronized the mailbox (mail_index_sync_begin).
-
-   If transaction is marked as hidden, the changes won't be listed when the
-   view is synchronized. Expunges can't be hidden.
-
-   External transactions describe changes to mailbox that have already
-   happened. */
+   you've synchronized the mailbox (mail_index_sync_begin). */
 struct mail_index_transaction *
 mail_index_transaction_begin(struct mail_index_view *view,
-			     bool hide, bool external);
+			     enum mail_index_transaction_flags flags);
 int mail_index_transaction_commit(struct mail_index_transaction **t,
 				  uint32_t *log_file_seq_r,
 				  uoff_t *log_file_offset_r);
diff -r 7639a6df4acb -r a19931ec66db src/lib-index/mail-transaction-log-append.c
--- a/src/lib-index/mail-transaction-log-append.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-transaction-log-append.c	Thu Jul 19 02:36:04 2007 +0300
@@ -36,7 +36,7 @@ static void log_append_buffer(struct log
 	hdr.type = type;
 	if (type == MAIL_TRANSACTION_EXPUNGE)
 		hdr.type |= MAIL_TRANSACTION_EXPUNGE_PROT;
-	if (ctx->trans->external)
+	if ((ctx->trans->flags & MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0)
 		hdr.type |= MAIL_TRANSACTION_EXTERNAL;
 
 	hdr_size = mail_index_uint32_to_offset(sizeof(hdr) + buf->used +
@@ -536,7 +536,7 @@ mail_transaction_log_append_locked(struc
 	/* NOTE: mailbox sync offset update must be the last change.
 	   it may update the sync offset to include this transaction, so it
 	   needs to know this transaction's size */
-	if (t->external)
+	if ((t->flags & MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0)
 		log_append_sync_offset_if_needed(&ctx);
 
 	if (file->sync_offset < file->last_size) {
@@ -560,7 +560,7 @@ mail_transaction_log_append_locked(struc
 	}
 	buffer_free(ctx.output);
 
-	if (t->hide_transaction) {
+	if ((t->flags & MAIL_INDEX_TRANSACTION_FLAG_HIDE) != 0) {
 		/* mark the area covered by this transaction hidden */
 		mail_index_view_add_hidden_transaction(view, file->hdr.file_seq,
 			append_offset, file->sync_offset - append_offset);
@@ -588,7 +588,8 @@ int mail_transaction_log_append(struct m
 
 	index = mail_index_view_get_index(t->view);
 	if (index->log_locked) {
-		i_assert(t->external);
+		i_assert((t->flags &
+			  MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0);
 	} else {
 		if (mail_transaction_log_lock_head(index->log) < 0)
 			return -1;
diff -r 7639a6df4acb -r a19931ec66db src/lib-storage/index/index-transaction.c
--- a/src/lib-storage/index/index-transaction.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-storage/index/index-transaction.c	Thu Jul 19 02:36:04 2007 +0300
@@ -61,13 +61,16 @@ index_transaction_begin(struct mailbox *
 	struct index_mailbox *ibox = (struct index_mailbox *)box;
 	struct mail_index_transaction *t;
 	struct index_transaction_context *it;
+	enum mail_index_transaction_flags trans_flags = 0;
 
 	if (!box->opened)
 		index_storage_mailbox_open(ibox);
 
-	t = mail_index_transaction_begin(ibox->view,
-		(flags & MAILBOX_TRANSACTION_FLAG_HIDE) != 0,
-		(flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
+	if ((flags & MAILBOX_TRANSACTION_FLAG_HIDE) != 0)
+		trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_HIDE;
+	if ((flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0)
+		trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL;
+	t = mail_index_transaction_begin(ibox->view, trans_flags);
 
 	it = MAIL_STORAGE_CONTEXT(t);
 	if (it == NULL) {
diff -r 7639a6df4acb -r a19931ec66db src/lib-storage/list/index-mailbox-list-sync.c
--- a/src/lib-storage/list/index-mailbox-list-sync.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list-sync.c	Thu Jul 19 02:36:04 2007 +0300
@@ -227,7 +227,8 @@ index_list_update(struct index_mailbox_l
 	unsigned int i;
 	int ret = 1;
 
-	trans = mail_index_transaction_begin(view, FALSE, TRUE);
+	trans = mail_index_transaction_begin(view,
+					MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
 
 	/* update counters */
 	for (i = 0; index_list_map[i].name != NULL; i++) {


More information about the dovecot-cvs mailing list