summaryrefslogtreecommitdiff
path: root/builtin/init-db.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/init-db.c')
-rw-r--r--builtin/init-db.c56
1 files changed, 38 insertions, 18 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c
index cb727c826f..096f96b9c4 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -3,14 +3,15 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
+#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "abspath.h"
-#include "config.h"
#include "environment.h"
#include "gettext.h"
#include "object-file.h"
#include "parse-options.h"
#include "path.h"
+#include "refs.h"
#include "setup.h"
#include "strbuf.h"
@@ -57,6 +58,7 @@ static int shared_callback(const struct option *opt, const char *arg, int unset)
static const char *const init_db_usage[] = {
N_("git init [-q | --quiet] [--bare] [--template=<template-directory>]\n"
" [--separate-git-dir <git-dir>] [--object-format=<format>]\n"
+ " [--ref-format=<format>]\n"
" [-b <branch-name> | --initial-branch=<branch-name>]\n"
" [--shared[=<permissions>]] [<directory>]"),
NULL
@@ -68,16 +70,23 @@ static const char *const init_db_usage[] = {
* On the other hand, it might just make lookup slower and messier. You
* be the judge. The default case is to have one DB per managed directory.
*/
-int cmd_init_db(int argc, const char **argv, const char *prefix)
+int cmd_init_db(int argc,
+ const char **argv,
+ const char *prefix,
+ struct repository *repo UNUSED)
{
- const char *git_dir;
+ char *git_dir;
const char *real_git_dir = NULL;
- const char *work_tree;
+ char *real_git_dir_to_free = NULL;
+ char *work_tree = NULL;
const char *template_dir = NULL;
+ char *template_dir_to_free = NULL;
unsigned int flags = 0;
const char *object_format = NULL;
+ const char *ref_format = NULL;
const char *initial_branch = NULL;
int hash_algo = GIT_HASH_UNKNOWN;
+ enum ref_storage_format ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
int init_shared_repository = -1;
const struct option init_db_options[] = {
OPT_STRING(0, "template", &template_dir, N_("template-directory"),
@@ -95,8 +104,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
N_("override the name of the initial branch")),
OPT_STRING(0, "object-format", &object_format, N_("hash"),
N_("specify the hash algorithm to use")),
+ OPT_STRING(0, "ref-format", &ref_format, N_("format"),
+ N_("specify the reference format to use")),
OPT_END()
};
+ int ret;
argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
@@ -104,12 +116,10 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
die(_("options '%s' and '%s' cannot be used together"), "--separate-git-dir", "--bare");
if (real_git_dir && !is_absolute_path(real_git_dir))
- real_git_dir = real_pathdup(real_git_dir, 1);
+ real_git_dir = real_git_dir_to_free = real_pathdup(real_git_dir, 1);
- if (template_dir && *template_dir && !is_absolute_path(template_dir)) {
- template_dir = absolute_pathdup(template_dir);
- UNLEAK(template_dir);
- }
+ if (template_dir && *template_dir && !is_absolute_path(template_dir))
+ template_dir = template_dir_to_free = absolute_pathdup(template_dir);
if (argc == 1) {
int mkdir_tried = 0;
@@ -158,6 +168,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
die(_("unknown hash algorithm '%s'"), object_format);
}
+ if (ref_format) {
+ ref_storage_format = ref_storage_format_by_name(ref_format);
+ if (ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
+ die(_("unknown ref storage format '%s'"), ref_format);
+ }
+
if (init_shared_repository != -1)
set_shared_repository(init_shared_repository);
@@ -177,7 +193,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
* Set up the default .git directory contents
*/
if (!git_dir)
- git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+ git_dir = xstrdup(DEFAULT_GIT_DIR_ENVIRONMENT);
/*
* When --separate-git-dir is used inside a linked worktree, take
@@ -198,6 +214,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
if (chdir(mainwt.buf) < 0)
die_errno(_("cannot chdir to %s"), mainwt.buf);
strbuf_release(&mainwt);
+ free(git_dir);
git_dir = strbuf_detach(&sb, NULL);
}
strbuf_release(&sb);
@@ -219,9 +236,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
set_git_work_tree(work_tree);
else
set_git_work_tree(git_work_tree_cfg);
- if (access(get_git_work_tree(), X_OK))
+ if (access(repo_get_work_tree(the_repository), X_OK))
die_errno (_("Cannot access work tree '%s'"),
- get_git_work_tree());
+ repo_get_work_tree(the_repository));
}
else {
if (real_git_dir)
@@ -230,11 +247,14 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
set_git_work_tree(work_tree);
}
- UNLEAK(real_git_dir);
- UNLEAK(git_dir);
- UNLEAK(work_tree);
-
flags |= INIT_DB_EXIST_OK;
- return init_db(git_dir, real_git_dir, template_dir, hash_algo,
- initial_branch, init_shared_repository, flags);
+ ret = init_db(git_dir, real_git_dir, template_dir, hash_algo,
+ ref_storage_format, initial_branch,
+ init_shared_repository, flags);
+
+ free(template_dir_to_free);
+ free(real_git_dir_to_free);
+ free(work_tree);
+ free(git_dir);
+ return ret;
}