From 2d3d6ec69ed3b900d7da54733422ce9e13dd18c6 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sun, 19 Jan 2014 22:32:26 +0200 Subject: [PATCH] [PATCH 5/7] cli: abstract notmuch new result printing --- 3f/0ef54d6a54a0b9fcbc034924b9c277329946b0 | 182 ++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 3f/0ef54d6a54a0b9fcbc034924b9c277329946b0 diff --git a/3f/0ef54d6a54a0b9fcbc034924b9c277329946b0 b/3f/0ef54d6a54a0b9fcbc034924b9c277329946b0 new file mode 100644 index 000000000..4bf8d53f5 --- /dev/null +++ b/3f/0ef54d6a54a0b9fcbc034924b9c277329946b0 @@ -0,0 +1,182 @@ +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 4D8B5431E64 + for ; Sun, 19 Jan 2014 12:33:09 -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 HUN9YlOFzSmI for ; + Sun, 19 Jan 2014 12:33:03 -0800 (PST) +Received: from mail-ea0-f173.google.com (mail-ea0-f173.google.com + [209.85.215.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 0A500431FC0 + for ; Sun, 19 Jan 2014 12:32:49 -0800 (PST) +Received: by mail-ea0-f173.google.com with SMTP id o10so2704189eaj.32 + for ; Sun, 19 Jan 2014 12:32:48 -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=GN27nkrca6L387o5tQ5mtCNaTql1AeLIZ3fwHje/bEA=; + b=D8Gnnxc6mkIGyR+qSRtA2tnD0juBN4RtPYBLKvmU92ItSnY01bg4GpaPcMzfMZ9EU4 + 2Lu2ERHdpg865Zij1kvBPvc50mYQfED8HPh/44MINJDO4SBv8o6bkmilA6NOvJlF/859 + kLwSFRLSEQmL/iiwwH3hcYzZmVsNI3hdRaHLjkTq5Uh4zn8cfDZ9nqWdl7nvqbh9Z6TZ + mq8BHNpQigOzT76x2/Ssd68GSnLDIaTwGSS2R+epletOITX5inCIlWW/yxQEEFTntZYm + PotFkC7RNHmPKIbJFMO3p+WbFW5LNZQsTw/5bOdme8vox4cueTDfQIKyQlUjIjp8JgnU + GjEQ== +X-Gm-Message-State: + ALoCoQkkNgl+kvYhTmM9tiXIUtvQpPjkzHr6gfImtoXMUIWJdfDssUBEA8lPX4PYa8Ayl4DBdARq +X-Received: by 10.15.94.201 with SMTP id bb49mr14162929eeb.45.1390163568893; + Sun, 19 Jan 2014 12:32:48 -0800 (PST) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) by mx.google.com with ESMTPSA id + j46sm46540798eew.18.2014.01.19.12.32.47 for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sun, 19 Jan 2014 12:32:48 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 5/7] cli: abstract notmuch new result printing +Date: Sun, 19 Jan 2014 22:32:26 +0200 +Message-Id: + <3c2ac7334d0f57b35c7cb53b6231f7a9b325d1b0.1390163335.git.jani@nikula.org> +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:33:09 -0000 + +The notmuch_new_command() function has grown huge, chop it up a +bit. This should also be helpful when adding a --quiet option to +notmuch new. No functional changes. +--- + notmuch-new.c | 80 +++++++++++++++++++++++++++++------------------------------ + 1 file changed, 39 insertions(+), 41 deletions(-) + +diff --git a/notmuch-new.c b/notmuch-new.c +index f6d9c3a..c443181 100644 +--- a/notmuch-new.c ++++ b/notmuch-new.c +@@ -864,13 +864,49 @@ _remove_directory (void *ctx, + return status; + } + ++static void ++print_results (const add_files_state_t *state) ++{ ++ double elapsed; ++ struct timeval tv_now; ++ ++ gettimeofday (&tv_now, NULL); ++ elapsed = notmuch_time_elapsed (state->tv_start, tv_now); ++ ++ if (state->processed_files) { ++ printf ("Processed %d %s in ", state->processed_files, ++ state->processed_files == 1 ? "file" : "total files"); ++ notmuch_time_print_formatted_seconds (elapsed); ++ if (elapsed > 1) ++ printf (" (%d files/sec.).\033[K\n", ++ (int) (state->processed_files / elapsed)); ++ else ++ printf (".\033[K\n"); ++ } ++ ++ if (state->added_messages) ++ printf ("Added %d new %s to the database.", state->added_messages, ++ state->added_messages == 1 ? "message" : "messages"); ++ else ++ printf ("No new mail."); ++ ++ if (state->removed_messages) ++ printf (" Removed %d %s.", state->removed_messages, ++ state->removed_messages == 1 ? "message" : "messages"); ++ ++ if (state->renamed_messages) ++ printf (" Detected %d file %s.", state->renamed_messages, ++ state->renamed_messages == 1 ? "rename" : "renames"); ++ ++ printf ("\n"); ++} ++ + int + notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) + { + notmuch_database_t *notmuch; + add_files_state_t add_files_state; +- double elapsed; +- struct timeval tv_now, tv_start; ++ struct timeval tv_start; + int ret = 0; + struct stat st; + const char *db_path; +@@ -1017,45 +1053,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) + if (timer_is_active) + stop_progress_printing_timer (); + +- gettimeofday (&tv_now, NULL); +- elapsed = notmuch_time_elapsed (add_files_state.tv_start, +- tv_now); +- +- if (add_files_state.processed_files) { +- printf ("Processed %d %s in ", add_files_state.processed_files, +- add_files_state.processed_files == 1 ? +- "file" : "total files"); +- notmuch_time_print_formatted_seconds (elapsed); +- if (elapsed > 1) { +- printf (" (%d files/sec.).\033[K\n", +- (int) (add_files_state.processed_files / elapsed)); +- } else { +- printf (".\033[K\n"); +- } +- } +- +- if (add_files_state.added_messages) { +- printf ("Added %d new %s to the database.", +- add_files_state.added_messages, +- add_files_state.added_messages == 1 ? +- "message" : "messages"); +- } else { +- printf ("No new mail."); +- } +- +- if (add_files_state.removed_messages) { +- printf (" Removed %d %s.", +- add_files_state.removed_messages, +- add_files_state.removed_messages == 1 ? "message" : "messages"); +- } +- +- if (add_files_state.renamed_messages) { +- printf (" Detected %d file %s.", +- add_files_state.renamed_messages, +- add_files_state.renamed_messages == 1 ? "rename" : "renames"); +- } +- +- printf ("\n"); ++ print_results (&add_files_state); + + if (ret) + fprintf (stderr, "Note: A fatal error was encountered: %s\n", +-- +1.8.5.2 + -- 2.26.2