From: Jani Nikula Date: Thu, 3 Sep 2015 19:39:58 +0000 (+0300) Subject: [PATCH v2 2/9] cli: abstract new mailbox creation X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2c09c5d548b7d6115833049f62f45995741c6394;p=notmuch-archives.git [PATCH v2 2/9] cli: abstract new mailbox creation --- diff --git a/68/33c1fd4ff9c9a8f62bbae5e7a2a69c049e006a b/68/33c1fd4ff9c9a8f62bbae5e7a2a69c049e006a new file mode 100644 index 000000000..2f74031cb --- /dev/null +++ b/68/33c1fd4ff9c9a8f62bbae5e7a2a69c049e006a @@ -0,0 +1,120 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 0D0A26DE17BF + for ; Thu, 3 Sep 2015 12:40:28 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.416 +X-Spam-Level: +X-Spam-Status: No, score=-0.416 tagged_above=-999 required=5 tests=[AWL=0.304, + RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id EoiBePqI9XWk for ; + Thu, 3 Sep 2015 12:40:26 -0700 (PDT) +Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com + [209.85.212.178]) + by arlo.cworth.org (Postfix) with ESMTPS id D04F26DE1534 + for ; Thu, 3 Sep 2015 12:40:15 -0700 (PDT) +Received: by wiclk2 with SMTP id lk2so19111569wic.1 + for ; Thu, 03 Sep 2015 12:40:13 -0700 (PDT) +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=7x21swL2LRVephKeotLrwmieDqRaO00TDhQTFy28Q6k=; + b=I5x4/Le4CQ9ij/EGute5b4TnQejQDVWowVLSBg8tooKl7i8AQzWvPa7388qDT4qxUt + 7gqhogx3SJBPY3/plgf+HuFw350Wm2weEHhD68LXLQKZHoF9rpszL7iUgwPfShBo9+to + F4BmBZ0c0fJdoDSsaG8Jt1gJpNzOXN2upHF4ZQz5xTlJkZTMlw8IJaFCNsY2iAiLb43Q + RuTCjtWihBrR6ln6KHcukkj0LmCb0oHN29pPjV36ghiKcJIH/2O3kcPBRrt27OuHLsxi + ojKEMrYAW8iHNP+rDvROz3g4nv0wbgDV0Q6ZWiMpenroqtPMpDrTYawX19yrXInuGtPR + m+Jw== +X-Gm-Message-State: + ALoCoQkGyD9dt5hpwztHMVu/LAAJNdM8QVZLoj5UsCu4lYGGVU+2dTsrA6ROiRwotIvIaXa0Lbeq +X-Received: by 10.180.104.68 with SMTP id gc4mr18128958wib.67.1441309212975; + Thu, 03 Sep 2015 12:40:12 -0700 (PDT) +Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi. + [188.238.79.131]) + by smtp.gmail.com with ESMTPSA id c11sm114253wib.1.2015.09.03.12.40.12 + (version=TLSv1/SSLv3 cipher=OTHER); + Thu, 03 Sep 2015 12:40:12 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2 2/9] cli: abstract new mailbox creation +Date: Thu, 3 Sep 2015 22:39:58 +0300 +Message-Id: + +X-Mailer: git-send-email 2.1.4 +In-Reply-To: +References: +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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: Thu, 03 Sep 2015 19:40:28 -0000 + +We'll be needing more mailbox creation soon, so abstract it +away. While at it, check for allocation failures. No other functional +changes. +--- + notmuch-search.c | 23 +++++++++++++++++++---- + 1 file changed, 19 insertions(+), 4 deletions(-) + +diff --git a/notmuch-search.c b/notmuch-search.c +index 7fdc6acaa2fe..36f58eb8d54c 100644 +--- a/notmuch-search.c ++++ b/notmuch-search.c +@@ -243,6 +243,21 @@ do_search_threads (search_context_t *ctx) + return 0; + } + ++static mailbox_t *new_mailbox (void *ctx, const char *name, const char *addr) ++{ ++ mailbox_t *mailbox; ++ ++ mailbox = talloc (ctx, mailbox_t); ++ if (! mailbox) ++ return NULL; ++ ++ mailbox->name = talloc_strdup (mailbox, name); ++ mailbox->addr = talloc_strdup (mailbox, addr); ++ mailbox->count = 1; ++ ++ return mailbox; ++} ++ + /* Returns TRUE iff name and addr is duplicate. If not, stores the + * name/addr pair in order to detect subsequent duplicates. */ + static notmuch_bool_t +@@ -262,10 +277,10 @@ is_duplicate (const search_context_t *ctx, const char *name, const char *addr) + return TRUE; + } + +- mailbox = talloc (ctx->format, mailbox_t); +- mailbox->name = talloc_strdup (mailbox, name); +- mailbox->addr = talloc_strdup (mailbox, addr); +- mailbox->count = 1; ++ mailbox = new_mailbox (ctx->format, name, addr); ++ if (! mailbox) ++ return FALSE; ++ + g_hash_table_insert (ctx->addresses, key, mailbox); + + return FALSE; +-- +2.1.4 +