git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 02/11] test-svn-fe: use parse-options

From
Dmitry Ivankov <divanorama@gmail.com>
Date
Jul 13, 2011, 12:21 UTC
Message-ID
<1310559673-5026-3-git-send-email-divanorama@gmail.com>
In-Reply-To
<1310559673-5026-1-git-send-email-divanorama@gmail.com>

There was custom options parsing. As more options arise it will be easier to add and document new options with parse-options api.

Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
---
 test-svn-fe.c |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/test-svn-fe.c b/test-svn-fe.c
index 332a5f7..0aab245 100644
--- a/test-svn-fe.c
+++ b/test-svn-fe.c
@@ -3,28 +3,38 @@
  */
 
 #include "git-compat-util.h"
+#include "parse-options.h"
 #include "vcs-svn/svndump.h"
 #include "vcs-svn/svndiff.h"
 #include "vcs-svn/sliding_window.h"
 #include "vcs-svn/line_buffer.h"
 
-static const char test_svnfe_usage[] =
-	"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)";
+static const char * const test_svnfe_usage[] = {
+	"test-svn-fe (<dumpfile> | -d <preimage> <delta> <len>)",
+	NULL
+};
 
-static int apply_delta(int argc, char *argv[])
+static int d;
+
+static struct option test_svnfe_options[] = {
+	OPT_SET_INT('d', NULL, &d, "test apply_delta", 1),
+	OPT_END()
+};
+
+static int apply_delta(int argc, const char *argv[])
 {
 	struct line_buffer preimage = LINE_BUFFER_INIT;
 	struct line_buffer delta = LINE_BUFFER_INIT;
 	struct sliding_view preimage_view = SLIDING_VIEW_INIT(&preimage, -1);
 
-	if (argc != 5)
-		usage(test_svnfe_usage);
+	if (argc != 3)
+		usage_with_options(test_svnfe_usage, test_svnfe_options);
 
-	if (buffer_init(&preimage, argv[2]))
+	if (buffer_init(&preimage, argv[0]))
 		die_errno("cannot open preimage");
-	if (buffer_init(&delta, argv[3]))
+	if (buffer_init(&delta, argv[1]))
 		die_errno("cannot open delta");
-	if (svndiff0_apply(&delta, (off_t) strtoull(argv[4], NULL, 0),
+	if (svndiff0_apply(&delta, (off_t) strtoull(argv[2], NULL, 0),
 					&preimage_view, stdout))
 		return 1;
 	if (buffer_deinit(&preimage))
@@ -37,10 +47,16 @@ static int apply_delta(int argc, char *argv[])
 	return 0;
 }
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
-	if (argc == 2) {
-		if (svndump_init(argv[1]))
+	argc = parse_options(argc, argv, NULL, test_svnfe_options,
+						test_svnfe_usage, 0);
+
+	if (d)
+		return apply_delta(argc, argv);
+
+	if (argc == 1) {
+		if (svndump_init(argv[0]))
 			return 1;
 		svndump_read(NULL);
 		svndump_deinit();
@@ -48,7 +64,5 @@ int main(int argc, char *argv[])
 		return 0;
 	}
 
-	if (argc >= 2 && !strcmp(argv[1], "-d"))
-		return apply_delta(argc, argv);
-	usage(test_svnfe_usage);
+	usage_with_options(test_svnfe_usage, test_svnfe_options);
 }
-- 
1.7.3.4
Previous: Jonathan NiederNext: Jonathan Nieder
Message 4 of 24 in “vcs-svn,svn-fe add a couple of options”
  1. 00/11 vcs-svn,svn-fe add a couple of optionsDmitry Ivankov, Jul 13, 2011
  2. 01/11 svn-fe: add man target to MakefileDmitry Ivankov, Jul 13, 2011
  3. Jonathan NiederJul 24, 2011
  4. 02/11 test-svn-fe: use parse-optionsDmitry Ivankov, Jul 13, 2011
  5. Jonathan NiederJul 24, 2011
  6. 03/11 svn-fe: add EXTLIBS needed for parse-optionsDmitry Ivankov, Jul 13, 2011
  7. Jonathan NiederJul 24, 2011
  8. 04/11 svn-fe: add usage and unpositional arguments versionsDmitry Ivankov, Jul 13, 2011
  9. Jonathan NiederJul 24, 2011
  10. 05/11 vcs-svn: move url parameter from _read to _initDmitry Ivankov, Jul 13, 2011
  11. Jonathan NiederJul 24, 2011
  12. 06/11 vcs-svn: move commit parameters logic to svndump.cDmitry Ivankov, Jul 13, 2011
  13. Jonathan NiederJul 24, 2011
  14. 07/11 vcs-svn,svn-fe: allow to specify dump destination refDmitry Ivankov, Jul 13, 2011
  15. Jonathan NiederJul 25, 2011
  16. 08/11 vcs-svn,svn-fe: convert REPORT_FILENO to an optionDmitry Ivankov, Jul 13, 2011
  17. Jonathan NiederJul 25, 2011
  18. 09/11 vcs-svn,svn-fe: allow to disable 'progress' linesDmitry Ivankov, Jul 13, 2011
  19. 10/11 vcs-svn,svn-fe: add --incremental optionDmitry Ivankov, Jul 13, 2011
  20. Jonathan NiederJul 25, 2011
  21. 11/11 vcs-svn,svn-fe: add an option to write svnrev notesDmitry Ivankov, Jul 13, 2011
  22. Jonathan NiederJul 25, 2011
  23. Dmitry IvankovJul 28, 2011
  24. Jonathan NiederJul 28, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.