Skip to content

Commit

Permalink
Fix initialization & freeing of inexistent repos
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <tanoku@gmail.com>
  • Loading branch information
vmg committed Dec 13, 2010
1 parent e0d9e12 commit 1f080e2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/fileops.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ int gitfo_isdir(const char *path)
stat_error = gitfo_stat(path, &st);
}

return (stat_error == 0 && S_ISDIR(st.st_mode)) ?
GIT_SUCCESS : GIT_ENOTFOUND;
if (stat_error < GIT_SUCCESS)
return GIT_ENOTFOUND;

if (!S_ISDIR(st.st_mode))
return GIT_ENOTFOUND;

return GIT_SUCCESS;
}

int gitfo_exists(const char *path)
Expand Down
3 changes: 2 additions & 1 deletion src/odb.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ void git_odb_close(git_odb *db)
{
unsigned int i;

assert(db);
if (db == NULL)
return;

for (i = 0; i < db->backends.length; ++i) {
git_odb_backend *b = git_vector_get(&db->backends, i);
Expand Down
17 changes: 12 additions & 5 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static int assign_repository_folders(git_repository *repo,
if (git_dir == NULL || gitfo_isdir(git_dir) < GIT_SUCCESS)
return GIT_ENOTFOUND;


/* store GIT_DIR */
path_len = strlen(git_dir);
strcpy(path_aux, git_dir);
Expand Down Expand Up @@ -279,6 +278,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
if (error < GIT_SUCCESS)
goto cleanup;


error = git_odb_open(&repo->db, repo->path_odb);
if (error < GIT_SUCCESS)
goto cleanup;
Expand All @@ -296,7 +296,8 @@ void git_repository_free(git_repository *repo)
git_hashtable_iterator it;
git_object *object;

assert(repo);
if (repo == NULL)
return;

free(repo->path_workdir);
free(repo->path_index);
Expand All @@ -310,8 +311,13 @@ void git_repository_free(git_repository *repo)
git_object_free(object);

git_hashtable_free(repo->objects);
git_odb_close(repo->db);
git_index_free(repo->index);

if (repo->db != NULL)
git_odb_close(repo->db);

if (repo->index != NULL)
git_index_free(repo->index);

free(repo);
}

Expand Down Expand Up @@ -511,7 +517,8 @@ int git_object_write(git_object *object)

void git_object_free(git_object *object)
{
assert(object);
if (object == NULL)
return;

git_object__source_close(object);
git_hashtable_remove(object->repo->objects, &object->id);
Expand Down
12 changes: 12 additions & 0 deletions src/revwalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)

void git_revwalk_free(git_revwalk *walk)
{
if (walk == NULL)
return;

git_revwalk_reset(walk);
git_hashtable_free(walk->commits);
free(walk);
Expand All @@ -90,6 +93,8 @@ git_repository *git_revwalk_repository(git_revwalk *walk)

int git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode)
{
assert(walk);

if (walk->walking)
return GIT_EBUSY;

Expand Down Expand Up @@ -165,6 +170,7 @@ static git_revwalk_commit *insert_commit(git_revwalk *walk, git_commit *commit_o

int git_revwalk_push(git_revwalk *walk, git_commit *commit)
{
assert(walk && commit);
return insert_commit(walk, commit) ? GIT_SUCCESS : GIT_ENOMEM;
}

Expand All @@ -186,6 +192,8 @@ static void mark_uninteresting(git_revwalk_commit *commit)
int git_revwalk_hide(git_revwalk *walk, git_commit *commit)
{
git_revwalk_commit *hide;

assert(walk && commit);

hide = insert_commit(walk, commit);
if (hide == NULL)
Expand Down Expand Up @@ -216,6 +224,8 @@ git_commit *git_revwalk_next(git_revwalk *walk)
{
git_revwalk_commit *next;

assert(walk);

if (!walk->walking)
prepare_walk(walk);

Expand All @@ -234,6 +244,8 @@ void git_revwalk_reset(git_revwalk *walk)
git_hashtable_iterator it;
git_revwalk_commit *commit;

assert(walk);

git_hashtable_iterator_init(walk->commits, &it);

while ((commit = (git_revwalk_commit *)
Expand Down

0 comments on commit 1f080e2

Please sign in to comment.