diff options
Diffstat (limited to 'include/git2')
-rw-r--r-- | include/git2/blob.h | 67 | ||||
-rw-r--r-- | include/git2/commit.h | 159 | ||||
-rw-r--r-- | include/git2/common.h | 3 | ||||
-rw-r--r-- | include/git2/object.h | 59 | ||||
-rw-r--r-- | include/git2/odb.h | 131 | ||||
-rw-r--r-- | include/git2/odb_backend.h | 40 | ||||
-rw-r--r-- | include/git2/tag.h | 99 | ||||
-rw-r--r-- | include/git2/tree.h | 116 | ||||
-rw-r--r-- | include/git2/types.h | 7 |
9 files changed, 338 insertions, 343 deletions
diff --git a/include/git2/blob.h b/include/git2/blob.h index 2b7154fb5..3cd1467bf 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,49 +53,12 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git } /** - * 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_INLINE(int) git_blob_new(git_blob **blob, git_repository *repo) -{ - return git_object_new((git_object **)blob, repo, GIT_OBJ_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. * * 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 +75,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 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 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 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 1556e52b1..ba18a5b39 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,8 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con } /** - * 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_INLINE(int) git_commit_new(git_commit **commit, git_repository *repo) -{ - return git_object_new((git_object **)commit, repo, GIT_OBJ_COMMIT); -} - -/** * Get the id of a commit. + * * @param commit a previously loaded commit. * @return object identity for the commit. */ @@ -80,6 +63,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 +71,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,6 +79,7 @@ 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 */ @@ -101,6 +87,7 @@ GIT_EXTERN(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 +95,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 +103,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,6 +111,7 @@ 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 0 on success; error code otherwise @@ -146,42 +136,129 @@ GIT_EXTERN(unsigned int) git_commit_parentcount(git_commit *commit); */ 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 - * @param 0 on success; error code otherwise + * 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(int) 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 f9045210c..7cfb8982e 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -158,6 +158,9 @@ /** 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) + GIT_BEGIN_DECL typedef struct { diff --git a/include/git2/object.h b/include/git2/object.h index 748386f69..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 */ @@ -137,14 +92,8 @@ GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj); * 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..8926b446c 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. + * + * 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 object descriptor to populate upon reading. + * @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,89 @@ 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); +/** + * 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 + * @para 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_rawobj_hash(git_oid *id, git_rawobj *obj); +GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type); /** - * Release all memory used by the obj structure. - * - * As a result of this call, obj->data will be set to NULL. + * Close an ODB object * - * If obj->data is already NULL, nothing happens. + * This method must always be called once a `git_odb_object` is no + * longer needed, otherwise memory will leak. * - * @param obj object descriptor to free. + * @param object object to close */ -GIT_EXTERN(void) git_rawobj_close(git_rawobj *obj); +GIT_EXTERN(void) git_odb_object_close(git_odb_object *object); /** @} */ GIT_END_DECL diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h index 0e817eb37..3875ec7f6 100644 --- a/include/git2/odb_backend.h +++ b/include/git2/odb_backend.h @@ -39,24 +39,32 @@ */ 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, + int (* writestream)( + struct git_odb_stream **, + struct git_odb_backend *, + size_t, + git_otype); + + int (* readstream)( + struct git_odb_stream **, struct git_odb_backend *, - git_rawobj *obj); + const git_oid *); int (* exists)( struct git_odb_backend *, @@ -65,12 +73,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/tag.h b/include/git2/tag.h index f1669eb90..c343f6bf4 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,8 @@ GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oi } /** - * 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_INLINE(int) git_tag_new(git_tag **tag, git_repository *repo) -{ - return git_object_new((git_object **)tag, repo, (git_otype)GIT_OBJ_TAG); -} - -/** * Get the id of a tag. + * * @param tag a previously loaded tag. * @return object identity for the tag. */ @@ -79,6 +62,10 @@ 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 @@ -87,6 +74,7 @@ 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 pointer to the OID */ @@ -94,6 +82,7 @@ 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 */ @@ -101,6 +90,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 */ @@ -108,6 +98,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 */ @@ -115,39 +106,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(int) 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 - * @return 0 on success; error code otherwise - */ -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/tree.h b/include/git2/tree.h index 3085b3fd6..ec2b51646 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,16 @@ GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git } /** - * 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_INLINE(int) git_tree_new(git_tree **tree, git_repository *repo) -{ - return git_object_new((git_object **)tree, repo, GIT_OBJ_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 +70,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 +79,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 +88,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 +96,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 +104,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 +114,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 b5a8d7b2d..64f7fc72e 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -71,7 +71,6 @@ typedef time_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 |