Commit 08190e2a by nulltoken

Simplified git_repository_init_results struct.

parent 4b8e27c8
...@@ -60,7 +60,6 @@ static struct { ...@@ -60,7 +60,6 @@ static struct {
typedef struct git_repository_init_results { typedef struct git_repository_init_results {
char *path_repository; char *path_repository;
char *path_workdir;
unsigned is_bare:1; unsigned is_bare:1;
unsigned has_been_reinit:1; unsigned has_been_reinit:1;
...@@ -737,23 +736,16 @@ void git_repository_init__results_free(git_repository_init_results* init_results ...@@ -737,23 +736,16 @@ void git_repository_init__results_free(git_repository_init_results* init_results
if (init_results == NULL) if (init_results == NULL)
return; return;
if (init_results->path_workdir)
free(init_results->path_workdir);
if (init_results->path_repository) if (init_results->path_repository)
free(init_results->path_repository); free(init_results->path_repository);
free(init_results);
} }
git_repository_init_results *git_repository_init_results__alloc() void git_repository_init__zero_init_results(git_repository_init_results* results)
{ {
git_repository_init_results *results = git__malloc(sizeof(git_repository_init_results));
if (!results) if (!results)
return NULL; return;
memset(results, 0x0, sizeof(git_repository_init_results)); memset(results, 0x0, sizeof(git_repository_init_results));
return results;
} }
int git_repository_init__reinit(git_repository_init_results* results) int git_repository_init__reinit(git_repository_init_results* results)
...@@ -786,7 +778,7 @@ int git_repository_init__create_structure(git_repository_init_results* results) ...@@ -786,7 +778,7 @@ int git_repository_init__create_structure(git_repository_init_results* results)
return GIT_SUCCESS; return GIT_SUCCESS;
} }
int git_repository_init__assign_folders(git_repository_init_results* results, const char* path) int git_repository_init__assign_git_directory(git_repository_init_results* results, const char* path)
{ {
const int MAX_GITDIR_TREE_STRUCTURE_PATH_LENGTH = 66; // TODO: How many ? const int MAX_GITDIR_TREE_STRUCTURE_PATH_LENGTH = 66; // TODO: How many ?
char temp_path[GIT_PATH_MAX]; char temp_path[GIT_PATH_MAX];
...@@ -805,13 +797,8 @@ int git_repository_init__assign_folders(git_repository_init_results* results, co ...@@ -805,13 +797,8 @@ int git_repository_init__assign_folders(git_repository_init_results* results, co
assert(path_len < GIT_PATH_MAX - MAX_GITDIR_TREE_STRUCTURE_PATH_LENGTH); assert(path_len < GIT_PATH_MAX - MAX_GITDIR_TREE_STRUCTURE_PATH_LENGTH);
if (results->is_bare) if (!results->is_bare)
{ {
results->path_workdir = NULL;
}
else
{
results->path_workdir = git__strdup(temp_path);
strcpy(temp_path + path_len - 1, GIT_FOLDER); strcpy(temp_path + path_len - 1, GIT_FOLDER);
path_len = path_len + strlen(GIT_FOLDER) - 1; /* Skip the leading slash from the constant */ path_len = path_len + strlen(GIT_FOLDER) - 1; /* Skip the leading slash from the constant */
} }
...@@ -823,22 +810,20 @@ int git_repository_init__assign_folders(git_repository_init_results* results, co ...@@ -823,22 +810,20 @@ int git_repository_init__assign_folders(git_repository_init_results* results, co
int git_repository_init(git_repository** repo_out, const char* path, unsigned is_bare) int git_repository_init(git_repository** repo_out, const char* path, unsigned is_bare)
{ {
git_repository_init_results* results; git_repository_init_results results;
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
assert(repo_out && path); assert(repo_out && path);
results = git_repository_init_results__alloc(); git_repository_init__zero_init_results(&results);
if (results == NULL)
return GIT_ENOMEM;
results->is_bare = is_bare; results.is_bare = is_bare;
error = git_repository_init__assign_folders(results, path); error = git_repository_init__assign_git_directory(&results, path);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
goto cleanup; goto cleanup;
error = git_repository_init__create_structure(results); error = git_repository_init__create_structure(&results);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
goto cleanup; goto cleanup;
...@@ -848,6 +833,6 @@ int git_repository_init(git_repository** repo_out, const char* path, unsigned is ...@@ -848,6 +833,6 @@ int git_repository_init(git_repository** repo_out, const char* path, unsigned is
// goto cleanup; // goto cleanup;
cleanup: cleanup:
git_repository_init__results_free(results); git_repository_init__results_free(&results);
return error; return error;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment