From 412de9a637e94b877c7762d90c87525f35018083 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 20 Dec 2010 10:43:23 +0100 Subject: [PATCH 1/7] Made gitfo_mkdir_recurs() gracefully recover when a given directory already exists. --- src/fileops.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fileops.c b/src/fileops.c index a25796a7b..f2a08e8fb 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -323,10 +323,15 @@ int gitfo_mkdir_recurs(const char *path, int mode) error = GIT_SUCCESS; pp = path_copy; - while (error == 0 && (sp = strchr(pp, '/')) != 0) { + while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != 0) { if (sp != pp && gitfo_isdir(path_copy) < GIT_SUCCESS) { *sp = 0; error = gitfo_mkdir(path_copy, mode); + + /* Do not choke while trying to recreate an existing directory */ + if (errno == EEXIST) + error = GIT_SUCCESS; + *sp = '/'; } From 2e29957a79592959c7b297722618536f8d977e88 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 20 Dec 2010 10:56:32 +0100 Subject: [PATCH 2/7] Made gitfo_mkdir_recurs() skip creation of the root of the path if it looks like a Windows drive. --- src/fileops.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/fileops.c b/src/fileops.c index f2a08e8fb..c5cc73ef2 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -1,5 +1,6 @@ #include "common.h" #include "fileops.h" +#include int gitfo_open(const char *path, int flags) { @@ -323,6 +324,10 @@ int gitfo_mkdir_recurs(const char *path, int mode) error = GIT_SUCCESS; pp = path_copy; + /* Does the root of the path look like a windows drive ? */ + if (isalpha(pp[0]) && (pp[1] == ':') && (pp[2] == '/')) + pp += 2; + while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != 0) { if (sp != pp && gitfo_isdir(path_copy) < GIT_SUCCESS) { *sp = 0; From 8ea2c83b5d21a8a15075943eba822b9ca928af3e Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 20 Dec 2010 16:46:13 +0100 Subject: [PATCH 3/7] Added creation of 'objects/info' and 'objects/pack' directories. --- src/repository.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/repository.c b/src/repository.c index 3551b8796..4ef4b1fc0 100644 --- a/src/repository.c +++ b/src/repository.c @@ -35,7 +35,8 @@ #define GIT_DIR "/.git/" #define GIT_OBJECTS_DIR "objects/" -#define GIT_REFS_DIR "refs/" +#define GIT_OBJECTS_INFO_DIR "objects/info/" +#define GIT_OBJECTS_PACK_DIR "objects/pack/" #define GIT_REFS_HEADS_DIR "refs/heads/" #define GIT_REFS_TAGS_DIR "refs/tags/" @@ -786,19 +787,19 @@ int repo_init_structure(repo_init *results) if (repo_init_createhead(temp_path) < GIT_SUCCESS) return GIT_ERROR; - /* Creates the '/objects/' directory */ - strcpy(temp_path + path_len, GIT_OBJECTS_DIR); - if (gitfo_mkdir(temp_path, mode)) + /* Creates the '/objects/info/' directory */ + strcpy(temp_path + path_len, GIT_OBJECTS_INFO_DIR); + if (gitfo_mkdir_recurs(temp_path, mode)) return GIT_ERROR; - /* Creates the '/refs/' directory */ - strcpy(temp_path + path_len, GIT_REFS_DIR); + /* Creates the '/objects/pack/' directory */ + strcpy(temp_path + path_len, GIT_OBJECTS_PACK_DIR); if (gitfo_mkdir(temp_path, mode)) return GIT_ERROR; /* Creates the '/refs/heads/' directory */ strcpy(temp_path + path_len, GIT_REFS_HEADS_DIR); - if (gitfo_mkdir(temp_path, mode)) + if (gitfo_mkdir_recurs(temp_path, mode)) return GIT_ERROR; /* Creates the '/refs/tags/' directory */ From f2d6a23aa6ed823b68d1a81c211044d581972aa3 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Tue, 21 Dec 2010 05:21:33 +0100 Subject: [PATCH 4/7] Small code maintenability improvement. --- src/repository.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/repository.c b/src/repository.c index 4ef4b1fc0..6af75f7d0 100644 --- a/src/repository.c +++ b/src/repository.c @@ -35,10 +35,11 @@ #define GIT_DIR "/.git/" #define GIT_OBJECTS_DIR "objects/" -#define GIT_OBJECTS_INFO_DIR "objects/info/" -#define GIT_OBJECTS_PACK_DIR "objects/pack/" -#define GIT_REFS_HEADS_DIR "refs/heads/" -#define GIT_REFS_TAGS_DIR "refs/tags/" +#define GIT_OBJECTS_INFO_DIR GIT_OBJECTS_DIR "info/" +#define GIT_OBJECTS_PACK_DIR GIT_OBJECTS_DIR "pack/" +#define GIT_REFS_DIR "refs/" +#define GIT_REFS_HEADS_DIR GIT_REFS_DIR "heads/" +#define GIT_REFS_TAGS_DIR GIT_REFS_DIR "tags/" #define GIT_INDEX_FILE "index" #define GIT_HEAD_FILE "HEAD" From 23a1edbd04250ac94071dae89d1d3014715e8112 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Tue, 21 Dec 2010 05:43:47 +0100 Subject: [PATCH 5/7] Wrapped the detection of a Windows rooted path within a conditional compilation directive. --- src/fileops.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/fileops.c b/src/fileops.c index c5cc73ef2..7a6ab731c 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -312,6 +312,19 @@ int gitfo_dirent( return GIT_SUCCESS; } +#ifdef GIT_WIN32 + +static int is_windows_rooted_path(const char* path) +{ + /* Does the root of the path look like a windows drive ? */ + if (isalpha(path[0]) && (path[1] == ':') && (path[2] == '/')) + return GIT_SUCCESS; + + return GIT_ERROR; +} + +#endif + int gitfo_mkdir_recurs(const char *path, int mode) { int error; @@ -324,9 +337,12 @@ int gitfo_mkdir_recurs(const char *path, int mode) error = GIT_SUCCESS; pp = path_copy; - /* Does the root of the path look like a windows drive ? */ - if (isalpha(pp[0]) && (pp[1] == ':') && (pp[2] == '/')) - pp += 2; +#ifdef GIT_WIN32 + + if (!is_windows_rooted_path(pp)) + pp += 2; /* Skip the drive name (eg. C: or D:) */ + +#endif while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != 0) { if (sp != pp && gitfo_isdir(path_copy) < GIT_SUCCESS) { From 2c08c3f0742d812bd3790c2541af87634fbb3ab4 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Tue, 21 Dec 2010 06:52:07 +0100 Subject: [PATCH 6/7] Made is_windows_rooted_path() able to cope with awkward but valid relative paths such as "C:..\File.txt". Path "C:..\File.txt" refers to a file called File.txt located in the parent directory of the current directory on drive C:. --- src/fileops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fileops.c b/src/fileops.c index 7a6ab731c..5f5944c62 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -317,7 +317,7 @@ int gitfo_dirent( static int is_windows_rooted_path(const char* path) { /* Does the root of the path look like a windows drive ? */ - if (isalpha(path[0]) && (path[1] == ':') && (path[2] == '/')) + if (isalpha(path[0]) && (path[1] == ':')) return GIT_SUCCESS; return GIT_ERROR; From 951d06e4e99d3a750ead21605bc71e78cfd5ab2d Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Dec 2010 17:00:35 +0100 Subject: [PATCH 7/7] Fixed placement of pointer argument. --- src/fileops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fileops.c b/src/fileops.c index 7b11c9c3a..ca9fb701b 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -314,7 +314,7 @@ int gitfo_dirent( #ifdef GIT_WIN32 -static int is_windows_rooted_path(const char* path) +static int is_windows_rooted_path(const char *path) { /* Does the root of the path look like a windows drive ? */ if (isalpha(path[0]) && (path[1] == ':'))