{"thread":{"id":"20090","subject":"[PATCH] init-db: migrate to parse-options","startedAt":"2009-07-11T22:53:13Z","lastAt":"2009-07-12T23:37:36Z","messageCount":7,"participants":["Michał Kiedrowicz","Stephen Boyd","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"117847","messageId":"1247352793-25675-1-git-send-email-michal.kiedrowicz@gmail.com","threadId":"20090","inReplyTo":null,"subject":"[PATCH] init-db: migrate to parse-options","fromName":"Michał Kiedrowicz","fromEmail":"michal.kiedrowicz@gmail.com","sentAt":"2009-07-11T22:53:13Z","receivedAt":"2009-07-11T22:53:13Z","isPatch":true,"sender":{"key":"michal.kiedrowicz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/14072847?v=4"},"body":"Also add missing --bare to init-db synopsis.\n\nSigned-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>\n---\n Documentation/git-init-db.txt |    2 +-\n builtin-init-db.c             |   51 ++++++++++++++++++++++++-----------------\n 2 files changed, 31 insertions(+), 22 deletions(-)\n\ndiff --git a/Documentation/git-init-db.txt b/Documentation/git-init-db.txt\nindex 1fd0ff2..eba3cb4 100644\n--- a/Documentation/git-init-db.txt\n+++ b/Documentation/git-init-db.txt\n@@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository\n \n SYNOPSIS\n --------\n-'git init-db' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]\n+'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]\n \n \n DESCRIPTION\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 4a56006..9b1ce45 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -6,6 +6,7 @@\n #include \"cache.h\"\n #include \"builtin.h\"\n #include \"exec_cmd.h\"\n+#include \"parse-options.h\"\n \n #ifndef DEFAULT_GIT_TEMPLATE_DIR\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\n@@ -370,8 +371,16 @@ static int guess_repository_type(const char *git_dir)\n \treturn 1;\n }\n \n-static const char init_db_usage[] =\n-\"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]\";\n+static int shared_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\t*((int *) opt->value) = (arg) ? git_config_perm(\"arg\", arg) : PERM_GROUP;\n+\treturn 0;\n+}\n+\n+static const char *const init_db_usage[] = {\n+\t\"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]\",\n+\tNULL\n+};\n \n /*\n  * If you want to, you can share the DB area with any number of branches.\n@@ -384,25 +393,25 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tconst char *git_dir;\n \tconst char *template_dir = NULL;\n \tunsigned int flags = 0;\n-\tint i;\n-\n-\tfor (i = 1; i < argc; i++, argv++) {\n-\t\tconst char *arg = argv[1];\n-\t\tif (!prefixcmp(arg, \"--template=\"))\n-\t\t\ttemplate_dir = arg+11;\n-\t\telse if (!strcmp(arg, \"--bare\")) {\n-\t\t\tstatic char git_dir[PATH_MAX+1];\n-\t\t\tis_bare_repository_cfg = 1;\n-\t\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,\n-\t\t\t\t\t\tsizeof(git_dir)), 0);\n-\t\t} else if (!strcmp(arg, \"--shared\"))\n-\t\t\tinit_shared_repository = PERM_GROUP;\n-\t\telse if (!prefixcmp(arg, \"--shared=\"))\n-\t\t\tinit_shared_repository = git_config_perm(\"arg\", arg+9);\n-\t\telse if (!strcmp(arg, \"-q\") || !strcmp(arg, \"--quiet\"))\n-\t\t\tflags |= INIT_DB_QUIET;\n-\t\telse\n-\t\t\tusage(init_db_usage);\n+\tconst struct option init_db_options[] = {\n+\t\tOPT_STRING(0, \"template\", &template_dir, \"template-directory\",\n+\t\t\t\t\"provide the directory from which templates will be used\"),\n+\t\tOPT_SET_INT(0, \"bare\", &is_bare_repository_cfg,\n+\t\t\t\t\"create a bare repository\", 1),\n+\t\t{ OPTION_CALLBACK, 0, \"shared\", &init_shared_repository,\n+\t\t\t\"permissions\",\n+\t\t\t\"specify that the git repository is to be shared amongst several users\",\n+\t\t\tPARSE_OPT_OPTARG, shared_callback, 0},\n+\t\tOPT_BIT('q', \"quiet\", &flags, \"be quiet\", INIT_DB_QUIET),\n+\t\tOPT_END()\n+\t};\n+\n+\tparse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);\n+\n+\tif(is_bare_repository_cfg == 1) {\n+\t\tstatic char git_dir[PATH_MAX+1];\n+\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,\n+\t\t\t\t\tsizeof(git_dir)), 0);\n \t}\n \n \tif (init_shared_repository != -1)\n-- \n1.6.3.3\n"},{"id":"117851","messageId":"4A598E03.10204@gmail.com","threadId":"20090","inReplyTo":"1247352793-25675-1-git-send-email-michal.kiedrowicz@gmail.com","subject":"Re: [PATCH] init-db: migrate to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-12T07:17:23Z","receivedAt":"2009-07-12T07:17:23Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Michał Kiedrowicz wrote:\n> Also add missing --bare to init-db synopsis.\n>\n> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>\n> ---\n\nHeh, I had a very similar patch queued up.\n\n>  Documentation/git-init-db.txt |    2 +-\n>  builtin-init-db.c             |   51 ++++++++++++++++++++++++-----------------\n>  2 files changed, 31 insertions(+), 22 deletions(-)\n>\n> diff --git a/Documentation/git-init-db.txt b/Documentation/git-init-db.txt\n> index 1fd0ff2..eba3cb4 100644\n> --- a/Documentation/git-init-db.txt\n> +++ b/Documentation/git-init-db.txt\n> @@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository\n>  \n>  SYNOPSIS\n>  --------\n> -'git init-db' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]\n> +'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]\n>  \n>  \n>  DESCRIPTION\n> diff --git a/builtin-init-db.c b/builtin-init-db.c\n> index 4a56006..9b1ce45 100644\n> --- a/builtin-init-db.c\n> +++ b/builtin-init-db.c\n> @@ -6,6 +6,7 @@\n>  #include \"cache.h\"\n>  #include \"builtin.h\"\n>  #include \"exec_cmd.h\"\n> +#include \"parse-options.h\"\n>  \n>  #ifndef DEFAULT_GIT_TEMPLATE_DIR\n>  #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\n> @@ -370,8 +371,16 @@ static int guess_repository_type(const char *git_dir)\n>  \treturn 1;\n>  }\n>  \n> -static const char init_db_usage[] =\n> -\"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]\";\n> +static int shared_callback(const struct option *opt, const char *arg, int unset)\n> +{\n> +\t*((int *) opt->value) = (arg) ? git_config_perm(\"arg\", arg) : PERM_GROUP;\n> +\treturn 0;\n> +}\n\nWhat occurs when \"--no-shared\" is used? I have this callback use an if,\nelse if, else to handle all possibilities.\n\n> +\n> +static const char *const init_db_usage[] = {\n> +\t\"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]\",\n> +\tNULL\n> +};\n>  \n>  /*\n>   * If you want to, you can share the DB area with any number of branches.\n> @@ -384,25 +393,25 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n>  \tconst char *git_dir;\n>  \tconst char *template_dir = NULL;\n>  \tunsigned int flags = 0;\n> -\tint i;\n> -\n> -\tfor (i = 1; i < argc; i++, argv++) {\n> -\t\tconst char *arg = argv[1];\n> -\t\tif (!prefixcmp(arg, \"--template=\"))\n> -\t\t\ttemplate_dir = arg+11;\n> -\t\telse if (!strcmp(arg, \"--bare\")) {\n> -\t\t\tstatic char git_dir[PATH_MAX+1];\n> -\t\t\tis_bare_repository_cfg = 1;\n> -\t\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,\n> -\t\t\t\t\t\tsizeof(git_dir)), 0);\n> -\t\t} else if (!strcmp(arg, \"--shared\"))\n> -\t\t\tinit_shared_repository = PERM_GROUP;\n> -\t\telse if (!prefixcmp(arg, \"--shared=\"))\n> -\t\t\tinit_shared_repository = git_config_perm(\"arg\", arg+9);\n> -\t\telse if (!strcmp(arg, \"-q\") || !strcmp(arg, \"--quiet\"))\n> -\t\t\tflags |= INIT_DB_QUIET;\n> -\t\telse\n> -\t\t\tusage(init_db_usage);\n> +\tconst struct option init_db_options[] = {\n> +\t\tOPT_STRING(0, \"template\", &template_dir, \"template-directory\",\n> +\t\t\t\t\"provide the directory from which templates will be used\"),\n> +\t\tOPT_SET_INT(0, \"bare\", &is_bare_repository_cfg,\n> +\t\t\t\t\"create a bare repository\", 1),\n> +\t\t{ OPTION_CALLBACK, 0, \"shared\", &init_shared_repository,\n> +\t\t\t\"permissions\",\n> +\t\t\t\"specify that the git repository is to be shared amongst several users\",\n> +\t\t\tPARSE_OPT_OPTARG, shared_callback, 0},\n\nOr you can add PARSE_OPT_NONEG here and avoid the above comment.\n\n> +\t\tOPT_BIT('q', \"quiet\", &flags, \"be quiet\", INIT_DB_QUIET),\n> +\t\tOPT_END()\n> +\t};\n> +\n> +\tparse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);\n> +\n> +\tif(is_bare_repository_cfg == 1) {\n> +\t\tstatic char git_dir[PATH_MAX+1];\n> +\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,\n> +\t\t\t\t\tsizeof(git_dir)), 0);\n>  \t}\n>  \n>  \tif (init_shared_repository != -1)\n"},{"id":"117853","messageId":"1247394272-6944-1-git-send-email-michal.kiedrowicz@gmail.com","threadId":"20090","inReplyTo":"4A598E03.10204@gmail.com","subject":"[PATCH v2] init-db: migrate to parse-options","fromName":"Michał Kiedrowicz","fromEmail":"michal.kiedrowicz@gmail.com","sentAt":"2009-07-12T10:24:32Z","receivedAt":"2009-07-12T10:24:32Z","isPatch":true,"sender":{"key":"michal.kiedrowicz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/14072847?v=4"},"body":"Also add missing --bare to init-db synopsis.\n\nSigned-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>\n---\n Documentation/git-init-db.txt |    2 +-\n builtin-init-db.c             |   51 ++++++++++++++++++++++++-----------------\n 2 files changed, 31 insertions(+), 22 deletions(-)\n\ndiff --git a/Documentation/git-init-db.txt b/Documentation/git-init-db.txt\nindex 1fd0ff2..eba3cb4 100644\n--- a/Documentation/git-init-db.txt\n+++ b/Documentation/git-init-db.txt\n@@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository\n \n SYNOPSIS\n --------\n-'git init-db' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]\n+'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]\n \n \n DESCRIPTION\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 4a56006..d68f61b 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -6,6 +6,7 @@\n #include \"cache.h\"\n #include \"builtin.h\"\n #include \"exec_cmd.h\"\n+#include \"parse-options.h\"\n \n #ifndef DEFAULT_GIT_TEMPLATE_DIR\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\n@@ -370,8 +371,16 @@ static int guess_repository_type(const char *git_dir)\n \treturn 1;\n }\n \n-static const char init_db_usage[] =\n-\"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]\";\n+static int shared_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\t*((int *) opt->value) = (arg) ? git_config_perm(\"arg\", arg) : PERM_GROUP;\n+\treturn 0;\n+}\n+\n+static const char *const init_db_usage[] = {\n+\t\"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]\",\n+\tNULL\n+};\n \n /*\n  * If you want to, you can share the DB area with any number of branches.\n@@ -384,25 +393,25 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tconst char *git_dir;\n \tconst char *template_dir = NULL;\n \tunsigned int flags = 0;\n-\tint i;\n-\n-\tfor (i = 1; i < argc; i++, argv++) {\n-\t\tconst char *arg = argv[1];\n-\t\tif (!prefixcmp(arg, \"--template=\"))\n-\t\t\ttemplate_dir = arg+11;\n-\t\telse if (!strcmp(arg, \"--bare\")) {\n-\t\t\tstatic char git_dir[PATH_MAX+1];\n-\t\t\tis_bare_repository_cfg = 1;\n-\t\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,\n-\t\t\t\t\t\tsizeof(git_dir)), 0);\n-\t\t} else if (!strcmp(arg, \"--shared\"))\n-\t\t\tinit_shared_repository = PERM_GROUP;\n-\t\telse if (!prefixcmp(arg, \"--shared=\"))\n-\t\t\tinit_shared_repository = git_config_perm(\"arg\", arg+9);\n-\t\telse if (!strcmp(arg, \"-q\") || !strcmp(arg, \"--quiet\"))\n-\t\t\tflags |= INIT_DB_QUIET;\n-\t\telse\n-\t\t\tusage(init_db_usage);\n+\tconst struct option init_db_options[] = {\n+\t\tOPT_STRING(0, \"template\", &template_dir, \"template-directory\",\n+\t\t\t\t\"provide the directory from which templates will be used\"),\n+\t\tOPT_SET_INT(0, \"bare\", &is_bare_repository_cfg,\n+\t\t\t\t\"create a bare repository\", 1),\n+\t\t{ OPTION_CALLBACK, 0, \"shared\", &init_shared_repository,\n+\t\t\t\"permissions\",\n+\t\t\t\"specify that the git repository is to be shared amongst several users\",\n+\t\t\tPARSE_OPT_OPTARG | PARSE_OPT_NONEG, shared_callback, 0},\n+\t\tOPT_BIT('q', \"quiet\", &flags, \"be quiet\", INIT_DB_QUIET),\n+\t\tOPT_END()\n+\t};\n+\n+\tparse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);\n+\n+\tif(is_bare_repository_cfg == 1) {\n+\t\tstatic char git_dir[PATH_MAX+1];\n+\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,\n+\t\t\t\t\tsizeof(git_dir)), 0);\n \t}\n \n \tif (init_shared_repository != -1)\n-- \n1.6.3.3\n"},{"id":"117869","messageId":"7v8witn4e5.fsf@alter.siamese.dyndns.org","threadId":"20090","inReplyTo":"1247394272-6944-1-git-send-email-michal.kiedrowicz@gmail.com","subject":"Re: [PATCH v2] init-db: migrate to parse-options","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-12T18:27:14Z","receivedAt":"2009-07-12T18:27:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:\n\n> Also add missing --bare to init-db synopsis.\n>\n> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>\n> ---\n>  Documentation/git-init-db.txt |    2 +-\n>  builtin-init-db.c             |   51 ++++++++++++++++++++++++-----------------\n>  2 files changed, 31 insertions(+), 22 deletions(-)\n\nThe subject says patch v2 but there is no description since the previous\nround, nor ...\n\n> diff --git a/Documentation/git-init-db.txt b/Documentation/git-init-db.txt\n> index 1fd0ff2..eba3cb4 100644\n> --- a/Documentation/git-init-db.txt\n> +++ b/Documentation/git-init-db.txt\n> @@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository\n>  ...\n> diff --git a/builtin-init-db.c b/builtin-init-db.c\n> index 4a56006..d68f61b 100644\n> --- a/builtin-init-db.c\n> +++ b/builtin-init-db.c\n> @@ -6,6 +6,7 @@\n> ...\n\n... I see any change in the blob object name recorded on the index line.\n\nWhat is going on?\n"},{"id":"117870","messageId":"20090712203716.20ac4261@gmail.com","threadId":"20090","inReplyTo":"7v8witn4e5.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] init-db: migrate to parse-options","fromName":"Michał Kiedrowicz","fromEmail":"michal.kiedrowicz@gmail.com","sentAt":"2009-07-12T18:37:16Z","receivedAt":"2009-07-12T18:37:16Z","isPatch":true,"sender":{"key":"michal.kiedrowicz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/14072847?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n\n> Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:\n> \n> > Also add missing --bare to init-db synopsis.\n> >\n> > Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>\n> > ---\n> >  Documentation/git-init-db.txt |    2 +-\n> >  builtin-init-db.c             |   51\n> > ++++++++++++++++++++++++----------------- 2 files changed, 31\n> > insertions(+), 22 deletions(-)\n> \n> The subject says patch v2 but there is no description since the\n> previous round, nor ...\n> \n> > diff --git a/Documentation/git-init-db.txt\n> > b/Documentation/git-init-db.txt index 1fd0ff2..eba3cb4 100644\n> > --- a/Documentation/git-init-db.txt\n> > +++ b/Documentation/git-init-db.txt\n> > @@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository\n> >  ...\n> > diff --git a/builtin-init-db.c b/builtin-init-db.c\n> > index 4a56006..d68f61b 100644\n> > --- a/builtin-init-db.c\n> > +++ b/builtin-init-db.c\n> > @@ -6,6 +6,7 @@\n> > ...\n> \n> ... I see any change in the blob object name recorded on the index\n> line.\n> \n> What is going on?\n\nI just added \"PARSE_OPT_NONEG\" flag to \"shared\" option in reply to\nStephen's comment:\n\nStephen Boyd <bebarino@gmail.com> wrote:\n> Or you can add PARSE_OPT_NONEG here and avoid the above comment.\n\nSorry I haven't described the change, I just thought it was obvious.\n\n\nBTW: There is a difference:\n\n> diff --git a/builtin-init-db.c b/builtin-init-db.c\n> index 4a56006..9b1ce45 100644\n\nand \n\n> diff --git a/builtin-init-db.c b/builtin-init-db.c\n> index 4a56006..d68f61b 100644\n\n\n-- \nMichał Kiedrowicz\n"},{"id":"117876","messageId":"7vbpnplh50.fsf@alter.siamese.dyndns.org","threadId":"20090","inReplyTo":"20090712203716.20ac4261@gmail.com","subject":"Re: [PATCH v2] init-db: migrate to parse-options","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-12T21:34:51Z","receivedAt":"2009-07-12T21:34:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michał Kiedrowicz <michal.kiedrowicz@gmail.com> writes:\n\n> BTW: There is a difference:\n>\n>> diff --git a/builtin-init-db.c b/builtin-init-db.c\n>> index 4a56006..9b1ce45 100644\n>\n> and \n>\n>> diff --git a/builtin-init-db.c b/builtin-init-db.c\n>> index 4a56006..d68f61b 100644\n\nYeah, I was blind; I see them now.\n\nThanks, will queue.\n"},{"id":"117882","messageId":"780e0a6b0907121637x3e4c1e5ax786266c59566cae5@mail.gmail.com","threadId":"20090","inReplyTo":"1247394272-6944-1-git-send-email-michal.kiedrowicz@gmail.com","subject":"Re: [PATCH v2] init-db: migrate to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-12T23:37:36Z","receivedAt":"2009-07-12T23:37:36Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"2009/7/12 Michał Kiedrowicz <michal.kiedrowicz@gmail.com>:\n> Also add missing --bare to init-db synopsis.\n>\n> Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>\n> ---\n\nAcked-by: Stephen Boyd <bebarino@gmail.com>\n"}]}