diff options
author | Marc Pegon <pegon.marc@gmail.com> | 2011-05-27 22:46:41 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-06-01 23:40:41 +0200 |
commit | dd453c4dbf9a1fa38530b1f51e079852736b8f66 (patch) | |
tree | 19a16a4248757e21b700e27231fb334fe468861a /include/git2 | |
parent | 53c0bd81a2915d6f82ef2f9c0703770783a3dc89 (diff) | |
download | libgit2-dd453c4dbf9a1fa38530b1f51e079852736b8f66.tar.gz |
Added git.git sha1 lookup method to replace simple binary search in pack backend.
Implemented find_unique_short_oid for pack backend, based on git sha1 lookup method;
finding an object given its full oid is just a particular case of searching
the unique object matching an oid prefix (short oid).
Added git_odb_read_unique_short_oid, which iterates over all the backends to
find and read the unique object matching the given oid prefix.
Added a git_object_lookup_short_oid method to find the unique object in
the repository matching a given oid prefix : it generalizes git_object_lookup
which now does nothing but calls git_object_lookup_short_oid.
Diffstat (limited to 'include/git2')
-rw-r--r-- | include/git2/object.h | 30 | ||||
-rw-r--r-- | include/git2/odb.h | 32 |
2 files changed, 61 insertions, 1 deletions
diff --git a/include/git2/object.h b/include/git2/object.h index 7fca1c988..4cb6af0ad 100644 --- a/include/git2/object.h +++ b/include/git2/object.h @@ -59,6 +59,36 @@ GIT_BEGIN_DECL GIT_EXTERN(int) git_object_lookup(git_object **object, git_repository *repo, const git_oid *id, git_otype type); /** + * Lookup a reference to one of the objects in a repostory, + * given a prefix of its identifier (short id). + * + * The object obtained will be so that its identifier + * matches the first 'len' hexadecimal characters + * (packets of 4 bits) of the given 'id'. + * 'len' must be long enough to identify a unique + * object matching the prefix; otherwise the method will + * fail. + * + * The generated reference is owned by the repository and + * 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. + * The special value 'GIT_OBJ_ANY' may be passed to let + * the method guess the object's type. + * + * @param object pointer to the looked-up object + * @param repo the repository to look up the object + * @param id a short identifier for the object + * @param len the length of the short identifier + * @param type the type of the object + * @return a reference to the object + */ +GIT_EXTERN(int) git_object_lookup_short_oid(git_object **object_out, git_repository *repo, + const git_oid *id, unsigned int len, git_otype type); + +/** * Get the id (SHA1) of a repository object * * @param obj the repository object diff --git a/include/git2/odb.h b/include/git2/odb.h index 1d351beea..483934ad3 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -109,7 +109,7 @@ GIT_EXTERN(void) git_odb_close(git_odb *db); /** * Read an object from the database. * - * This method queries all avaiable ODB backends + * This method queries all available ODB backends * trying to read the given OID. * * The returned object is reference counted and @@ -126,6 +126,36 @@ GIT_EXTERN(void) git_odb_close(git_odb *db); GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id); /** + * Read an object from the database, given a prefix + * of its identifier. + * + * This method queries all available ODB backends + * trying to match the 'len' first hexadecimal + * characters of the 'short_id'. + * The remaining bits (GIT_OID_HEXSZ-len)*4 bits of + * 'short_id' must be 0s. + * The prefix must be long enough to identify + * a unique object in all the backends; the + * method will fail otherwise. + * + * 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_oid the oid of the unique object matching + * the short id + * @param out pointer where to store the read object + * @param db database to search for the object in. + * @param short_id a prefix of the id of the object to read. + * @param len the length of the prefix + * @return + * - GIT_SUCCESS if the object was read; + * - GIT_ENOTFOUND if the object is not in the database. + * - GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix) + */ +GIT_EXTERN(int) git_odb_read_unique_short_oid(git_oid *out_oid, git_odb_object **out, git_odb *db, const git_oid *short_id, unsigned int len); + +/** * Read the header of an object from the database, without * reading its full contents. * |