]> git.proxmox.com Git - libgit2.git/commitdiff
Rename git_threads_ to git_libgit2_
authorCarlos Martín Nieto <cmn@dwim.me>
Thu, 23 Oct 2014 15:34:41 +0000 (17:34 +0200)
committerCarlos Martín Nieto <cmn@dwim.me>
Sat, 8 Nov 2014 22:46:39 +0000 (23:46 +0100)
This describes their purpose better, as we now initialize ssl and some
other global stuff in there. Calling the init function is not something
which has been optional for a while now.

22 files changed:
CHANGELOG.md
examples/add.c
examples/blame.c
examples/cat-file.c
examples/describe.c
examples/diff.c
examples/general.c
examples/init.c
examples/log.c
examples/network/git2.c
examples/rev-list.c
examples/rev-parse.c
examples/showindex.c
examples/status.c
examples/tag.c
include/git2.h
include/git2/global.h [new file with mode: 0644]
include/git2/threads.h
src/global.c
src/hash/hash_win32.c
tests/main.c
tests/threads/basic.c

index f268f6f598c2927b333545d979e1bdb28003bb46..4b9d9244215f4621130fff1f02bc3d1700a8725d 100644 (file)
@@ -122,3 +122,7 @@ v0.21 + 1
 * 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.
index 0c6076e811e80481650751fbdccd2cd77f5030d3..0101ab9ae15a25396b427bd8a35847b0b7269b94 100644 (file)
@@ -40,7 +40,7 @@ int main (int argc, char** argv)
        int options = 0, count = 0;
        struct print_payload payload = {0};
 
-       git_threads_init();
+       git_libgit2_init();
 
        parse_opts(&options, &count, argc, argv);
 
@@ -66,7 +66,7 @@ int main (int argc, char** argv)
        git_index_free(index);
        git_repository_free(repo);
 
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index fda605bcefa18519be58f21052f7a971b199b3f7..9d38f25a43d12d0412469956cf33a9a7b3ea5991 100644 (file)
@@ -48,7 +48,7 @@ int main(int argc, char *argv[])
        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;
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
        git_blame_free(blame);
        git_repository_free(repo);
 
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index 52399fa8a61b7fc04127ffeca9fd7461d9ae0949..f948740a1cace85df9b155cf1a5bb039cfd168b5 100644 (file)
@@ -127,7 +127,7 @@ int main(int argc, char *argv[])
        git_object *obj = NULL;
        char oidstr[GIT_OID_HEXSZ + 1];
 
-       git_threads_init();
+       git_libgit2_init();
 
        parse_opts(&o, argc, argv);
 
@@ -190,7 +190,7 @@ int main(int argc, char *argv[])
        git_object_free(obj);
        git_repository_free(repo);
 
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index cbf73b012e13418cef763893d90ca39856f2b2c5..09a4fd008d6ecd44b46322c374db95c91259d2f4 100644 (file)
@@ -145,7 +145,7 @@ int main(int argc, char **argv)
        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);
@@ -156,7 +156,7 @@ int main(int argc, char **argv)
        do_describe(repo, &opts);
 
        git_repository_free(repo);
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index 76ac2f31147177f0cd8ea35f1a7f08584d23d96a..b69cb22182ceadad5067907be2d02b7deac07ede 100644 (file)
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
                -1, 0, 0, GIT_DIFF_FORMAT_PATCH, NULL, NULL, "."
        };
 
-       git_threads_init();
+       git_libgit2_init();
 
        parse_opts(&o, argc, argv);
 
@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
        git_tree_free(t2);
        git_repository_free(repo);
 
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index 051d693800c5366561e219ce476e3a6960e93469..8981cacab911407841d0c40b94bd9f5abd906659 100644 (file)
@@ -59,6 +59,10 @@ static void check_error(int error_code, const char *action)
 
 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
index 0e823ab81866cb52b625ea941dc7c4c094b0d58b..fe7a672246ad839503855458a598eeab4cfb628a 100644 (file)
@@ -46,7 +46,7 @@ int main(int argc, char *argv[])
        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);
 
@@ -116,7 +116,7 @@ int main(int argc, char *argv[])
        }
 
        git_repository_free(repo);
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index d5f75a29720cc3ea5f7ad444f3182cbf074ab569..e54eed3cef098ab1d8b6e9d218f0ff8420041cb7 100644 (file)
@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
        git_commit *commit = NULL;
        git_pathspec *ps = NULL;
 
-       git_threads_init();
+       git_libgit2_init();
 
        /** Parse arguments and set up revwalker. */
 
@@ -180,7 +180,7 @@ int main(int argc, char *argv[])
        git_pathspec_free(ps);
        git_revwalk_free(s.walker);
        git_repository_free(s.repo);
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index 5b32ac809a03d70092eef8b605aa96a5cc90e328..d44334b858805d67d8e988bea0810abe83a4d3f0 100644 (file)
@@ -54,7 +54,7 @@ int main(int argc, char **argv)
                exit(EXIT_FAILURE);
        }
 
-       git_threads_init();
+       git_libgit2_init();
 
        for (i = 0; commands[i].name != NULL; ++i) {
                if (!strcmp(argv[1], commands[i].name))
index 940a01136d5375116d882a4d2893ea01d89aa1c3..ee9afc441111ac6a742656df94fef5a7b558fe75 100644 (file)
@@ -24,7 +24,7 @@ int main (int argc, char **argv)
        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);
@@ -36,7 +36,7 @@ int main (int argc, char **argv)
                printf("%s\n", buf);
        }
 
-       git_threads_shutdown();
+       git_libgit2_shutdown();
        return 0;
 }
 
index a248337671ae90fc9a10a012c7c086da73b15628..483d6e019bbe995194f94f551da2d80348747cc3 100644 (file)
@@ -29,13 +29,13 @@ int main(int argc, char *argv[])
 {
        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;
 }
index 604124f12d131fc6043bbac861d55ddc4be27572..43be5e24cce8020835afc8ce16bfa14b08265b0f 100644 (file)
@@ -23,7 +23,7 @@ int main (int argc, char** argv)
        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);
@@ -64,7 +64,7 @@ int main (int argc, char** argv)
        }
 
        git_index_free(index);
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index a59f34454d0983a25ad072017440e428ee363e7f..62cb5b24f0373520a8fb1f73707d70df6f55bc8a 100644 (file)
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
        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 |
@@ -135,7 +135,7 @@ show_status:
        }
 
        git_repository_free(repo);
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index 1d254aee52d04bdf261cbb9588a49d685793698e..c6a70d90eef0f33ea1abf6a410fcb1655b1fc98e 100644 (file)
@@ -300,7 +300,7 @@ int main(int argc, char **argv)
        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);
@@ -313,7 +313,7 @@ int main(int argc, char **argv)
        action(&state);
 
        git_repository_free(repo);
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return 0;
 }
index 41adbbad2e753a82b7802aef7c5ba3cc9776371b..388cd82d042ad5fb70af432ae22d9f6c4ce78be8 100644 (file)
@@ -56,7 +56,7 @@
 #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"
diff --git a/include/git2/global.h b/include/git2/global.h
new file mode 100644 (file)
index 0000000..4f90c4c
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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
+
index 6b42870333e4d80f583589b169a000dfa6e6c7d3..c0c3898d935f1076782d66ef326f2a4ae51278ae 100644 (file)
  */
 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
  *
index 3c91860cd5b2881eccc9c2db00fa7826b7c1d734..da903cb94b7e1839fc4c5c74535efa9fc8b1d2b6 100644 (file)
@@ -9,6 +9,7 @@
 #include "hash.h"
 #include "sysdir.h"
 #include "git2/threads.h"
+#include "git2/global.h"
 #include "thread-utils.h"
 
 
@@ -133,7 +134,7 @@ int git_openssl_set_locking(void)
  * 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
@@ -146,7 +147,7 @@ int git_openssl_set_locking(void)
  * 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
@@ -156,9 +157,9 @@ int git_openssl_set_locking(void)
  */
 
 /*
- * `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.
@@ -185,7 +186,7 @@ static int synchronized_threads_init(void)
        return error;
 }
 
-int git_threads_init(void)
+int git_libgit2_init(void)
 {
        int error = 0;
 
@@ -210,7 +211,7 @@ static void synchronized_threads_shutdown(void)
        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); }
@@ -272,14 +273,14 @@ static void init_once(void)
        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;
@@ -320,7 +321,7 @@ git_global_st *git__global_state(void)
 
 static git_global_st __state;
 
-int git_threads_init(void)
+int git_libgit2_init(void)
 {
        static int ssl_inited = 0;
 
@@ -333,7 +334,7 @@ int git_threads_init(void)
        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))
index bb2231364463d1729d7867da465e97a00af7e235..6bae53e55adb742925d1102f7214afeb4b91e4cc 100644 (file)
@@ -236,7 +236,7 @@ int git_hash_ctx_init(git_hash_ctx *ctx)
 
        /*
         * 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)
index 3de4f980109c508ecbf9e748839be8a9edffbfd0..a092b8ba4f669b4adeec203ad32cb97ba50eb766 100644 (file)
@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
 
        clar_test_init(argc, argv);
 
-       git_threads_init();
+       git_libgit2_init();
        cl_sandbox_set_search_path_defaults();
 
        /* Run the test suite */
@@ -19,7 +19,7 @@ int main(int argc, char *argv[])
        clar_test_shutdown();
 
        giterr_clear();
-       git_threads_shutdown();
+       git_libgit2_shutdown();
 
        return res;
 }
index eb15293c72e67c5c8802f455d8e6ffd533ec47fe..9c342bc42c37df8d9a3c897d506940d2ffe3ef1d 100644 (file)
@@ -27,11 +27,11 @@ void test_threads_basic__multiple_init(void)
 {
        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);
 }