git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Johan Herland <johan@herland.net>
Date
Apr 19, 2008, 18:11 UTC
Message-ID
<200804192011.50628.johan@herland.net>
In-Reply-To
<alpine.LNX.1.00.0804171932050.19665@iabervon.org>
On Friday 18 April 2008, Daniel Barkalow wrote:
Show 15 quoted lines
> 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 ...]
Show 62 quoted lines
> @@ -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
Previous: Daniel Barkalow
Message 2 of 2 in “Provide API access to init_db()”
  1. 7/8 Provide API access to init_db()Daniel Barkalow, Apr 17, 2008
  2. Johan HerlandApr 19, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.