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 EE312431FC4 for ; Sun, 19 Jan 2014 12:32:48 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" 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 ehi70FpH3FEX for ; Sun, 19 Jan 2014 12:32:42 -0800 (PST) Received: from mail-ea0-f169.google.com (mail-ea0-f169.google.com [209.85.215.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 3A661431FC0 for ; Sun, 19 Jan 2014 12:32:42 -0800 (PST) Received: by mail-ea0-f169.google.com with SMTP id l9so2371573eaj.14 for ; Sun, 19 Jan 2014 12:32:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ZlZO3SgikNTtTG871qD0qm4K3Hzd6zaq6UH2X0CJPDo=; b=Oaw+5gdLHB+qlC1PEHtTJNOoqbcKHsh6OoOcq1OnE7ZaaGde6CJICNwXRFG6FKmkqo AbpdiVsmCFzxVEopZKFfQHtaLOKA3Sp12B2bo07V7NvSs5OGgOohVbHJxx9mGxuHlkQT g18s90Xh6jtkj8u4aLI2xj2tS461ywWRJT3gg5mS/+5JwyRHSYry8j83gB7lsGgaOwfb yaQwkKvYWHWkqhOOvq8o18bDGVKnJ3U1EutFUTl4Siq9UfPfVNsDaa7SpGmPJtrFZqlZ e8Dxu4DG66TNOkJ/aOsl2gReax0rrmiV/w7gOgEaFtFNL3dZnaKEMCKkQ0SGnLpZ8bwP jTKA== X-Gm-Message-State: ALoCoQmGoaz1AtOsqlHdIdgHJwqHpsWQ7YxPihXjxLFC3guDsLvgDp8tWzQ4FvxFRByBenPu2All X-Received: by 10.15.54.72 with SMTP id s48mr13906238eew.3.1390163559636; Sun, 19 Jan 2014 12:32:39 -0800 (PST) Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. [88.195.111.91]) by mx.google.com with ESMTPSA id 4sm46526754eed.14.2014.01.19.12.32.37 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 19 Jan 2014 12:32:38 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH 1/7] cli: extract single message addition in notmuch new to clarify code Date: Sun, 19 Jan 2014 22:32:22 +0200 Message-Id: X-Mailer: git-send-email 1.8.5.2 In-Reply-To: References: In-Reply-To: References: 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: Sun, 19 Jan 2014 20:32:49 -0000 The add_files() function has grown huge, chop it up a bit. No functional changes. --- notmuch-new.c | 109 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 6a8b1b2..1dd8fc9 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -240,6 +240,60 @@ _entry_in_ignore_list (const char *entry, add_files_state_t *state) return FALSE; } +/* Add a single file to the database. */ +static notmuch_status_t +add_file (notmuch_database_t *notmuch, const char *filename, + add_files_state_t *state) +{ + notmuch_message_t *message = NULL; + const char **tag; + notmuch_status_t status; + + status = notmuch_database_begin_atomic (notmuch); + if (status) + goto DONE; + + status = notmuch_database_add_message (notmuch, filename, &message); + switch (status) { + /* Success. */ + case NOTMUCH_STATUS_SUCCESS: + state->added_messages++; + notmuch_message_freeze (message); + for (tag = state->new_tags; *tag != NULL; tag++) + notmuch_message_add_tag (message, *tag); + if (state->synchronize_flags) + notmuch_message_maildir_flags_to_tags (message); + notmuch_message_thaw (message); + break; + /* Non-fatal issues (go on to next file). */ + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: + if (state->synchronize_flags) + notmuch_message_maildir_flags_to_tags (message); + break; + case NOTMUCH_STATUS_FILE_NOT_EMAIL: + fprintf (stderr, "Note: Ignoring non-mail file: %s\n", filename); + break; + /* Fatal issues. Don't process anymore. */ + case NOTMUCH_STATUS_READ_ONLY_DATABASE: + case NOTMUCH_STATUS_XAPIAN_EXCEPTION: + case NOTMUCH_STATUS_OUT_OF_MEMORY: + fprintf (stderr, "Error: %s. Halting processing.\n", + notmuch_status_to_string (status)); + goto DONE; + default: + INTERNAL_ERROR ("add_message returned unexpected value: %d", status); + goto DONE; + } + + status = notmuch_database_end_atomic (notmuch); + + DONE: + if (message) + notmuch_message_destroy (message); + + return status; +} + /* Examine 'path' recursively as follows: * * o Ask the filesystem for the mtime of 'path' (fs_mtime) @@ -291,7 +345,6 @@ add_files (notmuch_database_t *notmuch, char *next = NULL; time_t fs_mtime, db_mtime; notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS; - notmuch_message_t *message = NULL; struct dirent **fs_entries = NULL; int i, num_fs_entries = 0, entry_type; notmuch_directory_t *directory; @@ -300,7 +353,6 @@ add_files (notmuch_database_t *notmuch, time_t stat_time; struct stat st; notmuch_bool_t is_maildir; - const char **tag; if (stat (path, &st)) { fprintf (stderr, "Error reading directory %s: %s\n", @@ -527,63 +579,12 @@ add_files (notmuch_database_t *notmuch, fflush (stdout); } - status = notmuch_database_begin_atomic (notmuch); + status = add_file (notmuch, next, state); if (status) { ret = status; goto DONE; } - status = notmuch_database_add_message (notmuch, next, &message); - switch (status) { - /* success */ - case NOTMUCH_STATUS_SUCCESS: - state->added_messages++; - notmuch_message_freeze (message); - for (tag=state->new_tags; *tag != NULL; tag++) - notmuch_message_add_tag (message, *tag); - if (state->synchronize_flags == TRUE) - notmuch_message_maildir_flags_to_tags (message); - notmuch_message_thaw (message); - break; - /* Non-fatal issues (go on to next file) */ - case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: - if (state->synchronize_flags == TRUE) - notmuch_message_maildir_flags_to_tags (message); - break; - case NOTMUCH_STATUS_FILE_NOT_EMAIL: - fprintf (stderr, "Note: Ignoring non-mail file: %s\n", - next); - break; - /* Fatal issues. Don't process anymore. */ - case NOTMUCH_STATUS_READ_ONLY_DATABASE: - case NOTMUCH_STATUS_XAPIAN_EXCEPTION: - case NOTMUCH_STATUS_OUT_OF_MEMORY: - fprintf (stderr, "Error: %s. Halting processing.\n", - notmuch_status_to_string (status)); - ret = status; - goto DONE; - default: - case NOTMUCH_STATUS_FILE_ERROR: - case NOTMUCH_STATUS_NULL_POINTER: - case NOTMUCH_STATUS_TAG_TOO_LONG: - case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: - case NOTMUCH_STATUS_UNBALANCED_ATOMIC: - case NOTMUCH_STATUS_LAST_STATUS: - INTERNAL_ERROR ("add_message returned unexpected value: %d", status); - goto DONE; - } - - status = notmuch_database_end_atomic (notmuch); - if (status) { - ret = status; - goto DONE; - } - - if (message) { - notmuch_message_destroy (message); - message = NULL; - } - if (do_print_progress) { do_print_progress = 0; generic_print_progress ("Processed", "files", state->tv_start, -- 1.8.5.2