Merge lp:~vjsamuel/drizzle/refactor-archive_reader into lp:~drizzle-trunk/drizzle/development

Proposed by Vijay Samuel
Status: Merged
Merged at revision: 1579
Proposed branch: lp:~vjsamuel/drizzle/refactor-archive_reader
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 316 lines (+86/-132)
6 files modified
plugin/archive/archive_performance.cc (+0/-1)
plugin/archive/archive_reader.cc (+85/-127)
plugin/archive/archive_test.cc (+0/-1)
plugin/archive/concurrency_test.cc (+0/-1)
plugin/archive/plugin.am (+1/-1)
plugin/myisam/mi_check.cc (+0/-1)
To merge this branch: bzr merge lp:~vjsamuel/drizzle/refactor-archive_reader
Reviewer Review Type Date Requested Status
Drizzle Developers Pending
Review via email: mp+25931@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stewart Smith (stewart) wrote :

I'd love to see a test for archive_reader command line options before
(and after) this change.

review: Needs Fixing

--
Stewart Smith

Revision history for this message
Monty Taylor (mordred) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/24/2010 08:10 PM, Stewart Smith wrote:
>
> I'd love to see a test for archive_reader command line options before
> (and after) this change.

Hrm. Good point... do we have any of those?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkv7Rf4ACgkQ2Jv7/VK1RgFtTQCgt1D11gqWwlvgixxPOBuo55f7
638AniCjU0ewVYKyliC/vEHkfdi8MuXM
=uIbu
-----END PGP SIGNATURE-----

1562. By Vijay Samuel <vijay@vijay>

Command line of archive_reader refactored with boost::program_options.

Revision history for this message
Stewart Smith (stewart) wrote :

On Tue, 25 May 2010 03:40:51 -0000, Monty Taylor <email address hidden> wrote:
> On 05/24/2010 08:10 PM, Stewart Smith wrote:
> > I'd love to see a test for archive_reader command line options before
> > (and after) this change.
>
> Hrm. Good point... do we have any of those?

I'd almost place $5000 on us not having any decent tests for it.
--
Stewart Smith

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugin/archive/archive_performance.cc'
2--- plugin/archive/archive_performance.cc 2010-03-30 09:29:02 +0000
3+++ plugin/archive/archive_performance.cc 2010-05-26 17:21:37 +0000
4@@ -23,7 +23,6 @@
5 #include <string.h>
6 #include <fcntl.h>
7 #include <sys/stat.h>
8-#include "drizzled/option.h"
9
10 #if TIME_WITH_SYS_TIME
11 # include <sys/time.h>
12
13=== modified file 'plugin/archive/archive_reader.cc'
14--- plugin/archive/archive_reader.cc 2010-03-30 09:29:02 +0000
15+++ plugin/archive/archive_reader.cc 2010-05-26 17:21:37 +0000
16@@ -19,7 +19,12 @@
17 */
18
19 #include "config.h"
20-
21+#include CSTDINT_H
22+#include <iostream>
23+#include <string>
24+using namespace std;
25+#include <boost/program_options.hpp>
26+namespace po= boost::program_options;
27 #include "azio.h"
28 #include <string.h>
29 #include <assert.h>
30@@ -34,38 +39,98 @@
31
32 using namespace drizzled;
33
34-int get_one_option(int optid, const struct option *opt, char *argument);
35-
36-static void get_options(int *argc,char * * *argv);
37-static void print_version(void);
38-static void usage(void);
39-static const char *opt_tmpdir;
40-static const char *new_auto_increment;
41+string opt_tmpdir;
42 uint64_t new_auto_increment_value;
43 static const char *load_default_groups[]= { "archive_reader", 0 };
44 static char **default_argv;
45-int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_table_message;
46-int opt_autoincrement;
47+bool opt_check,
48+ opt_force,
49+ opt_backup,
50+ opt_extract_table_message,
51+ opt_silent,
52+ opt_quiet,
53+ opt_quick,
54+ opt_autoincrement;
55
56 int main(int argc, char *argv[])
57 {
58+try
59+{
60+ po::options_description long_options("Allowed Options");
61+ long_options.add_options()
62+ ("back_up,b",po::value<bool>(&opt_backup)->default_value(false)->zero_tokens(),
63+ "Make a backup of an archive table.")
64+ ("check,c",po::value<bool>(&opt_check)->default_value(false)->zero_tokens(),
65+ "Check table for errors")
66+ ("extract-table-message,e",po::value<bool>(&opt_extract_table_message)->default_value(false)->zero_tokens(),
67+ "Extract the table protobuf message.")
68+ ("force,f",po::value<bool>(&opt_force)->default_value(false)->zero_tokens(),
69+ "Restart with -r if there are any errors in the table")
70+ ("help,?","Display this help and exit")
71+ ("quick,q",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
72+ "Faster repair but not modifying the data")
73+ ("repair,r",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
74+ "Repair a damaged Archive version 3 or above file.")
75+ ("set-auto-increment,A",po::value<uint64_t>(&new_auto_increment_value)->default_value(0),
76+ "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.")
77+ ("silent,s",po::value<bool>(&opt_silent)->default_value(false)->zero_tokens(),
78+ "Only print errors. One can use two -s to make archive_reader very silent.")
79+ ("tmpdir,t",po::value<string>(&opt_tmpdir)->default_value(""),
80+ "Path for temporary files.")
81+ ("version,V","Print version and exit")
82+ ;
83+
84 unsigned int ret;
85 azio_stream reader_handle;
86
87 internal::my_init();
88 MY_INIT(argv[0]);
89- get_options(&argc, &argv);
90-
91+ internal::load_defaults("drizzle", load_default_groups, &argc, &argv);
92+ default_argv= argv;
93+
94+ po::variables_map vm;
95+ po::store(po::parse_command_line(argc,argv,long_options),vm);
96+ po::notify(vm);
97+
98+ if(vm.count("force")||vm.count("quiet")||vm.count("tmpdir"))
99+ cout<<"Not implemented yet";
100+
101+ if(vm.count("version"))
102+ {
103+ printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
104+ HOST_VENDOR, HOST_OS, HOST_CPU);
105+ exit(0);
106+ }
107+
108+ if(vm.count("set-auto-increment"))
109+ {
110+ opt_autoincrement= true;
111+ }
112+
113+ if(vm.count("help")||argc == 0)
114+ {
115+ printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
116+ HOST_VENDOR, HOST_OS, HOST_CPU);
117+ puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
118+ \nand you are welcome to modify and redistribute it under the GPL \
119+ license\n");
120+ puts("Read and modify Archive files directly\n");
121+ printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);
122+ internal::print_defaults("drizzle", load_default_groups);
123+ cout<<long_options<<endl;
124+ exit(0);
125+ }
126+
127 if (argc < 1)
128 {
129 printf("No file specified. \n");
130- return 0;
131+ return -1;
132 }
133
134 if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY, AZ_METHOD_BLOCK)))
135 {
136 printf("Could not open Archive file\n");
137- return 0;
138+ return -1;
139 }
140
141 if (opt_autoincrement)
142@@ -255,119 +320,12 @@
143 azclose(&reader_handle);
144
145 internal::my_end();
146- return 0;
147-}
148-
149-int get_one_option(int optid, const struct option *opt, char *argument)
150-{
151- (void)opt;
152- switch (optid) {
153- case 'b':
154- opt_backup= 1;
155- break;
156- case 'c':
157- opt_check= 1;
158- break;
159- case 'e':
160- opt_extract_table_message= 1;
161- break;
162- case 'f':
163- opt_force= 1;
164- printf("Not implemented yet\n");
165- break;
166- case 'q':
167- opt_quiet= 1;
168- printf("Not implemented yet\n");
169- break;
170- case 'V':
171- print_version();
172- exit(0);
173- case 't':
174- printf("Not implemented yet\n");
175- break;
176- case 'A':
177- opt_autoincrement= 1;
178- if (argument)
179- new_auto_increment_value= strtoull(argument, NULL, 0);
180- else
181- new_auto_increment_value= 0;
182- break;
183- case '?':
184- usage();
185- exit(0);
186- }
187- return 0;
188-}
189-
190-static struct option my_long_options[] =
191-{
192- {"backup", 'b',
193- "Make a backup of an archive table.",
194- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
195- {"check", 'c', "Check table for errors.",
196- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
197- {"extract-table-message", 'e',
198- "Extract the table protobuf message.",
199- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
200- {"force", 'f',
201- "Restart with -r if there are any errors in the table.",
202- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
203- {"help", '?',
204- "Display this help and exit.",
205- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
206- {"quick", 'q', "Faster repair by not modifying the data file.",
207- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
208- {"repair", 'r', "Repair a damaged Archive version 3 or above file.",
209- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
210- {"set-auto-increment", 'A',
211- "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.",
212- (char**) &new_auto_increment,
213- (char**) &new_auto_increment,
214- 0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
215- {"silent", 's',
216- "Only print errors. One can use two -s to make archive_reader very silent.",
217- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
218- {"tmpdir", 't',
219- "Path for temporary files.",
220- (char**) &opt_tmpdir,
221- 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
222- {"version", 'V',
223- "Print version and exit.",
224- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
225- { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
226-};
227-
228-static void usage(void)
229-{
230- print_version();
231- puts("Copyright (C) 2007 MySQL AB");
232- puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
233- \nand you are welcome to modify and redistribute it under the GPL \
234- license\n");
235- puts("Read and modify Archive files directly\n");
236- printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);
237- internal::print_defaults("drizzle", load_default_groups);
238- my_print_help(my_long_options);
239-}
240-
241-static void print_version(void)
242-{
243- printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
244- HOST_VENDOR, HOST_OS, HOST_CPU);
245-}
246-
247-static void get_options(int *argc, char ***argv)
248-{
249- internal::load_defaults("drizzle", load_default_groups, argc, argv);
250- default_argv= *argv;
251-
252- handle_options(argc, argv, my_long_options, get_one_option);
253-
254- if (*argc == 0)
255+
256+}
257+ catch(exception &e)
258 {
259- usage();
260- exit(-1);
261+ cerr<<"Error"<<e.what()<<endl;
262 }
263+ return 0;
264+}
265
266- return;
267-} /* get options */
268
269=== modified file 'plugin/archive/archive_test.cc'
270--- plugin/archive/archive_test.cc 2010-03-30 09:29:02 +0000
271+++ plugin/archive/archive_test.cc 2010-05-26 17:21:37 +0000
272@@ -22,7 +22,6 @@
273 #include <fcntl.h>
274 #include <unistd.h>
275 #include <cstdlib>
276-#include "drizzled/option.h"
277
278 #if TIME_WITH_SYS_TIME
279 # include <sys/time.h>
280
281=== modified file 'plugin/archive/concurrency_test.cc'
282--- plugin/archive/concurrency_test.cc 2010-03-30 09:29:02 +0000
283+++ plugin/archive/concurrency_test.cc 2010-05-26 17:21:37 +0000
284@@ -24,7 +24,6 @@
285 #include "config.h"
286
287 #include "azio.h"
288-#include "drizzled/option.h"
289 #include <stdio.h>
290 #include <stdlib.h>
291 #include <sys/types.h>
292
293=== modified file 'plugin/archive/plugin.am'
294--- plugin/archive/plugin.am 2010-05-12 05:00:55 +0000
295+++ plugin/archive/plugin.am 2010-05-26 17:21:37 +0000
296@@ -45,7 +45,7 @@
297 plugin_archive_archive_test_LDADD= $(test_archive_LDADD)
298
299 plugin_archive_archive_reader_SOURCES= plugin/archive/archive_reader.cc
300-plugin_archive_archive_reader_LDADD= $(test_archive_LDADD)
301+plugin_archive_archive_reader_LDADD= $(test_archive_LDADD) ${BOOST_LIBS}
302
303 plugin_archive_concurrency_test_SOURCES= plugin/archive/concurrency_test.cc
304 plugin_archive_concurrency_test_LDADD= $(test_archive_LDADD)
305
306=== modified file 'plugin/myisam/mi_check.cc'
307--- plugin/myisam/mi_check.cc 2010-04-19 19:23:14 +0000
308+++ plugin/myisam/mi_check.cc 2010-05-26 17:21:37 +0000
309@@ -43,7 +43,6 @@
310 #include "myisam_priv.h"
311 #include "drizzled/internal/m_string.h"
312 #include <stdarg.h>
313-#include "drizzled/option.h"
314 #ifdef HAVE_SYS_VADVISE_H
315 #include <sys/vadvise.h>
316 #endif