Re: [PATCH] create .mailmap file (for git shortlog/blame)
[notmuch-archives.git] / 94 / de0ea3123b76e07ae67ed0c7703137843282a7
1 Return-Path: <bremner@tethera.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5  by arlo.cworth.org (Postfix) with ESMTP id 7CF0C6DE189C\r
6  for <notmuch@notmuchmail.org>; Sat, 12 Mar 2016 04:31:40 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.033\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.033 tagged_above=-999 required=5\r
12  tests=[AWL=-0.022, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
13  autolearn=disabled\r
14 Received: from arlo.cworth.org ([127.0.0.1])\r
15  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
16  with ESMTP id bcW7UzuvYYzg for <notmuch@notmuchmail.org>;\r
17  Sat, 12 Mar 2016 04:31:38 -0800 (PST)\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id 1D4606DE1534\r
20  for <notmuch@notmuchmail.org>; Sat, 12 Mar 2016 04:31:37 -0800 (PST)\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
22  (envelope-from <bremner@tethera.net>)\r
23  id 1aeiiL-0004yp-Qv; Sat, 12 Mar 2016 07:32:13 -0500\r
24 Received: (nullmailer pid 17183 invoked by uid 1000);\r
25  Sat, 12 Mar 2016 12:31:33 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
28 Subject: [PATCH 5/6] CLI: optionally restore config data.\r
29 Date: Sat, 12 Mar 2016 08:31:29 -0400\r
30 Message-Id: <1457785890-17058-6-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.7.0\r
32 In-Reply-To: <1457785890-17058-1-git-send-email-david@tethera.net>\r
33 References: <1453561198-2893-1-git-send-email-david@tethera.net>\r
34  <1457785890-17058-1-git-send-email-david@tethera.net>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.20\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39  <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
41  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
46  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Sat, 12 Mar 2016 12:31:40 -0000\r
48 \r
49 Like the corresponding change to dump, this needs documentation\r
50 ---\r
51  notmuch-restore.c      | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
52  test/T590-libconfig.sh | 11 +++++++++++\r
53  2 files changed, 64 insertions(+)\r
54 \r
55 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
56 index 9abc64f..e06fbde 100644\r
57 --- a/notmuch-restore.c\r
58 +++ b/notmuch-restore.c\r
59 @@ -24,6 +24,38 @@\r
60  #include "string-util.h"\r
61  #include "zlib-extra.h"\r
62  \r
63 +static int\r
64 +process_config_line(notmuch_database_t *notmuch, const char* line){\r
65 +    const char *key_p, *val_p;\r
66 +    char *key, *val;\r
67 +    size_t key_len,val_len;\r
68 +    const char *delim=" \t\n";\r
69 +    int ret = EXIT_FAILURE;\r
70 +\r
71 +    void *local = talloc_new(NULL);\r
72 +\r
73 +    key_p = strtok_len_c(line, delim, &key_len);\r
74 +    val_p = strtok_len_c(key_p+key_len, delim, &val_len);\r
75 +\r
76 +    key = talloc_strndup(local, key_p, key_len);\r
77 +    val = talloc_strndup(local, val_p, val_len);\r
78 +    if (hex_decode_inplace (key) != HEX_SUCCESS ||\r
79 +       hex_decode_inplace (val) != HEX_SUCCESS ) {\r
80 +       fprintf (stderr, "hex decoding failure on line %s\n", line);\r
81 +       goto DONE;\r
82 +    }\r
83 +\r
84 +    if (print_status_database ("notmuch restore", notmuch,\r
85 +                              notmuch_database_set_config (notmuch, key, val)))\r
86 +       goto DONE;\r
87 +\r
88 +    ret = EXIT_SUCCESS;\r
89 +\r
90 + DONE:\r
91 +    talloc_free (local);\r
92 +    return ret;\r
93 +}\r
94 +\r
95  static regex_t regex;\r
96  \r
97  /* Non-zero return indicates an error in retrieving the message,\r
98 @@ -137,6 +169,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
99  \r
100      int ret = 0;\r
101      int opt_index;\r
102 +    int include=0;\r
103      int input_format = DUMP_FORMAT_AUTO;\r
104  \r
105      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
106 @@ -152,6 +185,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
107                                   { "batch-tag", DUMP_FORMAT_BATCH_TAG },\r
108                                   { "sup", DUMP_FORMAT_SUP },\r
109                                   { 0, 0 } } },\r
110 +       { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',\r
111 +         (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },\r
112 +                                 { "tags", DUMP_INCLUDE_TAGS} } },\r
113 +\r
114         { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
115         { NOTMUCH_OPT_BOOLEAN,  &accumulate, "accumulate", 'a', 0 },\r
116         { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
117 @@ -167,6 +204,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
118      notmuch_process_shared_options (argv[0]);\r
119      notmuch_exit_if_unmatched_db_uuid (notmuch);\r
120  \r
121 +    if (include == 0) {\r
122 +       include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;\r
123 +    }\r
124 +\r
125      name_for_error = input_file_name ? input_file_name : "stdin";\r
126  \r
127      if (! accumulate)\r
128 @@ -225,11 +266,23 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
129             ret = EXIT_FAILURE;\r
130             goto DONE;\r
131         }\r
132 +\r
133 +       if ((include & DUMP_INCLUDE_CONFIG) && line_len >= 2 && line[0] == '#' && line[1] == '@') {\r
134 +           ret = process_config_line(notmuch, line+2);\r
135 +           if (ret)\r
136 +               goto DONE;\r
137 +       }\r
138 +\r
139      } while ((line_len == 0) ||\r
140              (line[0] == '#') ||\r
141              /* the cast is safe because we checked about for line_len < 0 */\r
142              (strspn (line, " \t\n") == (unsigned)line_len));\r
143  \r
144 +    if (! (include & DUMP_INCLUDE_TAGS)) {\r
145 +       ret = EXIT_SUCCESS;\r
146 +       goto DONE;\r
147 +    }\r
148 +\r
149      char *p;\r
150      for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {\r
151         if (*p == '(')\r
152 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh\r
153 index 5ea5300..9c1e566 100755\r
154 --- a/test/T590-libconfig.sh\r
155 +++ b/test/T590-libconfig.sh\r
156 @@ -132,4 +132,15 @@ cat <<'EOF' >EXPECTED\r
157  EOF\r
158  test_expect_equal_file EXPECTED OUTPUT\r
159  \r
160 +test_begin_subtest "restore config"\r
161 +notmuch dump --include=config >EXPECTED\r
162 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
163 +{\r
164 +    RUN(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));\r
165 +}\r
166 +EOF\r
167 +notmuch restore --include=config <EXPECTED\r
168 +notmuch dump --include=config >OUTPUT\r
169 +test_expect_equal_file EXPECTED OUTPUT\r
170 +\r
171  test_done\r
172 -- \r
173 2.7.0\r
174 \r