summaryrefslogtreecommitdiff
path: root/src/clone.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-10-01 16:12:15 -0700
committerRussell Belfer <rb@github.com>2013-10-03 10:44:13 -0700
commit219d3457324e8c2652e3462cedaf648912b40281 (patch)
tree4dcd3bd4aa22d5a9827fbc87c52546ce2a2cd7a1 /src/clone.c
parent2fe54afa2a8f87d03d2d550dcde7718f27e40967 (diff)
downloadlibgit2-219d3457324e8c2652e3462cedaf648912b40281.tar.gz
Initial iconv hookup for precomposed unicode
This hooks up git_path_direach and git_path_dirload so that they will take a flag indicating if directory entry names should be tested and converted from decomposed unicode to precomposed form. This code will only come into play on the Apple platform and even then, only when certain types of filesystems are used. This involved adding a flag to these functions which involved changing a lot of places in the code. This was an opportunity to do a bit of code cleanup here and there, for example, getting rid of the git_futils_cleanupdir_r function in favor of a simple flag to git_futils_rmdir_r to not remove the top level entry. That ended up adding depth tracking during rmdir_r which led to a safety check for infinite directory recursion. Yay. This hasn't actually been tested on the Mac filesystems where the issue occurs. I still need to get test environment for that.
Diffstat (limited to 'src/clone.c')
-rw-r--r--src/clone.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/clone.c b/src/clone.c
index f3e365c07..657243945 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -391,11 +391,11 @@ int git_clone(
const char *local_path,
const git_clone_options *_options)
{
- int retcode = GIT_ERROR;
+ int error = 0;
git_repository *repo = NULL;
git_remote *origin;
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
- int remove_directory_on_failure = 0;
+ uint32_t rmdir_flags = GIT_RMDIR_REMOVE_FILES;
assert(out && url && local_path);
@@ -408,33 +408,29 @@ int git_clone(
if (git_path_exists(local_path) && !git_path_is_empty_dir(local_path)) {
giterr_set(GITERR_INVALID,
"'%s' exists and is not an empty directory", local_path);
- return GIT_ERROR;
+ return GIT_EEXISTS;
}
- /* Only remove the directory on failure if we create it */
- remove_directory_on_failure = !git_path_exists(local_path);
+ /* Only remove the root directory on failure if we create it */
+ if (git_path_exists(local_path))
+ rmdir_flags |= GIT_RMDIR_SKIP_ROOT;
- if ((retcode = git_repository_init(&repo, local_path, options.bare)) < 0)
- return retcode;
+ if ((error = git_repository_init(&repo, local_path, options.bare)) < 0)
+ return error;
- if ((retcode = create_and_configure_origin(&origin, repo, url, &options)) < 0)
- goto cleanup;
+ if (!(error = create_and_configure_origin(&origin, repo, url, &options))) {
+ error = git_clone_into(
+ repo, origin, &options.checkout_opts, options.checkout_branch);
- retcode = git_clone_into(repo, origin, &options.checkout_opts, options.checkout_branch);
- git_remote_free(origin);
+ git_remote_free(origin);
+ }
- if (retcode < 0)
- goto cleanup;
+ if (error < 0) {
+ git_repository_free(repo);
+ repo = NULL;
+ (void)git_futils_rmdir_r(local_path, NULL, rmdir_flags);
+ }
*out = repo;
- return 0;
-
-cleanup:
- git_repository_free(repo);
- if (remove_directory_on_failure)
- git_futils_rmdir_r(local_path, NULL, GIT_RMDIR_REMOVE_FILES);
- else
- git_futils_cleanupdir_r(local_path);
-
- return retcode;
+ return error;
}