suggestion: notmuch-talloc.[ch]
authorTomi Ollila <tomi.ollila@iki.fi>
Sat, 10 Sep 2011 09:15:36 +0000 (12:15 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:39:25 +0000 (09:39 -0800)
b9/7b8c5610bfc34ef7b3441c764cded56c2e41f2 [new file with mode: 0644]

diff --git a/b9/7b8c5610bfc34ef7b3441c764cded56c2e41f2 b/b9/7b8c5610bfc34ef7b3441c764cded56c2e41f2
new file mode 100644 (file)
index 0000000..51a71ec
--- /dev/null
@@ -0,0 +1,134 @@
+Return-Path: <tomi.ollila@nixu.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 5D089431FD0\r
+       for <notmuch@notmuchmail.org>; Sat, 10 Sep 2011 02:15:54 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id Eh3rsZRPTCwB for <notmuch@notmuchmail.org>;\r
+       Sat, 10 Sep 2011 02:15:52 -0700 (PDT)\r
+Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id D45E6431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 10 Sep 2011 02:15:39 -0700 (PDT)\r
+Received: from taco2.nixu.fi (localhost [127.0.0.1])\r
+       by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id\r
+       p8A9FbEc023439\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT)\r
+       for <notmuch@notmuchmail.org>; Sat, 10 Sep 2011 12:15:37 +0300\r
+Received: (from too@localhost)\r
+       by taco2.nixu.fi (8.14.3/8.14.3/Submit) id p8A9FaLw023438;\r
+       Sat, 10 Sep 2011 12:15:36 +0300\r
+X-Authentication-Warning: taco2.nixu.fi: too set sender to\r
+       tomi.ollila@nixu.com using -f\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: <notmuch@notmuchmail.org>\r
+Subject: suggestion: notmuch-talloc.[ch]\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sat, 10 Sep 2011 12:15:36 +0300\r
+Message-ID: <yf6sjo4rc5j.fsf@taco2.nixu.fi>\r
+User-Agent: Gnus/5.110014 (No Gnus v0.14) Emacs/22.2 (gnu/linux)\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 10 Sep 2011 09:15:54 -0000\r
+\r
+\r
+In addition to notmuch_config_get_new_tags() I started to think\r
+how to add notmuch_config_get_database_exclude() (for excluding\r
+directories; needed by me and many others)\r
+\r
+to copy and modify from notmuch_config_get_new_tags() would cause\r
+lots of duplicate code so I started to look how to generalise.\r
+\r
+Not so simple so I started to look "bigger picture" and this leads\r
+to suggestion:\r
+\r
+new c file called 'notmuch-talloc.c', with the following initial\r
+content:\r
+\r
+--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--\r
+\r
+# include <add required includes...>\r
+\r
+static void \r
+notmuch_talloc_g_string_list_destructor (void * ptr)\r
+{\r
+    g_strfreev ( (gchar **)ptr );\r
+}\r
+\r
+/* tallocify wrapper for g_key_file_get_string_list */\r
+\r
+gchar **\r
+void notmuch_talloc_g_key_file_get_string_list (const void * ctx,\r
+                                               GFile *key_file,\r
+                                               const gchar *group_name,\r
+                                               const gchar *key,\r
+                                               gsize *length,\r
+                                               GError **error)\r
+{\r
+    gchar ** tags = g_key_file_get_string_list (key_file,\r
+                                               group_name, key,\r
+                                               length, error);\r
+    if (tags) {\r
+       talloc_reference(ctx, tags);\r
+       talloc_set_destructor(tags, notmuch_talloc_g_string_list_destructor);\r
+    }\r
+    return tags;\r
+}\r
+                                                                                        \r
+--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--\r
+\r
+Provided that the above is proven correct, this would simplify\r
+notmuch_config_get_new_tags() as: \r
+\r
+const char **\r
+notmuch_config_get_new_tags (notmuch_config_t *config,\r
+                            size_t *length)\r
+{\r
+    if (config->new_tags == NULL) {\r
+       config->new_tags = notmuch_talloc_g_key_file_get_string_list(\r
+                               config,\r
+                               config->key_file,\r
+                               "new", "tags",\r
+                               &config->tags_length, NULL);\r
+       }\r
+    }\r
+    return config->new_tags;\r
+}\r
+\r
+Thus adding notmuch_config_get_database_exclude() avoids the\r
+CopyPasteProgramming threshold. \r
+\r
+new code to the notmuch-talloc.c (and interface declarations to\r
+notmuch-talloc.h) would be added on demand, per need basis. \r
+\r
+Note that this code is unproven code. For obvious reason i'm currently\r
+hesitant to investigate further -- all of us have priorities -- but\r
+if this idea gets good response I'm willing to do the proper patches;\r
+for now, for my own use, I just hardcode excluded directories to\r
+notmuch-new.c :D\r
+\r
+tomi\r
+\r