git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Michele Ballabio <barra_cuda@katamail.com>
To: Olivier Marin <dkr+ml.git@free.fr>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: [PATCH 6/9 - v2] builtin-init-db.c: use parse_options()
Date: Fri, 25 Jul 2008 10:15:18 +0200	[thread overview]
Message-ID: <200807251015.18143.barra_cuda@katamail.com> (raw)
In-Reply-To: <200807242207.02195.barra_cuda@katamail.com>

Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---

On Thursday 24 July 2008, Michele Ballabio wrote:
> +static int parse_opt_shared_cb(const struct option *opt, const char *arg,
> +                              int unset)
> +{
> +       *(int *)(opt->value) = unset ? PERM_UMASK : git_config_perm("arg", arg);
> +       return 0;
> +}
> 

Did it this way (and changed help strings).

 builtin-init-db.c |   57 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/builtin-init-db.c b/builtin-init-db.c
index 38b4fcb..42c2e20 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -6,6 +6,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "exec_cmd.h"
+#include "parse-options.h"
 
 #ifndef DEFAULT_GIT_TEMPLATE_DIR
 #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -353,8 +354,18 @@ static int guess_repository_type(const char *git_dir)
 	return 1;
 }
 
-static const char init_db_usage[] =
-"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
+static const char * const init_db_usage[] = {
+	"git init [-q | --quiet] [--bare] [--template=<dir>] [--shared[=<type>]]",
+	NULL
+};
+
+static int parse_opt_shared_cb(const struct option *opt, const char *arg,
+			       int unset)
+{
+	*(int *)(opt->value) = unset ? PERM_UMASK :
+				       git_config_perm("arg", arg);
+	return 0;
+}
 
 /*
  * If you want to, you can share the DB area with any number of branches.
@@ -367,25 +378,29 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 	const char *git_dir;
 	const char *template_dir = NULL;
 	unsigned int flags = 0;
-	int i;
-
-	for (i = 1; i < argc; i++, argv++) {
-		const char *arg = argv[1];
-		if (!prefixcmp(arg, "--template="))
-			template_dir = arg+11;
-		else if (!strcmp(arg, "--bare")) {
-			static char git_dir[PATH_MAX+1];
-			is_bare_repository_cfg = 1;
-			setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
-						sizeof(git_dir)), 0);
-		} else if (!strcmp(arg, "--shared"))
-			shared_repository = PERM_GROUP;
-		else if (!prefixcmp(arg, "--shared="))
-			shared_repository = git_config_perm("arg", arg+9);
-		else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
-			flags |= INIT_DB_QUIET;
-		else
-			usage(init_db_usage);
+	int bare = 0;
+
+	const struct option options[] = {
+		OPT_STRING(0, "template", &template_dir, "path",
+			   "path to the template directory"),
+		OPT_BOOLEAN(0, "bare", &bare, "set up a bare repository"),
+		{ OPTION_CALLBACK, 0, "shared", &shared_repository,
+		  "permissions", "set up a shared repository",
+		  PARSE_OPT_OPTARG, parse_opt_shared_cb, PERM_GROUP },
+		OPT_BIT('q', "quiet", &flags, "be quiet", INIT_DB_QUIET),
+		OPT_END()
+	};
+
+	argc = parse_options(argc, argv, options, init_db_usage, 0);
+
+	if (argc > 0)
+		usage_with_options(init_db_usage, options);
+
+	if (bare) {
+		static char git_dir[PATH_MAX+1];
+		is_bare_repository_cfg = 1;
+		setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
+					sizeof(git_dir)), 0);
 	}
 
 	/*
-- 
1.5.6.3

  reply	other threads:[~2008-07-25  8:09 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-23 21:42 [PATCH 0/9] Extend use of parse_options() Michele Ballabio
2008-07-23 21:42 ` [PATCH 1/9] builtin-verify-tag.c: use parse_options() Michele Ballabio
2008-07-24 16:59   ` Olivier Marin
2008-07-24 17:08     ` Johannes Schindelin
2008-07-25 15:20       ` Olivier Marin
2008-07-26  0:53         ` Johannes Schindelin
2008-07-28 10:48         ` [PATCH] builtin-verify-tag: fix -v option parsing Olivier Marin
2008-07-28 11:06           ` Johannes Schindelin
2008-07-28 11:42             ` Olivier Marin
2008-07-28 12:10               ` Johannes Schindelin
2008-07-23 21:42 ` [PATCH 2/9] builtin-write-tree.c: use parse_options() Michele Ballabio
2008-07-23 21:42 ` [PATCH 3/9] builtin-prune-packed.c: " Michele Ballabio
2008-07-23 21:42 ` [PATCH 4/9] builtin-ls-tree.c: " Michele Ballabio
2008-07-23 21:42 ` [PATCH 5/9] builtin-rev-list.c: " Michele Ballabio
2008-07-23 21:42 ` [PATCH 6/9] builtin-init-db.c: " Michele Ballabio
2008-07-24 16:15   ` Olivier Marin
2008-07-24 17:07     ` Johannes Schindelin
2008-07-25 15:20       ` Olivier Marin
2008-07-26  0:55         ` Johannes Schindelin
2008-07-24 20:07     ` Michele Ballabio
2008-07-25  8:15       ` Michele Ballabio [this message]
2008-07-25 15:20       ` Olivier Marin
2008-07-25 19:53         ` [PATCH 6/9 - v3] " Michele Ballabio
2008-07-23 21:42 ` [PATCH 7/9] builtin-checkout-index.c: " Michele Ballabio
2008-07-24 14:44   ` Johannes Schindelin
2008-07-24 20:08     ` Michele Ballabio
2008-07-24 20:35       ` Sverre Rabbelier
2008-07-25  9:01         ` René Scharfe
2008-07-25 16:25           ` [PATCH 7/9 - v2] " Michele Ballabio
2008-07-23 21:42 ` [PATCH 8/9] builtin-fetch-pack.c: " Michele Ballabio
2008-07-23 21:42 ` [PATCH 9/9] builtin-mailinfo.c: " Michele Ballabio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200807251015.18143.barra_cuda@katamail.com \
    --to=barra_cuda@katamail.com \
    --cc=dkr+ml.git@free.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).