diff options
author | Russell Belfer <rb@github.com> | 2014-05-12 14:38:39 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-05-15 14:11:19 -0700 |
commit | 575f107704255254f52d197240d55f2030af0454 (patch) | |
tree | af5149788297f3e9ec17992b342a3005eab36e31 /include/git2/object.h | |
parent | 88b1b36dfcc6b406f2b6f21e0e042071984b3b90 (diff) | |
download | libgit2-rb/object-parse-flexibility.tar.gz |
Add lax parsing for commit and tag objectsrb/object-parse-flexibility
This changes the behavior of object parsing for commits and tags
so that even when bad data is found inside the object, we will
continue to try to parse as much of the object as we can. The
existing functions (`git_object_lookup` for example) will still
delete the partially parsed object before returning an error, but
this also adds a new function `git_object_lookup_lax` that will
still return the error, but will also return the object with the
partial data (if we got far enough along in the parsing process to
even create the base object).
Diffstat (limited to 'include/git2/object.h')
-rw-r--r-- | include/git2/object.h | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/include/git2/object.h b/include/git2/object.h index 9b13d824e..cd67711e8 100644 --- a/include/git2/object.h +++ b/include/git2/object.h @@ -33,17 +33,18 @@ GIT_BEGIN_DECL * 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 out Pointer in which to store the looked-up object (must be + * freed by the caller when done) * @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 0 or an error code */ GIT_EXTERN(int) git_object_lookup( - git_object **object, - git_repository *repo, - const git_oid *id, - git_otype type); + git_object **out, + git_repository *repo, + const git_oid *id, + git_otype type); /** * Lookup a reference to one of the objects in a repository, @@ -65,7 +66,8 @@ GIT_EXTERN(int) git_object_lookup( * The special value 'GIT_OBJ_ANY' may be passed to let * the method guess the object's type. * - * @param object_out pointer where to store the looked-up object + * @param out Pointer in which to store the looked-up object (must be + * freed by the caller when done) * @param repo the repository to look up the object * @param id a short identifier for the object * @param len the length of the short identifier @@ -73,28 +75,56 @@ GIT_EXTERN(int) git_object_lookup( * @return 0 or an error code */ GIT_EXTERN(int) git_object_lookup_prefix( - git_object **object_out, - git_repository *repo, - const git_oid *id, - size_t len, - git_otype type); + git_object **out, + git_repository *repo, + const git_oid *id, + size_t len, + git_otype type); /** * Lookup an object that represents a tree entry. * - * @param out buffer that receives a pointer to the object (which must be freed - * by the caller) + * @param out Pointer in which to store the looked-up object (must be + * freed by the caller when done) * @param treeish root object that can be peeled to a tree * @param path relative path from the root object to the desired object * @param type type of object desired * @return 0 on success, or an error code */ GIT_EXTERN(int) git_object_lookup_bypath( - git_object **out, - const git_object *treeish, - const char *path, - git_otype type); + git_object **out, + const git_object *treeish, + const char *path, + git_otype type); + +/** + * Look up object by partial or full OID and type, trying to return the + * object even if a parse error is encountered. + * + * Unlike other APIs to look up objects, this tries to return a + * `git_object` even if the data is not well-formatted, so long as the + * basic object type can still be determined from the raw data. + * + * If the object does not parse correctly, this will still return an error + * code, but it will also set the `out` parameter to an object with as + * much data filled in as possible. The resulting object may return NULL + * for properties that should not be NULL or other strange things. + * + * @param out Pointer in which to store the looked-up object (must be + * freed by the caller when done) + * @param repo the repository to look up the object + * @param id a short identifier for the object + * @param len the length of the short identifier + * @param type the type of the object + * @return 0 or an error code + */ +GIT_EXTERN(int) git_object_lookup_lax( + git_object **out, + git_repository *repo, + const git_oid *id, + size_t len, + git_otype type); /** * Get the id (SHA1) of a repository object @@ -169,12 +199,13 @@ GIT_EXTERN(void) git_object_free(git_object *object); GIT_EXTERN(const char *) git_object_type2string(git_otype type); /** - * Convert a string object type representation to it's git_otype. + * Convert a string object type representation to its git_otype. * - * @param str the string to convert. - * @return the corresponding git_otype. + * @param str The string to convert. + * @param len Length of str (or 0 for unspecified but NUL-terminated input) + * @return The corresponding `git_otype` of `GIT_OBJ_BAD` if no match. */ -GIT_EXTERN(git_otype) git_object_string2type(const char *str); +GIT_EXTERN(git_otype) git_object_string2type(const char *str, size_t len); /** * Determine if the given git_otype is a valid loose object type. |