From 63377aad78e7efb8ebe760b8e886303b0cbb2d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 13 Sep 2014 17:30:32 +0200 Subject: [PATCH 1/2] Properly initialize the clone options libgit2 provides an initialization function to set sane defaults. Use that instead of setting the version by hand, as that's not the only thing it does. Using C.git_clone_init_options() sets the checkout strategy to SAFE, which will checkout the files after the clone, instead of the implicit NONE which we're setting by hand. This fixes #425, --- pygit2/__init__.py | 6 +++--- pygit2/decl.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pygit2/__init__.py b/pygit2/__init__.py index 0a901d4a4..6df8478af 100644 --- a/pygit2/__init__.py +++ b/pygit2/__init__.py @@ -151,6 +151,9 @@ def clone_repository( d['callback'] = credentials d_handle = ffi.new_handle(d) + # Perform the initialization with the version we compiled + C.git_clone_init_options(opts, C.GIT_CLONE_OPTIONS_VERSION) + # We need to keep the ref alive ourselves checkout_branch_ref = None if branch: @@ -160,11 +163,8 @@ def clone_repository( remote_name_ref = ffi.new('char []', to_bytes(remote_name)) opts.remote_name = remote_name_ref - opts.version = 1 opts.ignore_cert_errors = ignore_cert_errors opts.bare = bare - opts.remote_callbacks.version = 1 - opts.checkout_opts.version = 1 if credentials: opts.remote_callbacks.credentials = _credentials_cb opts.remote_callbacks.payload = d_handle diff --git a/pygit2/decl.h b/pygit2/decl.h index c7b700157..b8cd9c6b9 100644 --- a/pygit2/decl.h +++ b/pygit2/decl.h @@ -353,6 +353,9 @@ typedef struct git_clone_options { git_signature *signature; } git_clone_options; +#define GIT_CLONE_OPTIONS_VERSION ... +int git_clone_init_options(git_clone_options *opts, unsigned int version); + int git_clone(git_repository **out, const char *url, const char *local_path, From 7d34d2bb2722b8244657b9ffd20d86020fa070c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 13 Sep 2014 18:55:04 +0200 Subject: [PATCH 2/2] Use the initializer for repository init options --- pygit2/__init__.py | 2 +- pygit2/decl.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pygit2/__init__.py b/pygit2/__init__.py index 6df8478af..48b15c7aa 100644 --- a/pygit2/__init__.py +++ b/pygit2/__init__.py @@ -82,7 +82,7 @@ def init_repository(path, bare=False, # Options options = ffi.new('git_repository_init_options *') - options.version = 1 + C.git_repository_init_init_options(options, C.GIT_REPOSITORY_INIT_OPTIONS_VERSION) options.flags = flags options.mode = mode options.workdir_path = to_bytes(workdir_path) diff --git a/pygit2/decl.h b/pygit2/decl.h index b8cd9c6b9..c64e10f2b 100644 --- a/pygit2/decl.h +++ b/pygit2/decl.h @@ -462,6 +462,9 @@ typedef struct { const char *origin_url; } git_repository_init_options; +#define GIT_REPOSITORY_INIT_OPTIONS_VERSION ... +int git_repository_init_init_options(git_repository_init_options *opts, int version); + int git_repository_init( git_repository **out, const char *path,