git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] init-db: migrate to parse-options
@ 2009-07-11 22:53 Michał Kiedrowicz
  2009-07-12  7:17 ` Stephen Boyd
  0 siblings, 1 reply; 7+ messages in thread
From: Michał Kiedrowicz @ 2009-07-11 22:53 UTC (permalink / raw)
  To: git; +Cc: Michał Kiedrowicz

Also add missing --bare to init-db synopsis.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
---
 Documentation/git-init-db.txt |    2 +-
 builtin-init-db.c             |   51 ++++++++++++++++++++++++-----------------
 2 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/Documentation/git-init-db.txt b/Documentation/git-init-db.txt
index 1fd0ff2..eba3cb4 100644
--- a/Documentation/git-init-db.txt
+++ b/Documentation/git-init-db.txt
@@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository
 
 SYNOPSIS
 --------
-'git init-db' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]
+'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
 
 
 DESCRIPTION
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 4a56006..9b1ce45 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"
@@ -370,8 +371,16 @@ 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 int shared_callback(const struct option *opt, const char *arg, int unset)
+{
+	*((int *) opt->value) = (arg) ? git_config_perm("arg", arg) : PERM_GROUP;
+	return 0;
+}
+
+static const char *const init_db_usage[] = {
+	"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]",
+	NULL
+};
 
 /*
  * If you want to, you can share the DB area with any number of branches.
@@ -384,25 +393,25 @@ 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"))
-			init_shared_repository = PERM_GROUP;
-		else if (!prefixcmp(arg, "--shared="))
-			init_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);
+	const struct option init_db_options[] = {
+		OPT_STRING(0, "template", &template_dir, "template-directory",
+				"provide the directory from which templates will be used"),
+		OPT_SET_INT(0, "bare", &is_bare_repository_cfg,
+				"create a bare repository", 1),
+		{ OPTION_CALLBACK, 0, "shared", &init_shared_repository,
+			"permissions",
+			"specify that the git repository is to be shared amongst several users",
+			PARSE_OPT_OPTARG, shared_callback, 0},
+		OPT_BIT('q', "quiet", &flags, "be quiet", INIT_DB_QUIET),
+		OPT_END()
+	};
+
+	parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
+
+	if(is_bare_repository_cfg == 1) {
+		static char git_dir[PATH_MAX+1];
+		setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
+					sizeof(git_dir)), 0);
 	}
 
 	if (init_shared_repository != -1)
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] init-db: migrate to parse-options
  2009-07-11 22:53 [PATCH] init-db: migrate to parse-options Michał Kiedrowicz
@ 2009-07-12  7:17 ` Stephen Boyd
  2009-07-12 10:24   ` [PATCH v2] " Michał Kiedrowicz
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Boyd @ 2009-07-12  7:17 UTC (permalink / raw)
  To: Michał Kiedrowicz; +Cc: git

Michał Kiedrowicz wrote:
> Also add missing --bare to init-db synopsis.
>
> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
> ---

Heh, I had a very similar patch queued up.

>  Documentation/git-init-db.txt |    2 +-
>  builtin-init-db.c             |   51 ++++++++++++++++++++++++-----------------
>  2 files changed, 31 insertions(+), 22 deletions(-)
>
> diff --git a/Documentation/git-init-db.txt b/Documentation/git-init-db.txt
> index 1fd0ff2..eba3cb4 100644
> --- a/Documentation/git-init-db.txt
> +++ b/Documentation/git-init-db.txt
> @@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository
>  
>  SYNOPSIS
>  --------
> -'git init-db' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]
> +'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
>  
>  
>  DESCRIPTION
> diff --git a/builtin-init-db.c b/builtin-init-db.c
> index 4a56006..9b1ce45 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"
> @@ -370,8 +371,16 @@ 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 int shared_callback(const struct option *opt, const char *arg, int unset)
> +{
> +	*((int *) opt->value) = (arg) ? git_config_perm("arg", arg) : PERM_GROUP;
> +	return 0;
> +}

What occurs when "--no-shared" is used? I have this callback use an if,
else if, else to handle all possibilities.

> +
> +static const char *const init_db_usage[] = {
> +	"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]",
> +	NULL
> +};
>  
>  /*
>   * If you want to, you can share the DB area with any number of branches.
> @@ -384,25 +393,25 @@ 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"))
> -			init_shared_repository = PERM_GROUP;
> -		else if (!prefixcmp(arg, "--shared="))
> -			init_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);
> +	const struct option init_db_options[] = {
> +		OPT_STRING(0, "template", &template_dir, "template-directory",
> +				"provide the directory from which templates will be used"),
> +		OPT_SET_INT(0, "bare", &is_bare_repository_cfg,
> +				"create a bare repository", 1),
> +		{ OPTION_CALLBACK, 0, "shared", &init_shared_repository,
> +			"permissions",
> +			"specify that the git repository is to be shared amongst several users",
> +			PARSE_OPT_OPTARG, shared_callback, 0},

Or you can add PARSE_OPT_NONEG here and avoid the above comment.

> +		OPT_BIT('q', "quiet", &flags, "be quiet", INIT_DB_QUIET),
> +		OPT_END()
> +	};
> +
> +	parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
> +
> +	if(is_bare_repository_cfg == 1) {
> +		static char git_dir[PATH_MAX+1];
> +		setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
> +					sizeof(git_dir)), 0);
>  	}
>  
>  	if (init_shared_repository != -1)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] init-db: migrate to parse-options
  2009-07-12  7:17 ` Stephen Boyd
@ 2009-07-12 10:24   ` Michał Kiedrowicz
  2009-07-12 18:27     ` Junio C Hamano
  2009-07-12 23:37     ` Stephen Boyd
  0 siblings, 2 replies; 7+ messages in thread
From: Michał Kiedrowicz @ 2009-07-12 10:24 UTC (permalink / raw)
  To: git; +Cc: Michał Kiedrowicz

Also add missing --bare to init-db synopsis.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
---
 Documentation/git-init-db.txt |    2 +-
 builtin-init-db.c             |   51 ++++++++++++++++++++++++-----------------
 2 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/Documentation/git-init-db.txt b/Documentation/git-init-db.txt
index 1fd0ff2..eba3cb4 100644
--- a/Documentation/git-init-db.txt
+++ b/Documentation/git-init-db.txt
@@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository
 
 SYNOPSIS
 --------
-'git init-db' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]
+'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
 
 
 DESCRIPTION
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 4a56006..d68f61b 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"
@@ -370,8 +371,16 @@ 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 int shared_callback(const struct option *opt, const char *arg, int unset)
+{
+	*((int *) opt->value) = (arg) ? git_config_perm("arg", arg) : PERM_GROUP;
+	return 0;
+}
+
+static const char *const init_db_usage[] = {
+	"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]",
+	NULL
+};
 
 /*
  * If you want to, you can share the DB area with any number of branches.
@@ -384,25 +393,25 @@ 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"))
-			init_shared_repository = PERM_GROUP;
-		else if (!prefixcmp(arg, "--shared="))
-			init_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);
+	const struct option init_db_options[] = {
+		OPT_STRING(0, "template", &template_dir, "template-directory",
+				"provide the directory from which templates will be used"),
+		OPT_SET_INT(0, "bare", &is_bare_repository_cfg,
+				"create a bare repository", 1),
+		{ OPTION_CALLBACK, 0, "shared", &init_shared_repository,
+			"permissions",
+			"specify that the git repository is to be shared amongst several users",
+			PARSE_OPT_OPTARG | PARSE_OPT_NONEG, shared_callback, 0},
+		OPT_BIT('q', "quiet", &flags, "be quiet", INIT_DB_QUIET),
+		OPT_END()
+	};
+
+	parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
+
+	if(is_bare_repository_cfg == 1) {
+		static char git_dir[PATH_MAX+1];
+		setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
+					sizeof(git_dir)), 0);
 	}
 
 	if (init_shared_repository != -1)
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] init-db: migrate to parse-options
  2009-07-12 10:24   ` [PATCH v2] " Michał Kiedrowicz
@ 2009-07-12 18:27     ` Junio C Hamano
  2009-07-12 18:37       ` Michał Kiedrowicz
  2009-07-12 23:37     ` Stephen Boyd
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2009-07-12 18:27 UTC (permalink / raw)
  To: Michał Kiedrowicz; +Cc: git

Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:

> Also add missing --bare to init-db synopsis.
>
> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
> ---
>  Documentation/git-init-db.txt |    2 +-
>  builtin-init-db.c             |   51 ++++++++++++++++++++++++-----------------
>  2 files changed, 31 insertions(+), 22 deletions(-)

The subject says patch v2 but there is no description since the previous
round, nor ...

> diff --git a/Documentation/git-init-db.txt b/Documentation/git-init-db.txt
> index 1fd0ff2..eba3cb4 100644
> --- a/Documentation/git-init-db.txt
> +++ b/Documentation/git-init-db.txt
> @@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository
>  ...
> diff --git a/builtin-init-db.c b/builtin-init-db.c
> index 4a56006..d68f61b 100644
> --- a/builtin-init-db.c
> +++ b/builtin-init-db.c
> @@ -6,6 +6,7 @@
> ...

... I see any change in the blob object name recorded on the index line.

What is going on?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] init-db: migrate to parse-options
  2009-07-12 18:27     ` Junio C Hamano
@ 2009-07-12 18:37       ` Michał Kiedrowicz
  2009-07-12 21:34         ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Michał Kiedrowicz @ 2009-07-12 18:37 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano <gitster@pobox.com> wrote:

> Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:
> 
> > Also add missing --bare to init-db synopsis.
> >
> > Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
> > ---
> >  Documentation/git-init-db.txt |    2 +-
> >  builtin-init-db.c             |   51
> > ++++++++++++++++++++++++----------------- 2 files changed, 31
> > insertions(+), 22 deletions(-)
> 
> The subject says patch v2 but there is no description since the
> previous round, nor ...
> 
> > diff --git a/Documentation/git-init-db.txt
> > b/Documentation/git-init-db.txt index 1fd0ff2..eba3cb4 100644
> > --- a/Documentation/git-init-db.txt
> > +++ b/Documentation/git-init-db.txt
> > @@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository
> >  ...
> > diff --git a/builtin-init-db.c b/builtin-init-db.c
> > index 4a56006..d68f61b 100644
> > --- a/builtin-init-db.c
> > +++ b/builtin-init-db.c
> > @@ -6,6 +6,7 @@
> > ...
> 
> ... I see any change in the blob object name recorded on the index
> line.
> 
> What is going on?

I just added "PARSE_OPT_NONEG" flag to "shared" option in reply to
Stephen's comment:

Stephen Boyd <bebarino@gmail.com> wrote:
> Or you can add PARSE_OPT_NONEG here and avoid the above comment.

Sorry I haven't described the change, I just thought it was obvious.


BTW: There is a difference:

> diff --git a/builtin-init-db.c b/builtin-init-db.c
> index 4a56006..9b1ce45 100644

and 

> diff --git a/builtin-init-db.c b/builtin-init-db.c
> index 4a56006..d68f61b 100644


-- 
Michał Kiedrowicz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] init-db: migrate to parse-options
  2009-07-12 18:37       ` Michał Kiedrowicz
@ 2009-07-12 21:34         ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2009-07-12 21:34 UTC (permalink / raw)
  To: Michał Kiedrowicz; +Cc: git

Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:

> BTW: There is a difference:
>
>> diff --git a/builtin-init-db.c b/builtin-init-db.c
>> index 4a56006..9b1ce45 100644
>
> and 
>
>> diff --git a/builtin-init-db.c b/builtin-init-db.c
>> index 4a56006..d68f61b 100644

Yeah, I was blind; I see them now.

Thanks, will queue.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] init-db: migrate to parse-options
  2009-07-12 10:24   ` [PATCH v2] " Michał Kiedrowicz
  2009-07-12 18:27     ` Junio C Hamano
@ 2009-07-12 23:37     ` Stephen Boyd
  1 sibling, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2009-07-12 23:37 UTC (permalink / raw)
  To: Michał Kiedrowicz; +Cc: git

2009/7/12 Michał Kiedrowicz <michal.kiedrowicz@gmail.com>:
> Also add missing --bare to init-db synopsis.
>
> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
> ---

Acked-by: Stephen Boyd <bebarino@gmail.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-07-12 23:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-11 22:53 [PATCH] init-db: migrate to parse-options Michał Kiedrowicz
2009-07-12  7:17 ` Stephen Boyd
2009-07-12 10:24   ` [PATCH v2] " Michał Kiedrowicz
2009-07-12 18:27     ` Junio C Hamano
2009-07-12 18:37       ` Michał Kiedrowicz
2009-07-12 21:34         ` Junio C Hamano
2009-07-12 23:37     ` Stephen Boyd

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 NNTP newsgroup(s).