summaryrefslogtreecommitdiff
path: root/src/git2
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2010-12-06 23:03:16 +0200
committerVicent Marti <tanoku@gmail.com>2010-12-06 23:03:16 +0200
commit44908fe763b1a2097b65c86130ac679c458df7d2 (patch)
treed4b2e597ec985cabff2236895c4515100a5063e4 /src/git2
parentd12299fe22e549a20e632668fdbe13cab9def9df (diff)
downloadlibgit2-44908fe763b1a2097b65c86130ac679c458df7d2.tar.gz
Change the library include file
Libgit2 is now officially include as #include "<git2.h>" or indidividual files may be included as #include <git2/index.h> Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/git2')
-rw-r--r--src/git2/blob.h97
-rw-r--r--src/git2/commit.h150
-rw-r--r--src/git2/common.h125
-rw-r--r--src/git2/errors.h31
-rw-r--r--src/git2/index.h173
-rw-r--r--src/git2/object.h108
-rw-r--r--src/git2/odb.h160
-rw-r--r--src/git2/odb_backend.h40
-rw-r--r--src/git2/oid.h110
-rw-r--r--src/git2/repository.h143
-rw-r--r--src/git2/revwalk.h109
-rw-r--r--src/git2/tag.h116
-rw-r--r--src/git2/thread-utils.h56
-rw-r--r--src/git2/tree.h178
-rw-r--r--src/git2/types.h64
-rw-r--r--src/git2/zlib.h34
16 files changed, 1694 insertions, 0 deletions
diff --git a/src/git2/blob.h b/src/git2/blob.h
new file mode 100644
index 00000000..f94b1f96
--- /dev/null
+++ b/src/git2/blob.h
@@ -0,0 +1,97 @@
+#ifndef INCLUDE_git_blob_h__
+#define INCLUDE_git_blob_h__
+
+#include "common.h"
+#include "types.h"
+#include "oid.h"
+
+/**
+ * @file git/blob.h
+ * @brief Git blob load and write routines
+ * @defgroup git_blob Git blob load and write routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Lookup a blob object from a repository.
+ * The generated blob object is owned by the revision
+ * repo and shall not be freed by the user.
+ *
+ * @param blob pointer to the looked up blob
+ * @param repo the repo to use when locating the blob.
+ * @param id identity of the blob to locate.
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id);
+
+/**
+ * Create a new in-memory git_blob.
+ *
+ * The blob object must be manually filled using
+ * the 'set_rawcontent' methods before it can
+ * be written back to disk.
+ *
+ * @param blob pointer to the new blob
+ * @param repo The repository where the object will reside
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_blob_new(git_blob **blob, git_repository *repo);
+
+/**
+ * Fill a blob with the contents inside
+ * the pointed file.
+ *
+ * @param blob pointer to the new blob
+ * @param filename name of the file to read
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_blob_set_rawcontent_fromfile(git_blob *blob, const char *filename);
+
+/**
+ * Fill a blob with the contents inside
+ * the pointed buffer
+ *
+ * @param blob pointer to the blob
+ * @param buffer buffer with the contents for the blob
+ * @param len size of the buffer
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_blob_set_rawcontent(git_blob *blob, const void *buffer, size_t len);
+
+/**
+ * Get a read-only buffer with the raw content of a blob.
+ *
+ * A pointer to the raw content of a blob is returned;
+ * this pointer is owned internally by the object and shall
+ * not be free'd. The pointer may be invalidated at a later
+ * time (e.g. when changing the contents of the blob).
+ *
+ * @param blob pointer to the blob
+ * @return the pointer; NULL if the blob has no contents
+ */
+GIT_EXTERN(const char *) git_blob_rawcontent(git_blob *blob);
+
+/**
+ * Get the size in bytes of the contents of a blob
+ *
+ * @param blob pointer to the blob
+ * @return size on bytes
+ */
+GIT_EXTERN(int) git_blob_rawsize(git_blob *blob);
+
+/**
+ * Read a file from the working folder of a repository
+ * and write it to the Object Database as a loose blob,
+ * if such doesn't exist yet.
+ *
+ * @param written_id return the id of the written blob
+ * @param repo repository where the blob will be written
+ * @param path file from which the blob will be created
+ */
+GIT_EXTERN(int) git_blob_writefile(git_oid *written_id, git_repository *repo, const char *path);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/commit.h b/src/git2/commit.h
new file mode 100644
index 00000000..54ecb622
--- /dev/null
+++ b/src/git2/commit.h
@@ -0,0 +1,150 @@
+#ifndef INCLUDE_git_commit_h__
+#define INCLUDE_git_commit_h__
+
+#include "common.h"
+#include "types.h"
+#include "oid.h"
+
+/**
+ * @file git/commit.h
+ * @brief Git commit parsing, formatting routines
+ * @defgroup git_commit Git commit parsing, formatting routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Lookup a commit object from a repository.
+ * The generated commit object is owned by the revision
+ * repo and shall not be freed by the user.
+ *
+ * @param commit pointer to the looked up commit
+ * @param repo the repo to use when locating the commit.
+ * @param id identity of the commit to locate. If the object is
+ * an annotated tag it will be peeled back to the commit.
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id);
+
+/**
+ * Create a new in-memory git_commit.
+ *
+ * The commit object must be manually filled using
+ * setter methods before it can be written to its
+ * repository.
+ *
+ * @param commit pointer to the new commit
+ * @param repo The repository where the object will reside
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_commit_new(git_commit ** commit, git_repository *repo);
+
+/**
+ * Get the id of a commit.
+ * @param commit a previously loaded commit.
+ * @return object identity for the commit.
+ */
+GIT_EXTERN(const git_oid *) git_commit_id(git_commit *commit);
+
+/**
+ * Get the short (one line) message of a commit.
+ * @param commit a previously loaded commit.
+ * @return the short message of a commit
+ */
+GIT_EXTERN(const char *) git_commit_message_short(git_commit *commit);
+
+/**
+ * Get the full message of a commit.
+ * @param commit a previously loaded commit.
+ * @return the message of a commit
+ */
+GIT_EXTERN(const char *) git_commit_message(git_commit *commit);
+
+/**
+ * Get the commit time (i.e. committer time) of a commit.
+ * @param commit a previously loaded commit.
+ * @return the time of a commit
+ */
+GIT_EXTERN(time_t) git_commit_time(git_commit *commit);
+
+/**
+ * Get the committer of a commit.
+ * @param commit a previously loaded commit.
+ * @return the committer of a commit
+ */
+GIT_EXTERN(const git_person *) git_commit_committer(git_commit *commit);
+
+/**
+ * Get the author of a commit.
+ * @param commit a previously loaded commit.
+ * @return the author of a commit
+ */
+GIT_EXTERN(const git_person *) git_commit_author(git_commit *commit);
+
+/**
+ * Get the tree pointed to by a commit.
+ * @param commit a previously loaded commit.
+ * @return the tree of a commit
+ */
+GIT_EXTERN(const git_tree *) git_commit_tree(git_commit *commit);
+
+/**
+ * Get the number of parents of this commit
+ *
+ * @param commit a previously loaded commit.
+ * @return integer of count of parents
+ */
+GIT_EXTERN(unsigned int) git_commit_parentcount(git_commit *commit);
+
+/**
+ * Get the specified parent of the commit.
+ * @param commit a previously loaded commit.
+ * @param n the position of the entry
+ * @return a pointer to the commit; NULL if out of bounds
+ */
+GIT_EXTERN(git_commit *) git_commit_parent(git_commit *commit, unsigned int n);
+
+/**
+ * Add a new parent commit to an existing commit
+ * @param commit the commit object
+ * @param new_parent the new commit which will be a parent
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_commit_add_parent(git_commit *commit, git_commit *new_parent);
+
+/**
+ * Set the message of a commit
+ * @param commit the commit object
+ * @param message the new message
+ */
+GIT_EXTERN(void) git_commit_set_message(git_commit *commit, const char *message);
+
+/**
+ * Set the committer of a commit
+ * @param commit the commit object
+ * @param name name of the new committer
+ * @param email email of the new committer
+ * @param time time when the committer committed the commit
+ */
+GIT_EXTERN(void) git_commit_set_committer(git_commit *commit, const char *name, const char *email, time_t time);
+
+/**
+ * Set the author of a commit
+ * @param commit the commit object
+ * @param name name of the new author
+ * @param email email of the new author
+ * @param time time when the author created the commit
+ */
+GIT_EXTERN(void) git_commit_set_author(git_commit *commit, const char *name, const char *email, time_t time);
+
+/**
+ * Set the tree which is pointed to by a commit
+ * @param commit the commit object
+ * @param tree the new tree
+ */
+GIT_EXTERN(void) git_commit_set_tree(git_commit *commit, git_tree *tree);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/common.h b/src/git2/common.h
new file mode 100644
index 00000000..0a7de41e
--- /dev/null
+++ b/src/git2/common.h
@@ -0,0 +1,125 @@
+#ifndef INCLUDE_git_common_h__
+#define INCLUDE_git_common_h__
+
+#include "thread-utils.h"
+#include <time.h>
+
+#ifdef __cplusplus
+# define GIT_BEGIN_DECL extern "C" {
+# define GIT_END_DECL }
+#else
+ /** Start declarations in C mode */
+# define GIT_BEGIN_DECL /* empty */
+ /** End declarations in C mode */
+# define GIT_END_DECL /* empty */
+#endif
+
+/** Declare a public function exported for application use. */
+#ifdef __GNUC__
+# define GIT_EXTERN(type) extern \
+ __attribute__((visibility("default"))) \
+ type
+#elif defined(_MSC_VER)
+# define GIT_EXTERN(type) __declspec(dllexport) type
+#else
+# define GIT_EXTERN(type) extern type
+#endif
+
+/** Declare a public TLS symbol exported for application use. */
+#ifdef __GNUC__
+# define GIT_EXTERN_TLS(type) extern \
+ __attribute__((visibility("default"))) \
+ 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
+#else
+# define GIT_INLINE(type) static inline type
+#endif
+
+/** Declare a function's takes printf style arguments. */
+#ifdef __GNUC__
+# define GIT_FORMAT_PRINTF(a,b) __attribute__((format (printf, a, b)))
+#else
+# define GIT_FORMAT_PRINTF(a,b) /* empty */
+#endif
+
+/**
+ * @file git/common.h
+ * @brief Git common platform definitions
+ * @defgroup git_common Git common platform definitions
+ * @ingroup Git
+ * @{
+ */
+
+/** Operation completed successfully. */
+#define GIT_SUCCESS 0
+
+/**
+ * Operation failed, with unspecified reason.
+ * This value also serves as the base error code; all other
+ * error codes are subtracted from it such that all errors
+ * are < 0, in typical POSIX C tradition.
+ */
+#define GIT_ERROR -1
+
+/** Input was not a properly formatted Git object id. */
+#define GIT_ENOTOID (GIT_ERROR - 1)
+
+/** Input does not exist in the scope searched. */
+#define GIT_ENOTFOUND (GIT_ERROR - 2)
+
+/** Not enough space available. */
+#define GIT_ENOMEM (GIT_ERROR - 3)
+
+/** Consult the OS error information. */
+#define GIT_EOSERR (GIT_ERROR - 4)
+
+/** The specified object is of invalid type */
+#define GIT_EOBJTYPE (GIT_ERROR - 5)
+
+/** The specified object has its data corrupted */
+#define GIT_EOBJCORRUPTED (GIT_ERROR - 6)
+
+/** The specified repository is invalid */
+#define GIT_ENOTAREPO (GIT_ERROR - 7)
+
+/** The object type is invalid or doesn't match */
+#define GIT_EINVALIDTYPE (GIT_ERROR - 8)
+
+/** The object cannot be written that because it's missing internal data */
+#define GIT_EMISSINGOBJDATA (GIT_ERROR - 9)
+
+/** The packfile for the ODB is corrupted */
+#define GIT_EPACKCORRUPTED (GIT_ERROR - 10)
+
+/** Failed to adquire or release a file lock */
+#define GIT_EFLOCKFAIL (GIT_ERROR - 11)
+
+/** The Z library failed to inflate/deflate an object's data */
+#define GIT_EZLIB (GIT_ERROR - 12)
+
+/** The queried object is currently busy */
+#define GIT_EBUSY (GIT_ERROR - 13)
+
+/** The index file is not backed up by an existing repository */
+#define GIT_EBAREINDEX (GIT_ERROR -14)
+
+
+GIT_BEGIN_DECL
+
+/** Parsed representation of a person */
+typedef struct git_person git_person;
+
+const char *git_person_name(git_person *person);
+const char *git_person_email(git_person *person);
+time_t git_person_time(git_person *person);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/errors.h b/src/git2/errors.h
new file mode 100644
index 00000000..f4720beb
--- /dev/null
+++ b/src/git2/errors.h
@@ -0,0 +1,31 @@
+#ifndef INCLUDE_git_errors_h__
+#define INCLUDE_git_errors_h__
+
+/**
+ * @file git/errors.h
+ * @brief Git error handling routines and variables
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/** The git errno. */
+#if defined(GIT_TLS)
+GIT_EXTERN_TLS(int) git_errno;
+
+#elif defined(GIT_HAS_PTHREAD)
+# define git_errno (*git__errno_storage())
+GIT_EXTERN(int *) git__errno_storage(void);
+
+#endif
+
+/**
+ * strerror() for the Git library
+ * @param num The error code to explain
+ * @return a string explaining the error code
+ */
+GIT_EXTERN(const char *) git_strerror(int num);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/index.h b/src/git2/index.h
new file mode 100644
index 00000000..8bdced6a
--- /dev/null
+++ b/src/git2/index.h
@@ -0,0 +1,173 @@
+#ifndef INCLUDE_git_index_h__
+#define INCLUDE_git_index_h__
+
+#include "common.h"
+#include "types.h"
+
+/**
+ * @file git/index.h
+ * @brief Git index parsing and manipulation routines
+ * @defgroup git_index Git index parsing and manipulation routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+#define GIT_IDXENTRY_NAMEMASK (0x0fff)
+#define GIT_IDXENTRY_STAGEMASK (0x3000)
+#define GIT_IDXENTRY_EXTENDED (0x4000)
+#define GIT_IDXENTRY_VALID (0x8000)
+#define GIT_IDXENTRY_STAGESHIFT 12
+
+/** Time used in a git index entry */
+typedef struct {
+ unsigned int seconds;
+ unsigned int nanoseconds;
+} git_index_time;
+
+/** Memory representation of a file entry in the index. */
+typedef struct git_index_entry {
+ git_index_time ctime;
+ git_index_time mtime;
+
+ unsigned int dev;
+ unsigned int ino;
+ unsigned int mode;
+ unsigned int uid;
+ unsigned int gid;
+ unsigned int file_size;
+
+ git_oid oid;
+
+ unsigned short flags;
+ unsigned short flags_extended;
+
+ char *path;
+} git_index_entry;
+
+
+/**
+ * Create a new Git index object as a memory representation
+ * of the Git index file in 'index_path', without a repository
+ * to back it.
+ *
+ * Since there is no ODB behind this index, any Index methods
+ * which rely on the ODB (e.g. index_add) will fail with the
+ * GIT_EBAREINDEX error code.
+ *
+ * @param index the pointer for the new index
+ * @param index_path the path to the index file in disk
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_index_open_bare(git_index **index, const char *index_path);
+
+/**
+ * Open the Index inside the git repository pointed
+ * by 'repo'.
+ *
+ * @param repo the git repo which owns the index
+ * @param index_path the path to the index file in disk
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_index_open_inrepo(git_index **index, git_repository *repo);
+
+/**
+ * Clear the contents (all the entries) of an index object.
+ * This clears the index object in memory; changes must be manually
+ * written to disk for them to take effect.
+ *
+ * @param index an existing index object
+ */
+GIT_EXTERN(void) git_index_clear(git_index *index);
+
+/**
+ * Free an existing index object.
+ *
+ * @param index an existing index object
+ */
+GIT_EXTERN(void) git_index_free(git_index *index);
+
+/**
+ * Update the contents of an existing index object in memory
+ * by reading from the hard disk.
+ *
+ * @param index an existing index object
+ * @return 0 on success, otherwise an error code
+ */
+GIT_EXTERN(int) git_index_read(git_index *index);
+
+/**
+ * Write an existing index object from memory back to disk
+ * using an atomic file lock.
+ *
+ * @param index an existing index object
+ * @return 0 on success, otherwise an error code
+ */
+GIT_EXTERN(int) git_index_write(git_index *index);
+
+/**
+ * Find the first index of any entires which point to given
+ * path in the Git index.
+ *
+ * @param index an existing index object
+ * @param path path to search
+ * @return an index >= 0 if found, -1 otherwise
+ */
+GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
+
+/**
+ * Add or update an index entry from a file in disk.
+ *
+ * @param index an existing index object
+ * @param path filename to add
+ * @param stage stage for the entry
+ * @return 0 on success, otherwise an error code
+ */
+GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
+
+/**
+ * Remove an entry from the index
+ *
+ * @param index an existing index object
+ * @param position position of the entry to remove
+ * @return 0 on success, otherwise an error code
+ */
+GIT_EXTERN(int) git_index_remove(git_index *index, int position);
+
+/**
+ * Insert an entry into the index.
+ * A full copy (including the 'path' string) of the given
+ * 'source_entry' will be inserted on the index; if the index
+ * already contains an entry for the same path, the entry
+ * will be updated.
+ *
+ * @param index an existing index object
+ * @param source_entry new entry object
+ * @return 0 on success, otherwise an error code
+ */
+GIT_EXTERN(int) git_index_insert(git_index *index, const git_index_entry *source_entry);
+
+/**
+ * Get a pointer to one of the entries in the index
+ *
+ * This entry can be modified, and the changes will be written
+ * back to disk on the next write() call.
+ *
+ * @param index an existing index object
+ * @param n the position of the entry
+ * @return a pointer to the entry; NULL if out of bounds
+ */
+GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, int n);
+
+/**
+ * Get the count of entries currently in the index
+ *
+ * @param index an existing index object
+ * @return integer of count of current entries
+ */
+GIT_EXTERN(unsigned int) git_index_entrycount(git_index *index);
+
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/object.h b/src/git2/object.h
new file mode 100644
index 00000000..51659172
--- /dev/null
+++ b/src/git2/object.h
@@ -0,0 +1,108 @@
+#ifndef INCLUDE_git_object_h__
+#define INCLUDE_git_object_h__
+
+#include "common.h"
+#include "types.h"
+#include "oid.h"
+
+/**
+ * @file git/object.h
+ * @brief Git revision object management routines
+ * @defgroup git_object Git revision object management routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Write back an object to disk.
+ *
+ * The object will be written to its corresponding
+ * repository.
+ *
+ * If the object has no changes since it was first
+ * read from the repository, no actions will take place.
+ *
+ * If the object has been modified since it was read from
+ * the repository, or it has been created from scratch
+ * in memory, it will be written to the repository and
+ * its SHA1 ID will be updated accordingly.
+ *
+ * @param object Git object to write back
+ * @return 0 on success; otherwise an error code
+ */
+GIT_EXTERN(int) git_object_write(git_object *object);
+
+/**
+ * Get the id (SHA1) of a repository object
+ *
+ * In-memory objects created by git_object_new() do not
+ * have a SHA1 ID until they are written on a repository.
+ *
+ * @param obj the repository object
+ * @return the SHA1 id
+ */
+GIT_EXTERN(const git_oid *) git_object_id(git_object *obj);
+
+/**
+ * Get the object type of an object
+ *
+ * @param obj the repository object
+ * @return the object's type
+ */
+GIT_EXTERN(git_otype) git_object_type(git_object *obj);
+
+/**
+ * Get the repository that owns this object
+ *
+ * @param obj the object
+ * @return the repository who owns this object
+ */
+GIT_EXTERN(git_repository *) git_object_owner(git_object *obj);
+
+/**
+ * Free a reference to one of the objects in the repository.
+ *
+ * Repository objects are managed automatically by the library,
+ * but this method can be used to force freeing one of the
+ * objects.
+ *
+ * Careful: freeing objects in the middle of a repository
+ * traversal will most likely cause errors.
+ *
+ * @param object the object to free
+ */
+GIT_EXTERN(void) git_object_free(git_object *object);
+
+/**
+ * Convert an object type to it's string representation.
+ *
+ * The result is a pointer to a string in static memory and
+ * should not be free()'ed.
+ *
+ * @param type object type to convert.
+ * @return the corresponding string representation.
+ */
+GIT_EXTERN(const char *) git_object_type2string(git_otype type);
+
+/**
+ * Convert a string object type representation to it's git_otype.
+ *
+ * @param str the string to convert.
+ * @return the corresponding git_otype.
+ */
+GIT_EXTERN(git_otype) git_object_string2type(const char *str);
+
+/**
+ * Determine if the given git_otype is a valid loose object type.
+ *
+ * @param type object type to test.
+ * @return true if the type represents a valid loose object type,
+ * false otherwise.
+ */
+GIT_EXTERN(int) git_object_typeisloose(git_otype type);
+
+/** @} */
+GIT_END_DECL
+
+#endif
diff --git a/src/git2/odb.h b/src/git2/odb.h
new file mode 100644
index 00000000..6be6ea2c
--- /dev/null
+++ b/src/git2/odb.h
@@ -0,0 +1,160 @@
+#ifndef INCLUDE_git_odb_h__
+#define INCLUDE_git_odb_h__
+
+#include "common.h"
+#include "types.h"
+#include "oid.h"
+
+/**
+ * @file git/odb.h
+ * @brief Git object database routines
+ * @defgroup git_odb Git object database routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Create a new object database with no backends.
+ *
+ * Before the ODB can be used for read/writing, a custom database
+ * backend must be manually added using `git_odb_add_backend()`
+ *
+ * @param out location to store the database pointer, if opened.
+ * Set to NULL if the open failed.
+ * @return GIT_SUCCESS if the database was created; otherwise an error
+ * code describing why the open was not possible.
+ */
+GIT_EXTERN(int) git_odb_new(git_odb **out);
+
+/**
+ * Create a new object database and automatically add
+ * the two default backends:
+ *
+ * - git_odb_backend_loose: read and write loose object files
+ * from disk, assuming `objects_dir` as the Objects folder
+ *
+ * - git_odb_backend_pack: read objects from packfiles,
+ * assuming `objects_dir` as the Objects folder which
+ * contains a 'pack/' folder with the corresponding data
+ *
+ * @param out location to store the database pointer, if opened.
+ * Set to NULL if the open failed.
+ * @param objects_dir path of the backends' "objects" directory.
+ * @return GIT_SUCCESS if the database opened; otherwise an error
+ * code describing why the open was not possible.
+ */
+GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
+
+/**
+ * Add a custom backend to an existing Object DB
+ *
+ * Read <odb_backends.h> for more information.
+ *
+ * @param odb database to add the backend to
+ * @paramm backend pointer to a git_odb_backend instance
+ * @return 0 on sucess; error code otherwise
+ */
+GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend);
+
+/**
+ * Close an open object database.
+ * @param db database pointer to close. If NULL no action is taken.
+ */
+GIT_EXTERN(void) git_odb_close(git_odb *db);
+
+/** An object read from the database. */
+typedef struct {
+ void *data; /**< Raw, decompressed object data. */
+ size_t len; /**< Total number of bytes in data. */
+ git_otype type; /**< Type of this object. */
+} git_rawobj;
+
+/**
+ * Read an object from the database.
+ *
+ * If GIT_ENOTFOUND then out->data is set to NULL.
+ *
+ * @param out object descriptor to populate upon reading.
+ * @param db database to search for the object in.
+ * @param id identity of the object to read.
+ * @return
+ * - GIT_SUCCESS if the object was read;
+ * - GIT_ENOTFOUND if the object is not in the database.
+ */
+GIT_EXTERN(int) git_odb_read(git_rawobj *out, git_odb *db, const git_oid *id);
+
+/**
+ * Read the header of an object from the database, without
+ * reading its full contents.
+ *
+ * Only the 'type' and 'len' fields of the git_rawobj structure
+ * are filled. The 'data' pointer will always be NULL.
+ *
+ * The raw object pointed by 'out' doesn't need to be manually
+ * closed with git_rawobj_close().
+ *
+ * @param out object descriptor to populate upon reading.
+ * @param db database to search for the object in.
+ * @param id identity of the object to read.
+ * @return
+ * - GIT_SUCCESS if the object was read;
+ * - GIT_ENOTFOUND if the object is not in the database.
+ */
+GIT_EXTERN(int) git_odb_read_header(git_rawobj *out, git_odb *db, const git_oid *id);
+
+/**
+ * Write an object to the database.
+ *
+ * @param id identity of the object written.
+ * @param db database to which the object should be written.
+ * @param obj object descriptor for the object to write.
+ * @return
+ * - GIT_SUCCESS if the object was written;
+ * - GIT_ERROR otherwise.
+ */
+GIT_EXTERN(int) git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj);
+
+/**
+ * Determine if the given object can be found in the object database.
+ *
+ * @param db database to be searched for the given object.
+ * @param id the object to search for.
+ * @return
+ * - true, if the object was found
+ * - false, otherwise
+ */
+GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
+
+
+
+
+
+/**
+ * Determine the object-ID (sha1 hash) of the given git_rawobj.
+ *
+ * The input obj must be a valid loose object type and the data
+ * pointer must not be NULL, unless the len field is also zero.
+ *
+ * @param id the resulting object-ID.
+ * @param obj the object whose hash is to be determined.
+ * @return
+ * - GIT_SUCCESS if the object-ID was correctly determined.
+ * - GIT_ERROR if the given object is malformed.
+ */
+GIT_EXTERN(int) git_rawobj_hash(git_oid *id, git_rawobj *obj);
+
+/**
+ * Release all memory used by the obj structure.
+ *
+ * As a result of this call, obj->data will be set to NULL.
+ *
+ * If obj->data is already NULL, nothing happens.
+ *
+ * @param obj object descriptor to free.
+ */
+GIT_EXTERN(void) git_rawobj_close(git_rawobj *obj);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/odb_backend.h b/src/git2/odb_backend.h
new file mode 100644
index 00000000..747f4e97
--- /dev/null
+++ b/src/git2/odb_backend.h
@@ -0,0 +1,40 @@
+#ifndef INCLUDE_git_odb_backend_h__
+#define INCLUDE_git_odb_backend_h__
+
+#include "common.h"
+#include "types.h"
+#include "oid.h"
+
+GIT_BEGIN_DECL
+
+struct git_odb_backend {
+ git_odb *odb;
+
+ int priority;
+
+ int (* read)(
+ git_rawobj *,
+ struct git_odb_backend *,
+ const git_oid *);
+
+ int (* read_header)(
+ git_rawobj *,
+ struct git_odb_backend *,
+ const git_oid *);
+
+ int (* write)(
+ git_oid *id,
+ struct git_odb_backend *,
+ git_rawobj *obj);
+
+ int (* exists)(
+ struct git_odb_backend *,
+ const git_oid *);
+
+ void (* free)(struct git_odb_backend *);
+
+};
+
+GIT_END_DECL
+
+#endif
diff --git a/src/git2/oid.h b/src/git2/oid.h
new file mode 100644
index 00000000..f0e39da6
--- /dev/null
+++ b/src/git2/oid.h
@@ -0,0 +1,110 @@
+#ifndef INCLUDE_git_oid_h__
+#define INCLUDE_git_oid_h__
+
+/**
+ * @file git/oid.h
+ * @brief Git object id routines
+ * @defgroup git_oid Git object id routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/** Size (in bytes) of a raw/binary oid */
+#define GIT_OID_RAWSZ 20
+
+/** Size (in bytes) of a hex formatted oid */
+#define GIT_OID_HEXSZ (GIT_OID_RAWSZ * 2)
+
+/** Unique identity of any object (commit, tree, blob, tag). */
+typedef struct {
+ /** raw binary formatted id */
+ unsigned char id[GIT_OID_RAWSZ];
+} git_oid;
+
+/**
+ * Parse a hex formatted object id into a git_oid.
+ * @param out oid structure the result is written into.
+ * @param str input hex string; must be pointing at the start of
+ * the hex sequence and have at least the number of bytes
+ * needed for an oid encoded in hex (40 bytes).
+ * @return GIT_SUCCESS if valid; GIT_ENOTOID on failure.
+ */
+GIT_EXTERN(int) git_oid_mkstr(git_oid *out, const char *str);
+
+/**
+ * Copy an already raw oid into a git_oid structure.
+ * @param out oid structure the result is written into.
+ * @param raw the raw input bytes to be copied.
+ */
+GIT_EXTERN(void) git_oid_mkraw(git_oid *out, const unsigned char *raw);
+
+/**
+ * Format a git_oid into a hex string.
+ * @param str output hex string; must be pointing at the start of
+ * the hex sequence and have at least the number of bytes
+ * needed for an oid encoded in hex (40 bytes). Only the
+ * oid digits are written; a '\\0' terminator must be added
+ * by the caller if it is required.
+ * @param oid oid structure to format.
+ */
+GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid);
+
+/**
+ * Format a git_oid into a loose-object path string.
+ * <p>
+ * The resulting string is "aa/...", where "aa" is the first two
+ * hex digitis of the oid and "..." is the remaining 38 digits.
+ *
+ * @param str output hex string; must be pointing at the start of
+ * the hex sequence and have at least the number of bytes
+ * needed for an oid encoded in hex (41 bytes). Only the
+ * oid digits are written; a '\\0' terminator must be added
+ * by the caller if it is required.
+ * @param oid oid structure to format.
+ */
+GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
+
+/**
+ * Format a gid_oid into a newly allocated c-string.
+ * @param oid the oid structure to format
+ * @return the c-string; NULL if memory is exhausted. Caller must
+ * deallocate the string with free().
+ */
+GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
+
+/**
+ * Format a git_oid into a buffer as a hex format c-string.
+ * <p>
+ * If the buffer is smaller than GIT_OID_HEXSZ+1, then the resulting
+ * oid c-string will be truncated to n-1 characters. If there are
+ * any input parameter errors (out == NULL, n == 0, oid == NULL),
+ * then a pointer to an empty string is returned, so that the return
+ * value can always be printed.
+ *
+ * @param out the buffer into which the oid string is output.
+ * @param n the size of the out buffer.
+ * @param oid the oid structure to format.
+ * @return the out buffer pointer, assuming no input parameter
+ * errors, otherwise a pointer to an empty string.
+ */
+GIT_EXTERN(char *) git_oid_to_string(char *out, size_t n, const git_oid *oid);
+
+/**
+ * Copy an oid from one structure to another.
+ * @param out oid structure the result is written into.
+ * @param src oid structure to copy from.
+ */
+GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src);
+
+/**
+ * Compare two oid structures.
+ * @param a first oid structure.
+ * @param b second oid structure.
+ * @return <0, 0, >0 if a < b, a == b, a > b.
+ */
+GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/repository.h b/src/git2/repository.h
new file mode 100644
index 00000000..683e78fc
--- /dev/null
+++ b/src/git2/repository.h
@@ -0,0 +1,143 @@
+#ifndef INCLUDE_git_repository_h__
+#define INCLUDE_git_repository_h__
+
+#include "common.h"
+#include "types.h"
+#include "oid.h"
+
+/**
+ * @file git/repository.h
+ * @brief Git repository management routines
+ * @defgroup git_repository Git repository management routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Open a git repository.
+ *
+ * The 'path' argument must point to an existing git repository
+ * folder, e.g.
+ *
+ * /path/to/my_repo/.git/ (normal repository)
+ * objects/
+ * index
+ * HEAD
+ *
+ * /path/to/bare_repo/ (bare repository)
+ * objects/
+ * index
+ * HEAD
+ *
+ * The method will automatically detect if 'path' is a normal
+ * or bare repository or fail is 'path' is neither.
+ *
+ * @param repository pointer to the repo which will be opened
+ * @param path the path to the repository
+ * @return 0 on sucess; error code otherwise
+ */
+GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *path);
+
+
+/**
+ * Open a git repository by manually specifying all its paths
+ *
+ * @param repository pointer to the repo which will be opened
+ *
+ * @param git_dir The full path to the repository folder
+ * e.g. a '.git' folder for live repos, any folder for bare
+ * Equivalent to $GIT_DIR.
+ * Cannot be NULL.
+ *
+ * @param git_object_directory The full path to the ODB folder.
+ * the folder where all the loose and packed objects are stored
+ * Equivalent to $GIT_OBJECT_DIRECTORY.
+ * If NULL, "$GIT_DIR/objects/" is assumed.
+ *
+ * @param git_index_file The full path to the index (dircache) file
+ * Equivalent to $GIT_INDEX_FILE.
+ * If NULL, "$GIT_DIR/index" is assumed.
+ *
+ * @param git_work_tree The full path to the working tree of the repository,
+ * if the repository is not bare.
+ * Equivalent to $GIT_WORK_TREE.
+ * If NULL, the repository is assumed to be bare.
+ *
+ * @return 0 on sucess; error code otherwise
+ */
+GIT_EXTERN(int) git_repository_open2(git_repository **repository,
+ const char *git_dir,
+ const char *git_object_directory,
+ const char *git_index_file,
+ const char *git_work_tree);
+
+
+/**
+ * Lookup a reference to one of the objects in the repostory.
+ *
+ * The generated reference is owned by the repository and
+ * should not be freed by the user.
+ *
+ * The 'type' parameter must match the type of the object
+ * in the odb; the method will fail otherwise.
+ * The special value 'GIT_OBJ_ANY' may be passed to let
+ * the method guess the object's type.
+ *
+ * @param object pointer to the looked-up object
+ * @param repo the repository to look up the object
+ * @param id the unique identifier for the object
+ * @param type the type of the object
+ * @return a reference to the object
+ */
+GIT_EXTERN(int) git_repository_lookup(git_object **object, git_repository *repo, const git_oid *id, git_otype type);
+
+/**
+ * Get the object database behind a Git repository
+ *
+ * @param repo a repository object
+ * @return a pointer to the object db
+ */
+GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo);
+
+/**
+ * Get the Index file of a Git repository
+ *
+ * @param repo a repository object
+ * @return a pointer to the Index object;
+ * NULL if the index cannot be opened
+ */
+GIT_EXTERN(git_index *) git_repository_index(git_repository *rpeo);
+
+/**
+ * Create a new in-memory repository object with
+ * the given type.
+ *
+ * The object's attributes can be filled in using the
+ * corresponding setter methods.
+ *
+ * The object will be written back to given git_repository
+ * when the git_object_write() function is called; objects
+ * cannot be written to disk until all their main
+ * attributes have been properly filled.
+ *
+ * Objects are instantiated with no SHA1 id; their id
+ * will be automatically generated when writing to the
+ * repository.
+ *
+ * @param object pointer to the new object
+ * @parem repo Repository where the object belongs
+ * @param type Type of the object to be created
+ * @return the new object
+ */
+GIT_EXTERN(int) git_repository_newobject(git_object **object, git_repository *repo, git_otype type);
+
+/**
+ * Free a previously allocated repository
+ * @param repo repository handle to close. If NULL nothing occurs.
+ */
+GIT_EXTERN(void) git_repository_free(git_repository *repo);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/revwalk.h b/src/git2/revwalk.h
new file mode 100644
index 00000000..6a761088
--- /dev/null
+++ b/src/git2/revwalk.h
@@ -0,0 +1,109 @@
+#ifndef INCLUDE_git_revwalk_h__
+#define INCLUDE_git_revwalk_h__
+
+#include "common.h"
+#include "types.h"
+
+/**
+ * @file git/revwalk.h
+ * @brief Git revision traversal routines
+ * @defgroup git_revwalk Git revision traversal routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Sort the repository contents in no particular ordering;
+ * this sorting is arbitrary, implementation-specific
+ * and subject to change at any time.
+ * This is the default sorting for new walkers.
+ */
+#define GIT_SORT_NONE (0)
+
+/**
+ * Sort the repository contents in topological order
+ * (parents before children); this sorting mode
+ * can be combined with time sorting.
+ */
+#define GIT_SORT_TOPOLOGICAL (1 << 0)
+
+/**
+ * Sort the repository contents by commit time;
+ * this sorting mode can be combined with
+ * topological sorting.
+ */
+#define GIT_SORT_TIME (1 << 1)
+
+/**
+ * Iterate through the repository contents in reverse
+ * order; this sorting mode can be combined with
+ * any of the above.
+ */
+#define GIT_SORT_REVERSE (1 << 2)
+
+/**
+ * Allocate a new revision walker to iterate through a repo.
+ *
+ * @param walker pointer to the new revision walker
+ * @param repo the repo to walk through
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_revwalk_new(git_revwalk **walker, git_repository *repo);
+
+/**
+ * Reset the walking machinery for reuse.
+ * @param walker handle to reset.
+ */
+GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker);
+
+/**
+ * Mark a commit to start traversal from.
+ * The commit object must belong to the repo which is being walked through.
+ *
+ * @param walker the walker being used for the traversal.
+ * @param commit the commit to start from.
+ */
+GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, git_commit *commit);
+
+/**
+ * Mark a commit (and its ancestors) uninteresting for the output.
+ * @param walker the walker being used for the traversal.
+ * @param commit the commit that will be ignored during the traversal
+ */
+GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, git_commit *commit);
+
+/**
+ * Get the next commit from the revision traversal.
+ * @param walk the walker to pop the commit from.
+ * @return next commit; NULL if there is no more output.
+ */
+GIT_EXTERN(git_commit *) git_revwalk_next(git_revwalk *walk);
+
+/**
+ * Change the sorting mode when iterating through the
+ * repository's contents.
+ * Changing the sorting mode resets the walker.
+ * @param walk the walker being used for the traversal.
+ * @param sort_mode combination of GIT_RPSORT_XXX flags
+ */
+GIT_EXTERN(int) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
+
+/**
+ * Free a revwalk previously allocated.
+ * @param walk traversal handle to close. If NULL nothing occurs.
+ */
+GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
+
+/**
+ * Return the repository on which this walker
+ * is operating.
+ *
+ * @param walk the revision walker
+ * @return the repository being walked
+ */
+GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/tag.h b/src/git2/tag.h
new file mode 100644
index 00000000..d5700987
--- /dev/null
+++ b/src/git2/tag.h
@@ -0,0 +1,116 @@
+#ifndef INCLUDE_git_tag_h__
+#define INCLUDE_git_tag_h__
+
+#include "common.h"
+#include "types.h"
+#include "oid.h"
+
+/**
+ * @file git/tag.h
+ * @brief Git tag parsing routines
+ * @defgroup git_tag Git tag management
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Lookup a tag object from the repository.
+ * The generated tag object is owned by the revision
+ * repo and shall not be freed by the user.
+ *
+ * @param tag pointer to the looked up tag
+ * @param repo the repo to use when locating the tag.
+ * @param id identity of the tag to locate.
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oid *id);
+
+/**
+ * Create a new in-memory git_tag.
+ *
+ * The tag object must be manually filled using
+ * setter methods before it can be written to its
+ * repository.
+ *
+ * @param tag pointer to the new tag
+ * @param repo The repository where the object will reside
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_tag_new(git_tag **tag, git_repository *repo);
+
+/**
+ * Get the id of a tag.
+ * @param tag a previously loaded tag.
+ * @return object identity for the tag.
+ */
+GIT_EXTERN(const git_oid *) git_tag_id(git_tag *tag);
+
+/**
+ * Get the tagged object of a tag
+ * @param tag a previously loaded tag.
+ * @return reference to a repository object
+ */
+GIT_EXTERN(const git_object *) git_tag_target(git_tag *t);
+
+/**
+ * Get the type of a tag's tagged object
+ * @param tag a previously loaded tag.
+ * @return type of the tagged object
+ */
+GIT_EXTERN(git_otype) git_tag_type(git_tag *t);
+
+/**
+ * Get the name of a tag
+ * @param tag a previously loaded tag.
+ * @return name of the tag
+ */
+GIT_EXTERN(const char *) git_tag_name(git_tag *t);
+
+/**
+ * Get the tagger (author) of a tag
+ * @param tag a previously loaded tag.
+ * @return reference to the tag's author
+ */
+GIT_EXTERN(const git_person *) git_tag_tagger(git_tag *t);
+
+/**
+ * Get the message of a tag
+ * @param tag a previously loaded tag.
+ * @return message of the tag
+ */
+GIT_EXTERN(const char *) git_tag_message(git_tag *t);
+
+/**
+ * Set the target of a tag (i.e. the object that the tag points to)
+ * @param tag The tag to modify
+ * @param target the new tagged target
+ */
+GIT_EXTERN(void) git_tag_set_target(git_tag *tag, git_object *target);
+
+/**
+ * Set the name of a tag
+ * @param tag The tag to modify
+ * @param name the new name for the tag
+ */
+GIT_EXTERN(void) git_tag_set_name(git_tag *tag, const char *name);
+
+/**
+ * Set the tagger of a tag
+ * @param tag The tag to modify
+ * @param name the name of the new tagger
+ * @param email the email of the new tagger
+ * @param time the time when the tag was created
+ */
+GIT_EXTERN(void) git_tag_set_tagger(git_tag *tag, const char *name, const char *email, time_t time);
+
+/**
+ * Set the message of a tag
+ * @param tag The tag to modify
+ * @param message the new tagger for the tag
+ */
+GIT_EXTERN(void) git_tag_set_message(git_tag *tag, const char *message);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/thread-utils.h b/src/git2/thread-utils.h
new file mode 100644
index 00000000..241514f3
--- /dev/null
+++ b/src/git2/thread-utils.h
@@ -0,0 +1,56 @@
+#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
+ */
+
+#define GIT_HAS_TLS 1
+#define GIT_HAS_PTHREAD 1
+
+#if defined(__APPLE__) && defined(__MACH__)
+# undef GIT_TLS
+
+#elif defined(__GNUC__) || \
+ defined(__SUNPRO_C) || \
+ defined(__SUNPRO_CC) || \
+ defined(__xlc__) || \
+ defined(__xlC__)
+# define GIT_TLS __thread
+
+#elif defined(__INTEL_COMPILER)
+# if defined(_WIN32) || defined(_WIN32_CE)
+# define GIT_TLS __declspec(thread)
+# undef GIT_HAS_PTHREAD
+# else
+# define GIT_TLS __thread
+# endif
+
+#elif defined(_WIN32) || \
+ defined(_WIN32_CE) || \
+ defined(__BORLANDC__)
+# define GIT_TLS __declspec(thread)
+# undef GIT_HAS_PTHREAD
+
+#else
+# undef GIT_HAS_TLS
+# undef GIT_HAS_PTHREAD
+# define GIT_TLS /* nothing: tls vars are thread-global */
+#endif
+
+/* sparse and cygwin don't grok thread-local variables */
+#if defined(__CHECKER__) || defined(__CYGWIN__)
+# undef GIT_HAS_TLS
+# undef GIT_TLS
+# define GIT_TLS
+#endif
+
+#ifdef GIT_HAS_PTHREAD
+# define GIT_THREADS 1
+#else
+# undef GIT_THREADS
+#endif
+
+#endif /* INCLUDE_git_thread_utils_h__ */
diff --git a/src/git2/tree.h b/src/git2/tree.h
new file mode 100644
index 00000000..d935169d
--- /dev/null
+++ b/src/git2/tree.h
@@ -0,0 +1,178 @@
+#ifndef INCLUDE_git_tree_h__
+#define INCLUDE_git_tree_h__
+
+#include "common.h"
+#include "types.h"
+#include "oid.h"
+
+/**
+ * @file git/tree.h
+ * @brief Git tree parsing, loading routines
+ * @defgroup git_tree Git tree parsing, loading routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Lookup a tree object from the repository.
+ * The generated tree object is owned by the revision
+ * repo and shall not be freed by the user.
+ *
+ * @param tree pointer to the looked up tree
+ * @param repo the repo to use when locating the tree.
+ * @param id identity of the tree to locate.
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git_oid *id);
+
+/**
+ * Create a new in-memory git_tree.
+ *
+ * The tree object must be manually filled using
+ * setter methods before it can be written to its
+ * repository.
+ *
+ * @param tree pointer to the new tree
+ * @param repo The repository where the object will reside
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_tree_new(git_tree **tree, git_repository *repo);
+
+/**
+ * Get the id of a tree.
+ * @param tree a previously loaded tree.
+ * @return object identity for the tree.
+ */
+GIT_EXTERN(const git_oid *) git_tree_id(git_tree *tree);
+
+
+/**
+ * Get the number of entries listed in a tree
+ * @param tree a previously loaded tree.
+ * @return the number of entries in the tree
+ */
+GIT_EXTERN(size_t) git_tree_entrycount(git_tree *tree);
+
+/**
+ * Lookup a tree entry by its filename
+ * @param tree a previously loaded tree.
+ * @param filename the filename of the desired entry
+ * @return the tree entry; NULL if not found
+ */
+GIT_EXTERN(git_tree_entry *) git_tree_entry_byname(git_tree *tree, const char *filename);
+
+/**
+ * Lookup a tree entry by its position in the tree
+ * @param tree a previously loaded tree.
+ * @param idx the position in the entry list
+ * @return the tree entry; NULL if not found
+ */
+GIT_EXTERN(git_tree_entry *) git_tree_entry_byindex(git_tree *tree, int idx);
+
+/**
+ * Get the UNIX file attributes of a tree entry
+ * @param entry a tree entry
+ * @return attributes as an integer
+ */
+GIT_EXTERN(unsigned int) git_tree_entry_attributes(git_tree_entry *entry);
+
+/**
+ * Get the filename of a tree entry
+ * @param entry a tree entry
+ * @return the name of the file
+ */
+GIT_EXTERN(const char *) git_tree_entry_name(git_tree_entry *entry);
+
+/**
+ * Get the id of the object pointed by the entry
+ * @param entry a tree entry
+ * @return the oid of the object
+ */
+GIT_EXTERN(const git_oid *) git_tree_entry_id(git_tree_entry *entry);
+
+/**
+ * Convert a tree entry to the git_object it points too.
+ *
+ * @param object pointer to the converted object
+ * @param entry a tree entry
+ * @return a reference to the pointed object in the repository
+ */
+GIT_EXTERN(int) git_tree_entry_2object(git_object **object, git_tree_entry *entry);
+
+/**
+ * Add a new entry to a tree.
+ *
+ * This will mark the tree as modified; the new entry will
+ * be written back to disk on the next git_object_write()
+ *
+ * @param tree Tree object to store the entry
+ * @iparam id OID for the tree entry
+ * @param filename Filename for the tree entry
+ * @param attributes UNIX file attributes for the entry
+ * @return 0 on success; otherwise error code
+ */
+GIT_EXTERN(int) git_tree_add_entry(git_tree *tree, const git_oid *id, const char *filename, int attributes);
+
+/**
+ * Remove an entry by its index.
+ *
+ * Index must be >= 0 and < than git_tree_entrycount().
+ *
+ * This will mark the tree as modified; the modified entry will
+ * be written back to disk on the next git_object_write()
+ *
+ * @param tree Tree where to remove the entry
+ * @param idx index of the entry
+ * @return 0 on successful removal; GIT_ENOTFOUND if the entry wasn't found
+ */
+GIT_EXTERN(int) git_tree_remove_entry_byindex(git_tree *tree, int idx);
+
+/**
+ * Remove an entry by its filename.
+ *
+ * This will mark the tree as modified; the modified entry will
+ * be written back to disk on the next git_object_write()
+ *
+ * @param tree Tree where to remove the entry
+ * @param filename File name of the entry
+ * @return 0 on successful removal; GIT_ENOTFOUND if the entry wasn't found
+ */
+GIT_EXTERN(int) git_tree_remove_entry_byname(git_tree *tree, const char *filename);
+
+/**
+ * Change the SHA1 id of a tree entry.
+ *
+ * This will mark the tree that contains the entry as modified;
+ * the modified entry will be written back to disk on the next git_object_write()
+ *
+ * @param entry Entry object which will be modified
+ * @param oid new SHA1 oid for the entry
+ */
+GIT_EXTERN(void) git_tree_entry_set_id(git_tree_entry *entry, const git_oid *oid);
+
+/**
+ * Change the filename of a tree entry.
+ *
+ * This will mark the tree that contains the entry as modified;
+ * the modified entry will be written back to disk on the next git_object_write()
+ *
+ * @param entry Entry object which will be modified
+ * @param oid new filename for the entry
+ */
+GIT_EXTERN(void) git_tree_entry_set_name(git_tree_entry *entry, const char *name);
+
+/**
+ * Change the attributes of a tree entry.
+ *
+ * This will mark the tree that contains the entry as modified;
+ * the modified entry will be written back to disk on the next git_object_write()
+ *
+ * @param entry Entry object which will be modified
+ * @param oid new attributes for the entry
+ */
+GIT_EXTERN(void) git_tree_entry_set_attributes(git_tree_entry *entry, int attr);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git2/types.h b/src/git2/types.h
new file mode 100644
index 00000000..18684e13
--- /dev/null
+++ b/src/git2/types.h
@@ -0,0 +1,64 @@
+#ifndef INCLUDE_git_types_h__
+#define INCLUDE_git_types_h__
+
+/**
+ * @file git/types.h
+ * @brief libgit2 base types
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/** Basic type (loose or packed) of any Git object. */
+typedef enum {
+ GIT_OBJ_ANY = -2, /**< Object can be any of the following */
+ GIT_OBJ_BAD = -1, /**< Object is invalid. */
+ GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */
+ GIT_OBJ_COMMIT = 1, /**< A commit object. */
+ GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */
+ GIT_OBJ_BLOB = 3, /**< A file revision object. */
+ GIT_OBJ_TAG = 4, /**< An annotated tag object. */
+ GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */
+ GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */
+ GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */
+} git_otype;
+
+/** An open object database handle. */
+typedef struct git_odb git_odb;
+
+/** A custom backend in an ODB */
+typedef struct git_odb_backend git_odb_backend;
+
+/**
+ * Representation of an existing git repository,
+ * including all its object contents
+ */
+typedef struct git_repository git_repository;
+
+/** Representation of a generic object in a repository */
+typedef struct git_object git_object;
+
+typedef struct git_revwalk git_revwalk;
+
+/** Parsed representation of a tag object. */
+typedef struct git_tag git_tag;
+
+/** In-memory representation of a blob object. */
+typedef struct git_blob git_blob;
+
+/** Parsed representation of a commit object. */
+typedef struct git_commit git_commit;
+
+/** Representation of each one of the entries in a tree object. */
+typedef struct git_tree_entry git_tree_entry;
+
+/** Representation of a tree object. */
+typedef struct git_tree git_tree;
+
+/** Memory representation of an index file. */
+typedef struct git_index git_index;
+
+/** @} */
+GIT_END_DECL
+
+#endif
diff --git a/src/git2/zlib.h b/src/git2/zlib.h
new file mode 100644
index 00000000..b68db9bc
--- /dev/null
+++ b/src/git2/zlib.h
@@ -0,0 +1,34 @@
+#ifndef INCLUDE_git_zlib_h__
+#define INCLUDE_git_zlib_h__
+
+#include <zlib.h>
+
+/**
+ * @file git/zlib.h
+ * @brief Git data compression routines
+ * @defgroup git_zlib Git data compression routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
+/**
+ * deflateBound returns an upper bound on the compressed size.
+ *
+ * This is a stub function used when zlib does not supply the
+ * deflateBound() implementation itself.
+ *
+ * @param stream the stream pointer.
+ * @param s total length of the source data (in bytes).
+ * @return maximum length of the compressed data.
+ */
+GIT_INLINE(size_t) deflateBound(z_streamp stream, size_t s)
+{
+ return (s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11);
+}
+#endif
+
+/** @} */
+GIT_END_DECL
+#endif