Commit 4edd1a03 by Alan Rogers

Merge remote-tracking branch 'origin/development' into fix-git-status-list-new-unreadable-folder

parents 9e2d2f30 1589aa0c
......@@ -6,6 +6,7 @@ Alexei Sholik
Andreas Ericsson
Anton "antong" Gyllenberg
Ankur Sethi
Arthur Schreiber
Ben Noordhuis
Ben Straub
Benjamin C Meyer
......
......@@ -127,6 +127,9 @@ STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_V
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}")
SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}")
FILE(STRINGS "include/git2/version.h" GIT2_HEADER_SOVERSION REGEX "^#define LIBGIT2_SOVERSION [0-9]+$")
STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION ([0-9]+)$" "\\1" LIBGIT2_SOVERSION "${GIT2_HEADER_SOVERSION}")
# Find required dependencies
INCLUDE_DIRECTORIES(src include)
......@@ -397,7 +400,7 @@ MSVC_SPLIT_SOURCES(git2)
IF (SONAME)
SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_VERSION_MAJOR})
SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_SOVERSION})
IF (LIBGIT2_FILENAME)
ADD_DEFINITIONS(-DLIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
......
......@@ -23,10 +23,31 @@
*/
GIT_BEGIN_DECL
/**
* Options for bypassing the git-aware transport on clone. Bypassing
* it means that instead of a fetch, libgit2 will copy the object
* database directory instead of figuring out what it needs, which is
* faster. If possible, it will hardlink the files to save space.
*/
typedef enum {
/**
* Auto-detect (default), libgit2 will bypass the git-aware
* transport for local paths, but use a normal fetch for
* `file://` urls.
*/
GIT_CLONE_LOCAL_AUTO,
/**
* Bypass the git-aware transport even for a `file://` url.
*/
GIT_CLONE_LOCAL,
/**
* Do no bypass the git-aware transport
*/
GIT_CLONE_NO_LOCAL,
/**
* Bypass the git-aware transport, but do not try to use
* hardlinks.
*/
GIT_CLONE_LOCAL_NO_LINKS,
} git_clone_local_t;
......@@ -36,37 +57,58 @@ typedef enum {
* Use the GIT_CLONE_OPTIONS_INIT to get the default settings, like this:
*
* git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
*
* - `checkout_opts` are option passed to the checkout step. To disable
* checkout, set the `checkout_strategy` to GIT_CHECKOUT_NONE.
* Generally you will want the use GIT_CHECKOUT_SAFE_CREATE to create
* all files in the working directory for the newly cloned repository.
* - `bare` should be set to zero (false) to create a standard repo,
* or non-zero for a bare repo
* - `ignore_cert_errors` should be set to 1 if errors validating the
* remote host's certificate should be ignored.
*
* ** "origin" remote options: **
*
* - `remote_name` is the name to be given to the "origin" remote. The
* default is "origin".
* - `checkout_branch` gives the name of the branch to checkout. NULL
* means use the remote's HEAD.
* - `signature` is the identity used when updating the reflog. NULL means to
* use the default signature using the config.
*/
typedef struct git_clone_options {
unsigned int version;
/**
* These options are passed to the checkout step. To disable
* checkout, set the `checkout_strategy` to
* `GIT_CHECKOUT_NONE`. Generally you will want the use
* GIT_CHECKOUT_SAFE_CREATE to create all files in the working
* directory for the newly cloned repository.
*/
git_checkout_options checkout_opts;
/**
* Callbacks to use for reporting fetch progress.
*/
git_remote_callbacks remote_callbacks;
/**
* Set to zero (false) to create a standard repo, or non-zero
* for a bare repo
*/
int bare;
/**
* Set to 1 if errors validating the remote host's certificate
* should be ignored.
*/
int ignore_cert_errors;
/**
* Whether to use a fetch or copy the object database.
*/
git_clone_local_t local;
/**
* The name to be given to the remote that will be
* created. The default is "origin".
*/
const char *remote_name;
/**
* The name of the branch to checkout. NULL means use the
* remote's default branch.
*/
const char* checkout_branch;
/**
* The identity used when updating the reflog. NULL means to
* use the default signature using the config.
*/
git_signature *signature;
} git_clone_options;
......
......@@ -12,6 +12,8 @@
#include "strarray.h"
#include "diff.h"
GIT_BEGIN_DECL
/**
* Compiled pathspec
*/
......@@ -257,4 +259,5 @@ GIT_EXTERN(size_t) git_pathspec_match_list_failed_entrycount(
GIT_EXTERN(const char *) git_pathspec_match_list_failed_entry(
const git_pathspec_match_list *m, size_t pos);
GIT_END_DECL
#endif
......@@ -572,18 +572,17 @@ GIT_EXTERN(void) git_remote_set_autotag(
*
* A temporary in-memory remote cannot be given a name with this method.
*
* @param problems non-default refspecs cannot be renamed and will be
* stored here for further processing by the caller. Always free this
* strarray on succesful return.
* @param remote the remote to rename
* @param new_name the new name the remote should bear
* @param callback Optional callback to notify the consumer of fetch refspecs
* that haven't been automatically updated and need potential manual tweaking.
* @param payload Additional data to pass to the callback
* @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
*/
GIT_EXTERN(int) git_remote_rename(
git_strarray *problems,
git_remote *remote,
const char *new_name,
git_remote_rename_problem_cb callback,
void *payload);
const char *new_name);
/**
* Retrieve the update FETCH_HEAD setting.
......@@ -616,8 +615,6 @@ GIT_EXTERN(int) git_remote_is_valid_name(const char *remote_name);
* All remote-tracking branches and configuration settings
* for the remote will be removed.
*
* once deleted, the passed remote object will be freed and invalidated.
*
* @param remote A valid remote
* @return 0 on success, or an error code.
*/
......
......@@ -7,9 +7,11 @@
#ifndef INCLUDE_git_version_h__
#define INCLUDE_git_version_h__
#define LIBGIT2_VERSION "0.20.0"
#define LIBGIT2_VERSION "0.21.0"
#define LIBGIT2_VER_MAJOR 0
#define LIBGIT2_VER_MINOR 20
#define LIBGIT2_VER_MINOR 21
#define LIBGIT2_VER_REVISION 0
#define LIBGIT2_SOVERSION 21
#endif
......@@ -16,6 +16,12 @@ git_mutex git__mwindow_mutex;
#define MAX_SHUTDOWN_CB 8
#ifdef GIT_SSL
# include <openssl/ssl.h>
SSL_CTX *git__ssl_ctx;
static git_mutex *openssl_locks;
#endif
static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB];
static git_atomic git__n_shutdown_callbacks;
static git_atomic git__n_inits;
......@@ -39,6 +45,62 @@ static void git__shutdown(void)
}
#if defined(GIT_THREADS) && defined(GIT_SSL)
void openssl_locking_function(int mode, int n, const char *file, int line)
{
int lock;
GIT_UNUSED(file);
GIT_UNUSED(line);
lock = mode & CRYPTO_LOCK;
if (lock) {
git_mutex_lock(&openssl_locks[n]);
} else {
git_mutex_unlock(&openssl_locks[n]);
}
}
#endif
static void init_ssl(void)
{
#ifdef GIT_SSL
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
git__ssl_ctx = SSL_CTX_new(SSLv23_method());
SSL_CTX_set_mode(git__ssl_ctx, SSL_MODE_AUTO_RETRY);
SSL_CTX_set_verify(git__ssl_ctx, SSL_VERIFY_NONE, NULL);
if (!SSL_CTX_set_default_verify_paths(git__ssl_ctx)) {
SSL_CTX_free(git__ssl_ctx);
git__ssl_ctx = NULL;
}
# ifdef GIT_THREADS
{
int num_locks, i;
num_locks = CRYPTO_num_locks();
openssl_locks = git__calloc(num_locks, sizeof(git_mutex));
if (openssl_locks == NULL) {
SSL_CTX_free(git__ssl_ctx);
git__ssl_ctx = NULL;
}
for (i = 0; i < num_locks; i++) {
if (git_mutex_init(&openssl_locks[i]) != 0) {
SSL_CTX_free(git__ssl_ctx);
git__ssl_ctx = NULL;
}
}
CRYPTO_set_locking_callback(openssl_locking_function);
}
# endif
#endif
}
/**
* Handle the global state with TLS
*
......@@ -78,7 +140,7 @@ static void git__shutdown(void)
static DWORD _tls_index;
static volatile LONG _mutex = 0;
static int synchronized_threads_init()
static int synchronized_threads_init(void)
{
int error;
......@@ -112,7 +174,7 @@ int git_threads_init(void)
return error;
}
static void synchronized_threads_shutdown()
static void synchronized_threads_shutdown(void)
{
/* Shut down any subsystems that have global state */
git__shutdown();
......@@ -168,10 +230,14 @@ static void init_once(void)
return;
pthread_key_create(&_tls_key, &cb__free_status);
/* Initialize any other subsystems that have global state */
if ((init_error = git_hash_global_init()) >= 0)
init_error = git_sysdir_global_init();
/* OpenSSL needs to be initialized from the main thread */
init_ssl();
GIT_MEMORY_BARRIER;
}
......@@ -225,6 +291,7 @@ static git_global_st __state;
int git_threads_init(void)
{
init_ssl();
git_atomic_inc(&git__n_inits);
return 0;
}
......
......@@ -15,6 +15,11 @@ typedef struct {
git_error error_t;
} git_global_st;
#ifdef GIT_SSL
# include <openssl/ssl.h>
extern SSL_CTX *git__ssl_ctx;
#endif
git_global_st *git__global_state(void);
extern git_mutex git__mwindow_mutex;
......
......@@ -33,6 +33,7 @@
#include "posix.h"
#include "buffer.h"
#include "http_parser.h"
#include "global.h"
#ifdef GIT_WIN32
static void net_set_error(const char *str)
......@@ -157,7 +158,7 @@ void gitno_buffer_setup_callback(
void gitno_buffer_setup(gitno_socket *socket, gitno_buffer *buf, char *data, size_t len)
{
#ifdef GIT_SSL
if (socket->ssl.ctx) {
if (socket->ssl.ssl) {
gitno_buffer_setup_callback(socket, buf, data, len, gitno__recv_ssl, NULL);
return;
}
......@@ -202,7 +203,6 @@ static int gitno_ssl_teardown(gitno_ssl *ssl)
ret = 0;
SSL_free(ssl->ssl);
SSL_CTX_free(ssl->ctx);
return ret;
}
......@@ -390,18 +390,12 @@ static int ssl_setup(gitno_socket *socket, const char *host, int flags)
{
int ret;
SSL_library_init();
SSL_load_error_strings();
socket->ssl.ctx = SSL_CTX_new(SSLv23_method());
if (socket->ssl.ctx == NULL)
return ssl_set_error(&socket->ssl, 0);
SSL_CTX_set_mode(socket->ssl.ctx, SSL_MODE_AUTO_RETRY);
SSL_CTX_set_verify(socket->ssl.ctx, SSL_VERIFY_NONE, NULL);
if (!SSL_CTX_set_default_verify_paths(socket->ssl.ctx))
return ssl_set_error(&socket->ssl, 0);
if (git__ssl_ctx == NULL) {
giterr_set(GITERR_NET, "OpenSSL initialization failed");
return -1;
}
socket->ssl.ssl = SSL_new(socket->ssl.ctx);
socket->ssl.ssl = SSL_new(git__ssl_ctx);
if (socket->ssl.ssl == NULL)
return ssl_set_error(&socket->ssl, 0);
......@@ -538,7 +532,7 @@ int gitno_send(gitno_socket *socket, const char *msg, size_t len, int flags)
size_t off = 0;
#ifdef GIT_SSL
if (socket->ssl.ctx)
if (socket->ssl.ssl)
return gitno_send_ssl(&socket->ssl, msg, len, flags);
#endif
......@@ -559,7 +553,7 @@ int gitno_send(gitno_socket *socket, const char *msg, size_t len, int flags)
int gitno_close(gitno_socket *s)
{
#ifdef GIT_SSL
if (s->ssl.ctx &&
if (s->ssl.ssl &&
gitno_ssl_teardown(&s->ssl) < 0)
return -1;
#endif
......
......@@ -16,7 +16,6 @@
struct gitno_ssl {
#ifdef GIT_SSL
SSL_CTX *ctx;
SSL *ssl;
#else
size_t dummy;
......
......@@ -1209,7 +1209,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
git_mutex_unlock(&target->mutex);
if (!sub_size) {
git_thread_join(target->thread, NULL);
git_thread_join(&target->thread, NULL);
git_cond_free(&target->cond);
git_mutex_free(&target->mutex);
active_threads--;
......
......@@ -1359,19 +1359,24 @@ static int update_branch_remote_config_entry(
}
static int rename_one_remote_reference(
git_reference *reference,
git_reference *reference_in,
const char *old_remote_name,
const char *new_remote_name)
{
int error;
git_reference *ref = NULL, *dummy = NULL;
git_buf namespace = GIT_BUF_INIT, old_namespace = GIT_BUF_INIT;
git_buf new_name = GIT_BUF_INIT;
git_buf log_message = GIT_BUF_INIT;
size_t pfx_len;
const char *target;
if ((error = git_buf_printf(
&new_name,
GIT_REFS_REMOTES_DIR "%s%s",
new_remote_name,
reference->name + strlen(GIT_REFS_REMOTES_DIR) + strlen(old_remote_name))) < 0)
if ((error = git_buf_printf(&namespace, GIT_REFS_REMOTES_DIR "%s/", new_remote_name)) < 0)
return error;
pfx_len = strlen(GIT_REFS_REMOTES_DIR) + strlen(old_remote_name) + 1;
git_buf_puts(&new_name, namespace.ptr);
if ((error = git_buf_puts(&new_name, git_reference_name(reference_in) + pfx_len)) < 0)
goto cleanup;
if ((error = git_buf_printf(&log_message,
......@@ -1379,12 +1384,36 @@ static int rename_one_remote_reference(
old_remote_name, new_remote_name)) < 0)
goto cleanup;
error = git_reference_rename(
NULL, reference, git_buf_cstr(&new_name), 0,
NULL, git_buf_cstr(&log_message));
git_reference_free(reference);
if ((error = git_reference_rename(&ref, reference_in, git_buf_cstr(&new_name), 1,
NULL, git_buf_cstr(&log_message))) < 0)
goto cleanup;
if (git_reference_type(ref) != GIT_REF_SYMBOLIC)
goto cleanup;
/* Handle refs like origin/HEAD -> origin/master */
target = git_reference_symbolic_target(ref);
if ((error = git_buf_printf(&old_namespace, GIT_REFS_REMOTES_DIR "%s/", old_remote_name)) < 0)
goto cleanup;
if (git__prefixcmp(target, old_namespace.ptr))
goto cleanup;
git_buf_clear(&new_name);
git_buf_puts(&new_name, namespace.ptr);
if ((error = git_buf_puts(&new_name, target + pfx_len)) < 0)
goto cleanup;
error = git_reference_symbolic_set_target(&dummy, ref, git_buf_cstr(&new_name),
NULL, git_buf_cstr(&log_message));
git_reference_free(dummy);
cleanup:
git_reference_free(reference_in);
git_reference_free(ref);
git_buf_free(&namespace);
git_buf_free(&old_namespace);
git_buf_free(&new_name);
git_buf_free(&log_message);
return error;
......@@ -1396,18 +1425,20 @@ static int rename_remote_references(
const char *new_name)
{
int error;
git_buf buf = GIT_BUF_INIT;
git_reference *ref;
git_reference_iterator *iter;
if ((error = git_reference_iterator_new(&iter, repo)) < 0)
if ((error = git_buf_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0)
return error;
while ((error = git_reference_next(&ref, iter)) == 0) {
if (git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR)) {
git_reference_free(ref);
continue;
}
error = git_reference_iterator_glob_new(&iter, repo, git_buf_cstr(&buf));
git_buf_free(&buf);
if (error < 0)
return error;
while ((error = git_reference_next(&ref, iter)) == 0) {
if ((error = rename_one_remote_reference(ref, old_name, new_name)) < 0)
break;
}
......@@ -1417,11 +1448,7 @@ static int rename_remote_references(
return (error == GIT_ITEROVER) ? 0 : error;
}
static int rename_fetch_refspecs(
git_remote *remote,
const char *new_name,
int (*callback)(const char *problematic_refspec, void *payload),
void *payload)
static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const char *new_name)
{
git_config *config;
git_buf base = GIT_BUF_INIT, var = GIT_BUF_INIT, val = GIT_BUF_INIT;
......@@ -1432,6 +1459,9 @@ static int rename_fetch_refspecs(
if ((error = git_repository_config__weakptr(&config, remote->repo)) < 0)
return error;
if ((error = git_vector_init(problems, 1, NULL)) < 0)
return error;
if ((error = git_buf_printf(
&base, "+refs/heads/*:refs/remotes/%s/*", remote->name)) < 0)
return error;
......@@ -1440,15 +1470,15 @@ static int rename_fetch_refspecs(
if (spec->push)
continue;
/* Every refspec is a problem refspec for an anonymous remote, OR */
/* Does the dst part of the refspec follow the expected format? */
if (!remote->name ||
strcmp(git_buf_cstr(&base), spec->string)) {
if (strcmp(git_buf_cstr(&base), spec->string)) {
char *dup;
if ((error = callback(spec->string, payload)) != 0) {
giterr_set_after_callback(error);
dup = git__strdup(spec->string);
GITERR_CHECK_ALLOC(dup);
if ((error = git_vector_insert(problems, dup)) < 0)
break;
}
continue;
}
......@@ -1474,18 +1504,25 @@ static int rename_fetch_refspecs(
git_buf_free(&base);
git_buf_free(&var);
git_buf_free(&val);
if (error < 0) {
char *str;
git_vector_foreach(problems, i, str)
git__free(str);
git_vector_free(problems);
}
return error;
}
int git_remote_rename(
git_remote *remote,
const char *new_name,
git_remote_rename_problem_cb callback,
void *payload)
int git_remote_rename(git_strarray *out, git_remote *remote, const char *new_name)
{
int error;
git_vector problem_refspecs;
char *tmp, *dup;
assert(remote && new_name);
assert(out && remote && new_name);
if (!remote->name) {
giterr_set(GITERR_INVALID, "Can't rename an anonymous remote.");
......@@ -1495,54 +1532,30 @@ int git_remote_rename(
if ((error = ensure_remote_name_is_valid(new_name)) < 0)
return error;
if (remote->repo) {
if ((error = ensure_remote_doesnot_exist(remote->repo, new_name)) < 0)
return error;
if ((error = ensure_remote_doesnot_exist(remote->repo, new_name)) < 0)
return error;
if (!remote->name) {
if ((error = rename_fetch_refspecs(
remote,
new_name,
callback,
payload)) < 0)
return error;
if ((error = rename_remote_config_section(remote->repo, remote->name, new_name)) < 0)
return error;
remote->name = git__strdup(new_name);
GITERR_CHECK_ALLOC(remote->name);
if ((error = update_branch_remote_config_entry(remote->repo, remote->name, new_name)) < 0)
return error;
return git_remote_save(remote);
}
if ((error = rename_remote_references(remote->repo, remote->name, new_name)) < 0)
return error;
if ((error = rename_remote_config_section(
remote->repo,
remote->name,
new_name)) < 0)
return error;
if ((error = update_branch_remote_config_entry(
remote->repo,
remote->name,
new_name)) < 0)
return error;
if ((error = rename_remote_references(
remote->repo,
remote->name,
new_name)) < 0)
return error;
if ((error = rename_fetch_refspecs(
remote,
new_name,
callback,
payload)) < 0)
return error;
}
if ((error = rename_fetch_refspecs(&problem_refspecs, remote, new_name)) < 0)
return error;
git__free(remote->name);
out->count = problem_refspecs.length;
out->strings = (char **) problem_refspecs.contents;
remote->name = git__strdup(new_name);
GITERR_CHECK_ALLOC(remote->name);
dup = git__strdup(new_name);
GITERR_CHECK_ALLOC(dup);
tmp = remote->name;
remote->name = dup;
git__free(tmp);
return 0;
}
......@@ -1908,8 +1921,6 @@ int git_remote_delete(git_remote *remote)
repo, git_remote_name(remote), NULL)) < 0)
return error;
git_remote_free(remote);
return 0;
}
......
......@@ -48,7 +48,7 @@ static int mark_uninteresting(git_revwalk *walk, git_commit_list_node *commit)
assert(commit);
git_array_alloc(pending);
git_array_init_to_size(pending, 2);
GITERR_CHECK_ARRAY(pending);
do {
......@@ -67,7 +67,7 @@ static int mark_uninteresting(git_revwalk *walk, git_commit_list_node *commit)
tmp = git_array_pop(pending);
commit = tmp ? *tmp : NULL;
} while (git_array_size(pending) > 0);
} while (commit != NULL);
git_array_clear(pending);
......
......@@ -40,12 +40,18 @@ typedef git_atomic git_atomic_ssize;
#ifdef GIT_THREADS
#define git_thread pthread_t
#define git_thread_create(thread, attr, start_routine, arg) \
pthread_create(thread, attr, start_routine, arg)
#define git_thread_kill(thread) pthread_cancel(thread)
#define git_thread_exit(status) pthread_exit(status)
#define git_thread_join(id, status) pthread_join(id, status)
#if !defined(GIT_WIN32)
typedef struct {
pthread_t thread;
} git_thread;
#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
pthread_create(&(git_thread_ptr)->thread, attr, start_routine, arg)
#define git_thread_join(git_thread_ptr, status) \
pthread_join((git_thread_ptr)->thread, status)
#endif
#if defined(GIT_WIN32)
#define git_thread_yield() Sleep(0)
......@@ -179,8 +185,6 @@ GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
#define git_thread unsigned int
#define git_thread_create(thread, attr, start_routine, arg) 0
#define git_thread_kill(thread) (void)0
#define git_thread_exit(status) (void)0
#define git_thread_join(id, status) (void)0
#define git_thread_yield() (void)0
......
......@@ -260,7 +260,7 @@ static int on_headers_complete(http_parser *parser)
if (parser->status_code == 401 &&
get_verb == s->verb) {
if (!t->owner->cred_acquire_payload) {
if (!t->owner->cred_acquire_cb) {
no_callback = 1;
} else {
int allowed_types = 0;
......
......@@ -460,7 +460,7 @@ static int append_entry(
git_oid_cpy(&entry->oid, id);
entry->attr = (uint16_t)filemode;
if (git_vector_insert(&bld->entries, entry) < 0) {
if (git_vector_insert_sorted(&bld->entries, entry, NULL) < 0) {
git__free(entry);
return -1;
}
......@@ -671,7 +671,7 @@ int git_treebuilder_insert(
entry = alloc_entry(filename);
GITERR_CHECK_ALLOC(entry);
if (git_vector_insert(&bld->entries, entry) < 0) {
if (git_vector_insert_sorted(&bld->entries, entry, NULL) < 0) {
git__free(entry);
return -1;
}
......
......@@ -8,32 +8,64 @@
#include "pthread.h"
#include "../global.h"
int pthread_create(
pthread_t *GIT_RESTRICT thread,
#define CLEAN_THREAD_EXIT 0x6F012842
/* The thread procedure stub used to invoke the caller's procedure
* and capture the return value for later collection. Windows will
* only hold a DWORD, but we need to be able to store an entire
* void pointer. This requires the indirection. */
static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
{
git_win32_thread *thread = lpParameter;
thread->result = thread->proc(thread->param);
return CLEAN_THREAD_EXIT;
}
int git_win32__thread_create(
git_win32_thread *GIT_RESTRICT thread,
const pthread_attr_t *GIT_RESTRICT attr,
void *(*start_routine)(void*),
void *GIT_RESTRICT arg)
{
GIT_UNUSED(attr);
*thread = CreateThread(
NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL);
return *thread ? 0 : -1;
thread->result = NULL;
thread->param = arg;
thread->proc = start_routine;
thread->thread = CreateThread(
NULL, 0, git_win32__threadproc, thread, 0, NULL);
return thread->thread ? 0 : -1;
}
int pthread_join(pthread_t thread, void **value_ptr)
int git_win32__thread_join(
git_win32_thread *thread,
void **value_ptr)
{
DWORD ret = WaitForSingleObject(thread, INFINITE);
DWORD exit;
if (WaitForSingleObject(thread->thread, INFINITE) != WAIT_OBJECT_0)
return -1;
if (!GetExitCodeThread(thread->thread, &exit)) {
CloseHandle(thread->thread);
return -1;
}
if (ret == WAIT_OBJECT_0) {
if (value_ptr != NULL) {
*value_ptr = NULL;
GetExitCodeThread(thread, (void *)value_ptr);
}
CloseHandle(thread);
return 0;
/* Check for the thread having exited uncleanly. If exit was unclean,
* then we don't have a return value to give back to the caller. */
if (exit != CLEAN_THREAD_EXIT) {
assert(false);
thread->result = NULL;
}
return -1;
if (value_ptr)
*value_ptr = thread->result;
CloseHandle(thread->thread);
return 0;
}
int pthread_mutex_init(
......@@ -144,9 +176,6 @@ int pthread_num_processors_np(void)
return n ? n : 1;
}
static HINSTANCE win32_kernel32_dll;
typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *);
static win32_srwlock_fn win32_srwlock_initialize;
......@@ -159,7 +188,7 @@ int pthread_rwlock_init(
pthread_rwlock_t *GIT_RESTRICT lock,
const pthread_rwlockattr_t *GIT_RESTRICT attr)
{
(void)attr;
GIT_UNUSED(attr);
if (win32_srwlock_initialize)
win32_srwlock_initialize(&lock->native.srwl);
......@@ -217,38 +246,22 @@ int pthread_rwlock_destroy(pthread_rwlock_t *lock)
return 0;
}
static void win32_pthread_shutdown(void)
{
if (win32_kernel32_dll) {
FreeLibrary(win32_kernel32_dll);
win32_kernel32_dll = NULL;
}
}
int win32_pthread_initialize(void)
{
if (win32_kernel32_dll)
return 0;
win32_kernel32_dll = LoadLibrary("Kernel32.dll");
if (!win32_kernel32_dll) {
giterr_set(GITERR_OS, "Could not load Kernel32.dll!");
return -1;
HMODULE hModule = GetModuleHandleW(L"kernel32");
if (hModule) {
win32_srwlock_initialize = (win32_srwlock_fn)
GetProcAddress(hModule, "InitializeSRWLock");
win32_srwlock_acquire_shared = (win32_srwlock_fn)
GetProcAddress(hModule, "AcquireSRWLockShared");
win32_srwlock_release_shared = (win32_srwlock_fn)
GetProcAddress(hModule, "ReleaseSRWLockShared");
win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
GetProcAddress(hModule, "AcquireSRWLockExclusive");
win32_srwlock_release_exclusive = (win32_srwlock_fn)
GetProcAddress(hModule, "ReleaseSRWLockExclusive");
}
win32_srwlock_initialize = (win32_srwlock_fn)
GetProcAddress(win32_kernel32_dll, "InitializeSRWLock");
win32_srwlock_acquire_shared = (win32_srwlock_fn)
GetProcAddress(win32_kernel32_dll, "AcquireSRWLockShared");
win32_srwlock_release_shared = (win32_srwlock_fn)
GetProcAddress(win32_kernel32_dll, "ReleaseSRWLockShared");
win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
GetProcAddress(win32_kernel32_dll, "AcquireSRWLockExclusive");
win32_srwlock_release_exclusive = (win32_srwlock_fn)
GetProcAddress(win32_kernel32_dll, "ReleaseSRWLockExclusive");
git__on_shutdown(win32_pthread_shutdown);
return 0;
}
......@@ -16,13 +16,19 @@
# define GIT_RESTRICT __restrict__
#endif
typedef struct {
HANDLE thread;
void *(*proc)(void *);
void *param;
void *result;
} git_win32_thread;
typedef int pthread_mutexattr_t;
typedef int pthread_condattr_t;
typedef int pthread_attr_t;
typedef int pthread_rwlockattr_t;
typedef CRITICAL_SECTION pthread_mutex_t;
typedef HANDLE pthread_t;
typedef HANDLE pthread_cond_t;
typedef struct { void *Ptr; } GIT_SRWLOCK;
......@@ -36,13 +42,26 @@ typedef struct {
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}
int pthread_create(
pthread_t *GIT_RESTRICT thread,
const pthread_attr_t *GIT_RESTRICT attr,
void *(*start_routine)(void*),
void *GIT_RESTRICT arg);
int git_win32__thread_create(
git_win32_thread *GIT_RESTRICT,
const pthread_attr_t *GIT_RESTRICT,
void *(*) (void *),
void *GIT_RESTRICT);
int git_win32__thread_join(
git_win32_thread *,
void **);
#ifdef GIT_THREADS
int pthread_join(pthread_t, void **);
typedef git_win32_thread git_thread;
#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
git_win32__thread_create(git_thread_ptr, attr, start_routine, arg)
#define git_thread_join(git_thread_ptr, status) \
git_win32__thread_join(git_thread_ptr, status)
#endif
int pthread_mutex_init(
pthread_mutex_t *GIT_RESTRICT mutex,
......
......@@ -15,6 +15,7 @@ void test_network_remote_delete__initialize(void)
void test_network_remote_delete__cleanup(void)
{
git_remote_free(_remote);
cl_git_sandbox_cleanup();
}
......@@ -27,7 +28,6 @@ void test_network_remote_delete__cannot_delete_an_anonymous_remote(void)
cl_git_fail(git_remote_delete(remote));
git_remote_free(remote);
git_remote_free(_remote);
}
void test_network_remote_delete__remove_remote_tracking_branches(void)
......
......@@ -33,10 +33,14 @@ static int dont_call_me_cb(const char *fetch_refspec, void *payload)
void test_network_remote_rename__renaming_a_remote_moves_related_configuration_section(void)
{
git_strarray problems = {0};
assert_config_entry_existence(_repo, "remote.test.fetch", true);
assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false);
cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
cl_git_pass(git_remote_rename(&problems, _remote, "just/renamed"));
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
assert_config_entry_existence(_repo, "remote.test.fetch", false);
assert_config_entry_existence(_repo, "remote.just/renamed.fetch", true);
......@@ -44,16 +48,24 @@ void test_network_remote_rename__renaming_a_remote_moves_related_configuration_s
void test_network_remote_rename__renaming_a_remote_updates_branch_related_configuration_entries(void)
{
git_strarray problems = {0};
assert_config_entry_value(_repo, "branch.master.remote", "test");
cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
cl_git_pass(git_remote_rename(&problems, _remote, "just/renamed"));
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
assert_config_entry_value(_repo, "branch.master.remote", "just/renamed");
}
void test_network_remote_rename__renaming_a_remote_updates_default_fetchrefspec(void)
{
cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
git_strarray problems = {0};
cl_git_pass(git_remote_rename(&problems, _remote, "just/renamed"));
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/heads/*:refs/remotes/just/renamed/*");
}
......@@ -61,6 +73,7 @@ void test_network_remote_rename__renaming_a_remote_updates_default_fetchrefspec(
void test_network_remote_rename__renaming_a_remote_without_a_fetchrefspec_doesnt_create_one(void)
{
git_config *config;
git_strarray problems = {0};
git_remote_free(_remote);
cl_git_pass(git_repository_config__weakptr(&config, _repo));
......@@ -70,70 +83,64 @@ void test_network_remote_rename__renaming_a_remote_without_a_fetchrefspec_doesnt
assert_config_entry_existence(_repo, "remote.test.fetch", false);
cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
cl_git_pass(git_remote_rename(&problems, _remote, "just/renamed"));
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false);
}
static int ensure_refspecs(const char* refspec_name, void *payload)
{
int i = 0;
bool found = false;
const char ** exp = (const char **)payload;
while (exp[i]) {
if (strcmp(exp[i++], refspec_name))
continue;
found = true;
break;
}
cl_assert(found);
return 0;
}
void test_network_remote_rename__renaming_a_remote_notifies_of_non_default_fetchrefspec(void)
{
git_config *config;
char *expected_refspecs[] = {
"+refs/*:refs/*",
NULL
};
git_strarray problems = {0};
git_remote_free(_remote);
cl_git_pass(git_repository_config__weakptr(&config, _repo));
cl_git_pass(git_config_set_string(config, "remote.test.fetch", "+refs/*:refs/*"));
cl_git_pass(git_remote_load(&_remote, _repo, "test"));
cl_git_pass(git_remote_rename(_remote, "just/renamed", ensure_refspecs, &expected_refspecs));
cl_git_pass(git_remote_rename(&problems, _remote, "just/renamed"));
cl_assert_equal_i(1, problems.count);
cl_assert_equal_s("+refs/*:refs/*", problems.strings[0]);
git_strarray_free(&problems);
assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/*:refs/*");
git_strarray_free(&problems);
}
void test_network_remote_rename__new_name_can_contain_dots(void)
{
cl_git_pass(git_remote_rename(_remote, "just.renamed", dont_call_me_cb, NULL));
git_strarray problems = {0};
cl_git_pass(git_remote_rename(&problems, _remote, "just.renamed"));
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
cl_assert_equal_s("just.renamed", git_remote_name(_remote));
}
void test_network_remote_rename__new_name_must_conform_to_reference_naming_conventions(void)
{
git_strarray problems = {0};
cl_assert_equal_i(
GIT_EINVALIDSPEC,
git_remote_rename(_remote, "new@{name", dont_call_me_cb, NULL));
git_remote_rename(&problems, _remote, "new@{name"));
}
void test_network_remote_rename__renamed_name_is_persisted(void)
{
git_remote *renamed;
git_repository *another_repo;
git_strarray problems = {0};
cl_git_fail(git_remote_load(&renamed, _repo, "just/renamed"));
cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
cl_git_pass(git_remote_rename(&problems, _remote, "just/renamed"));
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
cl_git_pass(git_repository_open(&another_repo, "testrepo.git"));
cl_git_pass(git_remote_load(&renamed, _repo, "just/renamed"));
......@@ -144,19 +151,24 @@ void test_network_remote_rename__renamed_name_is_persisted(void)
void test_network_remote_rename__cannot_overwrite_an_existing_remote(void)
{
cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test", dont_call_me_cb, NULL));
cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test_with_pushurl", dont_call_me_cb, NULL));
git_strarray problems = {0};
cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(&problems, _remote, "test"));
cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(&problems, _remote, "test_with_pushurl"));
}
void test_network_remote_rename__renaming_a_remote_moves_the_underlying_reference(void)
{
git_reference *underlying;
git_strarray problems = {0};
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed"));
cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/test/master"));
git_reference_free(underlying);
cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
cl_git_pass(git_remote_rename(&problems, _remote, "just/renamed"));
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&underlying, _repo, "refs/remotes/test/master"));
cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed/master"));
......@@ -166,9 +178,91 @@ void test_network_remote_rename__renaming_a_remote_moves_the_underlying_referenc
void test_network_remote_rename__cannot_rename_an_inmemory_remote(void)
{
git_remote *remote;
git_strarray problems = {0};
cl_git_pass(git_remote_create_anonymous(&remote, _repo, "file:///blah", NULL));
cl_git_fail(git_remote_rename(remote, "newname", NULL, NULL));
cl_git_fail(git_remote_rename(&problems, remote, "newname"));
git_strarray_free(&problems);
git_remote_free(remote);
}
void test_network_remote_rename__overwrite_ref_in_target(void)
{
git_oid id;
char idstr[GIT_OID_HEXSZ + 1] = {0};
git_remote *remote;
git_reference *ref;
git_branch_t btype;
git_branch_iterator *iter;
git_strarray problems = {0};
cl_git_pass(git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
cl_git_pass(git_reference_create(&ref, _repo, "refs/remotes/renamed/master", &id, 1, NULL, NULL));
git_reference_free(ref);
cl_git_pass(git_remote_load(&remote, _repo, "test"));
cl_git_pass(git_remote_rename(&problems, remote, "renamed"));
git_remote_free(remote);
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
/* make sure there's only one remote-tracking branch */
cl_git_pass(git_branch_iterator_new(&iter, _repo, GIT_BRANCH_REMOTE));
cl_git_pass(git_branch_next(&ref, &btype, iter));
cl_assert_equal_s("refs/remotes/renamed/master", git_reference_name(ref));
git_oid_fmt(idstr, git_reference_target(ref));
cl_assert_equal_s("be3563ae3f795b2b4353bcce3a527ad0a4f7f644", idstr);
git_reference_free(ref);
cl_git_fail_with(GIT_ITEROVER, git_branch_next(&ref, &btype, iter));
git_branch_iterator_free(iter);
}
void test_network_remote_rename__symref_head(void)
{
int error;
git_remote *remote;
git_reference *ref;
git_branch_t btype;
git_branch_iterator *iter;
git_strarray problems = {0};
char idstr[GIT_OID_HEXSZ + 1] = {0};
git_vector refs;
cl_git_pass(git_reference_symbolic_create(&ref, _repo, "refs/remotes/test/HEAD", "refs/remotes/test/master", 0, NULL, NULL));
git_reference_free(ref);
cl_git_pass(git_remote_load(&remote, _repo, "test"));
cl_git_pass(git_remote_rename(&problems, remote, "renamed"));
git_remote_free(remote);
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
cl_git_pass(git_vector_init(&refs, 2, (git_vector_cmp) git_reference_cmp));
cl_git_pass(git_branch_iterator_new(&iter, _repo, GIT_BRANCH_REMOTE));
while ((error = git_branch_next(&ref, &btype, iter)) == 0) {
cl_git_pass(git_vector_insert(&refs, ref));
}
cl_assert_equal_i(GIT_ITEROVER, error);
git_vector_sort(&refs);
cl_assert_equal_i(2, refs.length);
ref = git_vector_get(&refs, 0);
cl_assert_equal_s("refs/remotes/renamed/HEAD", git_reference_name(ref));
cl_assert_equal_s("refs/remotes/renamed/master", git_reference_symbolic_target(ref));
git_reference_free(ref);
ref = git_vector_get(&refs, 1);
cl_assert_equal_s("refs/remotes/renamed/master", git_reference_name(ref));
git_oid_fmt(idstr, git_reference_target(ref));
cl_assert_equal_s("be3563ae3f795b2b4353bcce3a527ad0a4f7f644", idstr);
git_reference_free(ref);
git_vector_free(&refs);
cl_git_fail_with(GIT_ITEROVER, git_branch_next(&ref, &btype, iter));
git_branch_iterator_free(iter);
}
......@@ -229,7 +229,7 @@ void test_object_cache__threadmania(void)
#ifdef GIT_THREADS
for (th = 0; th < THREADCOUNT; ++th) {
cl_git_pass(git_thread_join(t[th], &data));
cl_git_pass(git_thread_join(&t[th], &data));
cl_assert_equal_i(th, ((int *)data)[0]);
git__free(data);
}
......@@ -276,7 +276,7 @@ void test_object_cache__fast_thread_rush(void)
#ifdef GIT_THREADS
for (th = 0; th < THREADCOUNT*2; ++th) {
void *rval;
cl_git_pass(git_thread_join(t[th], &rval));
cl_git_pass(git_thread_join(&t[th], &rval));
cl_assert_equal_i(th, *((int *)rval));
}
#endif
......
......@@ -8,10 +8,9 @@
#define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
#define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
#define BB_REPO_URL "https://libgit2@bitbucket.org/libgit2/testgitrepository.git"
#define BB_REPO_URL_WITH_PASS "https://libgit2:libgit2@bitbucket.org/libgit2/testgitrepository.git"
#define BB_REPO_URL_WITH_WRONG_PASS "https://libgit2:wrong@bitbucket.org/libgit2/testgitrepository.git"
#define ASSEMBLA_REPO_URL "https://libgit2:_Libgit2@git.assembla.com/libgit2-test-repos.git"
#define BB_REPO_URL "https://libgit3@bitbucket.org/libgit2/testgitrepository.git"
#define BB_REPO_URL_WITH_PASS "https://libgit3:libgit3@bitbucket.org/libgit2/testgitrepository.git"
#define BB_REPO_URL_WITH_WRONG_PASS "https://libgit3:wrong@bitbucket.org/libgit2/testgitrepository.git"
static git_repository *g_repo;
static git_clone_options g_options;
......@@ -194,6 +193,9 @@ void test_online_clone__clone_mirror(void)
git_remote_free(remote);
git_reference_free(head);
git_buf_free(&path);
git_repository_free(g_repo);
g_repo = NULL;
cl_fixture_cleanup("./foo.git");
}
......@@ -287,11 +289,6 @@ void test_online_clone__bitbucket_style(void)
cl_fixture_cleanup("./foo");
}
void test_online_clone__assembla_style(void)
{
cl_git_pass(git_clone(&g_repo, ASSEMBLA_REPO_URL, "./foo", NULL));
}
static int cancel_at_half(const git_transfer_progress *stats, void *payload)
{
GIT_UNUSED(payload);
......
......@@ -68,13 +68,16 @@ void test_submodule_add__url_relative(void)
{
git_submodule *sm;
git_remote *remote;
git_strarray problems = {0};
/* default remote url is https://github.com/libgit2/false.git */
g_repo = cl_git_sandbox_init("testrepo2");
/* make sure we don't default to origin - rename origin -> test_remote */
cl_git_pass(git_remote_load(&remote, g_repo, "origin"));
cl_git_pass(git_remote_rename(remote, "test_remote", NULL, NULL));
cl_git_pass(git_remote_rename(&problems, remote, "test_remote"));
cl_assert_equal_i(0, problems.count);
git_strarray_free(&problems);
cl_git_fail(git_remote_load(&remote, g_repo, "origin"));
git_remote_free(remote);
......
......@@ -19,8 +19,8 @@ void rewrite_gitmodules(const char *workdir)
cl_git_pass(git_buf_joinpath(&in_f, workdir, "gitmodules"));
cl_git_pass(git_buf_joinpath(&out_f, workdir, ".gitmodules"));
cl_assert((in = fopen(in_f.ptr, "r")) != NULL);
cl_assert((out = fopen(out_f.ptr, "w")) != NULL);
cl_assert((in = fopen(in_f.ptr, "rb")) != NULL);
cl_assert((out = fopen(out_f.ptr, "wb")) != NULL);
while (fgets(line, sizeof(line), in) != NULL) {
char *scan = line;
......
......@@ -84,7 +84,7 @@ void test_threads_refdb__iterator(void)
#ifdef GIT_THREADS
for (t = 0; t < THREADS; ++t) {
cl_git_pass(git_thread_join(th[t], NULL));
cl_git_pass(git_thread_join(&th[t], NULL));
}
#endif
......@@ -215,7 +215,7 @@ void test_threads_refdb__edit_while_iterate(void)
}
for (t = 0; t < THREADS; ++t) {
cl_git_pass(git_thread_join(th[t], NULL));
cl_git_pass(git_thread_join(&th[t], NULL));
}
#endif
}
......@@ -32,7 +32,7 @@ void run_in_parallel(
#ifdef GIT_THREADS
for (t = 0; t < threads; ++t)
cl_git_pass(git_thread_join(th[t], NULL));
cl_git_pass(git_thread_join(&th[t], NULL));
memset(th, 0, threads * sizeof(git_thread));
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment