Re: [PATCH 7/8] Provide API access to init_db()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
> ---
>  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@xxxxxxxxxxx>
www.herland.net
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux