init-db: migrate to parse-options
Also add missing --bare to init-db synopsis. Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michał Kiedrowicz committed
Jul 12, 2009 at 12:24 UTC
596f91ee70552230636aee5ee6cdabc0082d473a
2 files changed
+31
-22
Documentation/git-init-db.txt
+1
-1
@@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository
8
9
SYNOPSIS
10
--------
11
-'git init-db' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]
11
+'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
12
13
14
DESCRIPTION
builtin-init-db.c
+30
-21
@@ -6,6 +6,7 @@
6
#include "cache.h"
7
#include "builtin.h"
8
#include "exec_cmd.h"
9
+#include "parse-options.h"
10
11
#ifndef DEFAULT_GIT_TEMPLATE_DIR
12
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -370,8 +371,16 @@ static int guess_repository_type(const char *git_dir)
371
return 1;
372
}
373
373
-static const char init_db_usage[] =
374
-"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
374
+static int shared_callback(const struct option *opt, const char *arg, int unset)
375
+{
376
+ *((int *) opt->value) = (arg) ? git_config_perm("arg", arg) : PERM_GROUP;
377
+ return 0;
378
+}
379
+
380
+static const char *const init_db_usage[] = {
381
+ "git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]",
382
+ NULL
383
+};
384
385
/*
386
* 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)
393
const char *git_dir;
394
const char *template_dir = NULL;
395
unsigned int flags = 0;
387
- int i;
388
-
389
- for (i = 1; i < argc; i++, argv++) {
390
- const char *arg = argv[1];
391
- if (!prefixcmp(arg, "--template="))
392
- template_dir = arg+11;
393
- else if (!strcmp(arg, "--bare")) {
394
- static char git_dir[PATH_MAX+1];
395
- is_bare_repository_cfg = 1;
396
- setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
397
- sizeof(git_dir)), 0);
398
- } else if (!strcmp(arg, "--shared"))
399
- init_shared_repository = PERM_GROUP;
400
- else if (!prefixcmp(arg, "--shared="))
401
- init_shared_repository = git_config_perm("arg", arg+9);
402
- else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
403
- flags |= INIT_DB_QUIET;
404
- else
405
- usage(init_db_usage);
396
+ const struct option init_db_options[] = {
397
+ OPT_STRING(0, "template", &template_dir, "template-directory",
398
+ "provide the directory from which templates will be used"),
399
+ OPT_SET_INT(0, "bare", &is_bare_repository_cfg,
400
+ "create a bare repository", 1),
401
+ { OPTION_CALLBACK, 0, "shared", &init_shared_repository,
402
+ "permissions",
403
+ "specify that the git repository is to be shared amongst several users",
404
+ PARSE_OPT_OPTARG | PARSE_OPT_NONEG, shared_callback, 0},
405
+ OPT_BIT('q', "quiet", &flags, "be quiet", INIT_DB_QUIET),
406
+ OPT_END()
407
+ };
408
+
409
+ parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
410
+
411
+ if(is_bare_repository_cfg == 1) {
412
+ static char git_dir[PATH_MAX+1];
413
+ setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
414
+ sizeof(git_dir)), 0);
415
}
416
417
if (init_shared_repository != -1)