git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Herland <johan@herland.net>
To: Daniel Barkalow <barkalow@iabervon.org>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH 7/8] Provide API access to init_db()
Date: Sat, 19 Apr 2008 20:11:50 +0200	[thread overview]
Message-ID: <200804192011.50628.johan@herland.net> (raw)
In-Reply-To: <alpine.LNX.1.00.0804171932050.19665@iabervon.org>

On Friday 18 April 2008, Daniel Barkalow wrote:
> The caller first calls set_git_dir() to specify the GIT_DIR, and then
> calls init_db() to initialize it. This also cleans up various parts of
> the code to account for the fact that everything is done with GIT_DIR
> set, so it's unnecessary to pass the specified directory around.
> 
> Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
> ---
>  builtin-init-db.c |  180 +++++++++++++++++++++++++++-------------------------
>  cache.h           |    4 +
>  2 files changed, 97 insertions(+), 87 deletions(-)
> 
> diff --git a/builtin-init-db.c b/builtin-init-db.c
> index 2854868..f5ee209 100644
> --- a/builtin-init-db.c
> +++ b/builtin-init-db.c

[... snip snip ...]

> @@ -354,64 +392,32 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
>  		    GIT_WORK_TREE_ENVIRONMENT,
>  		    GIT_DIR_ENVIRONMENT);
>  
> -	guess_repository_type(git_dir);
> -
> -	if (is_bare_repository_cfg <= 0) {
> -		git_work_tree_cfg = xcalloc(PATH_MAX, 1);
> -		if (!getcwd(git_work_tree_cfg, PATH_MAX))
> -			die ("Cannot access current working directory.");
> -		if (access(get_git_work_tree(), X_OK))
> -			die ("Cannot access work tree '%s'",
> -			     get_git_work_tree());
> -	}
> -
>  	/*
>  	 * Set up the default .git directory contents
>  	 */
> -	git_dir = getenv(GIT_DIR_ENVIRONMENT);
>  	if (!git_dir)
>  		git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
> -	safe_create_dir(git_dir, 0);
>  
> -	/* Check to see if the repository version is right.
> -	 * Note that a newly created repository does not have
> -	 * config file, so this will not fail.  What we are catching
> -	 * is an attempt to reinitialize new repository with an old tool.
> -	 */
> -	check_repository_format();
> -
> -	reinit = create_default_files(git_dir, template_dir);
> +	if (is_bare_repository_cfg < 0)
> +		is_bare_repository_cfg = guess_repository_type(git_dir);
>  
> -	/*
> -	 * And set up the object store.
> -	 */
> -	sha1_dir = get_object_directory();
> -	len = strlen(sha1_dir);
> -	path = xmalloc(len + 40);
> -	memcpy(path, sha1_dir, len);
> -
> -	safe_create_dir(sha1_dir, 1);
> -	strcpy(path+len, "/pack");
> -	safe_create_dir(path, 1);
> -	strcpy(path+len, "/info");
> -	safe_create_dir(path, 1);
> -
> -	if (shared_repository) {
> -		char buf[10];
> -		/* We do not spell "group" and such, so that
> -		 * the configuration can be read by older version
> -		 * of git.
> -		 */
> -		sprintf(buf, "%d", shared_repository);
> -		git_config_set("core.sharedrepository", buf);
> -		git_config_set("receive.denyNonFastforwards", "true");
> +	if (!is_bare_repository_cfg) {
> +		if (git_dir) {
> +			const char *git_dir_parent = strrchr(git_dir, '/');
> +			if (git_dir_parent)
> +				git_work_tree_cfg = strdup(make_absolute_path(xstrndup(git_dir, git_dir_parent - git_dir)));

1. Aren't we leaking the xstrndup()?
2. s/strdup/xstrdup/?


...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

  reply	other threads:[~2008-04-19 18:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-17 23:32 [PATCH 7/8] Provide API access to init_db() Daniel Barkalow
2008-04-19 18:11 ` Johan Herland [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-04-27 17:39 Daniel Barkalow
2008-04-27 22:01 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200804192011.50628.johan@herland.net \
    --to=johan@herland.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).