Browse Source

Merge branch 'mk/init-db-parse-options'

* mk/init-db-parse-options:
  init-db: migrate to parse-options
maint
Junio C Hamano 16 years ago
parent
commit
4d4097da6b
  1. 2
      Documentation/git-init-db.txt
  2. 51
      builtin-init-db.c

2
Documentation/git-init-db.txt

@ -8,7 +8,7 @@ git-init-db - Creates an empty git repository


SYNOPSIS SYNOPSIS
-------- --------
'git init-db' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]] 'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]




DESCRIPTION DESCRIPTION

51
builtin-init-db.c

@ -6,6 +6,7 @@
#include "cache.h" #include "cache.h"
#include "builtin.h" #include "builtin.h"
#include "exec_cmd.h" #include "exec_cmd.h"
#include "parse-options.h"


#ifndef DEFAULT_GIT_TEMPLATE_DIR #ifndef DEFAULT_GIT_TEMPLATE_DIR
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates" #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; return 1;
} }


static const char init_db_usage[] = static int shared_callback(const struct option *opt, const char *arg, int unset)
"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]"; {
*((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. * 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 *git_dir;
const char *template_dir = NULL; const char *template_dir = NULL;
unsigned int flags = 0; unsigned int flags = 0;
int i; const struct option init_db_options[] = {

OPT_STRING(0, "template", &template_dir, "template-directory",
for (i = 1; i < argc; i++, argv++) { "provide the directory from which templates will be used"),
const char *arg = argv[1]; OPT_SET_INT(0, "bare", &is_bare_repository_cfg,
if (!prefixcmp(arg, "--template=")) "create a bare repository", 1),
template_dir = arg+11; { OPTION_CALLBACK, 0, "shared", &init_shared_repository,
else if (!strcmp(arg, "--bare")) { "permissions",
static char git_dir[PATH_MAX+1]; "specify that the git repository is to be shared amongst several users",
is_bare_repository_cfg = 1; PARSE_OPT_OPTARG | PARSE_OPT_NONEG, shared_callback, 0},
setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, OPT_BIT('q', "quiet", &flags, "be quiet", INIT_DB_QUIET),
sizeof(git_dir)), 0); OPT_END()
} else if (!strcmp(arg, "--shared")) };
init_shared_repository = PERM_GROUP;
else if (!prefixcmp(arg, "--shared=")) parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
init_shared_repository = git_config_perm("arg", arg+9);
else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet")) if(is_bare_repository_cfg == 1) {
flags |= INIT_DB_QUIET; static char git_dir[PATH_MAX+1];
else setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
usage(init_db_usage); sizeof(git_dir)), 0);
} }


if (init_shared_repository != -1) if (init_shared_repository != -1)

Loading…
Cancel
Save