diff options
| author | Vicent Marti <tanoku@gmail.com> | 2010-11-17 04:58:32 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2010-11-17 05:16:26 +0200 |
| commit | 50dd6ca54cfdfc362147f09ece4996970d0352bd (patch) | |
| tree | f4dd4bf700579c282d06e6bb1baa9bf484ef594d /src | |
| parent | d7c7cab8a41f3baee7e9eb748793c063f925d6fd (diff) | |
| download | libgit2-50dd6ca54cfdfc362147f09ece4996970d0352bd.tar.gz | |
Fix repository initialization
We cannot assume that non-bare repositories have an index file, because
'git index' doesn't create it by default.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/repository.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/repository.c b/src/repository.c index ef51b08e7..5dd1fdf89 100644 --- a/src/repository.c +++ b/src/repository.c @@ -68,8 +68,8 @@ int git__objtable_haskey(void *object, const void *key) static int parse_repository_folders(git_repository *repo, const char *repository_path) { - char path_aux[GIT_PATH_MAX]; - int path_len, i; + char path_aux[GIT_PATH_MAX], *last_folder; + int path_len; if (gitfo_isdir(repository_path) < 0) return GIT_ENOTAREPO; @@ -97,22 +97,24 @@ static int parse_repository_folders(git_repository *repo, const char *repository if (gitfo_exists(path_aux) < 0) return GIT_ENOTAREPO; - i = path_len - 2; - while (path_aux[i] != '/') - i--; + path_aux[path_len] = 0; - if (strcmp(path_aux, "/.git/") == 0) { - repo->is_bare = 0; + last_folder = (path_aux + path_len - 2); - path_aux[i + 1] = 0; - repo->path_workdir = git__strdup(path_aux); + while (*last_folder != '/') + last_folder--; + + if (strcmp(last_folder, "/.git/") == 0) { + repo->is_bare = 0; /* index file */ strcpy(path_aux + path_len, "index"); - if (gitfo_exists(path_aux) < 0) - return GIT_ENOTAREPO; repo->path_index = git__strdup(path_aux); + /* working dir */ + *(last_folder + 1) = 0; + repo->path_workdir = git__strdup(path_aux); + } else { repo->is_bare = 1; repo->path_workdir = NULL; @@ -199,7 +201,7 @@ git_index *git_repository_index(git_repository *repo) if (git_index_open_inrepo(&repo->index, repo) < 0) return NULL; - assert(repo->index && repo->index->on_disk); + assert(repo->index); } return repo->index; |
