summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2011-11-18 22:45:56 +0100
committerCarlos Martín Nieto <carlos@cmartin.tk>2011-11-18 22:45:56 +0100
commitbdd31dd5e832126b2f22fccbe244a1106c241ab0 (patch)
treeb08a2ad0fad57131563aa8c071221bea241128c1 /include
parent277b7efe493887081ce1dafd91199d0ee9f676c9 (diff)
parente4c93a392763a006d11e1c1dd01c12f85498dad5 (diff)
downloadlibgit2-error-handling.tar.gz
Merge branch 'development' into error-handlingerror-handling
The code in this branch has been modified so it works with the global state introduced in development.
Diffstat (limited to 'include')
-rw-r--r--include/git2.h1
-rw-r--r--include/git2/common.h13
-rw-r--r--include/git2/indexer.h4
-rw-r--r--include/git2/oid.h2
-rw-r--r--include/git2/refs.h68
-rw-r--r--include/git2/refspec.h2
-rw-r--r--include/git2/remote.h6
-rw-r--r--include/git2/thread-utils.h60
-rw-r--r--include/git2/threads.h48
-rw-r--r--include/git2/tree.h44
-rw-r--r--include/git2/windows.h59
11 files changed, 209 insertions, 98 deletions
diff --git a/include/git2.h b/include/git2.h
index ad92809bb..14c090e39 100644
--- a/include/git2.h
+++ b/include/git2.h
@@ -11,6 +11,7 @@
#include "git2/version.h"
#include "git2/common.h"
+#include "git2/threads.h"
#include "git2/errors.h"
#include "git2/zlib.h"
diff --git a/include/git2/common.h b/include/git2/common.h
index ef279eac1..eee918a23 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -7,7 +7,6 @@
#ifndef INCLUDE_git_common_h__
#define INCLUDE_git_common_h__
-#include "thread-utils.h"
#include <time.h>
#include <stdlib.h>
@@ -38,18 +37,6 @@
# define GIT_EXTERN(type) extern type
#endif
-/** Declare a public TLS symbol exported for application use. */
-#if __GNUC__ >= 4
-# define GIT_EXTERN_TLS(type) extern \
- __attribute__((visibility("default"))) \
- GIT_TLS \
- type
-#elif defined(_MSC_VER)
-# define GIT_EXTERN_TLS(type) __declspec(dllexport) GIT_TLS type
-#else
-# define GIT_EXTERN_TLS(type) extern GIT_TLS type
-#endif
-
/** Declare a function as always inlined. */
#if defined(_MSC_VER)
# define GIT_INLINE(type) static __inline type
diff --git a/include/git2/indexer.h b/include/git2/indexer.h
index bd9b9b6ab..1e5eb380c 100644
--- a/include/git2/indexer.h
+++ b/include/git2/indexer.h
@@ -7,8 +7,8 @@
#ifndef _INCLUDE_git_indexer_h__
#define _INCLUDE_git_indexer_h__
-#include "git2/common.h"
-#include "git2/oid.h"
+#include "common.h"
+#include "oid.h"
GIT_BEGIN_DECL
diff --git a/include/git2/oid.h b/include/git2/oid.h
index b9824b887..9cebda931 100644
--- a/include/git2/oid.h
+++ b/include/git2/oid.h
@@ -100,7 +100,7 @@ GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
*
* @param oid the oid structure to format
* @return the c-string; NULL if memory is exhausted. Caller must
- * deallocate the string with free().
+ * deallocate the string with git__free().
*/
GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
diff --git a/include/git2/refs.h b/include/git2/refs.h
index c319bfb3d..82c5d8881 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -23,8 +23,7 @@ GIT_BEGIN_DECL
/**
* Lookup a reference by its name in a repository.
*
- * The generated reference is owned by the repository and
- * should not be freed by the user.
+ * The generated reference must be freed by the user.
*
* @param reference_out pointer to the looked-up reference
* @param repo the repository to look up the reference
@@ -39,8 +38,7 @@ GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_reposito
* The reference will be created in the repository and written
* to the disk.
*
- * This reference is owned by the repository and shall not
- * be free'd by the user.
+ * The generated reference must be freed by the user.
*
* If `force` is true and there already exists a reference
* with the same name, it will be overwritten.
@@ -60,8 +58,7 @@ GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repos
* The reference will be created in the repository and written
* to the disk.
*
- * This reference is owned by the repository and shall not
- * be free'd by the user.
+ * The generated reference must be freed by the user.
*
* If `force` is true and there already exists a reference
* with the same name, it will be overwritten.
@@ -119,8 +116,13 @@ GIT_EXTERN(const char *) git_reference_name(git_reference *ref);
* Thie method iteratively peels a symbolic reference
* until it resolves to a direct reference to an OID.
*
+ * The peeled reference is returned in the `resolved_ref`
+ * argument, and must be freed manually once it's no longer
+ * needed.
+ *
* If a direct reference is passed as an argument,
- * that reference is returned immediately
+ * a copy of that reference is returned. This copy must
+ * be manually freed too.
*
* @param resolved_ref Pointer to the peeled reference
* @param ref The reference
@@ -173,9 +175,19 @@ GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id);
* The new name will be checked for validity and may be
* modified into a normalized form.
*
- * The refernece will be immediately renamed in-memory
+ * The given git_reference will be updated in place.
+ *
+ * The reference will be immediately renamed in-memory
* and on disk.
*
+ * If the `force` flag is not enabled, and there's already
+ * a reference with the given name, the renaming will fail.
+ *
+ * @param ref The reference to rename
+ * @param new_name The new name for the reference
+ * @param force Overwrite an existing reference
+ * @return GIT_SUCCESS or an error code
+ *
*/
GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name, int force);
@@ -187,6 +199,8 @@ GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name, i
* The reference will be immediately removed on disk and from
* memory. The given reference pointer will no longer be valid.
*
+ * @param ref The reference to remove
+ * @return GIT_SUCCESS or an error code
*/
GIT_EXTERN(int) git_reference_delete(git_reference *ref);
@@ -200,9 +214,6 @@ GIT_EXTERN(int) git_reference_delete(git_reference *ref);
* Once the `packed-refs` file has been written properly,
* the loose references will be removed from disk.
*
- * WARNING: calling this method may invalidate any existing
- * references previously loaded on the cache.
- *
* @param repo Repository where the loose refs will be packed
* @return GIT_SUCCESS or an error code
*/
@@ -253,6 +264,41 @@ GIT_EXTERN(int) git_reference_listall(git_strarray *array, git_repository *repo,
*/
GIT_EXTERN(int) git_reference_foreach(git_repository *repo, unsigned int list_flags, int (*callback)(const char *, void *), void *payload);
+/**
+ * Check if a reference has been loaded from a packfile
+ *
+ * @param ref A git reference
+ * @return 0 in case it's not packed; 1 otherwise
+ */
+GIT_EXTERN(int) git_reference_is_packed(git_reference *ref);
+
+/**
+ * Reload a reference from disk
+ *
+ * Reference pointers may become outdated if the Git
+ * repository is accessed simultaneously by other clients
+ * whilt the library is open.
+ *
+ * This method forces a reload of the reference from disk,
+ * to ensure that the provided information is still
+ * reliable.
+ *
+ * If the reload fails (e.g. the reference no longer exists
+ * on disk, or has become corrupted), an error code will be
+ * returned and the reference pointer will be invalidated.
+ *
+ * @param ref The reference to reload
+ * @return GIT_SUCCESS on success, or an error code
+ */
+GIT_EXTERN(int) git_reference_reload(git_reference *ref);
+
+/**
+ * Free the given reference
+ *
+ * @param ref git_reference
+ */
+GIT_EXTERN(void) git_reference_free(git_reference *ref);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/refspec.h b/include/git2/refspec.h
index eccbeaa7c..0f8b13cec 100644
--- a/include/git2/refspec.h
+++ b/include/git2/refspec.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_git_refspec_h__
#define INCLUDE_git_refspec_h__
-#include "git2/types.h"
+#include "types.h"
/**
* @file git2/refspec.h
diff --git a/include/git2/remote.h b/include/git2/remote.h
index e0be93757..54116c22e 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -7,9 +7,9 @@
#ifndef INCLUDE_git_remote_h__
#define INCLUDE_git_remote_h__
-#include "git2/common.h"
-#include "git2/repository.h"
-#include "git2/refspec.h"
+#include "common.h"
+#include "repository.h"
+#include "refspec.h"
/**
* @file git2/remote.h
* @brief Git remote management functions
diff --git a/include/git2/thread-utils.h b/include/git2/thread-utils.h
deleted file mode 100644
index 81c62d135..000000000
--- a/include/git2/thread-utils.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2009-2011 the libgit2 contributors
- *
- * 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_thread_utils_h__
-#define INCLUDE_git_thread_utils_h__
-
-/*
- * How TLS works is compiler+platform dependant
- * Sources: http://en.wikipedia.org/wiki/Thread-Specific_Storage
- * http://predef.sourceforge.net/precomp.html
- */
-
-#ifdef GIT_THREADS
-# define GIT_HAS_TLS 1
-
-/* No TLS in Cygwin */
-# if defined(__CHECKER__) || defined(__CYGWIN__)
-# undef GIT_HAS_TLS
-# define GIT_TLS
-
-/* No TLS in Mach binaries for Mac OS X */
-# elif defined(__APPLE__) && defined(__MACH__)
-# undef GIT_TLS
-# define GIT_TLS
-
-/* Normal TLS for GCC */
-# elif defined(__GNUC__) || \
- defined(__SUNPRO_C) || \
- defined(__SUNPRO_CC) || \
- defined(__xlc__) || \
- defined(__xlC__)
-# define GIT_TLS __thread
-
-/* ICC may run on Windows or Linux */
-# elif defined(__INTEL_COMPILER)
-# if defined(_WIN32) || defined(_WIN32_CE)
-# define GIT_TLS __declspec(thread)
-# else
-# define GIT_TLS __thread
-# endif
-
-/* Declspec for MSVC in Win32 */
-# elif defined(_WIN32) || \
- defined(_WIN32_CE) || \
- defined(__BORLANDC__)
-# define GIT_TLS __declspec(thread)
-
-/* Other platform; no TLS */
-# else
-# undef GIT_HAS_TLS
-# define GIT_TLS /* nothing: tls vars are thread-global */
-# endif
-#else /* Disable TLS if libgit2 is not threadsafe */
-# define GIT_TLS
-#endif /* GIT_THREADS */
-
-#endif /* INCLUDE_git_thread_utils_h__ */
diff --git a/include/git2/threads.h b/include/git2/threads.h
new file mode 100644
index 000000000..85472a441
--- /dev/null
+++ b/include/git2/threads.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * 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_threads_h__
+#define INCLUDE_git_threads_h__
+
+#include "common.h"
+
+/**
+ * @file git2/threads.h
+ * @brief Library level thread functions
+ * @defgroup git_thread Threading functions
+ * @ingroup Git
+ * @{
+ */
+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.
+ */
+GIT_EXTERN(void) 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);
+
+/** @} */
+GIT_END_DECL
+#endif
+
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 8d638f723..bd89de34f 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -269,19 +269,49 @@ GIT_EXTERN(void) git_treebuilder_filter(git_treebuilder *bld, int (*filter)(cons
GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld);
/**
- * Retrieve the tree object containing a tree entry, given
- * a relative path to this tree entry
+ * Retrieve a subtree contained in a tree, given its
+ * relative path.
*
* The returned tree is owned by the repository and
* should be closed with the `git_object_close` method.
*
- * @param parent_out Pointer where to store the parent tree
+ * @param subtree Pointer where to store the subtree
* @param root A previously loaded tree which will be the root of the relative path
- * @param treeentry_path Path to the tree entry from which to extract the last tree object
- * @return GIT_SUCCESS on success; GIT_ENOTFOUND if the path does not lead to an
- * entry, GIT_EINVALIDPATH or an error code
+ * @param subtree_path Path to the contained subtree
+ * @return GIT_SUCCESS on success; GIT_ENOTFOUND if the path does not lead to a
+ * subtree, GIT_EINVALIDPATH or an error code
*/
-GIT_EXTERN(int) git_tree_frompath(git_tree **parent_out, git_tree *root, const char *treeentry_path);
+GIT_EXTERN(int) git_tree_get_subtree(git_tree **subtree, git_tree *root, const char *subtree_path);
+
+/** Callback for the tree traversal method */
+typedef int (*git_treewalk_cb)(const char *root, git_tree_entry *entry, void *payload);
+
+/** Tree traversal modes */
+enum git_treewalk_mode {
+ GIT_TREEWALK_PRE = 0, /* Pre-order */
+ GIT_TREEWALK_POST = 1, /* Post-order */
+};
+
+/**
+ * Traverse the entries in a tree and its subtrees in
+ * post or pre order
+ *
+ * The entries will be traversed in the specified order,
+ * children subtrees will be automatically loaded as required,
+ * and the `callback` will be called once per entry with
+ * the current (relative) root for the entry and the entry
+ * data itself.
+ *
+ * If the callback returns a negative value, the passed entry
+ * will be skiped on the traversal.
+ *
+ * @param tree The tree to walk
+ * @param callback Function to call on each tree entry
+ * @param mode Traversal mode (pre or post-order)
+ * @return GIT_SUCCESS or an error code
+ */
+GIT_EXTERN(int) git_tree_walk(git_tree *walk, git_treewalk_cb callback, int mode, void *payload);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/windows.h b/include/git2/windows.h
new file mode 100644
index 000000000..6a2e9e2cd
--- /dev/null
+++ b/include/git2/windows.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * 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_windows_h__
+#define INCLUDE_git_windows_h__
+
+#include "common.h"
+
+/**
+ * @file git2/windows.h
+ * @brief Windows-specific functions
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Set the active codepage for Windows syscalls
+ *
+ * All syscalls performed by the library will assume
+ * this codepage when converting paths and strings
+ * to use by the Windows kernel.
+ *
+ * The default value of UTF-8 will work automatically
+ * with most Git repositories created on Unix systems.
+ *
+ * This settings needs only be changed when working
+ * with repositories that contain paths in specific,
+ * non-UTF codepages.
+ *
+ * A full list of all available codepage identifiers may
+ * be found at:
+ *
+ * http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx
+ *
+ * @param codepage numeric codepage identifier
+ */
+GIT_EXTERN(void) gitwin_set_codepage(unsigned int codepage);
+
+/**
+ * Return the active codepage for Windows syscalls
+ *
+ * @return numeric codepage identifier
+ */
+GIT_EXTERN(unsigned int) gitwin_get_codepage(void);
+
+/**
+ * Set the active Windows codepage to UTF-8 (this is
+ * the default value)
+ */
+GIT_EXTERN(void) gitwin_set_utf8(void);
+
+/** @} */
+GIT_END_DECL
+#endif
+