summaryrefslogtreecommitdiff
path: root/include/git2
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-03-31 15:29:13 +0200
committerCarlos Martín Nieto <cmn@elego.de>2011-03-31 15:29:13 +0200
commitf026f2b9ee5f0aeced5c366c890c4a29eee2a1c7 (patch)
treec26b59992df7ebe645cb9485a4eb70c41e127816 /include/git2
parent11d0e70578baf47fb1cb565e0336e18d417e5da6 (diff)
parenta796d24cf697b0b51aa0ca7ef887e980f0d9fb7a (diff)
downloadlibgit2-f026f2b9ee5f0aeced5c366c890c4a29eee2a1c7.tar.gz
Merge upstream/development
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'include/git2')
-rw-r--r--include/git2/blob.h69
-rw-r--r--include/git2/commit.h176
-rw-r--r--include/git2/common.h21
-rw-r--r--include/git2/index.h4
-rw-r--r--include/git2/object.h67
-rw-r--r--include/git2/odb.h189
-rw-r--r--include/git2/odb_backend.h46
-rw-r--r--include/git2/refs.h102
-rw-r--r--include/git2/repository.h10
-rw-r--r--include/git2/revwalk.h73
-rw-r--r--include/git2/signature.h4
-rw-r--r--include/git2/tag.h114
-rw-r--r--include/git2/thread-utils.h10
-rw-r--r--include/git2/tree.h120
-rw-r--r--include/git2/types.h18
15 files changed, 665 insertions, 358 deletions
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 2b7154fb5..0e05d6f89 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -41,8 +41,6 @@ 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.
@@ -55,41 +53,22 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git
}
/**
- * Create a new in-memory git_blob.
+ * Close an open blob
*
- * The blob object must be manually filled using
- * the 'set_rawcontent' methods before it can
- * be written back to disk.
+ * This is a wrapper around git_object_close()
*
- * @param blob pointer to the new blob
- * @param repo The repository where the object will reside
- * @return 0 on success; error code otherwise
+ * IMPORTANT:
+ * It *is* necessary to call this method when you stop
+ * using a blob. Failure to do so will cause a memory leak.
+ *
+ * @param blob the blob to close
*/
-GIT_INLINE(int) git_blob_new(git_blob **blob, git_repository *repo)
+
+GIT_INLINE(void) git_blob_close(git_blob *blob)
{
- return git_object_new((git_object **)blob, repo, GIT_OBJ_BLOB);
+ git_object_close((git_object *) blob);
}
-/**
- * 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.
@@ -97,7 +76,7 @@ GIT_EXTERN(int) git_blob_set_rawcontent(git_blob *blob, const void *buffer, size
* 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).
+ * time.
*
* @param blob pointer to the blob
* @return the pointer; NULL if the blob has no contents
@@ -114,14 +93,28 @@ 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.
+ * and write it to the Object Database as a loose blob
+ *
+ * @param oid return the id of the written blob
+ * @param repo repository where the blob will be written.
+ * this repository cannot be bare
+ * @param path file from which the blob will be created,
+ * relative to the repository's working dir
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path);
+
+
+/**
+ * Write an in-memory buffer to the ODB as a blob
*
- * @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
+ * @param oid return the oid of the written blob
+ * @param repo repository where to blob will be written
+ * @param buffer data to be written into the blob
+ * @param len length of the data
+ * @return 0 on success; error code otherwise
*/
-GIT_EXTERN(int) git_blob_writefile(git_oid *written_id, git_repository *repo, const char *path);
+GIT_EXTERN(int) git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *buffer, size_t len);
/** @} */
GIT_END_DECL
diff --git a/include/git2/commit.h b/include/git2/commit.h
index 21836dbbd..c09b34843 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -41,8 +41,6 @@ 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.
@@ -56,23 +54,25 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con
}
/**
- * Create a new in-memory git_commit.
+ * Close an open commit
*
- * The commit object must be manually filled using
- * setter methods before it can be written to its
- * repository.
+ * This is a wrapper around git_object_close()
*
- * @param commit pointer to the new commit
- * @param repo The repository where the object will reside
- * @return 0 on success; error code otherwise
+ * IMPORTANT:
+ * It *is* necessary to call this method when you stop
+ * using a commit. Failure to do so will cause a memory leak.
+ *
+ * @param commit the commit to close
*/
-GIT_INLINE(int) git_commit_new(git_commit **commit, git_repository *repo)
+
+GIT_INLINE(void) git_commit_close(git_commit *commit)
{
- return git_object_new((git_object **)commit, repo, GIT_OBJ_COMMIT);
+ git_object_close((git_object *) commit);
}
/**
* Get the id of a commit.
+ *
* @param commit a previously loaded commit.
* @return object identity for the commit.
*/
@@ -80,6 +80,7 @@ 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
*/
@@ -87,6 +88,7 @@ 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
*/
@@ -94,13 +96,15 @@ 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);
+GIT_EXTERN(git_time_t) git_commit_time(git_commit *commit);
/**
* Get the commit timezone offset (i.e. committer's preferred timezone) of a commit.
+ *
* @param commit a previously loaded commit.
* @return positive or negative timezone offset, in minutes from UTC
*/
@@ -108,6 +112,7 @@ GIT_EXTERN(int) git_commit_time_offset(git_commit *commit);
/**
* Get the committer of a commit.
+ *
* @param commit a previously loaded commit.
* @return the committer of a commit
*/
@@ -115,6 +120,7 @@ GIT_EXTERN(const git_signature *) git_commit_committer(git_commit *commit);
/**
* Get the author of a commit.
+ *
* @param commit a previously loaded commit.
* @return the author of a commit
*/
@@ -122,10 +128,12 @@ GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit);
/**
* Get the tree pointed to by a commit.
+ *
+ * @param tree_out pointer where to store the tree object
* @param commit a previously loaded commit.
- * @return the tree of a commit
+ * @return 0 on success; error code otherwise
*/
-GIT_EXTERN(const git_tree *) git_commit_tree(git_commit *commit);
+GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, git_commit *commit);
/**
* Get the number of parents of this commit
@@ -137,47 +145,137 @@ GIT_EXTERN(unsigned int) git_commit_parentcount(git_commit *commit);
/**
* Get the specified parent of the commit.
+ *
+ * @param parent Pointer where to store the parent 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
+ * @param n the position of the parent (from 0 to `parentcount`)
+ * @return 0 on success; error code otherwise
*/
-GIT_EXTERN(git_commit *) git_commit_parent(git_commit *commit, unsigned int n);
+GIT_EXTERN(int) git_commit_parent(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
+ * Create a new commit in the repository
+ *
+ *
+ * @param oid Pointer where to store the OID of the
+ * newly created commit
+ *
+ * @param repo Repository where to store the commit
+ *
+ * @param update_ref If not NULL, name of the reference that
+ * will be updated to point to this commit. If the reference
+ * is not direct, it will be resolved to a direct reference.
+ * Use "HEAD" to update the HEAD of the current branch and
+ * make it point to this commit
+ *
+ * @param author Signature representing the author and the authory
+ * time of this commit
+ *
+ * @param committer Signature representing the committer and the
+ * commit time of this commit
+ *
+ * @param message Full message for this commit
+ *
+ * @param tree_oid Object ID of the tree for this commit. Note that
+ * no validation is performed on this OID. Use the _o variants of
+ * this method to assure a proper tree is passed to the commit.
+ *
+ * @param parent_count Number of parents for this commit
+ *
+ * @param parents Array of pointers to parent OIDs for this commit.
+ * Note that no validation is performed on these OIDs. Use the _o
+ * variants of this method to assure that are parents for the commit
+ * are proper objects.
+ *
* @return 0 on success; error code otherwise
+ * The created commit will be written to the Object Database and
+ * the given reference will be updated to point to it
*/
-GIT_EXTERN(int) git_commit_add_parent(git_commit *commit, git_commit *new_parent);
+GIT_EXTERN(int) git_commit_create(
+ git_oid *oid,
+ git_repository *repo,
+ const char *update_ref,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message,
+ const git_oid *tree_oid,
+ int parent_count,
+ const git_oid *parent_oids[]);
/**
- * Set the message of a commit
- * @param commit the commit object
- * @param message the new message
+ * Create a new commit in the repository using `git_object`
+ * instances as parameters.
+ *
+ * The `tree_oid` and `parent_oids` paremeters now take a instance
+ * of `git_tree` and `git_commit`, respectively.
+ *
+ * All other parameters remain the same
+ *
+ * @see git_commit_create
*/
-GIT_EXTERN(void) git_commit_set_message(git_commit *commit, const char *message);
+GIT_EXTERN(int) git_commit_create_o(
+ git_oid *oid,
+ git_repository *repo,
+ const char *update_ref,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message,
+ const git_tree *tree,
+ int parent_count,
+ const git_commit *parents[]);
/**
- * Set the committer of a commit
- * @param commit the commit object
- * @param author_sig signature of the committer
+ * Create a new commit in the repository using `git_object`
+ * instances and a variable argument list.
+ *
+ * The `tree_oid` paremeter now takes a instance
+ * of `const git_tree *`.
+ *
+ * The parents for the commit are specified as a variable
+ * list of pointers to `const git_commit *`. Note that this
+ * is a convenience method which may not be safe to export
+ * for certain languages or compilers
+ *
+ * All other parameters remain the same
+ *
+ * @see git_commit_create
*/
-GIT_EXTERN(void) git_commit_set_committer(git_commit *commit, const git_signature *committer_sig);
+GIT_EXTERN(int) git_commit_create_ov(
+ git_oid *oid,
+ git_repository *repo,
+ const char *update_ref,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message,
+ const git_tree *tree,
+ int parent_count,
+ ...);
-/**
- * Set the author of a commit
- * @param commit the commit object
- * @param author_sig signature of the author
- */
-GIT_EXTERN(void) git_commit_set_author(git_commit *commit, const git_signature *author_sig);
/**
- * Set the tree which is pointed to by a commit
- * @param commit the commit object
- * @param tree the new tree
+ * Create a new commit in the repository using
+ * a variable argument list.
+ *
+ * The parents for the commit are specified as a variable
+ * list of pointers to `const git_oid *`. Note that this
+ * is a convenience method which may not be safe to export
+ * for certain languages or compilers
+ *
+ * All other parameters remain the same
+ *
+ * @see git_commit_create
*/
-GIT_EXTERN(void) git_commit_set_tree(git_commit *commit, git_tree *tree);
+GIT_EXTERN(int) git_commit_create_v(
+ git_oid *oid,
+ git_repository *repo,
+ const char *update_ref,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message,
+ const git_oid *tree_oid,
+ int parent_count,
+ ...);
/** @} */
GIT_END_DECL
diff --git a/include/git2/common.h b/include/git2/common.h
index ec338db4e..7cb98b824 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -27,6 +27,7 @@
#include "thread-utils.h"
#include <time.h>
+#include <stdlib.h>
#ifdef __cplusplus
# define GIT_BEGIN_DECL extern "C" {
@@ -118,13 +119,13 @@
/** The object or config variable 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 */
+/** The object cannot be written 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 */
+/** Failed to acquire or release a file lock */
#define GIT_EFLOCKFAIL (GIT_ERROR - 11)
/** The Z library failed to inflate/deflate an object's data */
@@ -145,7 +146,7 @@
/** The specified symbolic reference is too deeply nested */
#define GIT_ETOONESTEDSYMREF (GIT_ERROR - 17)
-/** The pack-refs file is either corrupted of its format is not currently supported */
+/** The pack-refs file is either corrupted or its format is not currently supported */
#define GIT_EPACKEDREFSCORRUPTED (GIT_ERROR - 18)
/** The path is invalid */
@@ -157,7 +158,21 @@
/** The state of the reference is not valid */
#define GIT_EINVALIDREFSTATE (GIT_ERROR - 21)
+/** This feature has not been implemented yet */
+#define GIT_ENOTIMPLEMENTED (GIT_ERROR - 22)
+
+/** A reference with this name already exists */
+#define GIT_EEXISTS (GIT_ERROR - 23)
+
GIT_BEGIN_DECL
+
+typedef struct {
+ char **strings;
+ size_t count;
+} git_strarray;
+
+GIT_EXTERN(void) git_strarray_free(git_strarray *array);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/index.h b/include/git2/index.h
index 605740c10..599512f8a 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -91,8 +91,8 @@ 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 index the pointer for the new index
* @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);
@@ -132,7 +132,7 @@ GIT_EXTERN(int) git_index_read(git_index *index);
GIT_EXTERN(int) git_index_write(git_index *index);
/**
- * Find the first index of any entires which point to given
+ * Find the first index of any entries which point to given
* path in the Git index.
*
* @param index an existing index object
diff --git a/include/git2/object.h b/include/git2/object.h
index af0f014e3..16dde8e56 100644
--- a/include/git2/object.h
+++ b/include/git2/object.h
@@ -42,7 +42,8 @@ GIT_BEGIN_DECL
* Lookup a reference to one of the objects in a repostory.
*
* The generated reference is owned by the repository and
- * should not be freed by the user.
+ * should be closed with the `git_object_close` method
+ * instead of free'd manually.
*
* The 'type' parameter must match the type of the object
* in the odb; the method will fail otherwise.
@@ -58,54 +59,8 @@ GIT_BEGIN_DECL
GIT_EXTERN(int) git_object_lookup(git_object **object, git_repository *repo, const git_oid *id, git_otype type);
/**
- * 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_object_new(git_object **object, git_repository *repo, git_otype type);
-
-
-/**
- * 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
*/
@@ -131,20 +86,14 @@ GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj);
* Close an open object
*
* This method instructs the library to close an existing
- * object; note that git_objects are owned by the repository
- * and are reference counted, so the object may or may not be
- * freed after this library call, depending on whether any other
- * objects still depend on it.
+ * object; note that git_objects are owned and cached by the repository
+ * so the object may or may not be freed after this library call,
+ * depending on how agressive is the caching mechanism used
+ * by the repository.
*
* IMPORTANT:
- * It is *not* necessary to call this method when you stop using
- * an object, since all object memory is automatically reclaimed
- * by the repository when it is freed.
- *
- * Forgetting to call `git_object_close` does not cause memory
- * leaks, but it's is recommended to close as soon as possible
- * the biggest objects (e.g. blobs) to prevent wasting memory
- * space.
+ * It *is* necessary to call this method when you stop using
+ * an object. Failure to do so will cause a memory leak.
*
* @param object the object to close
*/
diff --git a/include/git2/odb.h b/include/git2/odb.h
index 0d285897c..1d351beea 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -28,6 +28,7 @@
#include "common.h"
#include "types.h"
#include "oid.h"
+#include "odb_backend.h"
/**
* @file git2/odb.h
@@ -100,61 +101,49 @@ GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, in
/**
* 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.
+ * This method queries all avaiable ODB backends
+ * trying to read the given OID.
*
- * @param out object descriptor to populate upon reading.
+ * The returned object is reference counted and
+ * internally cached, so it should be closed
+ * by the user once it's no longer in use.
+ *
+ * @param out pointer where to store the read object
* @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);
+GIT_EXTERN(int) git_odb_read(git_odb_object **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 header includes the length and the type of an object.
*
- * The raw object pointed by 'out' doesn't need to be manually
- * closed with git_rawobj_close().
+ * Note that most backends do not support reading only the header
+ * of an object, so the whole object will be read and then the
+ * header will be returned.
*
- * @param out object descriptor to populate upon reading.
+ * @param len_p pointer where to store the length
+ * @param type_p pointer where to store the type
* @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);
+GIT_EXTERN(int) git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id);
/**
* Determine if the given object can be found in the object database.
@@ -162,39 +151,151 @@ GIT_EXTERN(int) git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj);
* @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
+ * - 1, if the object was found
+ * - 0, otherwise
*/
GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
+/**
+ * Write an object directly into the ODB
+ *
+ * This method writes a full object straight into the ODB.
+ * For most cases, it is preferred to write objects through a write
+ * stream, which is both faster and less memory intensive, specially
+ * for big objects.
+ *
+ * This method is provided for compatibility with custom backends
+ * which are not able to support streaming writes
+ *
+ * @param oid pointer to store the OID result of the write
+ * @param odb object database where to store the object
+ * @param data buffer with the data to storr
+ * @param len size of the buffer
+ * @param type type of the data to store
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size_t len, git_otype type);
+/**
+ * Open a stream to write an object into the ODB
+ *
+ * The type and final length of the object must be specified
+ * when opening the stream.
+ *
+ * The returned stream will be of type `GIT_STREAM_WRONLY` and
+ * will have the following methods:
+ *
+ * - stream->write: write `n` bytes into the stream
+ * - stream->finalize_write: close the stream and store the object in
+ * the odb
+ * - stream->free: free the stream
+ *
+ * The streaming write won't be effective until `stream->finalize_write`
+ * is called and returns without an error
+ *
+ * The stream must always be free'd or will leak memory.
+ *
+ * @see git_odb_stream
+ *
+ * @param stream pointer where to store the stream
+ * @param db object database where the stream will write
+ * @param size final size of the object that will be written
+ * @param type type of the object that will be written
+ * @return 0 if the stream was created; error code otherwise
+ */
+GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_t size, git_otype type);
-
+/**
+ * Open a stream to read an object from the ODB
+ *
+ * Note that most backends do *not* support streaming reads
+ * because they store their objects as compressed/delta'ed blobs.
+ *
+ * It's recommended to use `git_odb_read` instead, which is
+ * assured to work on all backends.
+ *
+ * The returned stream will be of type `GIT_STREAM_RDONLY` and
+ * will have the following methods:
+ *
+ * - stream->read: read `n` bytes from the stream
+ * - stream->free: free the stream
+ *
+ * The stream must always be free'd or will leak memory.
+ *
+ * @see git_odb_stream
+ *
+ * @param stream pointer where to store the stream
+ * @param db object database where the stream will read from
+ * @param oid oid of the object the stream will read from
+ * @return 0 if the stream was created; error code otherwise
+ */
+GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oid);
/**
- * Determine the object-ID (sha1 hash) of the given git_rawobj.
+ * Determine the object-ID (sha1 hash) of a data buffer
*
- * 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.
+ * The resulting SHA-1 OID will the itentifier for the data
+ * buffer as if the data buffer it were to written to the ODB.
*
* @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.
+ * @param data data to hash
+ * @param len size of the data
+ * @param type of the data to hash
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type);
+
+/**
+ * Close an ODB object
+ *
+ * This method must always be called once a `git_odb_object` is no
+ * longer needed, otherwise memory will leak.
+ *
+ * @param object object to close
+ */
+GIT_EXTERN(void) git_odb_object_close(git_odb_object *object);
+
+/**
+ * Return the OID of an ODB object
+ *
+ * This is the OID from which the object was read from
+ *
+ * @param object the object
+ * @return a pointer to the OID
+ */
+GIT_EXTERN(const git_oid *) git_odb_object_id(git_odb_object *object);
+
+/**
+ * Return the data of an ODB object
+ *
+ * This is the uncompressed, raw data as read from the ODB,
+ * without the leading header.
+ *
+ * This pointer is owned by the object and shall not be free'd.
+ *
+ * @param object the object
+ * @return a pointer to the data
*/
-GIT_EXTERN(int) git_rawobj_hash(git_oid *id, git_rawobj *obj);
+GIT_EXTERN(const void *) git_odb_object_data(git_odb_object *object);
/**
- * Release all memory used by the obj structure.
+ * Return the size of an ODB object
*
- * As a result of this call, obj->data will be set to NULL.
+ * This is the real size of the `data` buffer, not the
+ * actual size of the object.
*
- * If obj->data is already NULL, nothing happens.
+ * @param object the object
+ * @return the size
+ */
+GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
+
+/**
+ * Return the type of an ODB object
*
- * @param obj object descriptor to free.
+ * @param object the object
+ * @return the type
*/
-GIT_EXTERN(void) git_rawobj_close(git_rawobj *obj);
+GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
/** @} */
GIT_END_DECL
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index 0e817eb37..ba41f726c 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -28,7 +28,6 @@
#include "common.h"
#include "types.h"
#include "oid.h"
-#include "odb.h"
/**
* @file git2/backend.h
@@ -39,24 +38,39 @@
*/
GIT_BEGIN_DECL
+struct git_odb_stream;
+
/** An instance for a custom backend */
struct git_odb_backend {
git_odb *odb;
int (* read)(
- git_rawobj *,
+ void **, size_t *, git_otype *,
struct git_odb_backend *,
const git_oid *);
int (* read_header)(
- git_rawobj *,
+ size_t *, git_otype *,
struct git_odb_backend *,
const git_oid *);
int (* write)(
- git_oid *id,
+ git_oid *,
+ struct git_odb_backend *,
+ const void *,
+ size_t,
+ git_otype);
+
+ int (* writestream)(
+ struct git_odb_stream **,
struct git_odb_backend *,
- git_rawobj *obj);
+ size_t,
+ git_otype);
+
+ int (* readstream)(
+ struct git_odb_stream **,
+ struct git_odb_backend *,
+ const git_oid *);
int (* exists)(
struct git_odb_backend *,
@@ -65,12 +79,28 @@ struct git_odb_backend {
void (* free)(struct git_odb_backend *);
};
+/** A stream to read/write from a backend */
+struct git_odb_stream {
+ struct git_odb_backend *backend;
+ int mode;
+
+ int (*read)(struct git_odb_stream *stream, char *buffer, size_t len);
+ int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len);
+ int (*finalize_write)(git_oid *oid_p, struct git_odb_stream *stream);
+ void (*free)(struct git_odb_stream *stream);
+};
+
+/** Streaming mode */
+typedef enum {
+ GIT_STREAM_RDONLY = (1 << 1),
+ GIT_STREAM_WRONLY = (1 << 2),
+ GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
+} git_odb_streammode;
+
+
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir);
-
-#ifdef GIT2_SQLITE_BACKEND
GIT_EXTERN(int) git_odb_backend_sqlite(git_odb_backend **backend_out, const char *sqlite_db);
-#endif
GIT_END_DECL
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 1702d7ee1..298c66d51 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -69,6 +69,27 @@ GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_reposito
GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target);
/**
+ * Create a new symbolic reference, overwriting an existing one with
+ * the same name, if it exists.
+ *
+ * If the new reference isn't a symbolic one, any pointers to the old
+ * reference become invalid.
+ *
+ * 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.
+ *
+ * @param ref_out Pointer to the newly created reference
+ * @param repo Repository where that reference will live
+ * @param name The name of the reference
+ * @param target The target of the reference
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_reference_create_symbolic_f(git_reference **ref_out, git_repository *repo, const char *name, const char *target);
+
+/**
* Create a new object id reference.
*
* The reference will be created in the repository and written
@@ -86,6 +107,27 @@ GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repos
GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id);
/**
+ * Create a new object id reference, overwriting an existing one with
+ * the same name, if it exists.
+ *
+ * If the new reference isn't an object id one, any pointers to the
+ * old reference become invalid.
+ *
+ * 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.
+ *
+ * @param ref_out Pointer to the newly created reference
+ * @param repo Repository where that reference will live
+ * @param name The name of the reference
+ * @param id The object id pointed to by the reference.
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_reference_create_oid_f(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id);
+
+/**
* Get the OID pointed to by a reference.
*
* Only available if the reference is direct (i.e. not symbolic)
@@ -190,6 +232,20 @@ GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id);
GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name);
/**
+ * Rename an existing reference, overwriting an existing one with the
+ * same name, if it exists.
+ *
+ * This method works for both direct and symbolic references.
+ * The new name will be checked for validity and may be
+ * modified into a normalized form.
+ *
+ * The refernece will be immediately renamed in-memory
+ * and on disk.
+ *
+ */
+GIT_EXTERN(int) git_reference_rename_f(git_reference *ref, const char *new_name);
+
+/**
* Delete an existing reference
*
* This method works for both direct and symbolic references.
@@ -218,6 +274,52 @@ GIT_EXTERN(int) git_reference_delete(git_reference *ref);
*/
GIT_EXTERN(int) git_reference_packall(git_repository *repo);
+/**
+ * Fill a list with all the references that can be found
+ * in a repository.
+ *
+ * The listed references may be filtered by type, or using
+ * a bitwise OR of several types. Use the magic value
+ * `GIT_REF_LISTALL` to obtain all references, including
+ * packed ones.
+ *
+ * The string array will be filled with the names of all
+ * references; these values are owned by the user and
+ * should be free'd manually when no longer needed, using
+ * `git_strarray_free`.
+ *
+ * @param array Pointer to a git_strarray structure where
+ * the reference names will be stored
+ * @param repo Repository where to find the refs
+ * @param list_flags Filtering flags for the reference
+ * listing.
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_reference_listall(git_strarray *array, git_repository *repo, unsigned int list_flags);
+
+
+/**
+ * List all the references in the repository, calling a custom
+ * callback for each one.
+ *
+ * The listed references may be filtered by type, or using
+ * a bitwise OR of several types. Use the magic value
+ * `GIT_REF_LISTALL` to obtain all references, including
+ * packed ones.
+ *
+ * The `callback` function will be called for each of the references
+ * in the repository, and will receive the name of the reference and
+ * the `payload` value passed to this method.
+ *
+ * @param repo Repository where to find the refs
+ * @param list_flags Filtering flags for the reference
+ * listing.
+ * @param callback Function which will be called for every listed ref
+ * @param payload Additional data to pass to the callback
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_reference_listcb(git_repository *repo, unsigned int list_flags, int (*callback)(const char *, void *), void *payload);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 5327f8c58..00c1f20d0 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -154,13 +154,17 @@ GIT_EXTERN(int) git_repository_index(git_index **index, git_repository *repo);
/**
* Free a previously allocated repository
+ *
+ * Note that after a repository is free'd, all the objects it has spawned
+ * will still exist until they are manually closed by the user
+ * with `git_object_close`, but accessing any of the attributes of
+ * an object without a backing repository will result in undefined
+ * behavior
+ *
* @param repo repository handle to close. If NULL nothing occurs.
*/
GIT_EXTERN(void) git_repository_free(git_repository *repo);
-
-GIT_EXTERN(void) git_repository_free__no_gc(git_repository *repo);
-
/**
* Creates a new Git repository in the given folder.
*
diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h
index 841110499..f3e0152d4 100644
--- a/include/git2/revwalk.h
+++ b/include/git2/revwalk.h
@@ -27,6 +27,7 @@
#include "common.h"
#include "types.h"
+#include "oid.h"
/**
* @file git2/revwalk.h
@@ -69,6 +70,17 @@ GIT_BEGIN_DECL
/**
* Allocate a new revision walker to iterate through a repo.
*
+ * This revision walker uses a custom memory pool and an internal
+ * commit cache, so it is relatively expensive to allocate.
+ *
+ * For maximum performance, this revision walker should be
+ * reused for different walks.
+ *
+ * This revision walker is *not* thread safe: it may only be
+ * used to walk a repository on a single thread; however,
+ * it is possible to have several revision walkers in
+ * several different threads walking the same repository.
+ *
* @param walker pointer to the new revision walker
* @param repo the repo to walk through
* @return 0 on success; error code otherwise
@@ -76,48 +88,87 @@ GIT_BEGIN_DECL
GIT_EXTERN(int) git_revwalk_new(git_revwalk **walker, git_repository *repo);
/**
- * Reset the walking machinery for reuse.
+ * Reset the revision walker for reuse.
+ *
+ * This will clear all the pushed and hidden commits, and
+ * leave the walker in a blank state (just like at
+ * creation) ready to receive new commit pushes and
+ * start a new walk.
+ *
+ * The revision walk is automatically reset when a walk
+ * is over.
+ *
* @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.
+ *
+ * The given OID must belong to a commit on the walked
+ * repository.
+ *
+ * The given commit will be used as one of the roots
+ * when starting the revision walk. At least one commit
+ * must be pushed the repository before a walk can
+ * be started.
*
* @param walker the walker being used for the traversal.
- * @param commit the commit to start from.
+ * @param oid the oid of the commit to start from.
+ * @return 0 on success; error code otherwise
*/
-GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, git_commit *commit);
+GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *oid);
+
/**
* Mark a commit (and its ancestors) uninteresting for the output.
+ *
+ * The given OID must belong to a commit on the walked
+ * repository.
+ *
+ * The resolved commit and all its parents will be hidden from the
+ * output on the revision walk.
+ *
* @param walker the walker being used for the traversal.
* @param commit the commit that will be ignored during the traversal
+ * @return 0 on success; error code otherwise
*/
-GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, git_commit *commit);
+GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *oid);
/**
- * Get the next commit from the revision traversal.
+ * Get the next commit from the revision walk.
+ *
+ * The initial call to this method is *not* blocking when
+ * iterating through a repo with a time-sorting mode.
*
- * @param commit Pointer where to store the next commit
+ * Iterating with Topological or inverted modes makes the initial
+ * call blocking to preprocess the commit list, but this block should be
+ * mostly unnoticeable on most repositories (topological preprocessing
+ * times at 0.3s on the git.git repo).
+ *
+ * The revision walker is reset when the walk is over.
+ *
+ * @param oid Pointer where to store the oid of the next commit
* @param walk the walker to pop the commit from.
* @return GIT_SUCCESS if the next commit was found;
* GIT_EREVWALKOVER if there are no commits left to iterate
*/
-GIT_EXTERN(int) git_revwalk_next(git_commit **commit, git_revwalk *walk);
+GIT_EXTERN(int) git_revwalk_next(git_oid *oid, 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
+ * @param sort_mode combination of GIT_SORT_XXX flags
*/
-GIT_EXTERN(int) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
+GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
/**
- * Free a revwalk previously allocated.
+ * Free a revision walker previously allocated.
+ *
* @param walk traversal handle to close. If NULL nothing occurs.
*/
GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
diff --git a/include/git2/signature.h b/include/git2/signature.h
index 96275aa07..40412a45f 100644
--- a/include/git2/signature.h
+++ b/include/git2/signature.h
@@ -45,9 +45,9 @@ GIT_BEGIN_DECL
* @email email of the person
* @time time when the action happened
* @offset timezone offset in minutes for the time
- * @return the new sig, NULl on out of memory
+ * @return the new sig, NULL on out of memory
*/
-GIT_EXTERN(git_signature *) git_signature_new(const char *name, const char *email, time_t time, int offset);
+GIT_EXTERN(git_signature *) git_signature_new(const char *name, const char *email, git_time_t time, int offset);
/**
* Create a copy of an existing signature.
diff --git a/include/git2/tag.h b/include/git2/tag.h
index 2ca25c8a0..ee92cd5c2 100644
--- a/include/git2/tag.h
+++ b/include/git2/tag.h
@@ -41,8 +41,6 @@ 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.
@@ -55,23 +53,26 @@ GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oi
}
/**
- * Create a new in-memory git_tag.
+ * Close an open tag
*
- * The tag object must be manually filled using
- * setter methods before it can be written to its
- * repository.
+ * This is a wrapper around git_object_close()
*
- * @param tag pointer to the new tag
- * @param repo The repository where the object will reside
- * @return 0 on success; error code otherwise
+ * IMPORTANT:
+ * It *is* necessary to call this method when you stop
+ * using a tag. Failure to do so will cause a memory leak.
+ *
+ * @param tag the tag to close
*/
-GIT_INLINE(int) git_tag_new(git_tag **tag, git_repository *repo)
+
+GIT_INLINE(void) git_tag_close(git_tag *tag)
{
- return git_object_new((git_object **)tag, repo, (git_otype)GIT_OBJ_TAG);
+ git_object_close((git_object *) tag);
}
+
/**
* Get the id of a tag.
+ *
* @param tag a previously loaded tag.
* @return object identity for the tag.
*/
@@ -79,13 +80,27 @@ GIT_EXTERN(const git_oid *) git_tag_id(git_tag *tag);
/**
* Get the tagged object of a tag
+ *
+ * This method performs a repository lookup for the
+ * given object and returns it
+ *
+ * @param target pointer where to store the target
+ * @param tag a previously loaded tag.
+ * @return 0 on success; error code otherwise
+ */
+GIT_EXTERN(int) git_tag_target(git_object **target, git_tag *t);
+
+/**
+ * Get the OID of the tagged object of a tag
+ *
* @param tag a previously loaded tag.
- * @return reference to a repository object
+ * @return pointer to the OID
*/
-GIT_EXTERN(const git_object *) git_tag_target(git_tag *t);
+GIT_EXTERN(const git_oid *) git_tag_target_oid(git_tag *t);
/**
* Get the type of a tag's tagged object
+ *
* @param tag a previously loaded tag.
* @return type of the tagged object
*/
@@ -93,6 +108,7 @@ 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
*/
@@ -100,6 +116,7 @@ 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
*/
@@ -107,38 +124,69 @@ GIT_EXTERN(const git_signature *) 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
+ * Create a new tag in the repository from an OID
+ *
+ * @param oid Pointer where to store the OID of the
+ * newly created tag
+ *
+ * @param repo Repository where to store the tag
+ *
+ * @param tag_name Name for the tag; this name is validated
+ * for consistency
+ *
+ * @param target OID to which this tag points; note that no
+ * validation is done on this OID. Use the _o version of this
+ * method to assure a proper object is being tagged
+ *
+ * @param target_type Type of the tagged OID; note that no
+ * validation is performed here either
+ *
+ * @param tagger Signature of the tagger for this tag, and
+ * of the tagging time
+ *
+ * @param message Full message for this tag
+ *
+ * @return 0 on success; error code otherwise.
+ * A tag object is written to the ODB, and a proper reference
+ * is written in the /refs/tags folder, pointing to it
*/
-GIT_EXTERN(void) git_tag_set_name(git_tag *tag, const char *name);
+GIT_EXTERN(int) git_tag_create(
+ git_oid *oid,
+ git_repository *repo,
+ const char *tag_name,
+ const git_oid *target,
+ git_otype target_type,
+ const git_signature *tagger,
+ const char *message);
-/**
- * Set the tagger of a tag
- * @param tag The tag to modify
- * @param tagger_sig signature of the tagging action
- */
-GIT_EXTERN(void) git_tag_set_tagger(git_tag *tag, const git_signature *tagger_sig);
/**
- * Set the message of a tag
- * @param tag The tag to modify
- * @param message the new tagger for the tag
+ * Create a new tag in the repository from an existing
+ * `git_object` instance
+ *
+ * This method replaces the `target` and `target_type`
+ * paremeters of `git_tag_create` by a single instance
+ * of a `const git_object *`, which is assured to be
+ * a proper object in the ODB and hence will create
+ * a valid tag
+ *
+ * @see git_tag_create
*/
-GIT_EXTERN(void) git_tag_set_message(git_tag *tag, const char *message);
+GIT_EXTERN(int) git_tag_create_o(
+ git_oid *oid,
+ git_repository *repo,
+ const char *tag_name,
+ const git_object *target,
+ const git_signature *tagger,
+ const char *message);
/** @} */
GIT_END_DECL
diff --git a/include/git2/thread-utils.h b/include/git2/thread-utils.h
index c45a76e95..fb8644b93 100644
--- a/include/git2/thread-utils.h
+++ b/include/git2/thread-utils.h
@@ -32,7 +32,6 @@
*/
#define GIT_HAS_TLS 1
-#define GIT_HAS_PTHREAD 1
#if defined(__APPLE__) && defined(__MACH__)
# undef GIT_TLS
@@ -47,7 +46,6 @@
#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
@@ -56,11 +54,9 @@
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
@@ -71,10 +67,4 @@
# 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/include/git2/tree.h b/include/git2/tree.h
index 3085b3fd6..164aec9e2 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -41,8 +41,6 @@ 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.
@@ -55,31 +53,34 @@ GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git
}
/**
- * Create a new in-memory git_tree.
+ * Close an open tree
*
- * The tree object must be manually filled using
- * setter methods before it can be written to its
- * repository.
+ * This is a wrapper around git_object_close()
*
- * @param tree pointer to the new tree
- * @param repo The repository where the object will reside
- * @return 0 on success; error code otherwise
+ * IMPORTANT:
+ * It *is* necessary to call this method when you stop
+ * using a tree. Failure to do so will cause a memory leak.
+ *
+ * @param tree the tree to close
*/
-GIT_INLINE(int) git_tree_new(git_tree **tree, git_repository *repo)
+
+GIT_INLINE(void) git_tree_close(git_tree *tree)
{
- return git_object_new((git_object **)tree, repo, GIT_OBJ_TREE);
+ git_object_close((git_object *) tree);
}
+
/**
* 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
*/
@@ -87,6 +88,7 @@ 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
@@ -95,6 +97,7 @@ GIT_EXTERN(git_tree_entry *) git_tree_entry_byname(git_tree *tree, const char *f
/**
* 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
@@ -103,6 +106,7 @@ 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
*/
@@ -110,6 +114,7 @@ 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
*/
@@ -117,6 +122,7 @@ 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
*/
@@ -126,97 +132,11 @@ 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 repo repository where to lookup the pointed 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 and return the new entry.
- *
- * This will mark the tree as modified; the new entry will
- * be written back to disk on the next git_object_write()
- *
- * @param entry_out Pointer to the entry that just got
- * created. May be NULL if you are not interested on
- * getting the new entry
- * @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_entry **entry_out, 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);
-
-/**
- * Clear all the entries in a tree.
- *
- * 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 object whose entries are to be sorted
- */
-GIT_EXTERN(void) git_tree_clear_entries(git_tree *tree);
-
-/**
- * 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
- * @return 0 if the attributes were properly set; error code otherwise
- */
-GIT_EXTERN(int) git_tree_entry_set_attributes(git_tree_entry *entry, unsigned int attr);
+GIT_EXTERN(int) git_tree_entry_2object(git_object **object_out, git_repository *repo, git_tree_entry *entry);
/** @} */
GIT_END_DECL
diff --git a/include/git2/types.h b/include/git2/types.h
index aa53909d2..cb5adcc00 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -52,12 +52,12 @@ GIT_BEGIN_DECL
#if defined(_MSC_VER)
typedef __int64 git_off_t;
-typedef __time64_t git_time_t;
+typedef __time64_t git_time_t;
#elif defined(__MINGW32__)
typedef off64_t git_off_t;
-typedef time_t git_time_t;
+typedef __time64_t git_time_t;
#else /* POSIX */
@@ -66,12 +66,11 @@ typedef time_t git_time_t;
* before us (directly or indirectly), they'll get 32 bit off_t in their client
* app, even though /we/ define _FILE_OFFSET_BITS=64.
*/
-typedef long long git_off_t;
-typedef time_t git_time_t;
+typedef int64_t git_off_t;
+typedef int64_t git_time_t;
#endif
-
/** Basic type (loose or packed) of any Git object. */
typedef enum {
GIT_OBJ_ANY = -2, /**< Object can be any of the following */
@@ -92,6 +91,12 @@ typedef struct git_odb git_odb;
/** A custom backend in an ODB */
typedef struct git_odb_backend git_odb_backend;
+/** An object read from the ODB */
+typedef struct git_odb_object git_odb_object;
+
+/** A stream to read/write from the ODB */
+typedef struct git_odb_stream git_odb_stream;
+
/**
* Representation of an existing git repository,
* including all its object contents
@@ -130,7 +135,7 @@ typedef struct git_cvar git_cvar;
/** Time in a signature */
typedef struct git_time {
- time_t time; /** time in seconds from epoch */
+ git_time_t time; /** time in seconds from epoch */
int offset; /** timezone offset, in minutes */
} git_time;
@@ -151,6 +156,7 @@ typedef enum {
GIT_REF_SYMBOLIC = 2, /** A reference which points at another reference */
GIT_REF_PACKED = 4,
GIT_REF_HAS_PEEL = 8,
+ GIT_REF_LISTALL = GIT_REF_OID|GIT_REF_SYMBOLIC|GIT_REF_PACKED,
} git_rtype;
/** @} */