* The fetch behavior of remotes with autotag set to GIT_REMOTE_DOWNLOAD_TAGS_ALL
has been changed to match git 1.9.0 and later. In this mode, libgit2 now
fetches all tags in addition to whatever else needs to be fetched.
+
+* git_threads_init() and git_threads_shutdown() have been renamed to
+ git_libgit2_init() and git_libgit2_shutdown() to better explain what
+ their purpose is, as it's grown to be more than just about threads.
int options = 0, count = 0;
struct print_payload payload = {0};
- git_threads_init();
+ git_libgit2_init();
parse_opts(&options, &count, argc, argv);
git_index_free(index);
git_repository_free(repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
git_blob *blob;
git_object *obj;
- git_threads_init();
+ git_libgit2_init();
parse_opts(&o, argc, argv);
if (o.M) blameopts.flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES;
git_blame_free(blame);
git_repository_free(repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
git_object *obj = NULL;
char oidstr[GIT_OID_HEXSZ + 1];
- git_threads_init();
+ git_libgit2_init();
parse_opts(&o, argc, argv);
git_object_free(obj);
git_repository_free(repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
git_repository *repo;
describe_options opts;
- git_threads_init();
+ git_libgit2_init();
check_lg2(git_repository_open_ext(&repo, ".", 0, NULL),
"Could not open repository", NULL);
do_describe(repo, &opts);
git_repository_free(repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
-1, 0, 0, GIT_DIFF_FORMAT_PATCH, NULL, NULL, "."
};
- git_threads_init();
+ git_libgit2_init();
parse_opts(&o, argc, argv);
git_tree_free(t2);
git_repository_free(repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
int main (int argc, char** argv)
{
+ // Initialize the library, this will set up any global state which libgit2 needs
+ // including threading and crypto
+ git_libgit2_init();
+
// ### Opening the Repository
// There are a couple of methods for opening a repository, this being the
git_repository *repo = NULL;
struct opts o = { 1, 0, 0, 0, GIT_REPOSITORY_INIT_SHARED_UMASK, 0, 0, 0 };
- git_threads_init();
+ git_libgit2_init();
parse_opts(&o, argc, argv);
}
git_repository_free(repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
git_commit *commit = NULL;
git_pathspec *ps = NULL;
- git_threads_init();
+ git_libgit2_init();
/** Parse arguments and set up revwalker. */
git_pathspec_free(ps);
git_revwalk_free(s.walker);
git_repository_free(s.repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
exit(EXIT_FAILURE);
}
- git_threads_init();
+ git_libgit2_init();
for (i = 0; commands[i].name != NULL; ++i) {
if (!strcmp(argv[1], commands[i].name))
git_oid oid;
char buf[GIT_OID_HEXSZ+1];
- git_threads_init();
+ git_libgit2_init();
check_lg2(git_repository_open_ext(&repo, ".", 0, NULL), "opening repository", NULL);
check_lg2(git_revwalk_new(&walk, repo), "allocating revwalk", NULL);
printf("%s\n", buf);
}
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
{
struct parse_state ps = {0};
- git_threads_init();
+ git_libgit2_init();
parse_opts(&ps, argc, argv);
check_lg2(parse_revision(&ps), "Parsing", NULL);
git_repository_free(ps.repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
char out[GIT_OID_HEXSZ+1];
out[GIT_OID_HEXSZ] = '\0';
- git_threads_init();
+ git_libgit2_init();
if (argc > 2)
fatal("usage: showindex [<repo-dir>]", NULL);
}
git_index_free(index);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
git_status_list *status;
struct opts o = { GIT_STATUS_OPTIONS_INIT, "." };
- git_threads_init();
+ git_libgit2_init();
o.statusopt.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
o.statusopt.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
}
git_repository_free(repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
tag_action action;
tag_state state;
- git_threads_init();
+ git_libgit2_init();
check_lg2(git_repository_open_ext(&repo, ".", 0, NULL),
"Could not open repository", NULL);
action(&state);
git_repository_free(repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
return 0;
}
#include "git2/status.h"
#include "git2/submodule.h"
#include "git2/tag.h"
-#include "git2/threads.h"
+#include "git2/global.h"
#include "git2/transport.h"
#include "git2/tree.h"
#include "git2/types.h"
--- /dev/null
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_git_global_h__
+#define INCLUDE_git_global_h__
+
+#include "common.h"
+
+GIT_BEGIN_DECL
+
+/**
+ * Init the global state
+ *
+ * This function must the called before any other libgit2 function in
+ * order to set up global state and threading.
+ *
+ * This function may be called multiple times.
+ *
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_libgit2_init(void);
+
+/**
+ * Shutdown the global state
+ *
+ * Clean up the global state and threading context after calling it as
+ * many times as `git_libgit2_init()` was called.
+ *
+ */
+GIT_EXTERN(void) git_libgit2_shutdown(void);
+
+/** @} */
+GIT_END_DECL
+#endif
+
*/
GIT_BEGIN_DECL
-/**
- * Init the threading system.
- *
- * If libgit2 has been built with GIT_THREADS
- * on, this function must be called once before
- * any other library functions.
- *
- * If libgit2 has been built without GIT_THREADS
- * support, this function is a no-op.
- *
- * @return 0 or an error code
- */
-GIT_EXTERN(int) git_threads_init(void);
-
-/**
- * Shutdown the threading system.
- *
- * If libgit2 has been built with GIT_THREADS
- * on, this function must be called before shutting
- * down the library.
- *
- * If libgit2 has been built without GIT_THREADS
- * support, this function is a no-op.
- */
-GIT_EXTERN(void) git_threads_shutdown(void);
-
/**
* Initialize the OpenSSL locks
*
#include "hash.h"
#include "sysdir.h"
#include "git2/threads.h"
+#include "git2/global.h"
#include "thread-utils.h"
* Handle the global state with TLS
*
* If libgit2 is built with GIT_THREADS enabled,
- * the `git_threads_init()` function must be called
+ * the `git_libgit2_init()` function must be called
* before calling any other function of the library.
*
* This function allocates a TLS index (using pthreads
* allocated on each thread.
*
* Before shutting down the library, the
- * `git_threads_shutdown` method must be called to free
+ * `git_libgit2_shutdown` method must be called to free
* the previously reserved TLS index.
*
* If libgit2 is built without threading support, the
*/
/*
- * `git_threads_init()` allows subsystems to perform global setup,
+ * `git_libgit2_init()` allows subsystems to perform global setup,
* which may take place in the global scope. An explicit memory
- * fence exists at the exit of `git_threads_init()`. Without this,
+ * fence exists at the exit of `git_libgit2_init()`. Without this,
* CPU cores are free to reorder cache invalidation of `_tls_init`
* before cache invalidation of the subsystems' newly written global
* state.
return error;
}
-int git_threads_init(void)
+int git_libgit2_init(void)
{
int error = 0;
git_mutex_free(&git__mwindow_mutex);
}
-void git_threads_shutdown(void)
+void git_libgit2_shutdown(void)
{
/* Enter the lock */
while (InterlockedCompareExchange(&_mutex, 1, 0)) { Sleep(0); }
GIT_MEMORY_BARRIER;
}
-int git_threads_init(void)
+int git_libgit2_init(void)
{
pthread_once(&_once_init, init_once);
git_atomic_inc(&git__n_inits);
return init_error;
}
-void git_threads_shutdown(void)
+void git_libgit2_shutdown(void)
{
void *ptr = NULL;
pthread_once_t new_once = PTHREAD_ONCE_INIT;
static git_global_st __state;
-int git_threads_init(void)
+int git_libgit2_init(void)
{
static int ssl_inited = 0;
return 0;
}
-void git_threads_shutdown(void)
+void git_libgit2_shutdown(void)
{
/* Shut down any subsystems that have global state */
if (0 == git_atomic_dec(&git__n_inits))
/*
* When compiled with GIT_THREADS, the global hash_prov data is
- * initialized with git_threads_init. Otherwise, it must be initialized
+ * initialized with git_libgit2_init. Otherwise, it must be initialized
* at first use.
*/
if (hash_prov.type == INVALID && (error = git_hash_global_init()) < 0)
clar_test_init(argc, argv);
- git_threads_init();
+ git_libgit2_init();
cl_sandbox_set_search_path_defaults();
/* Run the test suite */
clar_test_shutdown();
giterr_clear();
- git_threads_shutdown();
+ git_libgit2_shutdown();
return res;
}
{
git_repository *nested_repo;
- git_threads_init();
+ git_libgit2_init();
cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git")));
git_repository_free(nested_repo);
- git_threads_shutdown();
+ git_libgit2_shutdown();
cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git")));
git_repository_free(nested_repo);
}