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 5D089431FD0 for ; Sat, 10 Sep 2011 02:15:54 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] 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 Eh3rsZRPTCwB for ; Sat, 10 Sep 2011 02:15:52 -0700 (PDT) Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D45E6431FB6 for ; Sat, 10 Sep 2011 02:15:39 -0700 (PDT) Received: from taco2.nixu.fi (localhost [127.0.0.1]) by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p8A9FbEc023439 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 10 Sep 2011 12:15:37 +0300 Received: (from too@localhost) by taco2.nixu.fi (8.14.3/8.14.3/Submit) id p8A9FaLw023438; Sat, 10 Sep 2011 12:15:36 +0300 X-Authentication-Warning: taco2.nixu.fi: too set sender to tomi.ollila@nixu.com using -f From: Tomi Ollila To: Subject: suggestion: notmuch-talloc.[ch] X-Face: HhBM'cA~ User-Agent: Gnus/5.110014 (No Gnus v0.14) Emacs/22.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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: Sat, 10 Sep 2011 09:15:54 -0000 In addition to notmuch_config_get_new_tags() I started to think how to add notmuch_config_get_database_exclude() (for excluding directories; needed by me and many others) to copy and modify from notmuch_config_get_new_tags() would cause lots of duplicate code so I started to look how to generalise. Not so simple so I started to look "bigger picture" and this leads to suggestion: new c file called 'notmuch-talloc.c', with the following initial content: --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- # include static void notmuch_talloc_g_string_list_destructor (void * ptr) { g_strfreev ( (gchar **)ptr ); } /* tallocify wrapper for g_key_file_get_string_list */ gchar ** void notmuch_talloc_g_key_file_get_string_list (const void * ctx, GFile *key_file, const gchar *group_name, const gchar *key, gsize *length, GError **error) { gchar ** tags = g_key_file_get_string_list (key_file, group_name, key, length, error); if (tags) { talloc_reference(ctx, tags); talloc_set_destructor(tags, notmuch_talloc_g_string_list_destructor); } return tags; } --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- Provided that the above is proven correct, this would simplify notmuch_config_get_new_tags() as: const char ** notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length) { if (config->new_tags == NULL) { config->new_tags = notmuch_talloc_g_key_file_get_string_list( config, config->key_file, "new", "tags", &config->tags_length, NULL); } } return config->new_tags; } Thus adding notmuch_config_get_database_exclude() avoids the CopyPasteProgramming threshold. new code to the notmuch-talloc.c (and interface declarations to notmuch-talloc.h) would be added on demand, per need basis. Note that this code is unproven code. For obvious reason i'm currently hesitant to investigate further -- all of us have priorities -- but if this idea gets good response I'm willing to do the proper patches; for now, for my own use, I just hardcode excluded directories to notmuch-new.c :D tomi