summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fileops.c7
-rw-r--r--src/repository.c31
2 files changed, 24 insertions, 14 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 56bf2927f..b1a6bb8b1 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -380,7 +380,7 @@ int gitfo_mkdir_recurs(const char *path, int mode)
if (root_path_offset > 0)
pp += root_path_offset; /* On Windows, will skip the drive name (eg. C: or D:) */
- while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != 0) {
+ while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != NULL) {
if (sp != pp && gitfo_isdir(path_copy) < GIT_SUCCESS) {
*sp = 0;
error = gitfo_mkdir(path_copy, mode);
@@ -395,8 +395,11 @@ int gitfo_mkdir_recurs(const char *path, int mode)
pp = sp + 1;
}
- if (*(pp - 1) != '/' && error == GIT_SUCCESS)
+ if (*pp != '\0' && error == GIT_SUCCESS) {
error = gitfo_mkdir(path, mode);
+ if (errno == EEXIST)
+ error = GIT_SUCCESS;
+ }
free(path_copy);
diff --git a/src/repository.c b/src/repository.c
index 249755b62..034e60a23 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -330,7 +330,7 @@ static int abspath(char *buffer_out, size_t size, const char *path)
return GIT_SUCCESS;
}
-static dev_t retrieve_device(dev_t *device_out, const char *path)
+static int retrieve_device(dev_t *device_out, const char *path)
{
struct stat path_info;
@@ -369,8 +369,7 @@ static int retrieve_ceiling_directories_offset(const char *path, const char *cei
strncpy(buf, ceil, len);
buf[len] = '\0';
- gitfo_posixify_path(buf);
- if (gitfo_prettify_dir_path(buf2, sizeof(buf2), buf, NULL) < GIT_SUCCESS)
+ if (abspath(buf2, sizeof(buf2), buf) < GIT_SUCCESS)
continue;
len = strlen(buf2);
@@ -410,15 +409,22 @@ static int read_gitfile(char *path_out, size_t size, const char *file_path, cons
end_offset = strlen(data) - 1;
- for (;data[end_offset] != '\r' && data[end_offset] != '\n'; --end_offset);
- data[end_offset] = '\0';
+ for (;data[end_offset] == '\r' || data[end_offset] == '\n'; --end_offset);
+ data[end_offset + 1] = '\0';
- if (GIT_FILE_CONTENT_PREFIX_LENGTH == end_offset) {
+ if (GIT_FILE_CONTENT_PREFIX_LENGTH == end_offset + 1) {
gitfo_free_buf(&file);
return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path);
}
error = gitfo_prettify_dir_path(path_out, size, data + GIT_FILE_CONTENT_PREFIX_LENGTH, base_path);
+ if (error == GIT_SUCCESS) {
+ end_offset = strlen(path_out);
+
+ if (end_offset > 0 && path_out[end_offset - 1] == '/')
+ path_out[end_offset - 1 ] = '\0';
+ }
+
gitfo_free_buf(&file);
return error;
@@ -521,12 +527,6 @@ int git_repository_discover(char *repository_path, size_t size, const char *star
git_repository__free_dirs(&repo);
- //nothing has been found, lets try the parent directory
- if (bare_path[ceiling_offset] == '\0') {
- error = git__throw(GIT_ENOTAREPO,"Not a git repository (or any of the parent directories): %s", start_path);
- goto cleanup;
- }
-
if (git__dirname_r(normal_path, sizeof(normal_path), bare_path) < GIT_SUCCESS)
goto cleanup;
@@ -547,6 +547,13 @@ int git_repository_discover(char *repository_path, size_t size, const char *star
strcpy(bare_path, normal_path);
git__joinpath(normal_path, bare_path, DOT_GIT);
+
+ //nothing has been found, lets try the parent directory
+ if (bare_path[ceiling_offset] == '\0') {
+ error = git__throw(GIT_ENOTAREPO,"Not a git repository (or any of the parent directories): %s", start_path);
+ goto cleanup;
+ }
+
}
if (size < (strlen(found_path) + 1) * sizeof(char)) {